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;
}
}
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);
}
}
}
}
}
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;
}
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);
}
}
}
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);
}
Aggregations