Search in sources :

Example 46 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class RecordStoreLayer method updateCachedRecords.

private void updateCachedRecords(final RecordStore recordStore, final Query query) {
    try (Transaction transaction = recordStore.newTransaction(Propagation.REQUIRES_NEW);
        RecordReader reader = recordStore.getRecords(query)) {
        for (final Record record : reader) {
            final Identifier identifier = record.getIdentifier();
            final RecordStoreLayerRecord cachedRecord = this.recordsByIdentifier.get(identifier);
            if (cachedRecord != null) {
                cachedRecord.refreshFromRecordStore(record);
            }
        }
    }
}
Also used : Identifier(com.revolsys.identifier.Identifier) Transaction(com.revolsys.transaction.Transaction) RecordReader(com.revolsys.record.io.RecordReader) Record(com.revolsys.record.Record)

Example 47 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class RecordStoreLayer method getRecordsCached.

@Override
public List<LayerRecord> getRecordsCached(final Label cacheId) {
    synchronized (getSync()) {
        final List<LayerRecord> records = super.getRecordsCached(cacheId);
        final Set<Identifier> recordIds = this.recordIdentifiersByCacheId.get(cacheId);
        if (recordIds != null) {
            for (final Identifier recordId : recordIds) {
                final LayerRecord record = getRecordById(recordId);
                if (record != null) {
                    records.add(record);
                }
            }
        }
        return records;
    }
}
Also used : Identifier(com.revolsys.identifier.Identifier)

Example 48 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class Record method setValueByPath.

@SuppressWarnings("rawtypes")
default boolean setValueByPath(final CharSequence path, final Object value) {
    boolean updated = false;
    final String name = path.toString();
    final int dotIndex = name.indexOf(".");
    String codeTableFieldName;
    String codeTableValueName = null;
    final RecordDefinition recordDefinition = getRecordDefinition();
    if (dotIndex == -1) {
        if (recordDefinition.isIdField(name)) {
            codeTableFieldName = null;
        } else {
            codeTableFieldName = name;
        }
    } else {
        codeTableFieldName = name.substring(0, dotIndex);
        codeTableValueName = name.substring(dotIndex + 1);
    }
    final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(codeTableFieldName);
    if (codeTable == null) {
        if (dotIndex != -1) {
            Logs.debug(this, "Cannot get code table for " + recordDefinition.getPath() + "." + name);
            return false;
        }
        updated = setValue(name, value);
    } else if (!Property.hasValue(value)) {
        updated = setValue(codeTableFieldName, null);
    } else {
        Object targetValue;
        if (codeTableValueName == null) {
            Identifier id;
            if (value instanceof List) {
                final List list = (List) value;
                id = codeTable.getIdentifier(list.toArray());
            } else {
                id = codeTable.getIdentifier(value);
            }
            if (id == null) {
                targetValue = value;
            } else {
                targetValue = Value.getValue(id);
            }
        } else {
            targetValue = codeTable.getIdentifier(Collections.singletonMap(codeTableValueName, value));
        }
        if (targetValue == null) {
            targetValue = value;
        }
        updated = setValue(codeTableFieldName, targetValue);
    }
    return updated;
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) TypedIdentifier(com.revolsys.identifier.TypedIdentifier) Identifier(com.revolsys.identifier.Identifier) ListIdentifier(com.revolsys.identifier.ListIdentifier) ArrayList(java.util.ArrayList) List(java.util.List) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 49 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class Record method setIdentifier.

default void setIdentifier(final Identifier identifier) {
    final RecordDefinition recordDefinition = getRecordDefinition();
    final RecordState state = getState();
    if (state == RecordState.NEW || state == RecordState.INITIALIZING) {
        final List<String> idFieldNames = recordDefinition.getIdFieldNames();
        Identifier.setIdentifier(this, idFieldNames, identifier);
    } else {
        final Identifier oldIdentifier = getIdentifier();
        if (!DataTypes.IDENTIFIER.equals(oldIdentifier, identifier)) {
            throw new IllegalStateException("Cannot change the ID on a persisted record: " + identifier + "!=" + oldIdentifier);
        }
    }
}
Also used : TypedIdentifier(com.revolsys.identifier.TypedIdentifier) Identifier(com.revolsys.identifier.Identifier) ListIdentifier(com.revolsys.identifier.ListIdentifier) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 50 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class CodeTable method getValues.

default <V> List<V> getValues() {
    final List<V> values = new ArrayList<>();
    for (final Identifier identifier : getIdentifiers()) {
        final V value = getValue(identifier);
        values.add(value);
    }
    return values;
}
Also used : Identifier(com.revolsys.identifier.Identifier) ArrayList(java.util.ArrayList)

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