Search in sources :

Example 21 with RecordStore

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;
    }
}
Also used : Condition(com.revolsys.record.query.Condition) Query(com.revolsys.record.query.Query) Transaction(com.revolsys.transaction.Transaction) RecordStore(com.revolsys.record.schema.RecordStore) RecordReader(com.revolsys.record.io.RecordReader) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 22 with RecordStore

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;
}
Also used : HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) MapEx(com.revolsys.collection.map.MapEx) RecordStore(com.revolsys.record.schema.RecordStore) PathName(com.revolsys.io.PathName) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 23 with RecordStore

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);
    }
}
Also used : AbstractRecordStore(com.revolsys.record.schema.AbstractRecordStore) RecordStore(com.revolsys.record.schema.RecordStore) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 24 with RecordStore

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;
    }
}
Also used : AbstractRecordStore(com.revolsys.record.schema.AbstractRecordStore) RecordStore(com.revolsys.record.schema.RecordStore) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 25 with RecordStore

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;
}
Also used : RecordStore(com.revolsys.record.schema.RecordStore)

Aggregations

RecordStore (com.revolsys.record.schema.RecordStore)25 RecordDefinition (com.revolsys.record.schema.RecordDefinition)11 Identifier (com.revolsys.identifier.Identifier)5 Transaction (com.revolsys.transaction.Transaction)4 ArrayList (java.util.ArrayList)4 PathName (com.revolsys.io.PathName)3 Record (com.revolsys.record.Record)3 RecordReader (com.revolsys.record.io.RecordReader)3 Query (com.revolsys.record.query.Query)3 HashMap (java.util.HashMap)3 BaseCloseable (com.revolsys.io.BaseCloseable)2 CodeTable (com.revolsys.record.code.CodeTable)2 Condition (com.revolsys.record.query.Condition)2 AbstractRecordStore (com.revolsys.record.schema.AbstractRecordStore)2 RecordStoreSchemaElement (com.revolsys.record.schema.RecordStoreSchemaElement)2 BaseTreeNode (com.revolsys.swing.tree.BaseTreeNode)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 MapEx (com.revolsys.collection.map.MapEx)1 JdbcRecordStore (com.revolsys.jdbc.io.JdbcRecordStore)1