Search in sources :

Example 16 with JdbcFieldDefinition

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

the class AbstractJdbcRecordStore method addRowIdFieldDefinition.

/**
 * Add a new field definition for record definitions that don't have a primary key.
 *
 * @param recordDefinition
 */
protected void addRowIdFieldDefinition(final RecordDefinitionImpl recordDefinition) {
    final Object tableType = recordDefinition.getProperty("tableType");
    if ("TABLE".equals(tableType)) {
        final JdbcFieldDefinition idFieldDefinition = newRowIdFieldDefinition();
        if (idFieldDefinition != null) {
            recordDefinition.addField(idFieldDefinition);
            final String idFieldName = idFieldDefinition.getName();
            recordDefinition.setIdFieldName(idFieldName);
        }
    }
}
Also used : JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition)

Example 17 with JdbcFieldDefinition

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

the class SqlCondition method appendParameters.

@Override
public int appendParameters(int index, final PreparedStatement statement) {
    for (int i = 0; i < this.parameterValues.size(); i++) {
        final Object value = this.parameterValues.get(i);
        JdbcFieldDefinition jdbcAttribute = null;
        if (i < this.parameterAttributes.size()) {
            final FieldDefinition attribute = this.parameterAttributes.get(i);
            if (attribute instanceof JdbcFieldDefinition) {
                jdbcAttribute = (JdbcFieldDefinition) attribute;
            }
        }
        if (jdbcAttribute == null) {
            jdbcAttribute = JdbcFieldDefinition.newFieldDefinition(value);
        }
        try {
            index = jdbcAttribute.setPreparedStatementValue(statement, index, value);
        } catch (final SQLException e) {
            throw new RuntimeException("Unable to set value: " + value, e);
        }
    }
    return index;
}
Also used : JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) SQLException(java.sql.SQLException) FieldDefinition(com.revolsys.record.schema.FieldDefinition) JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition)

Example 18 with JdbcFieldDefinition

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

the class PostgreSQLRecordStore method addField.

@Override
protected JdbcFieldDefinition addField(final JdbcRecordDefinition recordDefinition, final String dbColumnName, final String name, final String dbDataType, final int sqlType, final int length, final int scale, final boolean required, final String description) {
    final JdbcFieldDefinition field;
    if (dbDataType.charAt(0) == '_') {
        final String elementDbDataType = dbDataType.substring(1);
        final JdbcFieldAdder fieldAdder = getFieldAdder(elementDbDataType);
        final JdbcFieldDefinition elementField = fieldAdder.newField(this, recordDefinition, dbColumnName, name, elementDbDataType, sqlType, length, scale, required, description);
        final DataType elementDataType = elementField.getDataType();
        final CollectionDataType listDataType = new CollectionDataType("List" + elementDataType.getName(), List.class, elementDataType);
        field = new PostgreSQLArrayFieldDefinition(dbColumnName, name, listDataType, sqlType, length, scale, required, description, elementField, getProperties());
        recordDefinition.addField(field);
    } else {
        field = super.addField(recordDefinition, dbColumnName, name, dbDataType, sqlType, length, scale, required, description);
    }
    if (!dbColumnName.matches("[a-z_]+")) {
        field.setQuoteName(true);
    }
    return field;
}
Also used : JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) CollectionDataType(com.revolsys.datatype.CollectionDataType) PostgreSQLArrayFieldDefinition(com.revolsys.gis.postgresql.type.PostgreSQLArrayFieldDefinition) CollectionDataType(com.revolsys.datatype.CollectionDataType) DataType(com.revolsys.datatype.DataType) JdbcFieldAdder(com.revolsys.jdbc.field.JdbcFieldAdder)

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