Qore jni Module  1.0.1
org.qore.lang.bulksqlutil.AbstractBulkOperation Class Reference

Java wrapper for the base Qore class for bulk DML operations. More...

Inheritance diagram for org.qore.lang.bulksqlutil.AbstractBulkOperation:
org.qore.jni.QoreObjectWrapper org.qore.lang.bulksqlutil.BulkInsertOperation org.qore.lang.bulksqlutil.BulkUpsertOperation

Public Member Methods

 AbstractBulkOperation (QoreObject obj) throws Throwable
 creates a new AbstractBulkOperation object wrapping the Qore object
 
void queueData (Map< String, Object > data) throws Throwable
 queues row data in the block buffer; the block buffer is flushed to the DB if the buffer size reaches the limit defined by the block_size option; does not commit the transaction More...
 
void queueData (Map< String, Object >[] l) throws Throwable
 queues row data in the block buffer; the block buffer is flushed to the DB if the buffer size reaches the limit defined by the block_size option; does not commit the transaction More...
 
void flush () throws Throwable
 flushes any remaining batched data to the database; this method should always be called before committing the transaction or destroying the object More...
 
void discard () throws Throwable
 discards any buffered batched data; this method should be called before destroying the object if an error occurs More...
 
void commit () throws Throwable
 flushes any queued data and commits the transaction
 
void rollback () throws Throwable
 discards any queued data and rolls back the transaction
 
String getTableName () throws Throwable
 returns the table name
 
AbstractTable getTable () throws Throwable
 returns the underlying SqlUtil::AbstractTable object
 
AbstractDatasource getDatasource () throws Throwable
 returns the AbstractDatasource object associated with this object
 
int getRowCount () throws Throwable
 returns the affected row count
 
- Public Member Methods inherited from org.qore.jni.QoreObjectWrapper
 QoreObjectWrapper (QoreObject obj)
 creates the wrapper object with the Qore object
 
void release ()
 releases the Qore object; do not call any further methods on the object after this call
 
QoreObject getQoreObject ()
 returns the Qore object
 
String className ()
 returns the class name for the Qore object
 
boolean instanceOf (String class_name)
 returns true if the object is an instance of the given class
 

Additional Inherited Members

- Private Attributes inherited from org.qore.jni.QoreObjectWrapper
QoreObject obj
 the wrapper Qore object
 

Detailed Description

Java wrapper for the base Qore class for bulk DML operations.

This class provides the majority of the API support for bulk DML operations for the concrete child classes that inherit it.

Submitting Data
To use this class's API, queue data in the form of a hash (a single row or a set of rows) or a list of rows by calling the queueData() method.

The queueData() method queues data to be written to the database; the queue is flush()ed automatically when block_size rows have been queued.
Flushing and Discarding Data
Each call to flush() (whether implicit or explicit) will cause a single call to be made to the dataserver; all queued rows are sent in a single bulk DML call, which allows for efficient processing of large amounts of data.

A call to flush() must be made before committing the transaction to ensure that any remaining rows in the internal queue have been written to the database. Because the destructor() will throw an exception if any data is left in the internal queue when the object is destroyed, a call to discard() must be made prior to the destruction of the object in case of errors.
// single commit and rollback
try {
// data is queued and flushed automatically when the buffer is full
for (Map<String, Object> i : data1) {
op1.queueData(i);
}
for (Map<String, Object> i : data2) {
op2.queueData(i);
}
// each operation needs to be flushed or discarded individually
op1.flush();
op2.flush();
ds.commit();
} catch (Throwable e) {
op1.discard();
op2.discard();
ds.rollback();
throw e;
}
Note
  • Each bulk DML object must be manually flush()ed before committing or manually discard()ed before rolling back to ensure that all data is managed properly in the same transaction and to ensure that no exception is thrown in the destructor(). See the example above for more information.
  • If the underlying driver does not support bulk operations, then such support is emulated with single SQL operations; in such cases performance will be reduced. Call SqlUtil::AbstractTable::hasArrayBind() to check at runtime if the driver supports bulk SQL operations.
  • loads and initializes the Qore library and the jni module in static initialization if necessary

Member Function Documentation

◆ discard()

void org.qore.lang.bulksqlutil.AbstractBulkOperation.discard ( ) throws Throwable
inline

discards any buffered batched data; this method should be called before destroying the object if an error occurs

Example:
// single commit and rollback
try {
// data is queued and flushed automatically when the buffer is full
for (Map<String, Object> i : data1) {
op1.queueData(i);
}
for (Map<String, Object> i : data2) {
op2.queueData(i);
}
// each operation needs to be flushed or discarded individually
op1.flush();
op2.flush();
ds.commit();
} catch (Throwable e) {
op1.discard();
op2.discard();
ds.rollback();
throw e;
}
Note
  • make sure to call flush() before committing the transaction or discard() before rolling back the transaction or destroying the object when using this method
  • flush() or discard() needs to be executed individually for each bulk operation object used in the block whereas the DB transaction needs to be committed or rolled back once per datasource
See also

◆ flush()

void org.qore.lang.bulksqlutil.AbstractBulkOperation.flush ( ) throws Throwable
inline

flushes any remaining batched data to the database; this method should always be called before committing the transaction or destroying the object

Example:
// single commit and rollback
try {
// data is queued and flushed automatically when the buffer is full
for (Map<String, Object> i : data1) {
op1.queueData(i);
}
for (Map<String, Object> i : data2) {
op2.queueData(i);
}
// each operation needs to be flushed or discarded individually
op1.flush();
op2.flush();
ds.commit();
} catch (Throwable e) {
op1.discard();
op2.discard();
ds.rollback();
throw e;
}
Note
  • make sure to call flush() before committing the transaction or discard() before rolling back the transaction or destroying the object when using this method
  • flush() or discard() needs to be executed individually for each bulk operation object used in the block whereas the DB transaction needs to be committed or rolled back once per datasource
See also

◆ queueData() [1/2]

void org.qore.lang.bulksqlutil.AbstractBulkOperation.queueData ( Map< String, Object >  data) throws Throwable
inline

queues row data in the block buffer; the block buffer is flushed to the DB if the buffer size reaches the limit defined by the block_size option; does not commit the transaction

Example:
// single commit and rollback
try {
// data is queued and flushed automatically when the buffer is full
for (Map<String, Object> i : data1) {
op1.queueData(i);
}
for (Map<String, Object> i : data2) {
op2.queueData(i);
}
// each operation needs to be flushed or discarded individually
op1.flush();
op2.flush();
ds.commit();
} catch (Throwable e) {
op1.discard();
op2.discard();
ds.rollback();
throw e;
}
Parameters
datathe input record or record set in case a hash of lists is passed; each hash represents a row (keys are column names and values are column values); when inserting, sql_iop_funcs can also be used. If at least one hash value is a list, then any non-hash (indicating an insert opertor hash) and non-list values will be assumed to be constant values for every row and therefore future calls of this method (and overloaded variants) will ignore any values given for such keys and use the values given in the first call.
Note
  • the first row passed is taken as a template row; every other row must always have the same keys in the same order, otherwise the results are unpredictable
  • if any sql_iop_funcs are used, then they are assumed to be identical in every row
  • make sure to call flush() before committing the transaction or discard() before rolling back the transaction or destroying the object when using this method
  • flush() or discard() needs to be executed individually for each bulk operation object used in the block whereas the DB transaction needs to be committed or rolled back once per datasource
See also

◆ queueData() [2/2]

void org.qore.lang.bulksqlutil.AbstractBulkOperation.queueData ( Map< String, Object > []  l) throws Throwable
inline

queues row data in the block buffer; the block buffer is flushed to the DB if the buffer size reaches the limit defined by the block_size option; does not commit the transaction

Example:
// single commit and rollback
try {
// data is queued and flushed automatically when the buffer is full
op1.queueData(l1);
op2.queueData(l2);
// each operation needs to be flushed or discarded individually
op1.flush();
op2.flush();
ds.commit();
} catch (Throwable e) {
op1.discard();
op2.discard();
ds.rollback();
throw e;
}
Parameters
la list of hashes representing the input row data; each hash represents a row (keys are column names and values are column values); when inserting, sql_iop_funcs can also be used
Note
  • the first row passed is taken as a template row; every other row must always have the same keys in the same order, otherwise the results are unpredictable
  • if any sql_iop_funcs are used, then they are assumed to be identical in every row
  • make sure to call flush() before committing the transaction or discard() before rolling back the transaction or destroying the object when using this method
  • flush() or discard() needs to be executed individually for each bulk operation object used in the block whereas the DB transaction needs to be committed or rolled back once per datasource
See also

The documentation for this class was generated from the following file: