Package com.d3x.core.db
Class DatabaseUpdate<T>
- java.lang.Object
-
- com.d3x.core.db.DatabaseUpdate<T>
-
public class DatabaseUpdate<T> extends java.lang.ObjectA class used to setup and execute a database insert or update operation- Author:
- Xavier Witdouck
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classDatabaseUpdate.Type
-
Field Summary
Fields Modifier and Type Field Description private intbatchSizeprivate com.d3x.core.util.Option<DatabaseMapping.Binder<T>>binderprivate java.lang.Class<T>dataTypeprivate Databasedbprivate static org.slf4j.Loggerlogprivate com.d3x.core.util.Option<java.lang.String>sqlprivate DatabaseUpdate.Typetypeprivate booleanverbose
-
Constructor Summary
Constructors Constructor Description DatabaseUpdate(Database db, java.lang.Class<T> dataType, DatabaseUpdate.Type type)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intapply(java.util.Collection<T> records)Applies this database operation the collection of recordsintapply(java.util.Iterator<T> records)Applies this database operation the iterator of recordsintapply(java.util.stream.Stream<T> records)Applies this database operation the stream of recordsvoidapply(T record)Applies this operation to the record providedjava.util.concurrent.Future<java.lang.Integer>applyAsync(java.util.stream.Stream<T> records)Applies this operation asynchronously to the stream of recordsjava.util.concurrent.Future<java.lang.Integer>applyAsync(T record)Applies this operation asynchronously to the stream of recordsDatabaseUpdate<T>batchSize(int batchSize)Configures the batch size for this operationDatabaseUpdate<T>binder(DatabaseMapping.Binder<T> binder)Applies a custom binder to this updateprivate intexecute(java.util.Iterator<T> iterator, java.lang.String sql, DatabaseMapping.Binder<T> binder)Executes this operation over the stream of recordsprivate DatabaseMapping.Binder<T>resolveBinder()Returns the binder for this updateprivate java.lang.StringresolveSql()Returns the SQL for this updateDatabaseUpdate<T>sql(java.lang.String sql)Applies a custom SQL expression to this updateDatabaseUpdate<T>verbose(boolean verbose)Turns verbose logging on/off for this operation
-
-
-
Field Detail
-
log
private static final org.slf4j.Logger log
-
type
private DatabaseUpdate.Type type
-
db
private Database db
-
verbose
private boolean verbose
-
dataType
private java.lang.Class<T> dataType
-
sql
private com.d3x.core.util.Option<java.lang.String> sql
-
batchSize
private int batchSize
-
binder
private com.d3x.core.util.Option<DatabaseMapping.Binder<T>> binder
-
-
Constructor Detail
-
DatabaseUpdate
DatabaseUpdate(Database db, java.lang.Class<T> dataType, DatabaseUpdate.Type type)
Constructor- Parameters:
db- the database referencedataType- the data type for this updatetype- the update type (INSERT, UPDATE, DELETE)
-
-
Method Detail
-
sql
public DatabaseUpdate<T> sql(java.lang.String sql)
Applies a custom SQL expression to this update- Parameters:
sql- the SQL expression or classpath resource- Returns:
- this update
-
verbose
public DatabaseUpdate<T> verbose(boolean verbose)
Turns verbose logging on/off for this operation- Parameters:
verbose- true to enable verbose logging- Returns:
- this update
-
binder
public DatabaseUpdate<T> binder(DatabaseMapping.Binder<T> binder)
Applies a custom binder to this update- Parameters:
binder- the binder to apply- Returns:
- this update
-
batchSize
public DatabaseUpdate<T> batchSize(int batchSize)
Configures the batch size for this operation- Parameters:
batchSize- the batch size- Returns:
- this operation
-
apply
public void apply(T record)
Applies this operation to the record provided- Parameters:
record- the record instance
-
apply
public int apply(java.util.Collection<T> records)
Applies this database operation the collection of records- Parameters:
records- the collection of records- Returns:
- the number of records processed
-
apply
public int apply(java.util.Iterator<T> records)
Applies this database operation the iterator of records- Parameters:
records- the iterator of records- Returns:
- the number of records processed
-
apply
public int apply(java.util.stream.Stream<T> records)
Applies this database operation the stream of records- Parameters:
records- the stream of records- Returns:
- the number of records processed
-
applyAsync
public java.util.concurrent.Future<java.lang.Integer> applyAsync(T record)
Applies this operation asynchronously to the stream of records- Parameters:
record- the stream of records- Returns:
- the Future which exposes the record count
-
applyAsync
public java.util.concurrent.Future<java.lang.Integer> applyAsync(java.util.stream.Stream<T> records)
Applies this operation asynchronously to the stream of records- Parameters:
records- the stream of records- Returns:
- the Future which exposes the record count
-
resolveBinder
private DatabaseMapping.Binder<T> resolveBinder()
Returns the binder for this update- Returns:
- the binder for update
-
resolveSql
private java.lang.String resolveSql()
Returns the SQL for this update- Returns:
- the SQL for this update
-
execute
private int execute(java.util.Iterator<T> iterator, java.lang.String sql, DatabaseMapping.Binder<T> binder)
Executes this operation over the stream of records- Parameters:
iterator- the iterator of recordssql- the SQL expressionbinder- the binder to bind args to a prepared statement- Returns:
- the number of records processed
-
-