Search in sources :

Example 6 with JdbcFieldDefinition

use of com.revolsys.jdbc.field.JdbcFieldDefinition in project com.revolsys.open by revolsys.

the class JdbcRecordWriter method insert.

private void insert(final Record record, final JdbcRecordDefinition recordDefinition) throws SQLException {
    final PreparedStatement statement = insertStatementGet(recordDefinition, this.typeInsertStatementMap, this.typeInsertSqlMap, false, false);
    if (statement != null) {
        int parameterIndex = 1;
        for (final FieldDefinition fieldDefinition : recordDefinition.getFields()) {
            parameterIndex = ((JdbcFieldDefinition) fieldDefinition).setInsertPreparedStatementValue(statement, parameterIndex, record);
        }
        insertStatementAddBatch(recordDefinition, record, statement, this.typeInsertSqlMap, this.typeInsertBatchCountMap, this.typeInsertRecords, false);
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) PreparedStatement(java.sql.PreparedStatement)

Example 7 with JdbcFieldDefinition

use of com.revolsys.jdbc.field.JdbcFieldDefinition in project com.revolsys.open by revolsys.

the class JdbcRecordWriter method processCurrentBatch.

private void processCurrentBatch(final JdbcRecordDefinition recordDefinition, final Map<JdbcRecordDefinition, String> sqlMap, final PreparedStatement statement, final Map<JdbcRecordDefinition, Integer> batchCountMap, final Map<JdbcRecordDefinition, List<Record>> recordsByType, final boolean hasGeneratedKeys) {
    Integer batchCount = batchCountMap.get(recordDefinition);
    if (batchCount == null) {
        batchCount = 0;
    }
    try {
        Integer typeCount = this.typeCountMap.get(recordDefinition);
        if (typeCount == null) {
            typeCount = batchCount;
        } else {
            typeCount += batchCount;
        }
        this.typeCountMap.put(recordDefinition, typeCount);
        statement.executeBatch();
        if (hasGeneratedKeys) {
            final List<Record> records = recordsByType.remove(recordDefinition);
            if (records != null) {
                final ResultSet generatedKeyResultSet = statement.getGeneratedKeys();
                int recordIndex = 0;
                while (generatedKeyResultSet.next()) {
                    final Record record = records.get(recordIndex++);
                    int columnIndex = 1;
                    for (final FieldDefinition idField : recordDefinition.getIdFields()) {
                        ((JdbcFieldDefinition) idField).setFieldValueFromResultSet(generatedKeyResultSet, columnIndex++, record, false);
                    }
                }
            }
        }
    } catch (final SQLException e) {
        final String sql = sqlMap.get(recordDefinition);
        throw this.connection.getException("Process Batch", sql, e);
    } catch (final RuntimeException e) {
        LOG.error(sqlMap, e);
        throw e;
    } finally {
        batchCountMap.put(recordDefinition, 0);
    }
}
Also used : JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) SQLException(java.sql.SQLException) FieldDefinition(com.revolsys.record.schema.FieldDefinition) JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) ResultSet(java.sql.ResultSet) Record(com.revolsys.record.Record)

Example 8 with JdbcFieldDefinition

use of com.revolsys.jdbc.field.JdbcFieldDefinition in project com.revolsys.open by revolsys.

the class Value method setFieldDefinition.

@Override
public void setFieldDefinition(final FieldDefinition field) {
    if (field != null) {
        this.fieldDefinition = field;
        if (field instanceof JdbcFieldDefinition) {
            this.jdbcField = (JdbcFieldDefinition) field;
        } else {
            this.jdbcField = JdbcFieldDefinition.newFieldDefinition(this.queryValue);
        }
        CodeTable codeTable = null;
        if (field != null) {
            final RecordDefinition recordDefinition = field.getRecordDefinition();
            if (recordDefinition != null) {
                final String fieldName = field.getName();
                codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
                if (codeTable instanceof CodeTableProperty) {
                    final CodeTableProperty codeTableProperty = (CodeTableProperty) codeTable;
                    if (codeTableProperty.getRecordDefinition() == recordDefinition) {
                        codeTable = null;
                    }
                }
                if (codeTable != null) {
                    final Identifier id = codeTable.getIdentifier(this.queryValue);
                    if (id == null) {
                        this.displayValue = this.queryValue;
                    } else {
                        setQueryValue(id);
                        final List<Object> values = codeTable.getValues(id);
                        if (values.size() == 1) {
                            this.displayValue = values.get(0);
                        } else {
                            this.displayValue = Strings.toString(":", values);
                        }
                    }
                }
            }
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) TypedIdentifier(com.revolsys.identifier.TypedIdentifier) Identifier(com.revolsys.identifier.Identifier) JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) CodeTableProperty(com.revolsys.record.code.CodeTableProperty) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 9 with JdbcFieldDefinition

use of com.revolsys.jdbc.field.JdbcFieldDefinition in project com.revolsys.open by revolsys.

the class ArcSdeObjectIdJdbcFieldDefinition method replaceAttribute.

public static void replaceAttribute(final String schemaName, final RecordDefinition recordDefinition, final Integer registrationId, final String rowIdColumn) {
    final JdbcFieldDefinition objectIdAttribute = (JdbcFieldDefinition) recordDefinition.getField(rowIdColumn);
    if (objectIdAttribute != null && !(objectIdAttribute instanceof ArcSdeObjectIdJdbcFieldDefinition)) {
        final String name = objectIdAttribute.getName();
        final String description = objectIdAttribute.getDescription();
        final Map<String, Object> properties = objectIdAttribute.getProperties();
        final ArcSdeObjectIdJdbcFieldDefinition newObjectIdAttribute = new ArcSdeObjectIdJdbcFieldDefinition(objectIdAttribute.getDbName(), name, description, properties, schemaName, registrationId);
        newObjectIdAttribute.setRecordDefinition(recordDefinition);
        final RecordDefinitionImpl recordDefinitionImpl = (RecordDefinitionImpl) recordDefinition;
        recordDefinitionImpl.replaceField(objectIdAttribute, newObjectIdAttribute);
        if (recordDefinition.getIdFieldName() == null && recordDefinition.getIdFieldNames().isEmpty()) {
            recordDefinitionImpl.setIdFieldName(name);
        }
    }
}
Also used : JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl)

Example 10 with JdbcFieldDefinition

use of com.revolsys.jdbc.field.JdbcFieldDefinition in project com.revolsys.open by revolsys.

the class PostgreSQLRecordStore method insertStatementPrepareRowId.

@Override
public PreparedStatement insertStatementPrepareRowId(final JdbcConnection connection, final RecordDefinition recordDefinition, final String sql) throws SQLException {
    final List<FieldDefinition> idFields = recordDefinition.getIdFields();
    final String[] idColumnNames = new String[idFields.size()];
    for (int i = 0; i < idFields.size(); i++) {
        final FieldDefinition idField = idFields.get(0);
        final String columnName = ((JdbcFieldDefinition) idField).getDbName();
        idColumnNames[i] = columnName;
    }
    return connection.prepareStatement(sql, idColumnNames);
}
Also used : JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) FieldDefinition(com.revolsys.record.schema.FieldDefinition) PostgreSQLJdbcBlobFieldDefinition(com.revolsys.gis.postgresql.type.PostgreSQLJdbcBlobFieldDefinition) PostgreSQLArrayFieldDefinition(com.revolsys.gis.postgresql.type.PostgreSQLArrayFieldDefinition) PostgreSQLOidFieldDefinition(com.revolsys.gis.postgresql.type.PostgreSQLOidFieldDefinition) JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition)

Aggregations

JdbcFieldDefinition (com.revolsys.jdbc.field.JdbcFieldDefinition)18 FieldDefinition (com.revolsys.record.schema.FieldDefinition)11 SQLException (java.sql.SQLException)6 PostgreSQLArrayFieldDefinition (com.revolsys.gis.postgresql.type.PostgreSQLArrayFieldDefinition)2 Record (com.revolsys.record.Record)2 RecordDefinition (com.revolsys.record.schema.RecordDefinition)2 PreparedStatement (java.sql.PreparedStatement)2 CollectionDataType (com.revolsys.datatype.CollectionDataType)1 DataType (com.revolsys.datatype.DataType)1 PostgreSQLJdbcBlobFieldDefinition (com.revolsys.gis.postgresql.type.PostgreSQLJdbcBlobFieldDefinition)1 PostgreSQLOidFieldDefinition (com.revolsys.gis.postgresql.type.PostgreSQLOidFieldDefinition)1 Identifier (com.revolsys.identifier.Identifier)1 TypedIdentifier (com.revolsys.identifier.TypedIdentifier)1 JdbcFieldAdder (com.revolsys.jdbc.field.JdbcFieldAdder)1 CodeTable (com.revolsys.record.code.CodeTable)1 CodeTableProperty (com.revolsys.record.code.CodeTableProperty)1 Condition (com.revolsys.record.query.Condition)1 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)1 ResultSet (java.sql.ResultSet)1