Search in sources :

Example 26 with Identifier

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);
                }
            }
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) Identifier(com.revolsys.identifier.Identifier) Query(com.revolsys.record.query.Query) In(com.revolsys.record.query.In) RecordStore(com.revolsys.record.schema.RecordStore) FieldDefinition(com.revolsys.record.schema.FieldDefinition) ArrayList(java.util.ArrayList) PathName(com.revolsys.io.PathName) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 27 with Identifier

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();
        }
    }
}
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 28 with Identifier

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();
}
Also used : OsmElement(com.revolsys.record.io.format.openstreetmap.model.OsmElement) Geometry(com.revolsys.geometry.model.Geometry) Identifier(com.revolsys.identifier.Identifier) HashMap(java.util.HashMap) BoundingBox(com.revolsys.geometry.model.BoundingBox) ArrayList(java.util.ArrayList) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) OsmDocument(com.revolsys.record.io.format.openstreetmap.model.OsmDocument)

Example 29 with Identifier

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;
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) Identifier(com.revolsys.identifier.Identifier) FieldDefinition(com.revolsys.record.schema.FieldDefinition) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 30 with Identifier

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);
    }
}
Also used : In(com.revolsys.record.query.In) Matcher(java.util.regex.Matcher) ILike(com.revolsys.record.query.ILike) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) QueryValue(com.revolsys.record.query.QueryValue) SqlCondition(com.revolsys.record.query.SqlCondition) RightUnaryCondition(com.revolsys.record.query.RightUnaryCondition) CollectionValue(com.revolsys.record.query.CollectionValue) Like(com.revolsys.record.query.Like) ILike(com.revolsys.record.query.ILike) Identifier(com.revolsys.identifier.Identifier) SingleIdentifier(com.revolsys.identifier.SingleIdentifier) BinaryCondition(com.revolsys.record.query.BinaryCondition) Column(com.revolsys.record.query.Column) EnvelopeIntersects(com.revolsys.record.query.functions.EnvelopeIntersects) WithinDistance(com.revolsys.record.query.functions.WithinDistance) CollectionValue(com.revolsys.record.query.CollectionValue) Value(com.revolsys.record.query.Value) QueryValue(com.revolsys.record.query.QueryValue) List(java.util.List) LeftUnaryCondition(com.revolsys.record.query.LeftUnaryCondition) AbstractMultiCondition(com.revolsys.record.query.AbstractMultiCondition)

Aggregations

Identifier (com.revolsys.identifier.Identifier)56 Record (com.revolsys.record.Record)17 ArrayList (java.util.ArrayList)12 RecordDefinition (com.revolsys.record.schema.RecordDefinition)11 SingleIdentifier (com.revolsys.identifier.SingleIdentifier)8 ListIdentifier (com.revolsys.identifier.ListIdentifier)7 TypedIdentifier (com.revolsys.identifier.TypedIdentifier)6 CodeTable (com.revolsys.record.code.CodeTable)6 RecordReader (com.revolsys.record.io.RecordReader)5 RecordStore (com.revolsys.record.schema.RecordStore)5 Transaction (com.revolsys.transaction.Transaction)5 List (java.util.List)5 Geometry (com.revolsys.geometry.model.Geometry)4 BaseCloseable (com.revolsys.io.BaseCloseable)4 PathName (com.revolsys.io.PathName)4 ArrayRecord (com.revolsys.record.ArrayRecord)4 Query (com.revolsys.record.query.Query)4 OsmElement (com.revolsys.record.io.format.openstreetmap.model.OsmElement)3 FieldDefinition (com.revolsys.record.schema.FieldDefinition)3 CompoundCoordinateSystem (com.revolsys.geometry.cs.CompoundCoordinateSystem)2