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);
}
}
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);
}
}
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);
}
}
}
}
}
}
}
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);
}
}
}
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);
}
Aggregations