Search in sources :

Example 16 with Query

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

the class ModeAllPaged method loadPage.

private List<LayerRecord> loadPage(final int pageNumber) {
    final RecordLayerTableModel model = getTableModel();
    try {
        final Query query = model.getFilterQuery();
        if (query == null) {
            return Collections.emptyList();
        } else {
            query.setOffset(this.pageSize * pageNumber);
            query.setLimit(this.pageSize);
            return getRecordsLayer(query);
        }
    } finally {
        synchronized (this.loadingPageNumbers) {
            this.loadingPageNumbers.remove(pageNumber);
        }
    }
}
Also used : Query(com.revolsys.record.query.Query)

Example 17 with Query

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

the class RecordStoreLayerTest method testFilterRecordModifiedMatches.

@Test
public void testFilterRecordModifiedMatches() {
    final LayerRecord testRecord = testNewRecord();
    this.layer.saveChanges();
    assertRecordCounts(0, 1, 0, 0);
    testRecord.setValue("NAME", CHANGED_NAME);
    assertRecordState(testRecord, RecordState.MODIFIED);
    assertRecordCounts(0, 1, 1, 0);
    assertGetRecords(new Query(TEST).and(Q.equal("NAME", CHANGED_NAME)), 1);
    assertGetRecords(new Query(TEST).and(Q.equal("NAME", DEFAULT_NAME)), 0);
}
Also used : Query(com.revolsys.record.query.Query) NewProxyLayerRecord(com.revolsys.swing.map.layer.record.NewProxyLayerRecord) IdentifierProxyLayerRecord(com.revolsys.swing.map.layer.record.IdentifierProxyLayerRecord) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) Test(org.junit.Test)

Example 18 with Query

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

the class RecordHtmlUiBuilder method isPropertyUnique.

protected boolean isPropertyUnique(final Record object, final String fieldName) {
    final String value = object.getValue(fieldName);
    final RecordStore recordStore = getRecordStore();
    final RecordDefinition recordDefinition = recordStore.getRecordDefinition(this.tableName);
    if (recordDefinition == null) {
        return true;
    } else {
        final Query query = Query.equal(recordDefinition, fieldName, value);
        final Reader<Record> results = recordStore.getRecords(query);
        final List<Record> objects = results.toList();
        if (object.getState() == RecordState.NEW) {
            return objects.isEmpty();
        } else {
            final Identifier id = object.getIdentifier();
            for (final Iterator<Record> iterator = objects.iterator(); iterator.hasNext(); ) {
                final Record matchedObject = iterator.next();
                final Identifier matchedId = matchedObject.getIdentifier();
                if (DataType.equal(id, matchedId)) {
                    iterator.remove();
                }
            }
            return objects.isEmpty();
        }
    }
}
Also used : Identifier(com.revolsys.identifier.Identifier) Query(com.revolsys.record.query.Query) RecordStore(com.revolsys.record.schema.RecordStore) Record(com.revolsys.record.Record) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 19 with Query

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

the class CopyRecords method run.

@Override
public void run() {
    try {
        final Query query = this.sourceRecordStore.newQuery(this.typePath);
        query.setOrderBy(this.orderBy);
        try (final RecordReader reader = this.sourceRecordStore.getRecords(query);
            final RecordWriter targetWriter = this.targetRecordStore.newRecordWriter()) {
            final RecordDefinition targetRecordDefinition = this.targetRecordStore.getRecordDefinition(this.typePath);
            if (targetRecordDefinition == null) {
                Logs.error(this, "Cannot find target table: " + this.typePath);
            } else {
                if (this.hasSequence) {
                    final String idFieldName = targetRecordDefinition.getIdFieldName();
                    Identifier maxId = this.targetRecordStore.newPrimaryIdentifier(this.typePath);
                    for (final Record sourceRecord : reader) {
                        final Record targetRecord = this.targetRecordStore.newRecord(this.typePath, sourceRecord);
                        final Identifier sourceId = sourceRecord.getIdentifier(idFieldName);
                        while (CompareUtil.compare(maxId, sourceId) < 0) {
                            maxId = this.targetRecordStore.newPrimaryIdentifier(this.typePath);
                        }
                        targetWriter.write(targetRecord);
                    }
                } else {
                    for (final Record sourceRecord : reader) {
                        final Record targetRecord = this.targetRecordStore.newRecord(this.typePath, sourceRecord);
                        targetWriter.write(targetRecord);
                    }
                }
            }
        }
    } catch (final Throwable e) {
        throw new RuntimeException("Unable to copy records for " + this.typePath, e);
    }
}
Also used : RecordWriter(com.revolsys.record.io.RecordWriter) Identifier(com.revolsys.identifier.Identifier) Query(com.revolsys.record.query.Query) RecordReader(com.revolsys.record.io.RecordReader) Record(com.revolsys.record.Record) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 20 with Query

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

the class RecordLayerTableModel method forEachRecord.

public void forEachRecord(final Consumer<? super LayerRecord> action) {
    final TableRecordsMode tableRecordsMode = getTableRecordsMode();
    if (tableRecordsMode != null) {
        final Query query = getFilterQuery();
        try (BaseCloseable eventsDisabled = this.layer.eventsDisabled()) {
            tableRecordsMode.forEachRecord(query, action);
        }
        refresh();
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) Query(com.revolsys.record.query.Query)

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