Search in sources :

Example 1 with FBFlushableField

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());
}
Also used : FBField(org.firebirdsql.jdbc.field.FBField) FBFlushableField(org.firebirdsql.jdbc.field.FBFlushableField)

Example 2 with FBFlushableField

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);
    }
}
Also used : FBField(org.firebirdsql.jdbc.field.FBField) FBFlushableField(org.firebirdsql.jdbc.field.FBFlushableField)

Example 3 with FBFlushableField

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)));
}
Also used : FBFlushableField(org.firebirdsql.jdbc.field.FBFlushableField) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) RowValue(org.firebirdsql.gds.ng.fields.RowValue)

Example 4 with FBFlushableField

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());
}
Also used : FBField(org.firebirdsql.jdbc.field.FBField) FBFlushableField(org.firebirdsql.jdbc.field.FBFlushableField) FieldValue(org.firebirdsql.gds.ng.fields.FieldValue)

Example 5 with FBFlushableField

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);
}
Also used : FBField(org.firebirdsql.jdbc.field.FBField) FBFlushableField(org.firebirdsql.jdbc.field.FBFlushableField) RowValue(org.firebirdsql.gds.ng.fields.RowValue)

Aggregations

FBFlushableField (org.firebirdsql.jdbc.field.FBFlushableField)7 FBField (org.firebirdsql.jdbc.field.FBField)5 RowValue (org.firebirdsql.gds.ng.fields.RowValue)2 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 FieldValue (org.firebirdsql.gds.ng.fields.FieldValue)1 FieldDataProvider (org.firebirdsql.jdbc.field.FieldDataProvider)1