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);
}
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;
}
}
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;
}
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;
}
}
}
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);
}
}
}
Aggregations