use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class RecordStoreLayer method refreshDo.
@Override
protected void refreshDo() {
synchronized (getSync()) {
if (this.loadingWorker != null) {
this.loadingWorker.cancel(true);
}
this.loadedBoundingBox = BoundingBox.empty();
this.loadingBoundingBox = this.loadedBoundingBox;
super.refreshDo();
}
final RecordStore recordStore = getRecordStore();
final PathName pathName = getPathName();
final CodeTable codeTable = recordStore.getCodeTable(pathName);
if (codeTable != null) {
codeTable.refresh();
}
if (hasIdField()) {
final List<Identifier> identifiers = new ArrayList<>();
synchronized (getSync()) {
identifiers.addAll(this.recordsByIdentifier.keySet());
}
if (!identifiers.isEmpty()) {
identifiers.sort(Identifier.comparator());
final RecordDefinition recordDefinition = recordStore.getRecordDefinition(pathName);
final List<FieldDefinition> idFields = recordDefinition.getIdFields();
final int idFieldCount = idFields.size();
if (idFieldCount == 1) {
final FieldDefinition idField = idFields.get(0);
final int pageSize = 999;
final int identifierCount = identifiers.size();
for (int i = 0; i < identifiers.size(); i += pageSize) {
final List<Identifier> queryIdentifiers = identifiers.subList(i, Math.min(identifierCount, i + pageSize));
final In in = Q.in(idField, queryIdentifiers);
final Query query = new Query(recordDefinition, in);
updateCachedRecords(recordStore, query);
}
} else if (!idFields.isEmpty()) {
for (final Identifier identifier : identifiers) {
final Query query = new Query(recordDefinition, Q.equalId(idFields, identifier));
updateCachedRecords(recordStore, query);
}
}
}
}
}
use of com.revolsys.identifier.Identifier 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.identifier.Identifier in project com.revolsys.open by revolsys.
the class OsmOverpassLayer method getRecords.
@Override
public List<LayerRecord> getRecords(BoundingBox boundingBox) {
if (hasGeometryField()) {
boundingBox = convertBoundingBox(boundingBox);
if (Property.hasValue(boundingBox)) {
final Map<Identifier, LayerRecord> recordMap = new HashMap<>();
final List<BoundingBox> boundingBoxes = getTileBoundingBoxes(boundingBox);
for (final BoundingBox tileBoundingBox : boundingBoxes) {
final OsmDocument document = getTile(tileBoundingBox);
for (final OsmElement record : document.getRecords()) {
final Geometry geometry = record.getGeometry();
if (geometry != null && !geometry.isEmpty()) {
if (boundingBox.intersects(geometry.getBoundingBox())) {
final Identifier identifier = record.getIdentifier();
// final OsmProxyLayerRecord layerRecord = new
// OsmProxyLayerRecord(
// this, document, identifier);
// recordMap.put(identifier, layerRecord);
}
}
}
}
this.boundingBoxTileMap.keySet().retainAll(boundingBoxes);
return new ArrayList<>(recordMap.values());
}
}
return Collections.emptyList();
}
use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class AbstractRecordTableModel method toObjectValue.
public Object toObjectValue(final String fieldName, final Object displayValue) {
if (!Property.hasValue(displayValue)) {
return null;
}
final RecordDefinition recordDefinition = getRecordDefinition();
final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
if (codeTable == null) {
final FieldDefinition field = recordDefinition.getField(fieldName);
final Object recordValue = field.toFieldValue(displayValue);
return recordValue;
} else {
if (displayValue instanceof Identifier) {
final Identifier identifier = (Identifier) displayValue;
return identifier;
} else {
final Object objectValue = codeTable.getIdentifier(displayValue);
return objectValue;
}
}
}
use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method appendQueryValue.
@Override
public void appendQueryValue(final Query query, final StringBuilder buffer, final QueryValue condition) {
if (condition instanceof Like || condition instanceof ILike) {
final BinaryCondition like = (BinaryCondition) condition;
final QueryValue left = like.getLeft();
final QueryValue right = like.getRight();
buffer.append("UPPER(CAST(");
appendQueryValue(query, buffer, left);
buffer.append(" AS VARCHAR(4000))) LIKE ");
if (right instanceof Value) {
final Value valueCondition = (Value) right;
final Object value = valueCondition.getValue();
buffer.append("'");
if (value != null) {
final String string = DataTypes.toString(value);
buffer.append(string.toUpperCase().replaceAll("'", "''"));
}
buffer.append("'");
} else {
appendQueryValue(query, buffer, right);
}
} else if (condition instanceof LeftUnaryCondition) {
final LeftUnaryCondition unaryCondition = (LeftUnaryCondition) condition;
final String operator = unaryCondition.getOperator();
final QueryValue right = unaryCondition.getValue();
buffer.append(operator);
buffer.append(" ");
appendQueryValue(query, buffer, right);
} else if (condition instanceof RightUnaryCondition) {
final RightUnaryCondition unaryCondition = (RightUnaryCondition) condition;
final QueryValue left = unaryCondition.getValue();
final String operator = unaryCondition.getOperator();
appendQueryValue(query, buffer, left);
buffer.append(" ");
buffer.append(operator);
} else if (condition instanceof BinaryCondition) {
final BinaryCondition binaryCondition = (BinaryCondition) condition;
final QueryValue left = binaryCondition.getLeft();
final String operator = binaryCondition.getOperator();
final QueryValue right = binaryCondition.getRight();
appendQueryValue(query, buffer, left);
buffer.append(" ");
buffer.append(operator);
buffer.append(" ");
appendQueryValue(query, buffer, right);
} else if (condition instanceof AbstractMultiCondition) {
final AbstractMultiCondition multipleCondition = (AbstractMultiCondition) condition;
buffer.append("(");
boolean first = true;
final String operator = multipleCondition.getOperator();
for (final QueryValue subCondition : multipleCondition.getQueryValues()) {
if (first) {
first = false;
} else {
buffer.append(" ");
buffer.append(operator);
buffer.append(" ");
}
appendQueryValue(query, buffer, subCondition);
}
buffer.append(")");
} else if (condition instanceof In) {
final In in = (In) condition;
if (in.isEmpty()) {
buffer.append("1==0");
} else {
final QueryValue left = in.getLeft();
appendQueryValue(query, buffer, left);
buffer.append(" IN (");
appendQueryValue(query, buffer, in.getValues());
buffer.append(")");
}
} else if (condition instanceof Value) {
final Value valueCondition = (Value) condition;
Object value = valueCondition.getValue();
if (value instanceof Identifier) {
final Identifier identifier = (Identifier) value;
value = identifier.getValue(0);
}
appendValue(buffer, value);
} else if (condition instanceof CollectionValue) {
final CollectionValue collectionValue = (CollectionValue) condition;
final List<Object> values = collectionValue.getValues();
boolean first = true;
for (final Object value : values) {
if (first) {
first = false;
} else {
buffer.append(", ");
}
appendValue(buffer, value);
}
} else if (condition instanceof Column) {
final Column column = (Column) condition;
final Object name = column.getName();
buffer.append(name);
} else if (condition instanceof SqlCondition) {
final SqlCondition sqlCondition = (SqlCondition) condition;
final String where = sqlCondition.getSql();
final List<Object> parameters = sqlCondition.getParameterValues();
if (parameters.isEmpty()) {
if (where.indexOf('?') > -1) {
throw new IllegalArgumentException("No arguments specified for a where clause with placeholders: " + where);
} else {
buffer.append(where);
}
} else {
final Matcher matcher = PLACEHOLDER_PATTERN.matcher(where);
int i = 0;
while (matcher.find()) {
if (i >= parameters.size()) {
throw new IllegalArgumentException("Not enough arguments for where clause with placeholders: " + where);
}
final Object argument = parameters.get(i);
final StringBuffer replacement = new StringBuffer();
matcher.appendReplacement(replacement, DataTypes.toString(argument));
buffer.append(replacement);
appendValue(buffer, argument);
i++;
}
final StringBuffer tail = new StringBuffer();
matcher.appendTail(tail);
buffer.append(tail);
}
} else if (condition instanceof EnvelopeIntersects) {
buffer.append("1 = 1");
} else if (condition instanceof WithinDistance) {
buffer.append("1 = 1");
} else {
condition.appendDefaultSql(query, this, buffer);
}
}
Aggregations