use of com.revolsys.jdbc.field.JdbcFieldDefinition in project com.revolsys.open by revolsys.
the class CollectionValue method appendParameters.
@Override
public int appendParameters(int index, final PreparedStatement statement) {
for (final QueryValue queryValue : getQueryValues()) {
JdbcFieldDefinition jdbcField = this.jdbcField;
if (queryValue instanceof Value) {
final Value valueWrapper = (Value) queryValue;
final Object value = valueWrapper.getQueryValue();
if (jdbcField == null) {
jdbcField = JdbcFieldDefinition.newFieldDefinition(value);
}
try {
index = jdbcField.setPreparedStatementValue(statement, index, value);
} catch (final SQLException e) {
ExceptionUtil.throwIfUnchecked(e);
}
} else {
index = queryValue.appendParameters(index, statement);
}
}
return index;
}
use of com.revolsys.jdbc.field.JdbcFieldDefinition in project com.revolsys.open by revolsys.
the class JdbcRecordWriter method getInsertSql.
private String getInsertSql(final JdbcRecordDefinition recordDefinition, final boolean generatePrimaryKey, final Map<JdbcRecordDefinition, String> sqlMap) {
String sql = sqlMap.get(recordDefinition);
if (sql == null) {
final JdbcRecordStore recordStore = this.recordStore;
final String tableName = recordDefinition.getDbTableQualifiedName();
final boolean hasRowIdField = recordStore.isIdFieldRowid(recordDefinition);
final StringBuilder sqlBuffer = new StringBuilder();
if (this.sqlPrefix != null) {
sqlBuffer.append(this.sqlPrefix);
}
sqlBuffer.append("insert ");
sqlBuffer.append(" into ");
sqlBuffer.append(tableName);
sqlBuffer.append(" (");
boolean first = true;
for (final FieldDefinition fieldDefinition : recordDefinition.getFields()) {
if (!(hasRowIdField && fieldDefinition.isIdField())) {
if (first) {
first = false;
} else {
sqlBuffer.append(',');
}
fieldDefinition.appendColumnName(sqlBuffer, this.quoteColumnNames);
}
}
sqlBuffer.append(") VALUES (");
first = true;
for (final FieldDefinition fieldDefinition : recordDefinition.getFields()) {
final boolean idField = fieldDefinition.isIdField();
if (!(hasRowIdField && idField)) {
if (first) {
first = false;
} else {
sqlBuffer.append(',');
}
if (idField && generatePrimaryKey) {
final String primaryKeySql = recordStore.getGeneratePrimaryKeySql(recordDefinition);
sqlBuffer.append(primaryKeySql);
} else {
((JdbcFieldDefinition) fieldDefinition).addInsertStatementPlaceHolder(sqlBuffer, generatePrimaryKey);
}
}
}
sqlBuffer.append(")");
if (this.sqlSuffix != null) {
sqlBuffer.append(this.sqlSuffix);
}
sql = sqlBuffer.toString();
sqlMap.put(recordDefinition, sql);
}
return sql;
}
use of com.revolsys.jdbc.field.JdbcFieldDefinition in project com.revolsys.open by revolsys.
the class JdbcRecordWriter method update.
private void update(final JdbcRecordDefinition recordDefinition, final Record record) throws SQLException {
flushIfRequired(recordDefinition);
PreparedStatement statement = this.typeUpdateStatementMap.get(recordDefinition);
if (statement == null) {
final String sql = getUpdateSql(recordDefinition);
try {
statement = this.connection.prepareStatement(sql);
this.typeUpdateStatementMap.put(recordDefinition, statement);
} catch (final SQLException e) {
LOG.error(sql, e);
}
}
int parameterIndex = 1;
for (final FieldDefinition fieldDefinition : recordDefinition.getFields()) {
if (!fieldDefinition.isIdField()) {
final JdbcFieldDefinition jdbcFieldDefinition = (JdbcFieldDefinition) fieldDefinition;
parameterIndex = jdbcFieldDefinition.setInsertPreparedStatementValue(statement, parameterIndex, record);
}
}
parameterIndex = setIdEqualsValues(statement, parameterIndex, recordDefinition, record);
statement.addBatch();
final Integer batchCount = Maps.addCount(this.typeUpdateBatchCountMap, recordDefinition);
if (batchCount >= this.batchSize) {
processCurrentBatch(recordDefinition, this.typeUpdateSqlMap, statement, this.typeUpdateBatchCountMap, this.typeUpdateRecords, false);
}
this.recordStore.addStatistic("Update", record);
}
use of com.revolsys.jdbc.field.JdbcFieldDefinition in project com.revolsys.open by revolsys.
the class JdbcQueryIterator method getNextRecord.
public static Record getNextRecord(final JdbcRecordStore recordStore, final RecordDefinition recordDefinition, final List<FieldDefinition> fields, final RecordFactory<Record> recordFactory, final ResultSet resultSet, final boolean internStrings) {
final Record record = recordFactory.newRecord(recordDefinition);
if (record != null) {
record.setState(RecordState.INITIALIZING);
int columnIndex = 1;
for (final FieldDefinition field : fields) {
final JdbcFieldDefinition jdbcField = (JdbcFieldDefinition) field;
try {
columnIndex = jdbcField.setFieldValueFromResultSet(resultSet, columnIndex, record, internStrings);
} catch (final SQLException e) {
throw new RuntimeException("Unable to get value " + (columnIndex + 1) + " from result set", e);
}
}
record.setState(RecordState.PERSISTED);
recordStore.addStatistic("query", record);
}
return record;
}
use of com.revolsys.jdbc.field.JdbcFieldDefinition in project com.revolsys.open by revolsys.
the class AbstractJdbcRecordStore method getField.
public JdbcFieldDefinition getField(final String schemaName, final String tableName, final String columnName) {
final String typePath = PathUtil.toPath(schemaName, tableName);
final RecordDefinition recordDefinition = getRecordDefinition(typePath);
if (recordDefinition == null) {
return null;
} else {
final FieldDefinition attribute = recordDefinition.getField(columnName);
return (JdbcFieldDefinition) attribute;
}
}
Aggregations