Skip to content

Commit

Permalink
More cleanup, release helper-sql 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lucko committed Jun 5, 2019
1 parent 99097bf commit 4143cf4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 47 deletions.
4 changes: 2 additions & 2 deletions helper-sql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<artifactId>helper-sql</artifactId>
<packaging>jar</packaging>
<version>1.2.0</version>
<version>1.3.0</version>

<name>helper-sql</name>
<description>Provides SQL datasources using HikariCP.</description>
Expand Down Expand Up @@ -167,7 +167,7 @@
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.3.0</version>
<version>2.4.1</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
Expand Down
20 changes: 11 additions & 9 deletions helper-sql/src/main/java/me/lucko/helper/sql/Sql.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import me.lucko.helper.sql.batch.BatchBuilder;
import me.lucko.helper.terminable.Terminable;

import org.intellij.lang.annotations.Language;

import be.bendem.sqlstreams.SqlStream;
import be.bendem.sqlstreams.util.SqlConsumer;
import be.bendem.sqlstreams.util.SqlFunction;
Expand Down Expand Up @@ -85,7 +87,7 @@ public interface Sql extends Terminable {
* @see #execute(String) to perform this action synchronously
*/
@Nonnull
default Promise<Void> executeAsync(@Nonnull String statement) {
default Promise<Void> executeAsync(@Language("MySQL") @Nonnull String statement) {
return Schedulers.async().run(() -> this.execute(statement));
}

Expand All @@ -97,7 +99,7 @@ default Promise<Void> executeAsync(@Nonnull String statement) {
* @param statement the statement to be executed
* @see #executeAsync(String) to perform the same action asynchronously
*/
default void execute(@Nonnull String statement) {
default void execute(@Language("MySQL") @Nonnull String statement) {
this.execute(statement, stmt -> {});
}

Expand All @@ -112,7 +114,7 @@ default void execute(@Nonnull String statement) {
* @see #executeAsync(String, SqlConsumer) to perform this action synchronously
*/
@Nonnull
default Promise<Void> executeAsync(@Nonnull String statement, @Nonnull SqlConsumer<PreparedStatement> preparer) {
default Promise<Void> executeAsync(@Language("MySQL") @Nonnull String statement, @Nonnull SqlConsumer<PreparedStatement> preparer) {
return Schedulers.async().run(() -> this.execute(statement, preparer));
}

Expand All @@ -125,7 +127,7 @@ default Promise<Void> executeAsync(@Nonnull String statement, @Nonnull SqlConsum
* @param preparer the preparation used for this statement
* @see #executeAsync(String, SqlConsumer) to perform this action asynchronously
*/
void execute(@Nonnull String statement, @Nonnull SqlConsumer<PreparedStatement> preparer);
void execute(@Language("MySQL") @Nonnull String statement, @Nonnull SqlConsumer<PreparedStatement> preparer);

/**
* Executes a database query with no preparation.
Expand All @@ -142,7 +144,7 @@ default Promise<Void> executeAsync(@Nonnull String statement, @Nonnull SqlConsum
* @return a Promise of an asynchronous database query
* @see #query(String, SqlFunction) to perform this query synchronously
*/
default <R> Promise<Optional<R>> queryAsync(@Nonnull String query, @Nonnull SqlFunction<ResultSet, R> handler) {
default <R> Promise<Optional<R>> queryAsync(@Language("MySQL") @Nonnull String query, @Nonnull SqlFunction<ResultSet, R> handler) {
return Schedulers.async().supply(() -> this.query(query, handler));
}

Expand All @@ -161,7 +163,7 @@ default <R> Promise<Optional<R>> queryAsync(@Nonnull String query, @Nonnull SqlF
* @return the results of the database query
* @see #queryAsync(String, SqlFunction) to perform this query asynchronously
*/
default <R> Optional<R> query(@Nonnull String query, @Nonnull SqlFunction<ResultSet, R> handler) {
default <R> Optional<R> query(@Language("MySQL") @Nonnull String query, @Nonnull SqlFunction<ResultSet, R> handler) {
return this.query(query, stmt -> {}, handler);
}

Expand All @@ -181,7 +183,7 @@ default <R> Optional<R> query(@Nonnull String query, @Nonnull SqlFunction<Result
* @return a Promise of an asynchronous database query
* @see #query(String, SqlFunction) to perform this query synchronously
*/
default <R> Promise<Optional<R>> queryAsync(@Nonnull String query, @Nonnull SqlConsumer<PreparedStatement> preparer, @Nonnull SqlFunction<ResultSet, R> handler) {
default <R> Promise<Optional<R>> queryAsync(@Language("MySQL") @Nonnull String query, @Nonnull SqlConsumer<PreparedStatement> preparer, @Nonnull SqlFunction<ResultSet, R> handler) {
return Schedulers.async().supply(() -> this.query(query, preparer, handler));
}
/**
Expand All @@ -200,7 +202,7 @@ default <R> Promise<Optional<R>> queryAsync(@Nonnull String query, @Nonnull SqlC
* @return the results of the database query
* @see #queryAsync(String, SqlFunction) to perform this query asynchronously
*/
<R> Optional<R> query(@Nonnull String query, @Nonnull SqlConsumer<PreparedStatement> preparer, @Nonnull SqlFunction<ResultSet, R> handler);
<R> Optional<R> query(@Language("MySQL") @Nonnull String query, @Nonnull SqlConsumer<PreparedStatement> preparer, @Nonnull SqlFunction<ResultSet, R> handler);

/**
* Executes a batched database execution.
Expand Down Expand Up @@ -241,5 +243,5 @@ default Promise<Void> executeBatchAsync(@Nonnull BatchBuilder builder) {
* @param statement the statement to prepare for batching.
* @return a BatchBuilder
*/
BatchBuilder batch(@Nonnull String statement);
BatchBuilder batch(@Language("MySQL") @Nonnull String statement);
}
36 changes: 3 additions & 33 deletions helper-sql/src/main/java/me/lucko/helper/sql/plugin/HelperSql.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import me.lucko.helper.Schedulers;
import me.lucko.helper.promise.Promise;
import me.lucko.helper.sql.DatabaseCredentials;
import me.lucko.helper.sql.Sql;
import me.lucko.helper.sql.batch.BatchBuilder;
Expand Down Expand Up @@ -68,8 +66,6 @@ public class HelperSql implements Sql {
private static final long CONNECTION_TIMEOUT = TimeUnit.SECONDS.toMillis(10); // 10 seconds
private static final long LEAK_DETECTION_THRESHOLD = TimeUnit.SECONDS.toMillis(10); // 10 seconds

private static final String LANGUAGE = "MySQL";

static {
PROPERTIES = new Properties();

Expand Down Expand Up @@ -127,22 +123,8 @@ public SqlStream stream() {
return this.stream;
}

@Nonnull
public Promise<Void> executeAsync(@Language(LANGUAGE) @Nonnull String statement) {
return Schedulers.async().run(() -> this.execute(statement));
}

public void execute(@Language(LANGUAGE) @Nonnull String statement) {
this.execute(statement, stmt -> {});
}

@Nonnull
public Promise<Void> executeAsync(@Language(LANGUAGE) @Nonnull String statement, @Nonnull SqlConsumer<PreparedStatement> preparer) {
return Schedulers.async().run(() -> this.execute(statement, preparer));
}

@Override
public void execute(@Language(LANGUAGE) @Nonnull String statement, @Nonnull SqlConsumer<PreparedStatement> preparer) {
public void execute(@Language("MySQL") @Nonnull String statement, @Nonnull SqlConsumer<PreparedStatement> preparer) {
try (Connection c = this.getConnection(); PreparedStatement s = c.prepareStatement(statement)) {
preparer.accept(s);
s.execute();
Expand All @@ -151,20 +133,8 @@ public void execute(@Language(LANGUAGE) @Nonnull String statement, @Nonnull SqlC
}
}

public <R> Promise<Optional<R>> queryAsync(@Language(LANGUAGE) @Nonnull String query, @Nonnull SqlFunction<ResultSet, R> handler) {
return Schedulers.async().supply(() -> this.query(query, handler));
}

public <R> Optional<R> query(@Language(LANGUAGE) @Nonnull String query, @Nonnull SqlFunction<ResultSet, R> handler) {
return this.query(query, stmt -> {}, handler);
}

public <R> Promise<Optional<R>> queryAsync(@Language(LANGUAGE) @Nonnull String query, @Nonnull SqlConsumer<PreparedStatement> preparer, @Nonnull SqlFunction<ResultSet, R> handler) {
return Schedulers.async().supply(() -> this.query(query, preparer, handler));
}

@Override
public <R> Optional<R> query(@Language(LANGUAGE) @Nonnull String query, @Nonnull SqlConsumer<PreparedStatement> preparer, @Nonnull SqlFunction<ResultSet, R> handler) {
public <R> Optional<R> query(@Language("MySQL") @Nonnull String query, @Nonnull SqlConsumer<PreparedStatement> preparer, @Nonnull SqlFunction<ResultSet, R> handler) {
try (Connection c = this.getConnection(); PreparedStatement s = c.prepareStatement(query)) {
preparer.accept(s);
try (ResultSet r = s.executeQuery()) {
Expand Down Expand Up @@ -199,7 +169,7 @@ public void executeBatch(@Nonnull BatchBuilder builder) {
}

@Override
public BatchBuilder batch(@Language(LANGUAGE) @Nonnull String statement) {
public BatchBuilder batch(@Language("MySQL") @Nonnull String statement) {
return new HelperSqlBatchBuilder(this, statement);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

package me.lucko.helper.sql.plugin;

import com.google.common.collect.Lists;

import me.lucko.helper.promise.Promise;
import me.lucko.helper.sql.Sql;
import me.lucko.helper.sql.batch.BatchBuilder;
Expand All @@ -47,7 +45,7 @@ public class HelperSqlBatchBuilder implements BatchBuilder {
public HelperSqlBatchBuilder(@Nonnull Sql owner, @Nonnull String statement) {
this.owner = owner;
this.statement = statement;
this.handlers = Lists.newLinkedList();
this.handlers = new LinkedList<>();
}

@Nonnull
Expand Down

0 comments on commit 4143cf4

Please sign in to comment.