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