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