Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs committed Aug 28, 2024
2 parents 8e3f37c + ea92110 commit 61a7692
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* Copyright (C) RainbowDashLabs and Contributor
*/

package de.chojo.sadu.queries.exception;

import de.chojo.sadu.mapper.wrapper.Row;
import org.jetbrains.annotations.Nullable;

import java.sql.ResultSet;

public final class Check {
public static void assertQueryResult(@Nullable Object object) {
if (object instanceof Row) {
throw new IllegalQueryReturnTypeException("Result is of type Row. Using a row mapper to map to a Row is forbidden. Rows are mutable and are no longer accessible after query execution.");
}
if (object instanceof ResultSet) {
throw new IllegalQueryReturnTypeException("Result is of type ResultSet. Using a row mapper to map to a ResultSet is forbidden. ResultSets are mutable and are no longer accessible after query execution.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* Copyright (C) RainbowDashLabs and Contributor
*/

package de.chojo.sadu.queries.exception;

public class IllegalQueryReturnTypeException extends RuntimeException{
public IllegalQueryReturnTypeException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import de.chojo.sadu.queries.api.query.AppendedQuery;
import de.chojo.sadu.queries.api.results.reading.Result;
import de.chojo.sadu.queries.call.CallImpl;
import de.chojo.sadu.queries.exception.Check;
import de.chojo.sadu.queries.query.AppendedQueryImpl;
import de.chojo.sadu.queries.query.QueryImpl;
import de.chojo.sadu.queries.query.TokenizedQuery;
Expand Down Expand Up @@ -70,7 +71,9 @@ private SingleResult<V> mapOne() {
((CallImpl) call()).apply(sql(), stmt);
var resultSet = stmt.executeQuery();
if (resultSet.next()) {
return new SingleResult<>(this, mapper(resultSet).map(new Row(resultSet, mapperConfig())));
V mapped = mapper(resultSet).map(new Row(resultSet, mapperConfig()));
Check.assertQueryResult(mapped);
return new SingleResult<>(this, mapped);
}
}
return new SingleResult<>(this, null);
Expand All @@ -85,7 +88,11 @@ private MultiResult<List<V>> mapAll() {
((CallImpl) call()).apply(sql(), stmt);
var resultSet = stmt.executeQuery();
var row = new Row(resultSet, mapperConfig());
while (resultSet.next()) result.add(mapper(resultSet).map(row));
while (resultSet.next()) {
V mapped = mapper(resultSet).map(row);
Check.assertQueryResult(mapped);
result.add(mapped);
}
}
return new MultiResult<>(this, result);
});
Expand Down

0 comments on commit 61a7692

Please sign in to comment.