use of com.revolsys.jdbc.field.JdbcFieldDefinition in project com.revolsys.open by revolsys.
the class JdbcUtils method addSelectColumnName.
public static void addSelectColumnName(final StringBuilder sql, final String tablePrefix, final FieldDefinition fieldDefinition) {
if (fieldDefinition instanceof JdbcFieldDefinition) {
final JdbcFieldDefinition jdbcFieldDefinition = (JdbcFieldDefinition) fieldDefinition;
jdbcFieldDefinition.appendSelectColumnName(sql, tablePrefix);
} else {
sql.append(fieldDefinition.getName());
}
}
use of com.revolsys.jdbc.field.JdbcFieldDefinition in project com.revolsys.open by revolsys.
the class JdbcUtils method setPreparedStatementParameters.
public static void setPreparedStatementParameters(final PreparedStatement statement, final Query query) {
int index = 1;
for (final Object parameter : query.getParameters()) {
final JdbcFieldDefinition attribute = JdbcFieldDefinition.newFieldDefinition(parameter);
try {
index = attribute.setPreparedStatementValue(statement, index, parameter);
} catch (final SQLException e) {
throw new RuntimeException("Error setting value:" + parameter, e);
}
}
final Condition where = query.getWhereCondition();
if (!where.isEmpty()) {
where.appendParameters(index, statement);
}
}
use of com.revolsys.jdbc.field.JdbcFieldDefinition in project com.revolsys.open by revolsys.
the class JdbcRecordWriter method getUpdateSql.
private String getUpdateSql(final JdbcRecordDefinition recordDefinition) {
final List<FieldDefinition> idFields = recordDefinition.getIdFields();
if (idFields.isEmpty()) {
throw new RuntimeException("No primary key found for: " + recordDefinition);
} else {
final String tableName = recordDefinition.getDbTableQualifiedName();
String sql = this.typeUpdateSqlMap.get(recordDefinition);
if (sql == null) {
final StringBuilder sqlBuffer = new StringBuilder();
if (this.sqlPrefix != null) {
sqlBuffer.append(this.sqlPrefix);
}
sqlBuffer.append("update ");
sqlBuffer.append(tableName);
sqlBuffer.append(" set ");
boolean first = true;
for (final FieldDefinition fieldDefinition : recordDefinition.getFields()) {
if (!idFields.contains(fieldDefinition)) {
final JdbcFieldDefinition jdbcFieldDefinition = (JdbcFieldDefinition) fieldDefinition;
if (first) {
first = false;
} else {
sqlBuffer.append(", ");
}
jdbcFieldDefinition.appendColumnName(sqlBuffer, this.quoteColumnNames);
sqlBuffer.append(" = ");
jdbcFieldDefinition.addInsertStatementPlaceHolder(sqlBuffer, false);
}
}
sqlBuffer.append(" where ");
appendIdEquals(sqlBuffer, idFields);
sqlBuffer.append(" ");
if (this.sqlSuffix != null) {
sqlBuffer.append(this.sqlSuffix);
}
sql = sqlBuffer.toString();
this.typeUpdateSqlMap.put(recordDefinition, sql);
}
return sql;
}
}
use of com.revolsys.jdbc.field.JdbcFieldDefinition in project com.revolsys.open by revolsys.
the class JdbcRecordWriter method setIdEqualsValues.
private int setIdEqualsValues(final PreparedStatement statement, int parameterIndex, final JdbcRecordDefinition recordDefinition, final Record record) throws SQLException {
for (final FieldDefinition idField : recordDefinition.getIdFields()) {
final Object value = record.getValue(idField);
parameterIndex = ((JdbcFieldDefinition) idField).setPreparedStatementValue(statement, parameterIndex++, value);
}
return parameterIndex;
}
use of com.revolsys.jdbc.field.JdbcFieldDefinition 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);
}
}
Aggregations