Package dev.king.universal.wrapper.mysql
Class MysqlProvider
java.lang.Object
dev.king.universal.wrapper.mysql.PoolableConnection
dev.king.universal.wrapper.mysql.MysqlProvider
- All Implemented Interfaces:
JdbcProvider
,PoolableProvider
public final class MysqlProvider extends PoolableConnection implements JdbcProvider
-
Constructor Summary
Constructors Constructor Description MysqlProvider(@NonNull UniversalCredential credential, int maxConnections)
-
Method Summary
Modifier and Type Method Description <T> int[]
batch(@NonNull java.lang.String query, SafetyBiConsumer<T,ComputedBatchQuery> batchFunction, java.util.Collection<T> collection)
Execute massive updatevoid
closeConnection()
Close the all connections of jdbcstatic JdbcProvider
from(@NonNull UniversalCredential universalCredential)
static JdbcProvider
from(@NonNull UniversalCredential universalCredential, int maxConnections)
Creates provider to mysqlboolean
hasConnection()
Verify if the connections is valid<K> java.util.List<K>
map(@NonNull java.lang.String query, @NonNull SafetyFunction<java.sql.ResultSet,K> function, java.lang.Object... objects)
Uses just in select queryboolean
openConnection()
Connect to mysql serverJdbcProvider
preOpen()
Used to pre configure instance settings<K> K
query(@NonNull java.lang.String query, @NonNull SafetyFunction<java.sql.ResultSet,K> function, java.lang.Object... objects)
Uses just in select queryvoid
update(@NonNull java.lang.String query, java.lang.Object... objects)
Uses just in create, delete, insert and update queries
-
Constructor Details
-
Method Details
-
from
public static JdbcProvider from(@NonNull @NonNull UniversalCredential universalCredential, int maxConnections)Creates provider to mysql- Parameters:
universalCredential
- login credentials fromUniversalCredential
maxConnections
- number of max connections (idle connections are divided by 2)- Returns:
- instance of mysql provider
-
from
-
closeConnection
public void closeConnection()Description copied from interface:JdbcProvider
Close the all connections of jdbc- Specified by:
closeConnection
in interfaceJdbcProvider
-
hasConnection
public boolean hasConnection()Description copied from interface:JdbcProvider
Verify if the connections is valid- Specified by:
hasConnection
in interfaceJdbcProvider
- Returns:
- if an any valid connection
-
openConnection
public boolean openConnection()Description copied from interface:JdbcProvider
Connect to mysql server- Specified by:
openConnection
in interfaceJdbcProvider
- Returns:
- if has a valid connection
-
preOpen
Description copied from interface:JdbcProvider
Used to pre configure instance settings- Specified by:
preOpen
in interfaceJdbcProvider
- Returns:
- instance of current
JdbcProvider
-
query
public <K> K query(@NonNull @NonNull java.lang.String query, @NonNull @NonNull SafetyFunction<java.sql.ResultSet,K> function, java.lang.Object... objects)Description copied from interface:JdbcProvider
Uses just in select query- Specified by:
query
in interfaceJdbcProvider
- Type Parameters:
K
- the generic type, used to return your prefer value- Parameters:
query
- the query of mysqlfunction
- if has a valid entry, functional interfaceSafetyFunction
will be called and returns a resultobjects
- the objects that will be put in the prepared statement- Returns:
- returns a optional value, applied in function parameter
-
map
public <K> java.util.List<K> map(@NonNull @NonNull java.lang.String query, @NonNull @NonNull SafetyFunction<java.sql.ResultSet,K> function, java.lang.Object... objects)Description copied from interface:JdbcProvider
Uses just in select query- Specified by:
map
in interfaceJdbcProvider
- Type Parameters:
K
- the generic type, used to return your prefer value- Parameters:
query
- the query of mysqlfunction
- if has a valid entry, functional interfaceSafetyFunction
will be called and returns a resultobjects
- the objects that will be put in the prepared statement- Returns:
- returns a optional value, applied in function parameter
-
update
public void update(@NonNull @NonNull java.lang.String query, java.lang.Object... objects)Description copied from interface:JdbcProvider
Uses just in create, delete, insert and update queries- Specified by:
update
in interfaceJdbcProvider
- Parameters:
query
- the query of mysqlobjects
- the objects that will be putted in the prepared statement
-
batch
public <T> int[] batch(@NonNull @NonNull java.lang.String query, SafetyBiConsumer<T,ComputedBatchQuery> batchFunction, java.util.Collection<T> collection)Description copied from interface:JdbcProvider
Execute massive update- Specified by:
batch
in interfaceJdbcProvider
- Type Parameters:
T
- type of objects- Parameters:
query
- the query of mysqlbatchFunction
- to compute values from collectioncollection
- entry of computable objects- Returns:
- result of batch
-