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 update
    void closeConnection()
    Close the all connections of jdbc
    static JdbcProvider from​(@NonNull java.io.File file)
    Creates provider to sql
    boolean 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 query
    boolean openConnection()
    Connect to mysql server
    JdbcProvider 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 query
    void update​(@NonNull java.lang.String query, java.lang.Object... objects)
    Uses just in create, delete, insert and update queries

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • from

      public static JdbcProvider from​(@NonNull @NonNull java.io.File file)
      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 interface JdbcProvider
    • hasConnection

      public boolean hasConnection()
      Description copied from interface: JdbcProvider
      Verify if the connections is valid
      Specified by:
      hasConnection in interface JdbcProvider
      Returns:
      if an any valid connection
    • openConnection

      public boolean openConnection()
      Description copied from interface: JdbcProvider
      Connect to mysql server
      Specified by:
      openConnection in interface JdbcProvider
      Returns:
      if has a valid connection
    • preOpen

      public JdbcProvider preOpen()
      Description copied from interface: JdbcProvider
      Used to pre configure instance settings
      Specified by:
      preOpen in interface JdbcProvider
      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 interface JdbcProvider
      Type Parameters:
      K - the generic type, used to return your prefer value
      Parameters:
      query - the query of mysql
      consumer - if has a valid entry, functional interface SafetyFunction will be called and returns a result
      objects - 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 interface JdbcProvider
      Parameters:
      query - the query of mysql
      objects - 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 interface JdbcProvider
      Type Parameters:
      K - the generic type, used to return your prefer value
      Parameters:
      query - the query of mysql
      function - if has a valid entry, functional interface SafetyFunction will be called and returns a result
      objects - 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 interface JdbcProvider
      Type Parameters:
      T - type of objects
      Parameters:
      query - the query of mysql
      batchFunction - to compute values from collection
      collection - entry of computable objects
      Returns:
      result of batch