Search in sources :

Example 1 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class RecordGraph method getTypeName.

/**
 * Get the type name for the edge.
 *
 * @param edge The edge.
 * @return The type name.
 */
@Override
public String getTypeName(final Edge<Record> edge) {
    final Record record = edge.getObject();
    if (record == null) {
        return null;
    } else {
        final RecordDefinition recordDefinition = record.getRecordDefinition();
        final String typePath = recordDefinition.getPath();
        return typePath;
    }
}
Also used : Record(com.revolsys.record.Record) LineString(com.revolsys.geometry.model.LineString) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 2 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class JdbcUtils method getSelectSql.

public static String getSelectSql(final Query query) {
    final String tableName = query.getTypeName();
    final String dbTableName = getQualifiedTableName(tableName);
    String sql = query.getSql();
    final Map<? extends CharSequence, Boolean> orderBy = query.getOrderBy();
    RecordDefinition recordDefinition = query.getRecordDefinition();
    if (sql == null) {
        if (recordDefinition == null) {
            recordDefinition = new RecordDefinitionImpl(PathName.newPathName(tableName));
        // throw new IllegalArgumentException("Unknown table name " +
        // tableName);
        }
        final List<String> fieldNames = new ArrayList<>(query.getFieldNames());
        if (fieldNames.isEmpty()) {
            final List<String> recordDefinitionFieldNames = recordDefinition.getFieldNames();
            if (recordDefinitionFieldNames.isEmpty()) {
                fieldNames.add("T.*");
            } else {
                fieldNames.addAll(recordDefinitionFieldNames);
            }
        }
        final String fromClause = query.getFromClause();
        final LockMode lockMode = query.getLockMode();
        final boolean distinct = query.isDistinct();
        sql = newSelectSql(recordDefinition, "T", distinct, fromClause, fieldNames, query, orderBy, lockMode);
    } else {
        if (sql.toUpperCase().startsWith("SELECT * FROM ")) {
            final StringBuilder newSql = new StringBuilder("SELECT ");
            addColumnNames(newSql, recordDefinition, dbTableName);
            newSql.append(" FROM ");
            newSql.append(sql.substring(14));
            sql = newSql.toString();
        }
        if (!orderBy.isEmpty()) {
            final StringBuilder buffer = new StringBuilder(sql);
            addOrderBy(buffer, orderBy);
            sql = buffer.toString();
        }
    }
    return sql;
}
Also used : ArrayList(java.util.ArrayList) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) LockMode(com.revolsys.record.schema.LockMode) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 3 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class JdbcUtils method appendWhere.

public static void appendWhere(final StringBuilder sql, final Query query) {
    final Condition where = query.getWhereCondition();
    if (!where.isEmpty()) {
        sql.append(" WHERE ");
        final RecordDefinition recordDefinition = query.getRecordDefinition();
        if (recordDefinition == null) {
            where.appendSql(query, null, sql);
        } else {
            final RecordStore recordStore = recordDefinition.getRecordStore();
            where.appendSql(query, recordStore, sql);
        }
    }
}
Also used : Condition(com.revolsys.record.query.Condition) JdbcRecordStore(com.revolsys.jdbc.io.JdbcRecordStore) RecordStore(com.revolsys.record.schema.RecordStore) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 4 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class RecordCodeTableValueFilter method test.

/**
 * Match the fieldName on the data object with the required value.
 *
 * @param object The object.
 * @return True if the object matched the filter, false otherwise.
 */
@Override
public boolean test(final Record object) {
    final Object propertyValue = object.getValue(this.fieldName);
    if (this.values.contains(propertyValue)) {
        return true;
    } else {
        final RecordDefinition recordDefinition = object.getRecordDefinition();
        final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(this.fieldName);
        if (codeTable != null) {
            final Object codeValue = codeTable.getValue(Identifier.newIdentifier(propertyValue));
            if (this.values.contains(codeValue)) {
                this.values.add(propertyValue);
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 5 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class AbstractJdbcRecordStore method getRecordDefinition.

@Override
public JdbcRecordDefinition getRecordDefinition(String typePath, final ResultSetMetaData resultSetMetaData, final String dbTableName) {
    if (Property.isEmpty(typePath)) {
        typePath = "Record";
    }
    try {
        final PathName pathName = PathName.newPathName(typePath);
        final PathName schemaName = pathName.getParent();
        final JdbcRecordStoreSchema schema = getSchema(schemaName);
        final JdbcRecordDefinition resultRecordDefinition = newRecordDefinition(schema, pathName, dbTableName);
        final RecordDefinition recordDefinition = getRecordDefinition(typePath);
        for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
            final String fieldName = resultSetMetaData.getColumnName(i).toUpperCase();
            if (recordDefinition != null && recordDefinition.isIdField(fieldName)) {
                resultRecordDefinition.setIdFieldIndex(i - 1);
            }
            addField(resultSetMetaData, resultRecordDefinition, fieldName, i, null);
        }
        addRecordDefinitionProperties(resultRecordDefinition);
        return resultRecordDefinition;
    } catch (final SQLException e) {
        throw new IllegalArgumentException("Unable to load metadata for " + typePath);
    }
}
Also used : SQLException(java.sql.SQLException) PathName(com.revolsys.io.PathName) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

RecordDefinition (com.revolsys.record.schema.RecordDefinition)189 FieldDefinition (com.revolsys.record.schema.FieldDefinition)38 Record (com.revolsys.record.Record)34 Geometry (com.revolsys.geometry.model.Geometry)20 CodeTable (com.revolsys.record.code.CodeTable)19 Query (com.revolsys.record.query.Query)18 LineString (com.revolsys.geometry.model.LineString)17 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)16 PathName (com.revolsys.io.PathName)13 ArrayList (java.util.ArrayList)12 DataType (com.revolsys.datatype.DataType)11 Identifier (com.revolsys.identifier.Identifier)11 RecordReader (com.revolsys.record.io.RecordReader)11 RecordStore (com.revolsys.record.schema.RecordStore)11 HashMap (java.util.HashMap)9 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)8 ArrayRecord (com.revolsys.record.ArrayRecord)8 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)6 Table (com.revolsys.gis.esri.gdb.file.capi.swig.Table)5 RecordWriter (com.revolsys.record.io.RecordWriter)5