use of com.revolsys.record.schema.RecordStore in project com.revolsys.open by revolsys.
the class RecordHtmlUiBuilder method isPropertyUnique.
protected boolean isPropertyUnique(final Record object, final String fieldName) {
final String value = object.getValue(fieldName);
final RecordStore recordStore = getRecordStore();
final RecordDefinition recordDefinition = recordStore.getRecordDefinition(this.tableName);
if (recordDefinition == null) {
return true;
} else {
final Query query = Query.equal(recordDefinition, fieldName, value);
final Reader<Record> results = recordStore.getRecords(query);
final List<Record> objects = results.toList();
if (object.getState() == RecordState.NEW) {
return objects.isEmpty();
} else {
final Identifier id = object.getIdentifier();
for (final Iterator<Record> iterator = objects.iterator(); iterator.hasNext(); ) {
final Record matchedObject = iterator.next();
final Identifier matchedId = matchedObject.getIdentifier();
if (DataType.equal(id, matchedId)) {
iterator.remove();
}
}
return objects.isEmpty();
}
}
}
use of com.revolsys.record.schema.RecordStore in project com.revolsys.open by revolsys.
the class FileGdbWriter method write.
@Override
public synchronized void write(final Record record) {
final RecordDefinition recordDefinition = record.getRecordDefinition();
final RecordStore recordStore = recordDefinition.getRecordStore();
if (recordStore == this.recordStore) {
switch(record.getState()) {
case NEW:
insertRecord(record);
break;
case MODIFIED:
updateRecord(record);
break;
case PERSISTED:
// No action required
break;
case DELETED:
deleteRecord(record);
break;
default:
throw new IllegalStateException("State not known");
}
} else {
insertRecord(record);
}
}
use of com.revolsys.record.schema.RecordStore in project com.revolsys.open by revolsys.
the class OgrRecordWriter method write.
@Override
public synchronized void write(final Record record) {
try {
final RecordDefinition recordDefinition = record.getRecordDefinition();
final RecordStore recordStore = recordDefinition.getRecordStore();
if (recordStore == this.recordStore) {
switch(record.getState()) {
case NEW:
insert(record);
break;
case MODIFIED:
update(record);
break;
case PERSISTED:
// No action required
break;
case DELETED:
delete(record);
break;
default:
throw new IllegalStateException("State not known");
}
} else {
insert(record);
}
} catch (final RuntimeException e) {
throw e;
} catch (final Error e) {
throw e;
} catch (final Exception e) {
throw new RuntimeException("Unable to write", e);
}
}
use of com.revolsys.record.schema.RecordStore in project com.revolsys.open by revolsys.
the class JdbcRecordWriter method write.
@Override
public synchronized void write(final Record record) {
try {
final JdbcRecordDefinition recordDefinition = getRecordDefinition(record);
final RecordStore recordStore = recordDefinition.getRecordStore();
final RecordState state = record.getState();
if (recordStore != this.recordStore) {
if (state != RecordState.DELETED) {
insert(recordDefinition, record);
}
} else {
switch(state) {
case NEW:
insert(recordDefinition, record);
break;
case MODIFIED:
update(recordDefinition, record);
break;
case PERSISTED:
// No action required
break;
case DELETED:
delete(recordDefinition, record);
break;
default:
throw new IllegalStateException("State not known");
}
}
} catch (final RuntimeException e) {
throw e;
} catch (final Error e) {
throw e;
} catch (final BatchUpdateException e) {
for (SQLException e1 = e.getNextException(); e1 != null; e1 = e1.getNextException()) {
LOG.error("Unable to write", e1);
}
throw new RuntimeException("Unable to write", e);
} catch (final Exception e) {
throw new RuntimeException("Unable to write", e);
}
}
use of com.revolsys.record.schema.RecordStore in project com.revolsys.open by revolsys.
the class RecordStoreConnectionManager method releaseRecordStore.
@SuppressWarnings("unchecked")
public static void releaseRecordStore(final Map<String, ? extends Object> config) {
@SuppressWarnings("rawtypes") final Map<String, Object> configClone = (Map) JavaBeanUtil.clone(config);
synchronized (recordStoreByConfig) {
final RecordStore recordStore = recordStoreByConfig.get(configClone);
if (recordStore != null) {
final AtomicInteger count = recordStoreCounts.get(configClone);
if (count.decrementAndGet() == 0) {
final Map<String, ? extends Object> connectionProperties = (Map<String, ? extends Object>) configClone.get("connection");
final String name = (String) connectionProperties.get("name");
if (!Property.hasValue(name)) {
// TODO release for connections from connection registries
recordStore.close();
}
recordStoreByConfig.remove(configClone);
recordStoreCounts.remove(configClone);
}
}
}
}
Aggregations