Search in sources :

Example 1 with FieldDataProvider

use of org.firebirdsql.jdbc.field.FieldDataProvider in project jaybird by FirebirdSQL.

the class AbstractPreparedStatement method prepareFixedStatement.

/**
 * Prepare fixed statement and initialize parameters.
 */
protected void prepareFixedStatement(String sql) throws SQLException {
    super.prepareFixedStatement(sql);
    RowDescriptor rowDescriptor = fbStatement.getParameterDescriptor();
    assert rowDescriptor != null : "RowDescriptor should not be null after prepare";
    isParamSet = new boolean[rowDescriptor.getCount()];
    fieldValues = rowDescriptor.createDefaultFieldValues();
    fields = new FBField[rowDescriptor.getCount()];
    for (int i = 0; i < isParamSet.length; i++) {
        FieldDataProvider dataProvider = fieldValues.getFieldValue(i);
        // FIXME check if we can safely pass cached here
        fields[i] = FBField.createField(getParameterDescriptor(i + 1), dataProvider, gdsHelper, false);
    }
    this.isExecuteProcedureStatement = fbStatement.getType() == StatementType.STORED_PROCEDURE;
}
Also used : FieldDataProvider(org.firebirdsql.jdbc.field.FieldDataProvider) RowDescriptor(org.firebirdsql.gds.ng.fields.RowDescriptor)

Example 2 with FieldDataProvider

use of org.firebirdsql.jdbc.field.FieldDataProvider in project jaybird by FirebirdSQL.

the class FBCachedFetcher method cacheBlobsInRow.

private static void cacheBlobsInRow(final GDSHelper gdsHelper, final RowDescriptor rowDescriptor, final boolean[] isBlob, final RowValue localRow) throws SQLException {
    // ugly blob caching workaround.
    for (int j = 0; j < localRow.getCount(); j++) {
        // if field is blob and there is a value to cache
        if (isBlob[j] && localRow.getFieldValue(j).getFieldData() != null) {
            final byte[] tempData = localRow.getFieldValue(j).getFieldData();
            final FieldDataProvider dataProvider = new FieldDataProvider() {

                @Override
                public byte[] getFieldData() {
                    return tempData;
                }

                @Override
                public void setFieldData(byte[] data) {
                    throw new UnsupportedOperationException();
                }
            };
            // copy data from current row
            final FBFlushableField blob = (FBFlushableField) FBField.createField(rowDescriptor.getFieldDescriptor(j), dataProvider, gdsHelper, false);
            // TODO setCachedObject instead?
            localRow.getFieldValue(j).setFieldData(blob.getCachedData());
        }
    }
}
Also used : FBFlushableField(org.firebirdsql.jdbc.field.FBFlushableField) FieldDataProvider(org.firebirdsql.jdbc.field.FieldDataProvider)

Aggregations

FieldDataProvider (org.firebirdsql.jdbc.field.FieldDataProvider)2 RowDescriptor (org.firebirdsql.gds.ng.fields.RowDescriptor)1 FBFlushableField (org.firebirdsql.jdbc.field.FBFlushableField)1