Giter Site home page Giter Site logo

spark61 / asyncmysqlpoolhandler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mintui9976/asyncmysqlpoolhandler

0.0 0.0 0.0 123 KB

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

License: MIT License

Java 100.00%

asyncmysqlpoolhandler's Introduction

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
        });
    }

asyncmysqlpoolhandler's People

Contributors

azraanimating avatar kevin-gosa avatar mintui9976 avatar spark61 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.