Class InsertAndGetID
java.lang.Object
com.github.tadukoo.database.mysql.transaction.InsertAndGetID
- All Implemented Interfaces:
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic InsertAndGetID
createInsertAndGetID
(String table, String idColumnName, Collection<String> cols, Collection<Object> values) Creates a newInsertAndGetID
using the given information.execute
(Connection conn, com.github.tadukoo.util.logger.EasyLogger logger) Executes the transaction using the given connection, and will log messages as needed to the givenEasyLogger
abstract String
abstract String
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.github.tadukoo.database.mysql.transaction.SQLTransaction
getTransactionName
-
Constructor Details
-
InsertAndGetID
public InsertAndGetID()
-
-
Method Details
-
getInsertString
- Returns:
- The string to report when the insert is run (can be blank for no reporting)
-
getInsertSQL
- Returns:
- The MySQL string to use for the insert statement
-
getSelectString
- Returns:
- The string to report when the id retrieval is run (can be blank for no reporting)
-
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 givenEasyLogger
- Specified by:
execute
in interfaceSQLTransaction<Integer>
- Parameters:
conn
- TheConnection
to use for the transactionlogger
- TheEasyLogger
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 newInsertAndGetID
using the given information.- Parameters:
table
- The table to use for the insert and id retrievalidColumnName
- The name of the id column in the tablecols
- The columns of the table to use in the insertvalues
- 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
-