Skip to content

An simplify library to create jdbc pools via HikariCP. The Statement/PreparedStatement methods are performed asynchronously

License

Notifications You must be signed in to change notification settings

Spark61/AsyncMySQLPoolHandler

 
 

Repository files navigation

AsyncMySQLPoolHandler

forthebadge forthebadge forthebadge

GitHub release (latest SemVer including pre-releases) GitHub lines) GitHub license GitHub bytes) GitHub language count GitHub stars

An simplify library to create jdbc pools via HikariCP.

Statement/PreparedStatement methods are performed asynchronously.

Features

  • full asynchronously statement/preparedStatement methods
  • simple jdbc connector
  • simple configurator
  • default config available
  • instant query result via preparedStatement
  • multiple object update via preparedStatement
  • single update via statement
  • add selection PublicKeyRetrival

Implemented JDBC Frameworks

Repository

<repositories>
   <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
   </repository>
</repositories>

Dependency

<dependency>
  <groupId>com.github.mintUI9976</groupId>
  <artifactId>AsyncMySQLPoolHandler</artifactId>
  <version>Tag</version>
</dependency>

Utilization

Initialized AsyncMySQLPoolHandler Object

private final AsyncMySQLPoolHandler asyncMySQLPoolHandler = new AsyncMySQLPoolHandler(hostname, username, password, enumPoolFramework, configPoolFramework);
private final AsyncMySQLPoolHandler asyncMySQLPoolHandler = new AsyncMySQLPoolHandler(hostname, port, username, password, enumPoolFramework, configPoolFramework);
private final AsyncMySQLPoolHandler asyncMySQLPoolHandler = new AsyncMySQLPoolHandler(hostname, username, password , database, enumPoolFramework, configPoolFramework);
private final AsyncMySQLPoolHandler asyncMySQLPoolHandler = new AsyncMySQLPoolHandler(hostname, port, username, password, database, enumPoolFramework, configPoolFramework);

ConfigPoolFramework

private final ConfigPoolFramework configPoolFramework = ConfigBuilder.getConfigBuilder().build(); // returns a default configuration
// You do not have to change all values, the remaining values are filled with default values.

OpenPool:

private void openPool(){
        if (this.asyncMySQLPoolHandler.openPool()){
            //successful
        } else {
            //failed
        }
    }

ClosePool:

private void closePool(){
        if (this.asyncMySQLPoolHandler.closePool()){
            //successful
        } else {
            //failed
        }
    }

ExecuteQuery:

private void testQuery() {
        this.asyncMySQLPoolHandler.executeQueryAsync("SELECT * FROM `" + "yourTable" + "`;").whenComplete((cachedRowSet, throwable) -> {
            try {
                final Collection<String> collection = new ArrayList<>();
                while (cachedRowSet.next()) {
                    collection.add(cachedRowSet.getString(1));
                }
                // now you can work with the cachedRowSet
                cachedRowSet.close();
            } catch (final SQLException exception) {
                exception.printStackTrace();
            }
        });
    }

ReturnExecuteQuery:

ExecuteQueryAsync:
public int testQueryResult(final String value) {
        try {
            final CachedRowSet resultSet = this.asyncMySQLPoolHandler.executeQueryAsync("SELECT `yourColumn` FROM `" + "yourTable" + "` WHERE `yourValue`= '" + this.asyncMySQLPoolHandler.removeSQLInjectionPossibility(value) + "';").join();
            if (resultSet.last()) {
                final int test = resultSet.getInt("yourColumn");
                resultSet.close();
                // return your async request result
                return test;
            } else {
                resultSet.close();
                // return a custom result if your request has failed
                return -1;
            }
        } catch (final SQLException exception) {
            exception.printStackTrace();
        }
        return -1;
    }
ExecuteQueryInstantLastResultAsync:
public int test(final String value) {
        final Integer result = (Integer) this.asyncMySQLPoolHandler.executeQueryInstantLastResultAsync("SELECT `yourColumn` FROM `" + "yourTable" + "` WHERE `yourValue`= '" + this.asyncMySQLPoolHandler.removeSQLInjectionPossibility(value) + "';" , "yourColumn").join();
        return result != null ? result : -1;
    }
ExecuteQueryInstantFirstResultAsync:
public int test(final String value) {
        final Integer result = (Integer) this.asyncMySQLPoolHandler.executeQueryInstantFirstResultAsync("SELECT `yourColumn` FROM `" + "yourTable" + "` WHERE `yourValue`= '" + this.asyncMySQLPoolHandler.removeSQLInjectionPossibility(value) + "';" , "yourColumn").join();
        return result != null ? result : -1;
    }
ExecuteQueryInstantLastResultAsBooleanAsync:
public boolean test(final String value) {
        return this.asyncMySQLPoolHandler.executeQueryInstantLastResultAsBooleanAsync("SELECT `yourColumn` FROM `" + "yourTable" + "` WHERE `yourValue`= '" + this.asyncMySQLPoolHandler.removeSQLInjectionPossibility(value) + "';" , "yourColumn").join();
    }
ExecuteQueryInstantFirstResultAsBooleanAsync:
public boolean test(final String value) {
        return this.asyncMySQLPoolHandler.executeQueryInstantFirstResultAsBooleanAsync("SELECT `yourColumn` FROM `" + "yourTable" + "` WHERE `yourValue`= '" + this.asyncMySQLPoolHandler.removeSQLInjectionPossibility(value) + "';" , "yourColumn").join();
    }
ExecuteQueryInstantNextResultAsync:
public boolean test(final String value) {
        return this.asyncMySQLPoolHandler.executeQueryInstantNextResultAsync("SELECT * FROM `" + "yourTable" + "` WHERE `yourValue`= '" + this.asyncMySQLPoolHandler.removeSQLInjectionPossibility(value) + "';").join();
    }

ExecuteUpdate with Statement:

  private void testUpdate(final String yourValue) {
        this.asyncMySQLPoolHandler.executeUpdateAsync("INSERT INTO `" + "yourTable" + "` SET `yourColumn` = '" + this.asyncMySQLPoolHandler.removeSQLInjectionPossibility(yourValue) + "';").whenComplete((aVoid, throwable) -> {
            //now you can work with the result
        });
    }

ExecuteUpdate with PreparedStatement:

  private void testUpdate(final String... value) {
        this.asyncMySQLPoolHandler.executeUpdatePreparedStatementAsync("INSERT INTO `" + "yourTable" + "` (value1, value2, value3, value4) VALUES (?, ?, ?, ?)", value1,value2,value3,value4).whenComplete((aVoid, throwable) -> {
            //now you can work with the result
        });
    }

About

An simplify library to create jdbc pools via HikariCP. The Statement/PreparedStatement methods are performed asynchronously

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • Java 100.0%