use of com.revolsys.record.schema.RecordStore in project com.revolsys.open by revolsys.
the class RecordStoreLayer method getCachedRecord.
@SuppressWarnings("unchecked")
@Override
protected <R extends LayerRecord> R getCachedRecord(final Identifier identifier) {
final RecordDefinition recordDefinition = getInternalRecordDefinition();
synchronized (getSync()) {
LayerRecord record = this.recordsByIdentifier.get(identifier);
if (record == null) {
final List<String> idFieldNames = recordDefinition.getIdFieldNames();
if (idFieldNames.isEmpty()) {
return null;
} else {
final Condition where = getCachedRecordQuery(idFieldNames, identifier);
final Query query = new Query(recordDefinition, where);
final RecordStore recordStore = this.recordStore;
if (recordStore != null) {
try (Transaction transaction = recordStore.newTransaction(Propagation.REQUIRED);
RecordReader reader = newRecordStoreRecordReader(query)) {
record = reader.getFirst();
if (record != null) {
addCachedRecord(identifier, record);
}
}
}
}
}
return (R) record;
}
}
use of com.revolsys.record.schema.RecordStore in project com.revolsys.open by revolsys.
the class RecordStoreLayer method initializeDo.
@Override
protected boolean initializeDo() {
RecordStore recordStore = this.recordStore;
if (recordStore == null) {
final Map<String, String> connectionProperties = getProperty("connection");
if (connectionProperties == null) {
Logs.error(this, "A record store layer requires a connection entry with a name or url, username, and password: " + getPath());
return false;
} else {
final Map<String, Object> config = new HashMap<>();
config.put("connection", connectionProperties);
recordStore = RecordStoreConnectionManager.getRecordStore(config);
if (recordStore == null) {
Logs.error(this, "Unable to create record store for layer: " + getPath());
return false;
} else {
try {
recordStore.initialize();
} catch (final Throwable e) {
throw new RuntimeException("Unable to iniaitlize record store for layer " + getPath(), e);
}
setRecordStore(recordStore);
}
}
}
final PathName typePath = getPathName();
RecordDefinition recordDefinition = getRecordDefinition();
if (recordDefinition == null) {
recordDefinition = getRecordDefinition(typePath);
if (recordDefinition == null) {
Logs.error(this, "Cannot find table " + typePath + " for layer " + getPath());
return false;
} else {
final MapEx recordDefinitionProperties = getProperty("recordDefinitionProperties", MapEx.EMPTY);
recordDefinition.setProperties(recordDefinitionProperties);
setRecordDefinition(recordDefinition);
}
}
initRecordMenu();
return true;
}
use of com.revolsys.record.schema.RecordStore in project com.revolsys.open by revolsys.
the class DirectoryRecordStore method updateRecord.
@Override
public void updateRecord(final Record record) {
final RecordDefinition recordDefinition = record.getRecordDefinition();
final RecordStore recordStore = recordDefinition.getRecordStore();
if (recordStore == this) {
switch(record.getState()) {
case DELETED:
break;
case PERSISTED:
break;
case MODIFIED:
throw new UnsupportedOperationException();
default:
insertRecord(record);
break;
}
} else {
insertRecord(record);
}
}
use of com.revolsys.record.schema.RecordStore in project com.revolsys.open by revolsys.
the class DirectoryRecordStore method deleteRecord.
@Override
public boolean deleteRecord(final Record record) {
final RecordDefinition recordDefinition = record.getRecordDefinition();
final RecordStore recordStore = recordDefinition.getRecordStore();
if (recordStore == this) {
throw new UnsupportedOperationException("Deleting records not supported");
} else {
return false;
}
}
use of com.revolsys.record.schema.RecordStore in project com.revolsys.open by revolsys.
the class RecordStoreFactoryBean method createInstance.
@Override
protected RecordStore createInstance() throws Exception {
final RecordStore recordStore = RecordStore.newRecordStore(this.config);
recordStore.setProperties(this.properties);
recordStore.initialize();
return recordStore;
}
Aggregations