Package dev.king.universal.wrapper.sql
Class SqlProvider
java.lang.Object
dev.king.universal.wrapper.sql.SqlProvider
- All Implemented Interfaces:
JdbcProvider
public final class SqlProvider extends java.lang.Object implements JdbcProvider
-
Constructor Summary
Constructors Constructor Description SqlProvider()
-
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 java.io.File file)
Creates provider to sqlboolean
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> consumer, 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
-
SqlProvider
public SqlProvider()
-
-
Method Details
-
from
Creates provider to sql- Parameters:
file
- path of file- Returns:
- instance of sql provider
-
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> consumer, 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 mysqlconsumer
- 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
-
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
-
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
-