use of com.revolsys.record.query.Query in project com.revolsys.open by revolsys.
the class CodeTableProperty method loadId.
@Override
protected synchronized Identifier loadId(final List<Object> values, final boolean createId) {
if (this.loadAll && !this.loadMissingCodes && !isEmpty()) {
return null;
}
Identifier id = null;
if (createId && this.loadAll && !isLoaded()) {
loadAll();
id = getIdentifier(values, false);
} else {
final Query query = new Query(this.typePath);
final And and = new And();
if (!values.isEmpty()) {
int i = 0;
for (final String fieldName : this.valueFieldNames) {
final Object value = values.get(i);
if (value == null) {
and.and(Q.isNull(fieldName));
} else {
final FieldDefinition fieldDefinition = this.recordDefinition.getField(fieldName);
and.and(Q.equal(fieldDefinition, value));
}
i++;
}
}
query.setWhereCondition(and);
final Reader<Record> reader = this.recordStore.getRecords(query);
try {
final List<Record> codes = reader.toList();
if (codes.size() > 0) {
final CategoryLabelCountMap statistics = this.recordStore.getStatistics();
if (statistics != null) {
statistics.getLabelCountMap("query").addCount(this.typePath, -codes.size());
}
addValues(codes);
}
id = getIdByValue(values);
Property.firePropertyChange(this, "valuesChanged", false, true);
} finally {
reader.close();
}
}
if (createId && id == null) {
return newIdentifier(values);
} else {
return id;
}
}
use of com.revolsys.record.query.Query in project com.revolsys.open by revolsys.
the class RecordStoreQueryTask method run.
@Override
public void run() {
this.objects = new ArrayList<>();
final RecordDefinition recordDefinition = this.recordStore.getRecordDefinition(this.path);
final Query query = Query.intersects(recordDefinition, this.boundingBox);
try (final Reader<Record> reader = this.recordStore.getRecords(query)) {
for (final Record object : reader) {
try {
this.objects.add(object);
} catch (final NullPointerException e) {
return;
}
}
}
}
use of com.revolsys.record.query.Query in project com.revolsys.open by revolsys.
the class RecordStore method newGetRecordQuery.
default Query newGetRecordQuery(final PathName typePath, final Identifier id) {
final RecordDefinition recordDefinition = getRecordDefinition(typePath);
if (recordDefinition == null || id == null) {
return null;
} else {
final List<Object> values = id.getValues();
final List<String> idFieldNames = recordDefinition.getIdFieldNames();
if (idFieldNames.isEmpty()) {
throw new IllegalArgumentException(typePath + " does not have a primary key");
} else if (values.size() != idFieldNames.size()) {
throw new IllegalArgumentException(id + " not a valid id for " + typePath + " requires " + idFieldNames);
} else {
final Query query = new Query(recordDefinition);
for (int i = 0; i < idFieldNames.size(); i++) {
final String name = idFieldNames.get(i);
final Object value = values.get(i);
final FieldDefinition field = recordDefinition.getField(name);
query.and(Q.equal(field, value));
}
return query;
}
}
}
use of com.revolsys.record.query.Query in project com.revolsys.open by revolsys.
the class RecordStore method getRecordLocked.
default Record getRecordLocked(final PathName typePath, final LockMode lockMode, final Identifier id) {
final Query query = newGetRecordQuery(typePath, id);
if (query == null) {
return null;
} else {
query.setLockMode(lockMode);
final RecordReader records = getRecords(query);
return records.getFirst();
}
}
use of com.revolsys.record.query.Query in project com.revolsys.open by revolsys.
the class RecordStore method getRecords.
default RecordReader getRecords(final PathName path) {
final RecordStoreSchemaElement element = getRootSchema().getElement(path);
if (element instanceof RecordDefinition) {
final RecordDefinition recordDefinition = (RecordDefinition) element;
final Query query = new Query(recordDefinition);
return getRecords(query);
} else if (element instanceof RecordStoreSchema) {
final RecordStoreSchema schema = (RecordStoreSchema) element;
final List<Query> queries = new ArrayList<>();
for (final RecordDefinition recordDefinition : schema.getRecordDefinitions()) {
final Query query = new Query(recordDefinition);
queries.add(query);
}
return getRecords(queries);
} else {
return new ListRecordReader(null, Collections.emptyList());
}
}
Aggregations