use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class RecordStoreLayer method saveChangesDo.
@Override
protected boolean saveChangesDo(final RecordLayerErrors errors, final LayerRecord record) {
boolean deleted = super.isDeleted(record);
if (isExists()) {
final RecordStore recordStore = getRecordStore();
if (recordStore == null) {
return true;
} else {
try (Transaction transaction = recordStore.newTransaction(Propagation.REQUIRES_NEW)) {
try {
Identifier identifier = record.getIdentifier();
try (final Writer<Record> writer = recordStore.newRecordWriter()) {
if (isRecordCached(getCacheIdDeleted(), record) || super.isDeleted(record)) {
preDeleteRecord(record);
record.setState(RecordState.DELETED);
writeDelete(writer, record);
deleted = true;
} else {
final RecordDefinition recordDefinition = getRecordDefinition();
if (super.isNew(record)) {
final List<String> idFieldNames = recordDefinition.getIdFieldNames();
if (identifier == null && !idFieldNames.isEmpty()) {
identifier = recordStore.newPrimaryIdentifier(this.typePath);
if (identifier != null) {
identifier.setIdentifier(record, idFieldNames);
}
}
}
final int fieldCount = recordDefinition.getFieldCount();
for (int fieldIndex = 0; fieldIndex < fieldCount; fieldIndex++) {
record.validateField(fieldIndex);
}
if (super.isModified(record)) {
writeUpdate(writer, record);
} else if (super.isNew(record)) {
writer.write(record);
}
}
}
if (!deleted) {
record.setState(RecordState.PERSISTED);
}
removeFromRecordIdToRecordMap(identifier);
return true;
} catch (final Throwable e) {
throw transaction.setRollbackOnly(e);
}
}
}
} else {
return true;
}
}
use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class RecordStoreLayer method removeRecordFromCache.
@Override
protected boolean removeRecordFromCache(final LayerRecord record) {
boolean removed = false;
if (isLayerRecord(record)) {
synchronized (getSync()) {
final Identifier identifier = record.getIdentifier();
if (identifier != null) {
for (final Iterator<Set<Identifier>> iterator = this.recordIdentifiersByCacheId.values().iterator(); iterator.hasNext(); ) {
final Set<Identifier> identifiers = iterator.next();
identifiers.remove(identifier);
if (identifiers.isEmpty()) {
iterator.remove();
}
}
}
removed |= super.removeRecordFromCache(record);
}
}
return removed;
}
use of com.revolsys.identifier.Identifier 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);
}
}
}
}
}
}
}
use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class RecordStoreLayer method deleteRecordDo.
@Override
protected boolean deleteRecordDo(final LayerRecord record) {
final Identifier identifier = record.getIdentifier();
final boolean result = super.deleteRecordDo(record);
removeFromRecordIdToRecordMap(identifier);
return result;
}
use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class RecordStoreLayer method getCacheIdsDo.
@Override
protected Set<Label> getCacheIdsDo(final LayerRecord record) {
final Set<Label> cacheIds = super.getCacheIdsDo(record);
final Identifier identifier = record.getIdentifier();
if (identifier != null) {
for (final Entry<Label, Set<Identifier>> entry : this.recordIdentifiersByCacheId.entrySet()) {
final Label cacheId = entry.getKey();
if (!cacheIds.contains(cacheId)) {
final Collection<Identifier> identifiers = entry.getValue();
if (identifiers.contains(identifier)) {
cacheIds.add(cacheId);
}
}
}
}
return cacheIds;
}
Aggregations