Skip to content

Commit

Permalink
Release 2.1.0 (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs authored Feb 24, 2024
2 parents f80417b + e38450e commit c8addb1
Show file tree
Hide file tree
Showing 33 changed files with 429 additions and 112 deletions.
2 changes: 1 addition & 1 deletion 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.0.0"
publishingVersion = "2.1.0"
}

group = "de.chojo.sadu"
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.core.configuration;

/**
* This interface represents the configuration for a database connection.
* It provides methods to retrieve the address, port, user, password, and database name.
*/
public interface DatabaseConfig {
/**
* Returns the address of the database server.
*
* @return the address of the database server
*/
String host();

/**
* Returns the port for the database connection.
*
* @return the port for the database connection
*/
String port();

/**
* Retrieves the username associated with the database connection.
*
* @return The username as a string.
*/
String user();

/**
* Returns the password for the database user.
*
* @return the password for the database user
*/
String password();

/**
* Returns the database for the database connection.
*
* @return The name of the database.
*/
String database();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* Copyright (C) RainbowDashLabs and Contributor
*/

package de.chojo.sadu.core.configuration;

public interface SchemaProvider {
String schema();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package de.chojo.sadu.core.jdbc;

import de.chojo.sadu.core.configuration.DatabaseConfig;
import org.jetbrains.annotations.ApiStatus;

import java.util.Optional;
Expand All @@ -27,6 +28,23 @@ public abstract class RemoteJdbcConfig<T extends RemoteJdbcConfig<?>> extends Jd
public RemoteJdbcConfig() {
}

/**
* Apply the given {@link DatabaseConfig} to configure the connection settings.
*
* @param config the database configuration
* @return the builder instance with the applied configuration
* @throws IllegalArgumentException when an invalid port or database name is provided
* @throws IllegalArgumentException when the host, port, user, password, or database are empty or null
*/
public T withConfig(DatabaseConfig config) {
host(config.host())
.port(config.port())
.user(config.user())
.password(config.password())
.database(config.database());
return self();
}

/**
* Sets the host explicit to local host.
* <p>
Expand Down
1 change: 1 addition & 0 deletions sadu-core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
requires transitive org.slf4j;

exports de.chojo.sadu.core.base;
exports de.chojo.sadu.core.configuration;
exports de.chojo.sadu.core.conversion;
exports de.chojo.sadu.core.databases;
exports de.chojo.sadu.core.databases.exceptions;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* Copyright (C) RainbowDashLabs and Contributor
*/

package de.chojo.sadu.datasource.configuration;

import de.chojo.sadu.core.configuration.DatabaseConfig;
import de.chojo.sadu.core.configuration.SchemaProvider;

/**
* Record which provides basic data for a database connection with a schema
*/

public record SchemaDatabaseConfig(String host, String port, String user, String password, String database,
String schema) implements DatabaseConfig, SchemaProvider {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* Copyright (C) RainbowDashLabs and Contributor
*/

package de.chojo.sadu.datasource.configuration;

/**
* Record which provides basic data for a database connection
*/
public record SimpleDatabaseConfig(String host, String port, String user, String password,
String database) implements de.chojo.sadu.core.configuration.DatabaseConfig {
}
1 change: 1 addition & 0 deletions sadu-datasource/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
exports de.chojo.sadu.datasource.stage;
exports de.chojo.sadu.datasource;
exports de.chojo.sadu.datasource.exceptions;
exports de.chojo.sadu.datasource.configuration;
}
2 changes: 1 addition & 1 deletion sadu-examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ dependencies {
// database driver
compileOnly("org.xerial", "sqlite-jdbc", "3.45.1.0")
compileOnly("org.postgresql", "postgresql", "42.7.2")
compileOnly("org.mariadb.jdbc", "mariadb-java-client", "3.3.2")
compileOnly("org.mariadb.jdbc", "mariadb-java-client", "3.3.3")
compileOnly("mysql", "mysql-connector-java", "8.0.33")
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -78,4 +80,11 @@ public static Set<String> columnTypes(ResultSetMetaData meta) throws SQLExceptio
}
return columns;
}

public static List<Long> generatedKeys(Statement stmt) throws SQLException {
var keys = new ArrayList<Long>();
var generatedKeys = stmt.getGeneratedKeys();
while (generatedKeys.next()) keys.add(generatedKeys.getLong(1));
return keys;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

package de.chojo.sadu.postgresql.jdbc;

import de.chojo.sadu.core.configuration.DatabaseConfig;
import de.chojo.sadu.core.configuration.SchemaProvider;
import de.chojo.sadu.core.jdbc.RemoteJdbcConfig;

/**
Expand All @@ -21,6 +23,14 @@ public String driver() {
return "postgresql";
}

@Override
public PostgreSqlJdbc withConfig(DatabaseConfig config) {
if (config instanceof SchemaProvider s) {
currentSchema(s.schema());
}
return super.withConfig(config);
}

/**
* The connection timeout value, in milliseconds, or zero for no timeout.
* Default: 30 000.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

package de.chojo.sadu.queries.api.execution.writing;

import de.chojo.sadu.queries.api.results.writing.ManipulationBatchResult;
import de.chojo.sadu.queries.api.results.writing.insertion.InsertionBatchResult;
import de.chojo.sadu.queries.api.results.writing.insertion.InsertionResult;
import de.chojo.sadu.queries.api.results.writing.manipulation.ManipulationBatchResult;
import de.chojo.sadu.queries.api.results.writing.manipulation.ManipulationResult;

/**
* The CalledBatchQuery interface represents a batch query that can perform insert, update, and delete operations
Expand All @@ -16,22 +19,32 @@ public interface CalledBatchQuery {
/**
* Inserts the specified values into the table.
*
* @return The {@link ManipulationBatchResult} that represents the results of the insert operations.
* @return The {@link InsertionBatchResult} that represents the results of the insert operations.
*/
ManipulationBatchResult insert();
InsertionBatchResult<InsertionResult> insert();

/**
* Inserts the specified values into the table.
* <p>
* Additionally, generated keys will be retrieved.
*
* @return The {@link InsertionBatchResult} that represents the results of the insert operations.
*/
InsertionBatchResult<InsertionResult> insertAndGetKeys();


/**
* Executes update operations as part of a batch query.
* Returns the result of the update operation.
*
* @return The {@link ManipulationBatchResult} that represents the results of the update operations.
*/
ManipulationBatchResult update();
ManipulationBatchResult<ManipulationResult> update();

/**
* Deletes the selected items or records from the data source.
*
* @return The {@link ManipulationBatchResult} that represents the results of the delete operations.
*/
ManipulationBatchResult delete();
ManipulationBatchResult<ManipulationResult> delete();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import de.chojo.sadu.mapper.MapperConfig;
import de.chojo.sadu.mapper.rowmapper.RowMapping;
import de.chojo.sadu.queries.api.execution.reading.Reader;
import de.chojo.sadu.queries.api.results.writing.ManipulationResult;
import de.chojo.sadu.queries.api.results.writing.insertion.InsertionResult;
import de.chojo.sadu.queries.api.results.writing.manipulation.ManipulationResult;

/**
* Represents a query that can be executed as a singleton call.
Expand Down Expand Up @@ -48,9 +49,17 @@ public interface CalledSingletonQuery {
* Inserts a row into the database table represented by the initial symbol of the containing class,
* and returns the result of the manipulation operation.
*
* @return The result of the manipulation operation as a {@link ManipulationResult} object.
* @return The result of the manipulation operation as a {@link InsertionResult} object.
*/
InsertionResult insertAndGetKeys();

/**
* Inserts a row into the database table represented by the initial symbol of the containing class,
* and returns the result of the manipulation operation.
*
* @return The result of the manipulation operation as a {@link InsertionResult} object.
*/
ManipulationResult insert();
InsertionResult insert();

/**
* Updates the data in the database based on the provided query.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* Copyright (C) RainbowDashLabs and Contributor
*/

package de.chojo.sadu.queries.api.results.writing.insertion;

import de.chojo.sadu.queries.api.results.writing.manipulation.ManipulationBatchResult;

import java.util.List;

/**
* The InsertionBatchResult interface represents the result of a batch insertion operation.
* It extends the ManipulationBatchResult interface and adds the ability to retrieve the keys of the inserted rows.
*
* @param <T> the type of InsertionResult
*/
public interface InsertionBatchResult<T extends InsertionResult> extends ManipulationBatchResult<T>, InsertionResult {
/**
* Retrieves the keys of the inserted rows of all executed statements.
*
* @return a List of Long representing the keys of the inserted rows
*/
@Override
List<Long> keys();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* Copyright (C) RainbowDashLabs and Contributor
*/

package de.chojo.sadu.queries.api.results.writing.insertion;

import de.chojo.sadu.queries.api.results.writing.manipulation.ManipulationResult;

import java.util.List;

/**
* The InsertionResult interface represents the result of an insertion operation.
* It extends the ManipulationResult interface and adds the ability to retrieve the keys of the inserted rows.
*/
public interface InsertionResult extends ManipulationResult {
/**
* Retrieves the keys of the inserted rows.
*
* @return a List of Long representing the keys of the inserted rows
*/
List<Long> keys();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Defines the result of an insertion action.
*/
package de.chojo.sadu.queries.api.results.writing.insertion;
Loading

0 comments on commit c8addb1

Please sign in to comment.