Search in sources :

Example 36 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class AbstractRecordLayer method cancelChanges.

public void cancelChanges() {
    try {
        synchronized (this.getSync()) {
            boolean cancelled = true;
            try (BaseCloseable eventsEnabled = eventsDisabled()) {
                cancelled &= internalCancelChanges(this.cacheIdNew);
                cancelled &= internalCancelChanges(this.cacheIdDeleted);
                cancelled &= internalCancelChanges(this.cacheIdModified);
                clearSelectedRecordsIndex();
                cleanCachedRecords();
            } finally {
                fireRecordsChanged();
            }
            if (!cancelled) {
                JOptionPane.showMessageDialog(getMapPanel(), "<html><p>There was an error cancelling changes for one or more records.</p>" + "<p>" + getPath() + "</p>" + "<p>Check the logging panel for details.</html>", "Error Cancelling Changes", JOptionPane.ERROR_MESSAGE);
            }
        }
    } finally {
        fireHasChangedRecords();
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable)

Example 37 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class AbstractRecordLayer method deleteRecords.

public void deleteRecords(final Collection<? extends LayerRecord> records) {
    removeForms(records);
    final List<LayerRecord> recordsDeleted = new ArrayList<>();
    final List<LayerRecord> recordsSelected = new ArrayList<>();
    try (BaseCloseable eventsEnabled = eventsDisabled()) {
        synchronized (this.getSync()) {
            final boolean canDelete = isCanDeleteRecords();
            for (final LayerRecord record : records) {
                final boolean selected = isSelected(record);
                boolean deleted = false;
                if (removeRecordFromCache(this.cacheIdNew, record)) {
                    removeRecordFromCache(record);
                    record.setState(RecordState.DELETED);
                    deleted = true;
                } else if (canDelete) {
                    if (deleteRecordDo(record)) {
                        deleted = true;
                    }
                }
                if (deleted) {
                    final LayerRecord recordProxy = record.newRecordProxy();
                    recordsDeleted.add(recordProxy);
                    if (selected) {
                        removeSelectedRecord(recordProxy);
                        recordsSelected.add(recordProxy);
                    }
                }
            }
        }
    }
    deleteRecordsPost(recordsDeleted, recordsSelected);
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) ArrayList(java.util.ArrayList)

Example 38 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class ArrayLayerRecord method cancelChanges.

/**
 * Internal method to revert the records values to the original
 */
@Override
public final boolean cancelChanges() {
    boolean cancelled = false;
    synchronized (getSync()) {
        final Map<String, Object> originalValues = this.originalValues;
        RecordState state = getState();
        final AbstractRecordLayer layer = getLayer();
        try (BaseCloseable disabled = layer.eventsDisabled()) {
            if (originalValues != EMPTY_ORIGINAL_VALUES) {
                setState(RecordState.INITIALIZING);
                super.setValues(originalValues);
            }
            if (state == RecordState.MODIFIED || state == RecordState.DELETED) {
                state = RecordState.PERSISTED;
                cancelled = true;
            }
        } finally {
            setState(state);
        }
        this.originalValues = EMPTY_ORIGINAL_VALUES;
    }
    if (cancelled) {
        firePropertyChange(EVENT_RECORD_CHANGED, false, true);
    }
    return cancelled;
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) RecordState(com.revolsys.record.RecordState)

Example 39 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class RecordStoreLayer method forEachRecordInternal.

@Override
protected void forEachRecordInternal(Query query, final Consumer<? super LayerRecord> consumer) {
    if (isExists()) {
        try {
            final RecordStore recordStore = getRecordStore();
            if (recordStore != null && query != null) {
                final Predicate<Record> filter = query.getWhereCondition();
                final Map<? extends CharSequence, Boolean> orderBy = query.getOrderBy();
                final List<LayerRecord> changedRecords = new ArrayList<>();
                changedRecords.addAll(getRecordsNew());
                changedRecords.addAll(getRecordsModified());
                Records.filterAndSort(changedRecords, filter, orderBy);
                final Iterator<LayerRecord> changedIterator = changedRecords.iterator();
                LayerRecord currentChangedRecord = Iterators.next(changedIterator);
                final RecordDefinition internalRecordDefinition = getInternalRecordDefinition();
                query = query.newQuery(internalRecordDefinition);
                final Comparator<Record> comparator = Records.newComparatorOrderBy(orderBy);
                try (final BaseCloseable booleanValueCloseable = eventsDisabled();
                    Transaction transaction = recordStore.newTransaction(Propagation.REQUIRES_NEW);
                    final RecordReader reader = newRecordStoreRecordReader(query)) {
                    for (LayerRecord record : reader.<LayerRecord>i()) {
                        boolean write = true;
                        final Identifier identifier = getId(record);
                        if (identifier == null) {
                            record = newProxyLayerRecordNoId(record);
                        } else {
                            final LayerRecord cachedRecord = this.recordsByIdentifier.get(identifier);
                            if (cachedRecord != null) {
                                record = cachedRecord;
                                if (record.isChanged() || isDeleted(record)) {
                                    write = false;
                                }
                            }
                        }
                        if (!isDeleted(record) && write) {
                            while (currentChangedRecord != null && comparator.compare(currentChangedRecord, record) < 0) {
                                consumer.accept(currentChangedRecord);
                                currentChangedRecord = Iterators.next(changedIterator);
                            }
                            consumer.accept(record);
                        }
                    }
                    while (currentChangedRecord != null) {
                        consumer.accept(currentChangedRecord);
                        currentChangedRecord = Iterators.next(changedIterator);
                    }
                }
            }
        } catch (final CancellationException e) {
        } catch (final RuntimeException e) {
            Logs.error(this, "Error executing query: " + query, e);
            throw e;
        }
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) RecordReader(com.revolsys.record.io.RecordReader) ArrayList(java.util.ArrayList) RecordDefinition(com.revolsys.record.schema.RecordDefinition) Identifier(com.revolsys.identifier.Identifier) Transaction(com.revolsys.transaction.Transaction) CancellationException(java.util.concurrent.CancellationException) RecordStore(com.revolsys.record.schema.RecordStore) Record(com.revolsys.record.Record)

Example 40 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class RecordStoreLayer method forEachRecordsPersisted.

@SuppressWarnings("unchecked")
public <R extends LayerRecord> void forEachRecordsPersisted(final Query query, final Consumer<? super R> consumer) {
    if (query != null && isExists()) {
        final RecordStore recordStore = getRecordStore();
        if (recordStore != null) {
            try (final BaseCloseable booleanValueCloseable = eventsDisabled();
                Transaction transaction = recordStore.newTransaction(Propagation.REQUIRES_NEW);
                final RecordReader reader = newRecordStoreRecordReader(query)) {
                final LabelCountMap labelCountMap = query.getProperty("statistics");
                for (final LayerRecord record : reader.<LayerRecord>i()) {
                    final Identifier identifier = getId(record);
                    R proxyRecord = null;
                    if (identifier == null) {
                        proxyRecord = (R) newProxyLayerRecordNoId(record);
                    } else {
                        synchronized (getSync()) {
                            final LayerRecord cachedRecord = getCachedRecord(identifier, record, true);
                            if (!cachedRecord.isDeleted()) {
                                proxyRecord = newProxyLayerRecord(identifier);
                            }
                        }
                    }
                    if (proxyRecord != null) {
                        consumer.accept(proxyRecord);
                        if (labelCountMap != null) {
                            labelCountMap.addCount(record);
                        }
                    }
                }
            }
        }
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) Identifier(com.revolsys.identifier.Identifier) Transaction(com.revolsys.transaction.Transaction) LabelCountMap(com.revolsys.util.count.LabelCountMap) RecordStore(com.revolsys.record.schema.RecordStore) RecordReader(com.revolsys.record.io.RecordReader)

Aggregations

BaseCloseable (com.revolsys.io.BaseCloseable)46 Point (com.revolsys.geometry.model.Point)9 BoundingBox (com.revolsys.geometry.model.BoundingBox)8 Geometry (com.revolsys.geometry.model.Geometry)7 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)6 Polygon (com.revolsys.geometry.model.Polygon)6 Record (com.revolsys.record.Record)5 LineString (com.revolsys.geometry.model.LineString)4 Identifier (com.revolsys.identifier.Identifier)4 RecordReader (com.revolsys.record.io.RecordReader)4 Graphics2D (java.awt.Graphics2D)4 ArrayList (java.util.ArrayList)4 Vertex (com.revolsys.geometry.model.vertex.Vertex)3 RecordDefinition (com.revolsys.record.schema.RecordDefinition)3 CloseableAffineTransform (com.revolsys.awt.CloseableAffineTransform)2 GeoreferencedImage (com.revolsys.raster.GeoreferencedImage)2 ArrayRecord (com.revolsys.record.ArrayRecord)2 RecordStore (com.revolsys.record.schema.RecordStore)2 Resource (com.revolsys.spring.resource.Resource)2 MapPanel (com.revolsys.swing.map.MapPanel)2