Search in sources :

Example 26 with Query

use of com.revolsys.record.query.Query in project com.revolsys.open by revolsys.

the class RecordStoreLayer method getRecordsPersisted.

protected List<LayerRecord> getRecordsPersisted(final BoundingBox boundingBox) {
    final RecordDefinition recordDefinition = getInternalRecordDefinition();
    final Query query = Query.intersects(recordDefinition, boundingBox);
    return getRecords(query);
}
Also used : Query(com.revolsys.record.query.Query) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 27 with Query

use of com.revolsys.record.query.Query in project com.revolsys.open by revolsys.

the class RecordStoreLayer method getCachedRecord.

@SuppressWarnings("unchecked")
@Override
protected <R extends LayerRecord> R getCachedRecord(final Identifier identifier) {
    final RecordDefinition recordDefinition = getInternalRecordDefinition();
    synchronized (getSync()) {
        LayerRecord record = this.recordsByIdentifier.get(identifier);
        if (record == null) {
            final List<String> idFieldNames = recordDefinition.getIdFieldNames();
            if (idFieldNames.isEmpty()) {
                return null;
            } else {
                final Condition where = getCachedRecordQuery(idFieldNames, identifier);
                final Query query = new Query(recordDefinition, where);
                final RecordStore recordStore = this.recordStore;
                if (recordStore != null) {
                    try (Transaction transaction = recordStore.newTransaction(Propagation.REQUIRED);
                        RecordReader reader = newRecordStoreRecordReader(query)) {
                        record = reader.getFirst();
                        if (record != null) {
                            addCachedRecord(identifier, record);
                        }
                    }
                }
            }
        }
        return (R) record;
    }
}
Also used : Condition(com.revolsys.record.query.Condition) Query(com.revolsys.record.query.Query) Transaction(com.revolsys.transaction.Transaction) RecordStore(com.revolsys.record.schema.RecordStore) RecordReader(com.revolsys.record.io.RecordReader) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 28 with Query

use of com.revolsys.record.query.Query in project com.revolsys.open by revolsys.

the class RecordStoreLayer method getRecordCountPersisted.

@Override
public int getRecordCountPersisted() {
    if (isExists()) {
        final RecordDefinition recordDefinition = getRecordDefinition();
        final Query query = new Query(recordDefinition);
        return getRecordCountPersisted(query);
    }
    return 0;
}
Also used : Query(com.revolsys.record.query.Query) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 29 with Query

use of com.revolsys.record.query.Query in project com.revolsys.open by revolsys.

the class ModeAllPaged method getRecordCount.

@Override
public int getRecordCount() {
    synchronized (this) {
        if (this.persistedRecordCount < 0) {
            if (this.recordCountWorker == null) {
                final long refreshIndex = getRefreshIndexNext();
                final AbstractRecordLayer layer = getLayer();
                this.recordCountWorker = Invoke.background("Query row count " + layer.getName(), this::getRecordCountPersisted, (rowCount) -> {
                    if (canRefreshFinish(refreshIndex)) {
                        this.persistedRecordCount = rowCount;
                        this.recordCountWorker = null;
                        fireTableDataChanged();
                    }
                });
            }
            return 0;
        } else {
            int count = super.getRecordCount();
            count += this.persistedRecordCount;
            return count;
        }
    }
}
Also used : AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) LruMap(com.revolsys.collection.map.LruMap) Icons(com.revolsys.swing.Icons) Condition(com.revolsys.record.query.Condition) Set(java.util.Set) Property(com.revolsys.util.Property) Icon(javax.swing.Icon) Record(com.revolsys.record.Record) Logs(com.revolsys.logging.Logs) Invoke(com.revolsys.swing.parallel.Invoke) Consumer(java.util.function.Consumer) List(java.util.List) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) Predicates(com.revolsys.predicate.Predicates) Map(java.util.Map) SwingWorker(javax.swing.SwingWorker) Comparator(java.util.Comparator) Collections(java.util.Collections) LinkedHashSet(java.util.LinkedHashSet) Query(com.revolsys.record.query.Query) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer)

Example 30 with Query

use of com.revolsys.record.query.Query in project com.revolsys.open by revolsys.

the class Records method copyRecords.

static void copyRecords(final RecordStore sourceRecordStore, final String sourceTableName, final RecordStore targetRecordStore, final String targetTableName, final BiConsumer<Record, Record> recordEditor) {
    final Query query = new Query(sourceTableName);
    try (RecordReader reader = sourceRecordStore.getRecords(query);
        RecordWriter writer = targetRecordStore.newRecordWriter()) {
        final RecordDefinition recordDefinition = targetRecordStore.getRecordDefinition(targetTableName);
        for (final Record record : reader) {
            final Record newRecord = recordDefinition.newRecord();
            newRecord.setValuesAll(record);
            recordEditor.accept(record, newRecord);
            writer.write(newRecord);
        }
    }
}
Also used : RecordWriter(com.revolsys.record.io.RecordWriter) Query(com.revolsys.record.query.Query) RecordReader(com.revolsys.record.io.RecordReader) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

Query (com.revolsys.record.query.Query)32 RecordDefinition (com.revolsys.record.schema.RecordDefinition)18 Record (com.revolsys.record.Record)10 FieldDefinition (com.revolsys.record.schema.FieldDefinition)8 Condition (com.revolsys.record.query.Condition)6 RecordReader (com.revolsys.record.io.RecordReader)5 Identifier (com.revolsys.identifier.Identifier)4 ArrayList (java.util.ArrayList)4 RecordWriter (com.revolsys.record.io.RecordWriter)3 RecordStore (com.revolsys.record.schema.RecordStore)3 JdbcRecordStore (com.revolsys.jdbc.io.JdbcRecordStore)2 ListRecordReader (com.revolsys.record.io.ListRecordReader)2 BinaryCondition (com.revolsys.record.query.BinaryCondition)2 SqlCondition (com.revolsys.record.query.SqlCondition)2 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)2 CategoryLabelCountMap (com.revolsys.util.count.CategoryLabelCountMap)2 List (java.util.List)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 LruMap (com.revolsys.collection.map.LruMap)1