Class SQLContext

  • All Implemented Interfaces:
    Serializable

    public class SQLContext
    extends Object
    implements Serializable

    A context combines a JDBC Connection with an SQLDialect to perform updates and queries against a database. The executor provides wrappers around JDBC elements that will auto close when they are no longer in memory.

    See Also:
    Serialized Form
    • Field Detail

      • DEFAULT_BATCH_SIZE

        public static int DEFAULT_BATCH_SIZE
        The default batch size for batch operations when no batch size is given
    • Constructor Detail

      • SQLContext

        public SQLContext()
    • Method Detail

      • create

        public static SQLContext create​(@NonNull
                                        @NonNull Connection connection,
                                        @NonNull
                                        @NonNull SQLDialect dialect)
        Creates an SQLContext from the given JDBC Connection and will generate SQL using the given SQLDialect**.
        Parameters:
        connection - the connection to the database
        dialect - the SQL dialect for converting Mango SQL objects to SQL statements.
        Returns:
        the SQLExecutor
      • batch

        public final int batch​(@NonNull
                               @NonNull UpdateStatement... updateStatements)
                        throws SQLException
        Performs a batch update for a set of update statements that do not require any values to be specified. Note that the entire collection of statements is performed as a single batch update.
        Parameters:
        updateStatements - the update statements
        Returns:
        the total number of items that were updated
        Throws:
        SQLException - something happened trying to update
      • batch

        public final int batch​(@NonNull
                               @NonNull Collection<? extends UpdateStatement> updateStatements)
                        throws SQLException
        Performs a batch update for a set of update statements that do not require any values to be specified. Note that the entire collection of statements is performed as a single batch update.
        Parameters:
        updateStatements - the update statements
        Returns:
        the total number of items that were updated
        Throws:
        SQLException - something happened trying to update
      • multiThreadedBatch

        public <T> int multiThreadedBatch​(@NonNull
                                          @NonNull SQLElement sql,
                                          @NonNull
                                          @NonNull Stream<? extends T> items,
                                          @NonNull
                                          @NonNull CheckedBiConsumer<T,​NamedPreparedStatement> consumer,
                                          int batchSize)
                                   throws SQLException
        Multi threaded batch int.
        Type Parameters:
        T - the type parameter
        Parameters:
        sql - the sql
        items - the items
        consumer - the consumer
        batchSize - the batch size
        Returns:
        the int
        Throws:
        SQLException - the sql exception
      • render

        public String render​(@NonNull
                             @NonNull SQLElement sql)
        Render string.
        Parameters:
        sql - the sql
        Returns:
        the string