Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.3.1 #224

Merged
merged 22 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e796ed3
Update dependency gradle to v8.10.1
renovate[bot] Sep 9, 2024
de4e155
Update dependency gradle to v8.10.2
renovate[bot] Sep 24, 2024
4e9ffa9
Update junit to v5.11.1
renovate[bot] Sep 25, 2024
f37c86e
Update dependency org.xerial:sqlite-jdbc to v3.47.0.0 (#219)
renovate[bot] Nov 11, 2024
3327717
Update dependency com.zaxxer:HikariCP to v6 (#217)
renovate[bot] Nov 11, 2024
f6ddf50
Update junit5 monorepo to v5.11.3 (#221)
renovate[bot] Nov 11, 2024
bd28bb0
Update junit to v5.11.3 (#222)
renovate[bot] Nov 11, 2024
ca8ade2
Update dependency gradle to v8.11 (#226)
renovate[bot] Nov 11, 2024
d599f78
Update dependency org.mariadb.jdbc:mariadb-java-client to v3.5.0 (#227)
renovate[bot] Nov 15, 2024
41f0d76
Update dependency com.mysql:mysql-connector-j to v9.1.0 (#225)
renovate[bot] Nov 15, 2024
d5a12e5
Update testcontainers-java monorepo to v1.20.3 (#223)
renovate[bot] Nov 15, 2024
4e76539
Remove ApiStatus annotation from UpdaterBuilder (#228)
Kaktushose Nov 15, 2024
c9402f8
Update dependency org.jetbrains:annotations to v26 (#229)
renovate[bot] Nov 15, 2024
c40aede
Update dependency gradle to v8.11.1 (#231)
renovate[bot] Nov 20, 2024
3adb393
Update dependency org.mariadb.jdbc:mariadb-java-client to v3.5.1 (#232)
renovate[bot] Nov 21, 2024
3e11f8a
Update testcontainers-java monorepo to v1.20.4 (#233)
renovate[bot] Nov 21, 2024
1764709
Update dependency com.zaxxer:HikariCP to v6.2.1 (#230)
renovate[bot] Nov 21, 2024
b0ccbea
Update plugin org.gradle.toolchains.foojay-resolver-convention to v0.…
renovate[bot] Dec 2, 2024
d2c2720
Feature: Ensure token format (#236)
rainbowdashlabs Dec 4, 2024
bdbb830
Feature: Improve error handling and assertions for parameters (#237)
rainbowdashlabs Dec 5, 2024
2689932
Update dependency org.xerial:sqlite-jdbc to v3.47.1.0 (#234)
renovate[bot] Dec 5, 2024
8dbd674
Update build.gradle.kts
rainbowdashlabs Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ plugins {

publishData {
useEldoNexusRepos(false)
publishingVersion = "2.3.0"
publishingVersion = "2.3.1"
}

group = "de.chojo.sadu"
Expand Down Expand Up @@ -122,8 +122,8 @@ allprojects {


dependencies {
testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.11.0")
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", "5.11.0")
testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.11.3")
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", "5.11.3")
testImplementation("org.mockito", "mockito-core", "5.+")
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion sadu-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ description = "SADU core module, containing common logic between modules."

dependencies {
api(libs.slf4j.api)
api("org.jetbrains", "annotations", "24.1.0")
api("org.jetbrains", "annotations", "26.0.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
package de.chojo.sadu.core.updater;

import de.chojo.sadu.core.jdbc.JdbcConfig;
import org.jetbrains.annotations.ApiStatus;

import javax.sql.DataSource;

@ApiStatus.Internal
public interface UpdaterBuilder<T extends JdbcConfig<?>, S extends UpdaterBuilder<T, ?>> {
/**
* Set the datasource that should be used
Expand Down
2 changes: 1 addition & 1 deletion sadu-datasource/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description = "SADU module to create a hikaricp datasource"

dependencies {
api("com.zaxxer", "HikariCP", "5.1.0")
api("com.zaxxer", "HikariCP", "6.2.1")
api(project(":sadu-core"))

testImplementation(project(":sadu-sqlite"))
Expand Down
4 changes: 2 additions & 2 deletions sadu-examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ dependencies {
compileOnly(project(":sadu-postgresql"))

// database driver
compileOnly("org.xerial", "sqlite-jdbc", "3.46.1.0")
compileOnly("org.xerial", "sqlite-jdbc", "3.47.1.0")
compileOnly("org.postgresql", "postgresql", "42.7.4")
compileOnly("org.mariadb.jdbc", "mariadb-java-client", "3.4.1")
compileOnly("org.mariadb.jdbc", "mariadb-java-client", "3.5.1")
compileOnly("mysql", "mysql-connector-java", "8.0.33")
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import de.chojo.sadu.queries.call.adapter.StandardAdapter;
import de.chojo.sadu.queries.calls.BatchCall;
import de.chojo.sadu.queries.calls.SingletonCall;
import de.chojo.sadu.queries.exception.Check;
import de.chojo.sadu.queries.parameter.IndexParameter;
import de.chojo.sadu.queries.parameter.TokenParameter;
import de.chojo.sadu.queries.query.TokenizedQuery;
Expand Down Expand Up @@ -44,7 +45,7 @@
* A call is a subelement of a {@link Calls}. It represents a single query call of any kind.
*/
public final class CallImpl implements Call {
private final List<BaseParameter> tokens = new ArrayList<>();
private final List<BaseParameter> parameter = new ArrayList<>();
private int index = 1;

public CallImpl() {
Expand All @@ -55,12 +56,12 @@ private int nextIndex() {
}

private Call addToken(String token, ThrowingBiConsumer<PreparedStatement, Integer, SQLException> apply) {
tokens.add(new TokenParameter(token, apply));
parameter.add(new TokenParameter(token, apply));
return this;
}

private Call addToken(ThrowingBiConsumer<PreparedStatement, Integer, SQLException> apply) {
tokens.add(new IndexParameter(nextIndex(), apply));
parameter.add(new IndexParameter(nextIndex(), apply));
return this;
}

Expand Down Expand Up @@ -350,9 +351,15 @@ public <T> Call bind(T value, Adapter<T> adapter) {
}

public void apply(TokenizedQuery query, PreparedStatement stmt) throws SQLException {
for (var token : tokens) {
token.apply(query, stmt);
int indexCount = 0;
var tokens = query.getNamedTokens();
for (var param : parameter) {
param.apply(query, stmt);
if (param instanceof IndexParameter) indexCount++;
if (param instanceof TokenParameter token) tokens.remove(token.token());
}
Check.assertIndexFilled(indexCount, query);
Check.missingToken(tokens, query);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
package de.chojo.sadu.queries.exception;

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

import java.sql.ResultSet;
import java.util.Set;

public final class Check {
public static void assertQueryResult(@Nullable Object object) {
Expand All @@ -20,4 +22,19 @@ public static void assertQueryResult(@Nullable Object object) {
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.");
}
}

public static void assertIndexRange(int index, TokenizedQuery query) {
if (query.indexSize() >= index) return;
throw new IllegalQueryParameterException("No parameter with index %s exists in query \"%s\". Only %s parameter(s) is/are defined".formatted(index, query.sql(), query.indexSize()));
}

public static void assertIndexFilled(int count, TokenizedQuery query) {
if (query.indexSize() == count) return;
throw new IllegalQueryParameterException("Missing index parameter. %s were given, but %s were set in query: \"%s\"".formatted(count, query.indexSize(), query.sql()));
}

public static void missingToken(Set<String> tokens, TokenizedQuery query) {
if (tokens.isEmpty()) return;
throw new IllegalQueryParameterException("The parameters %s are not bound in query: %s".formatted(String.join(", ", tokens), query.sql()));
}
}
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 IllegalQueryParameterException extends RuntimeQueryException{
public IllegalQueryParameterException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

package de.chojo.sadu.queries.exception;

public class IllegalQueryReturnTypeException extends RuntimeException{
public class IllegalQueryReturnTypeException extends RuntimeQueryException{
public IllegalQueryReturnTypeException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* Copyright (C) RainbowDashLabs and Contributor
*/

package de.chojo.sadu.queries.exception;

import de.chojo.sadu.queries.query.ParsedQueryImpl;

import java.io.Serial;
import java.sql.SQLException;

public class QueryException extends SQLException {

@Serial
private static final long serialVersionUID = 1;

/**
* Cause of the exception
*/
private final SQLException cause;

/**
* Creates a new exception.
*/
public QueryException(ParsedQueryImpl query, SQLException throwable) {
super("An error occurred: %s\nWhile executing query:\n%s".formatted(throwable.getMessage(), query.sql().sql().stripIndent()), throwable);
cause = throwable;
}

/**
* SQL state of the exception
*
* @return sql state
*/
public String getSQLState() {
return cause.getSQLState();
}

/**
* Error code of the exception
*
* @return error code
*/
public int getErrorCode() {
return cause.getErrorCode();
}
}
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 RuntimeQueryException extends RuntimeException{
public RuntimeQueryException(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.results.writing.manipulation.ManipulationResult;
import de.chojo.sadu.queries.call.CallImpl;
import de.chojo.sadu.queries.calls.BatchCall;
import de.chojo.sadu.queries.exception.QueryException;
import de.chojo.sadu.queries.query.ParsedQueryImpl;
import de.chojo.sadu.queries.query.QueryImpl;
import de.chojo.sadu.queries.results.writing.insertion.InsertionBatchResultImpl;
Expand Down Expand Up @@ -46,7 +47,7 @@ public InsertionBatchResult<InsertionResult> insertAndGetKeys() {
var changes = stmt.executeUpdate();
changed.add(new InsertionResultImpl(this, changes, Results.generatedKeys(stmt)));
} catch (SQLException ex) {
query().handleException(ex);
query().handleException(new QueryException(parsedQuery, ex));
}
}
return new InsertionBatchResultImpl(this, changed);
Expand All @@ -62,7 +63,7 @@ public InsertionBatchResult<InsertionResult> insert() {
((CallImpl) call).apply(parsedQuery.sql(), stmt);
changed.add(new InsertionResultImpl(this, stmt.executeUpdate(), Collections.emptyList()));
} catch (SQLException ex) {
query().handleException(ex);
query().handleException(new QueryException(parsedQuery, ex));
}
}
return new InsertionBatchResultImpl(this, changed);
Expand All @@ -79,7 +80,7 @@ public ManipulationBatchResult<ManipulationResult> update() {
((CallImpl) call).apply(parsedQuery.sql(), stmt);
changed.add(new ManipulationResultImpl(this, stmt.executeUpdate()));
} catch (SQLException ex) {
query().handleException(ex);
query().handleException(new QueryException(parsedQuery, ex));
}
}
return new ManipulationBatchResultImpl<>(this, changed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import de.chojo.sadu.queries.api.results.writing.manipulation.ManipulationResult;
import de.chojo.sadu.queries.call.CallImpl;
import de.chojo.sadu.queries.calls.SingletonCall;
import de.chojo.sadu.queries.exception.QueryException;
import de.chojo.sadu.queries.execution.reading.AutoMappedQuery;
import de.chojo.sadu.queries.execution.reading.MappedQuery;
import de.chojo.sadu.queries.query.ParsedQueryImpl;
Expand Down Expand Up @@ -62,7 +63,7 @@ public InsertionResult insert() {
((CallImpl) call.call()).apply(query.sql(), stmt);
changed = stmt.executeUpdate();
} catch (SQLException ex) {
query().handleException(ex);
query().handleException(new QueryException(query, ex));
}
return new InsertionResultImpl(this, changed, Collections.emptyList());
});
Expand All @@ -78,7 +79,7 @@ public InsertionResult insertAndGetKeys() {
changed = stmt.executeUpdate();
return new InsertionResultImpl(this, changed, Results.generatedKeys(stmt));
} catch (SQLException ex) {
query().handleException(ex);
query().handleException(new QueryException(query, ex));
}
return InsertionResultImpl.empty(this);
});
Expand All @@ -93,7 +94,7 @@ public ManipulationResult update() {
((CallImpl) call.call()).apply(query.sql(), stmt);
changed = stmt.executeUpdate();
} catch (SQLException ex) {
query().handleException(ex);
query().handleException(new QueryException(query, ex));
}
return new ManipulationResultImpl(this, changed);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import de.chojo.sadu.core.exceptions.ThrowingBiConsumer;
import de.chojo.sadu.queries.api.parameter.BaseParameter;
import de.chojo.sadu.queries.exception.Check;
import de.chojo.sadu.queries.query.TokenizedQuery;

import java.sql.PreparedStatement;
Expand All @@ -24,6 +25,7 @@ public IndexParameter(int index, ThrowingBiConsumer<PreparedStatement, Integer,

@Override
public void apply(TokenizedQuery query, PreparedStatement stmt) throws SQLException {
Check.assertIndexRange(index, query);
apply.accept(stmt, query.getIndexTokenIndex(index));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@

import de.chojo.sadu.core.exceptions.ThrowingBiConsumer;
import de.chojo.sadu.queries.api.parameter.BaseParameter;
import de.chojo.sadu.queries.exception.IllegalQueryParameterException;
import de.chojo.sadu.queries.query.TokenizedQuery;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import static de.chojo.sadu.queries.query.TokenizedQuery.ALLOWED_TOKEN_CHARACTER;
import static de.chojo.sadu.queries.query.TokenizedQuery.TOKEN_PATTERN;

public class TokenParameter implements BaseParameter {
private final String token;
Expand All @@ -23,12 +28,23 @@ public TokenParameter(String token, ThrowingBiConsumer<PreparedStatement, Intege
} else {
this.token = token;
}
if (!TOKEN_PATTERN.matcher(this.token).matches()) {
throw new IllegalArgumentException("Illegal token \"" + this.token.substring(1) + "\". Tokens may only contain characters which match the expression: \"" + ALLOWED_TOKEN_CHARACTER + "\"");
}
this.apply = apply;
}

public void apply(TokenizedQuery query, PreparedStatement stmt) throws SQLException {
for (var index : query.getNamedTokenIndex(token)) {
List<Integer> tokens = query.getNamedTokenIndex(token);
if (tokens.isEmpty()) {
throw new IllegalQueryParameterException("Parameter \"%s\" is bound, but not present in query: \"%s\"".formatted(token, query.sql()));
}
for (var index : tokens) {
apply.accept(stmt, index);
}
}

public String token() {
return token;
}
}
Loading
Loading