Class RedGDatabaseUtil

java.lang.Object
de.yamass.redg.runtime.jdbc.RedGDatabaseUtil

public class RedGDatabaseUtil extends Object
  • Method Details

    • insertDataIntoDatabase

      public static void insertDataIntoDatabase(List<? extends RedGEntity> gObjects, Connection connection)
      Parameters:
      connection - The JDBC connection
      gObjects - 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 the Connection 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 an ExistingEntryMissingException will be thrown.
      Parameters:
      connection - The database connection
      gObjects - The entities that should be inserted into the database
      preparedStatementParameterSetter - 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 database
      InsertionFailedException - When problems with the prepared statement occur. This is often the result of a faulty data type mapping or PreparedStatementParameterSetter
    • distinctByKey

      public static <T> Predicate<T> distinctByKey(Function<? super T,?> keyExtractor)
      Taken from http://stackoverflow.com/a/27872852
      Type Parameters:
      T - the generic type
      Parameters:
      keyExtractor - The key extractor function
      Returns:
      a predicate for filtering