Class InsertAndGetID

java.lang.Object
com.github.tadukoo.database.mysql.transaction.InsertAndGetID
All Implemented Interfaces:
SQLTransaction<Integer>

public abstract class InsertAndGetID extends Object implements SQLTransaction<Integer>
Insert and Get ID is a SQLTransaction that will run an insert statement on a table and then retrieve the id of the new entry.
Version:
Alpha v.0.3
Author:
Logan Ferree (Tadukoo)
  • Constructor Details

    • InsertAndGetID

      public InsertAndGetID()
  • Method Details

    • getInsertString

      public String getInsertString()
      Returns:
      The string to report when the insert is run (can be blank for no reporting)
    • getInsertSQL

      public abstract String getInsertSQL()
      Returns:
      The MySQL string to use for the insert statement
    • getSelectString

      public String getSelectString()
      Returns:
      The string to report when the id retrieval is run (can be blank for no reporting)
    • getSelectSQL

      public abstract String getSelectSQL()
      Returns:
      The MySQL string to use for retrieving the id from the table
    • execute

      public Integer execute(Connection conn, com.github.tadukoo.util.logger.EasyLogger logger) throws SQLException
      Executes the transaction using the given connection, and will log messages as needed to the given EasyLogger
      Specified by:
      execute in interface SQLTransaction<Integer>
      Parameters:
      conn - The Connection to use for the transaction
      logger - The EasyLogger to use for logging messages as needed
      Returns:
      The result of the transaction
      Throws:
      SQLException - If anything goes wrong
    • createInsertAndGetID

      public static InsertAndGetID createInsertAndGetID(String table, String idColumnName, Collection<String> cols, Collection<Object> values)
      Creates a new InsertAndGetID using the given information.
      Parameters:
      table - The table to use for the insert and id retrieval
      idColumnName - The name of the id column in the table
      cols - The columns of the table to use in the insert
      values - The values to use for the insert (should be in the same order as the cols)
      Returns:
      An InsertAndGetID object to use for a transaction