use of org.firebirdsql.jdbc.field.FBFlushableField in project jaybird by FirebirdSQL.
the class FBPreparedStatement method executeSingleForBatch.
private void executeSingleForBatch(BatchedRowValue data, List<Long> results) throws SQLException {
fieldValues.reset();
for (int i = 0; i < fieldValues.getCount(); i++) {
FBField field = getField(i + 1);
if (field instanceof FBFlushableField) {
((FBFlushableField) field).setCachedObject((CachedObject) data.getCachedObject(i));
} else {
fieldValues.setFieldData(i, data.getFieldData(i));
}
}
if (internalExecute(isExecuteProcedureStatement)) {
throw createBatchUpdateException("Statements executed as batch should not produce a result set", SQLStateConstants.SQL_STATE_INVALID_STMT_TYPE, 0, toLargeArray(results), null);
}
results.add(getLargeUpdateCount());
}
use of org.firebirdsql.jdbc.field.FBFlushableField in project jaybird by FirebirdSQL.
the class FBPreparedStatement method addBatch.
@Override
public void addBatch() throws SQLException {
checkValidity();
checkAllParametersSet();
synchronized (getSynchronizationObject()) {
final BatchedRowValue batchedValues = new BatchedRowValue(fieldValues.deepCopy());
for (int i = 0; i < batchedValues.getCount(); i++) {
FBField field = getField(i + 1);
if (field instanceof FBFlushableField) {
batchedValues.setCachedObject(i, ((FBFlushableField) field).getCachedObject());
}
}
batchList.add(batchedValues);
}
}
use of org.firebirdsql.jdbc.field.FBFlushableField in project jaybird by FirebirdSQL.
the class FBRowUpdater method executeStatement.
private void executeStatement(int statementType, FbStatement stmt) throws SQLException {
if (inInsertRow && statementType != INSERT_STATEMENT_TYPE) {
throw new SQLException("Only insertRow() is allowed when result set is positioned on insert row.");
}
if (statementType != INSERT_STATEMENT_TYPE && oldRow == null) {
throw new SQLException("Result set is not positioned on a row.");
}
// in turn can change the parameter distribution
for (int i = 0; i < rowDescriptor.getCount(); i++) {
if (fields[i] instanceof FBFlushableField)
((FBFlushableField) fields[i]).flushCachedData();
}
int[] parameterMask = getParameterMask();
String sql;
switch(statementType) {
case UPDATE_STATEMENT_TYPE:
sql = buildUpdateStatement(parameterMask);
break;
case DELETE_STATEMENT_TYPE:
sql = buildDeleteStatement(parameterMask);
break;
case INSERT_STATEMENT_TYPE:
sql = buildInsertStatement();
break;
case SELECT_STATEMENT_TYPE:
sql = buildSelectStatement(parameterMask);
break;
default:
throw new IllegalArgumentException("Incorrect statement type specified.");
}
stmt.prepare(sql);
List<byte[]> params = new ArrayList<>();
if (statementType == UPDATE_STATEMENT_TYPE) {
for (int i = 0; i < rowDescriptor.getCount(); i++) {
if (!updatedFlags[i])
continue;
params.add(newRow.getFieldData(i));
}
}
RowValue source = statementType == INSERT_STATEMENT_TYPE ? insertRow : oldRow;
for (int i = 0; i < rowDescriptor.getCount(); i++) {
if (parameterMask[i] == PARAMETER_UNUSED && statementType != INSERT_STATEMENT_TYPE) {
continue;
} else if (!updatedFlags[i] && statementType == INSERT_STATEMENT_TYPE) {
continue;
}
params.add(source.getFieldData(i));
}
stmt.execute(RowValue.of(params.toArray(EMPTY_2D_BYTES)));
}
use of org.firebirdsql.jdbc.field.FBFlushableField in project jaybird by FirebirdSQL.
the class AbstractPreparedStatement method executeSingleForBatch.
private void executeSingleForBatch(RowValue data, List<Long> results) throws SQLException {
for (int i = 0; i < fieldValues.getCount(); i++) {
FieldValue fieldValue = fieldValues.getFieldValue(i);
fieldValue.reset();
FBField field = getField(i + 1);
if (field instanceof FBFlushableField) {
// Explicitly set to null to ensure initialized property set to true
fieldValue.setFieldData(null);
((FBFlushableField) field).setCachedObject((CachedObject) data.getFieldValue(i).getCachedObject());
} else {
fieldValue.setFieldData(data.getFieldValue(i).getFieldData());
}
isParamSet[i] = true;
}
if (internalExecute(isExecuteProcedureStatement)) {
throw jdbcVersionSupport.createBatchUpdateException("Statements executed as batch should not produce a result set", SQLStateConstants.SQL_STATE_INVALID_STMT_TYPE, 0, toLargeArray(results), null);
}
results.add(getLargeUpdateCount());
}
use of org.firebirdsql.jdbc.field.FBFlushableField in project jaybird by FirebirdSQL.
the class AbstractPreparedStatement method addBatch.
/**
* Adds a set of parameters to this <code>PreparedStatement</code>
* object's batch of commands.
*
* @exception SQLException
* if a database access error occurs
* @see Statement#addBatch
* @since 1.2
* @see <a href="package-summary.html#2.0 API">What Is in the JDBC 2.0 API
* </a>
*/
public void addBatch() throws SQLException {
checkValidity();
boolean allParamsSet = true;
// TODO Replace with check of FieldValue#isInitialized
for (boolean anIsParamSet : isParamSet) {
allParamsSet &= anIsParamSet;
}
if (!allParamsSet)
throw new FBSQLException("Not all parameters set.");
final RowValue batchedValues = fieldValues.deepCopy();
for (int i = 0; i < batchedValues.getCount(); i++) {
FBField field = getField(i + 1);
if (field instanceof FBFlushableField)
batchedValues.getFieldValue(i).setCachedObject(((FBFlushableField) field).getCachedObject());
}
batchList.add(batchedValues);
}
Aggregations