Package de.yamass.redg.runtime.jdbc
Class RedGDatabaseUtil
java.lang.Object
de.yamass.redg.runtime.jdbc.RedGDatabaseUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Predicate<T>
distinctByKey
(Function<? super T, ?> keyExtractor) Taken from http://stackoverflow.com/a/27872852static void
insertDataIntoDatabase
(List<? extends RedGEntity> gObjects, Connection connection) static void
insertDataIntoDatabase
(List<? extends RedGEntity> gObjects, Connection connection, PreparedStatementParameterSetter preparedStatementParameterSetter) Inserts all data previously prepared by RedG into the database theConnection
connects to.
-
Method Details
-
insertDataIntoDatabase
public static void insertDataIntoDatabase(List<? extends RedGEntity> gObjects, Connection connection) - Parameters:
connection
- The JDBC connectiongObjects
- The entities to insert- See Also:
-
insertDataIntoDatabase
public static void insertDataIntoDatabase(List<? extends RedGEntity> gObjects, Connection connection, PreparedStatementParameterSetter preparedStatementParameterSetter) Inserts all data previously prepared by RedG into the database theConnection
connects to. Entities are going to be inserted in the order they were added.
This method uses prepared statements to efficiently insert even great amount of data.
If a Insertion/Update updates more than 1 entry, a warning will be logged to the console. If a entity that is marked as "existing" (via redG.existingX()) is not found, an error will be logged and anExistingEntryMissingException
will be thrown.- Parameters:
connection
- The database connectiongObjects
- The entities that should be inserted into the databasepreparedStatementParameterSetter
- The prepared statement parameter setter that should be used to set the values on the prepared statements- Throws:
ExistingEntryMissingException
- When an entry defined as "existing" (via redG.existingX()) cannot be found in the databaseInsertionFailedException
- When problems with the prepared statement occur. This is often the result of a faulty data type mapping orPreparedStatementParameterSetter
-
distinctByKey
Taken from http://stackoverflow.com/a/27872852- Type Parameters:
T
- the generic type- Parameters:
keyExtractor
- The key extractor function- Returns:
- a predicate for filtering
-