Class MySqlHelper

java.lang.Object
io.github.devlibx.easy.database.mysql.MySqlHelper
All Implemented Interfaces:
IMysqlHelper

public class MySqlHelper extends Object implements IMysqlHelper
  • Constructor Details

  • Method Details

    • execute

      public boolean execute(String metricsName, String sql, IMysqlHelper.IStatementBuilder statementBuilder)
      Description copied from interface: IMysqlHelper
      Execute a SQL (Do not use it for UPDATE query - use executeUpdate)

      NOTE - a "CREATE TABLE" using this returns false (as per the Java Doc of PreparedStatement)

      Specified by:
      execute in interface IMysqlHelper
      Parameters:
      metricsName - metric name to log this execution
      sql - SQL to execute
      statementBuilder - callback hook to set param in SQL statement
      Returns:
      true if success otherwise false
    • executeUpdate

      public boolean executeUpdate(String metricsName, String sql, IMysqlHelper.IStatementBuilder statementBuilder)
      Description copied from interface: IMysqlHelper
      Execute a SQL
      Specified by:
      executeUpdate in interface IMysqlHelper
      Parameters:
      metricsName - metric name to log this execution
      sql - SQL to execute
      statementBuilder - callback hook to set param in SQL statement
      Returns:
      true if success otherwise false
    • persist

      public Long persist(String metricsName, String sql, IMysqlHelper.IStatementBuilder statementBuilder)
      Description copied from interface: IMysqlHelper
      Persist a record
      Specified by:
      persist in interface IMysqlHelper
      Parameters:
      metricsName - metric name to log this execution
      sql - SQL to execute
      statementBuilder - callback hook to set param in SQL statement
      Returns:
      PK for this row as long
    • persist

      public <T> T persist(String metricsName, String sql, IMysqlHelper.IStatementBuilder statementBuilder, Function<ResultSet,T> keyFunction)
      Description copied from interface: IMysqlHelper
      Persist a record
      Specified by:
      persist in interface IMysqlHelper
      Parameters:
      metricsName - metric name to log this execution
      sql - SQL to execute
      statementBuilder - callback hook to set param in SQL statement
      keyFunction - function to extract key of this row
      Returns:
      PK for this row
    • findOne

      public <T> Optional<T> findOne(String metricsName, String sql, IMysqlHelper.IStatementBuilder statementBuilder, IMysqlHelper.IRowMapper<T> rowMapper, Class<T> cls)
      Description copied from interface: IMysqlHelper
      Fina a single record
      Specified by:
      findOne in interface IMysqlHelper
      Parameters:
      metricsName - metric name to log this execution
      sql - SQL to execute
      statementBuilder - callback hook to set param in SQL statement
      rowMapper - mapper to build object from DB row
      Returns:
      Optional object with found record
    • findAll

      public <T> Optional<List<T>> findAll(String metricsName, String sql, IMysqlHelper.IStatementBuilder statementBuilder, IMysqlHelper.IRowMapper<T> rowMapper, Class<T> cls)
      Description copied from interface: IMysqlHelper
      Fina all record
      Specified by:
      findAll in interface IMysqlHelper
      Parameters:
      metricsName - metric name to log this execution
      sql - SQL to execute
      statementBuilder - callback hook to set param in SQL statement
      rowMapper - mapper to build object from DB row
      Returns:
      Optional object (of type list) with found record