Search in sources :

Example 71 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class RecordStoreLayer method newLayerRecord.

@Override
public LayerRecord newLayerRecord(final Map<String, ? extends Object> values) {
    if (!isReadOnly() && isEditable() && isCanAddRecords()) {
        final RecordDefinition recordDefinition = getRecordDefinition();
        final ArrayLayerRecord newRecord = new RecordStoreLayerRecord(this);
        if (values != null) {
            newRecord.setState(RecordState.INITIALIZING);
            final List<FieldDefinition> idFields = recordDefinition.getIdFields();
            for (final FieldDefinition fieldDefinition : recordDefinition.getFields()) {
                if (!idFields.contains(fieldDefinition)) {
                    final String fieldName = fieldDefinition.getName();
                    final Object value = values.get(fieldName);
                    fieldDefinition.setValue(newRecord, value);
                }
            }
            newRecord.setState(RecordState.NEW);
        }
        addRecordToCache(getCacheIdNew(), newRecord);
        if (isEventsEnabled()) {
            cleanCachedRecords();
        }
        final LayerRecord proxyRecord = new NewProxyLayerRecord(this, newRecord);
        fireRecordInserted(proxyRecord);
        return proxyRecord;
    } else {
        return null;
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 72 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition 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 73 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class AbstractRecordLayer method getPasteNewValues.

public Map<String, Object> getPasteNewValues(final Record sourceRecord) {
    final RecordDefinition recordDefinition = getRecordDefinition();
    final Set<String> ignoreFieldNames = getIgnorePasteFieldNames();
    final Map<String, Object> newValues = new LinkedHashMap<>();
    for (final String fieldName : recordDefinition.getFieldNames()) {
        if (!ignoreFieldNames.contains(fieldName)) {
            final Object value = sourceRecord.getValue(fieldName);
            if (value != null) {
                newValues.put(fieldName, value);
            }
        }
    }
    final FieldDefinition geometryFieldDefinition = recordDefinition.getGeometryField();
    if (geometryFieldDefinition != null) {
        final GeometryFactory geometryFactory = getGeometryFactory();
        Geometry sourceGeometry = sourceRecord.getGeometry();
        final String geometryFieldName = geometryFieldDefinition.getName();
        if (sourceGeometry == null) {
            final Object value = sourceRecord.getValue(geometryFieldName);
            sourceGeometry = geometryFieldDefinition.toFieldValue(value);
        }
        Geometry geometry = geometryFieldDefinition.toFieldValue(sourceGeometry);
        if (geometry == null) {
            if (sourceGeometry != null) {
                newValues.put(geometryFieldName, sourceGeometry);
            }
        } else {
            geometry = geometry.convertGeometry(geometryFactory);
            newValues.put(geometryFieldName, geometry);
        }
    }
    return newValues;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) FieldDefinition(com.revolsys.record.schema.FieldDefinition) LineString(com.revolsys.geometry.model.LineString) RecordDefinition(com.revolsys.record.schema.RecordDefinition) LinkedHashMap(java.util.LinkedHashMap)

Example 74 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class AbstractRecordLayer method exportRecords.

public void exportRecords(final Iterable<LayerRecord> records, final Predicate<? super LayerRecord> filter, final Map<? extends CharSequence, Boolean> orderBy, final Object target) {
    if (Property.hasValue(records) && target != null) {
        final List<LayerRecord> exportRecords = Lists.toArray(records);
        Records.filterAndSort(exportRecords, filter, orderBy);
        if (!exportRecords.isEmpty()) {
            final RecordDefinition recordDefinition = getRecordDefinition();
            RecordIo.copyRecords(recordDefinition, exportRecords, target);
        }
    }
}
Also used : RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 75 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class AbstractRecordLayer method getQuery.

public final Query getQuery() {
    final RecordDefinition recordDefinition = getRecordDefinition();
    final Condition whereCondition = getFilter();
    return new Query(recordDefinition, whereCondition);
}
Also used : Condition(com.revolsys.record.query.Condition) Query(com.revolsys.record.query.Query) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

RecordDefinition (com.revolsys.record.schema.RecordDefinition)189 FieldDefinition (com.revolsys.record.schema.FieldDefinition)38 Record (com.revolsys.record.Record)34 Geometry (com.revolsys.geometry.model.Geometry)20 CodeTable (com.revolsys.record.code.CodeTable)19 Query (com.revolsys.record.query.Query)18 LineString (com.revolsys.geometry.model.LineString)17 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)16 PathName (com.revolsys.io.PathName)13 ArrayList (java.util.ArrayList)12 DataType (com.revolsys.datatype.DataType)11 Identifier (com.revolsys.identifier.Identifier)11 RecordReader (com.revolsys.record.io.RecordReader)11 RecordStore (com.revolsys.record.schema.RecordStore)11 HashMap (java.util.HashMap)9 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)8 ArrayRecord (com.revolsys.record.ArrayRecord)8 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)6 Table (com.revolsys.gis.esri.gdb.file.capi.swig.Table)5 RecordWriter (com.revolsys.record.io.RecordWriter)5