use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class JdbcRecordWriter method appendIdEquals.
public void appendIdEquals(final StringBuilder sqlBuffer, final List<FieldDefinition> idFields) {
boolean first = true;
for (final FieldDefinition idField : idFields) {
if (first) {
first = false;
} else {
sqlBuffer.append(" AND ");
}
idField.appendColumnName(sqlBuffer, this.quoteColumnNames);
sqlBuffer.append(" = ");
((JdbcFieldDefinition) idField).addStatementPlaceHolder(sqlBuffer);
}
}
use of com.revolsys.record.schema.FieldDefinition 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.record.schema.FieldDefinition 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.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class CsvRecordWriter method write.
@Override
public void write(final Record record) {
Writer out = this.out;
if (this.paused) {
this.paused = false;
final Resource resource = getResource();
out = this.out = resource.newWriterAppend();
}
if (out != null) {
try {
final RecordDefinition recordDefinition = this.recordDefinition;
final char fieldSeparator = this.fieldSeparator;
boolean first = true;
for (final FieldDefinition field : recordDefinition.getFields()) {
if (first) {
first = false;
} else {
out.write(fieldSeparator);
}
final String fieldName = field.getName();
final Object value;
if (isWriteCodeValues()) {
value = record.getCodeValue(fieldName);
} else {
value = record.getValue(fieldName);
}
if (value instanceof Geometry) {
final Geometry geometry = (Geometry) value;
if (this.useQuotes) {
out.write('"');
EWktWriter.write(out, geometry, this.ewkt);
out.write('"');
} else {
EWktWriter.write(out, geometry, this.ewkt);
}
} else if (value != null) {
final DataType dataType = field.getDataType();
final String stringValue = dataType.toString(value);
if (dataType.isRequiresQuotes()) {
string(stringValue);
} else {
out.write(stringValue, 0, stringValue.length());
}
}
}
out.write('\n');
} catch (final IOException e) {
throw Exceptions.wrap(e);
}
}
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class EsriGeodatabaseXmlRecordWriter method writeFields.
private void writeFields(final RecordDefinition recordDefinition) {
this.out.startTag(FIELDS);
this.out.attribute(XsiConstants.TYPE, FIELDS_TYPE);
this.out.startTag(FIELD_ARRAY);
this.out.attribute(XsiConstants.TYPE, FIELD_ARRAY_TYPE);
for (final FieldDefinition attribute : recordDefinition.getFields()) {
writeField(attribute);
}
if (recordDefinition.getField("OBJECTID") == null) {
writeOidField();
}
this.out.endTag(FIELD_ARRAY);
this.out.endTag(FIELDS);
}
Aggregations