Package com.gengoai.sql
Class SQLContext
- java.lang.Object
-
- com.gengoai.sql.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 Summary
Fields Modifier and Type Field Description static int
DEFAULT_BATCH_SIZE
The default batch size for batch operations when no batch size is given
-
Constructor Summary
Constructors Constructor Description SQLContext()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
batch(@NonNull UpdateStatement... updateStatements)
Performs a batch update for a set of update statements that do not require any values to be specified.int
batch(@NonNull Collection<? extends UpdateStatement> updateStatements)
Performs a batch update for a set of update statements that do not require any values to be specified.static SQLContext
create(@NonNull Connection connection, @NonNull SQLDialect dialect)
Creates anSQLContext
from the given JDBC Connection and will generate SQL using the givenSQLDialect
**.<T> int
multiThreadedBatch(@NonNull SQLElement sql, @NonNull Stream<? extends T> items, @NonNull CheckedBiConsumer<T,NamedPreparedStatement> consumer, int batchSize)
Multi threaded batch int.String
render(@NonNull SQLElement sql)
Render string.
-
-
-
Method Detail
-
create
public static SQLContext create(@NonNull @NonNull Connection connection, @NonNull @NonNull SQLDialect dialect)
Creates anSQLContext
from the given JDBC Connection and will generate SQL using the givenSQLDialect
**.- Parameters:
connection
- the connection to the databasedialect
- 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 sqlitems
- the itemsconsumer
- the consumerbatchSize
- 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
-
-