Search in sources :

Example 26 with RecordDefinition

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

the class Query method setWhereCondition.

public Query setWhereCondition(final Condition whereCondition) {
    if (whereCondition == null) {
        this.whereCondition = Condition.ALL;
    } else {
        this.whereCondition = whereCondition;
        final RecordDefinition recordDefinition = getRecordDefinition();
        if (recordDefinition != null) {
            whereCondition.setRecordDefinition(recordDefinition);
        }
    }
    return this;
}
Also used : RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 27 with RecordDefinition

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

the class OracleJdbcQueryResultPager method updateResults.

/**
 * Update the cached results for the current page.
 */
@Override
protected void updateResults() {
    synchronized (this) {
        final JdbcRecordStore recordStore = getRecordStore();
        final Query query = getQuery();
        setNumResults(recordStore.getRecordCount(query));
        updateNumPages();
        final ArrayList<Record> results = new ArrayList<>();
        final int pageSize = getPageSize();
        final int pageNumber = getPageNumber();
        if (pageNumber != -1) {
            String sql = getSql();
            final int startRowNum = (pageNumber - 1) * pageSize + 1;
            final int endRowNum = startRowNum + pageSize - 1;
            sql = "SELECT * FROM ( SELECT  T2.*, ROWNUM TROWNUM FROM ( " + sql + ") T2 ) WHERE TROWNUM BETWEEN " + startRowNum + " AND " + endRowNum;
            try (final JdbcConnection connection = getRecordStore().getJdbcConnection()) {
                final RecordFactory<Record> recordFactory = getRecordFactory();
                final RecordDefinition recordDefinition = getRecordDefinition();
                final List<FieldDefinition> attributes = new ArrayList<>();
                final List<String> fieldNames = query.getFieldNames();
                if (fieldNames.isEmpty()) {
                    attributes.addAll(recordDefinition.getFields());
                } else {
                    for (final String fieldName : fieldNames) {
                        if (fieldName.equals("*")) {
                            attributes.addAll(recordDefinition.getFields());
                        } else {
                            final FieldDefinition attribute = recordDefinition.getField(fieldName);
                            if (attribute != null) {
                                attributes.add(attribute);
                            }
                        }
                    }
                }
                try (final PreparedStatement statement = connection.prepareStatement(sql);
                    final ResultSet resultSet = JdbcQueryIterator.getResultSet(statement, getQuery())) {
                    if (resultSet.next()) {
                        int i = 0;
                        do {
                            final Record record = JdbcQueryIterator.getNextRecord(recordStore, recordDefinition, attributes, recordFactory, resultSet, this.internStrings);
                            results.add(record);
                            i++;
                        } while (resultSet.next() && i < pageSize);
                    }
                } catch (final SQLException e) {
                    throw connection.getException("updateResults", sql, e);
                }
            }
            setResults(results);
        }
    }
}
Also used : Query(com.revolsys.record.query.Query) SQLException(java.sql.SQLException) JdbcRecordStore(com.revolsys.jdbc.io.JdbcRecordStore) FieldDefinition(com.revolsys.record.schema.FieldDefinition) ArrayList(java.util.ArrayList) JdbcConnection(com.revolsys.jdbc.JdbcConnection) PreparedStatement(java.sql.PreparedStatement) RecordDefinition(com.revolsys.record.schema.RecordDefinition) ResultSet(java.sql.ResultSet) Record(com.revolsys.record.Record)

Example 28 with RecordDefinition

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

the class OgrRecordStore method getSql.

protected String getSql(final Query query) {
    final RecordDefinition recordDefinition = query.getRecordDefinition();
    final String typePath = recordDefinition.getPath();
    final Map<? extends CharSequence, Boolean> orderBy = query.getOrderBy();
    final StringBuilder sql = new StringBuilder();
    sql.append("SELECT ");
    List<String> fieldNames = query.getFieldNames();
    if (fieldNames.isEmpty()) {
        fieldNames = recordDefinition.getFieldNames();
    }
    fieldNames.remove("ROWID");
    StringBuilders.append(sql, fieldNames);
    sql.append(" FROM ");
    final String layerName = getLayerName(typePath);
    sql.append(layerName);
    final StringBuilder whereClause = getWhereClause(query);
    if (whereClause.length() > 0) {
        sql.append(" WHERE ");
        sql.append(whereClause);
    }
    boolean first = true;
    for (final Entry<? extends CharSequence, Boolean> entry : orderBy.entrySet()) {
        final CharSequence fieldName = entry.getKey();
        if (first) {
            sql.append(" ORDER BY ");
            first = false;
        } else {
            sql.append(", ");
        }
        if (fieldName instanceof FieldDefinition) {
            final FieldDefinition field = (FieldDefinition) fieldName;
            field.appendColumnName(sql);
        } else {
            sql.append(fieldName);
        }
        final Boolean ascending = entry.getValue();
        if (!ascending) {
            sql.append(" DESC");
        }
    }
    return sql.toString();
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 29 with RecordDefinition

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

the class OgrRecordStore method newIterator.

@Override
public AbstractIterator<Record> newIterator(final Query query, final Map<String, Object> properties) {
    String typePath = query.getTypeName();
    RecordDefinition recordDefinition = query.getRecordDefinition();
    if (recordDefinition == null) {
        typePath = query.getTypeName();
        recordDefinition = getRecordDefinition(typePath);
        if (recordDefinition == null) {
            throw new IllegalArgumentException("Type name does not exist " + typePath);
        } else {
            query.setRecordDefinition(recordDefinition);
        }
    } else {
        typePath = recordDefinition.getPath();
    }
    final OgrQueryIterator iterator = new OgrQueryIterator(this, query);
    return iterator;
}
Also used : RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 30 with RecordDefinition

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

the class OgrRecordWriter method delete.

private void delete(final Record record) {
    final RecordDefinition recordDefinition = record.getRecordDefinition();
    final Layer layer = getLayer(recordDefinition);
    final String driverName = this.recordStore.getDriverName();
    if (OgrRecordStore.SQLITE.equals(driverName) || OgrRecordStore.GEO_PAKCAGE.equals(driverName)) {
        final Integer fid = record.getInteger(OgrRecordStore.ROWID);
        if (fid != null) {
            layer.DeleteFeature(fid);
        }
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) Layer(org.gdal.ogr.Layer) 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