Search in sources :

Example 11 with RecordStore

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();
        }
    }
}
Also used : Identifier(com.revolsys.identifier.Identifier) Query(com.revolsys.record.query.Query) RecordStore(com.revolsys.record.schema.RecordStore) Record(com.revolsys.record.Record) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 12 with RecordStore

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

Example 13 with RecordStore

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

Example 14 with RecordStore

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);
    }
}
Also used : SQLException(java.sql.SQLException) RecordStore(com.revolsys.record.schema.RecordStore) RecordState(com.revolsys.record.RecordState) DataAccessException(org.springframework.dao.DataAccessException) BatchUpdateException(java.sql.BatchUpdateException) SQLException(java.sql.SQLException) BatchUpdateException(java.sql.BatchUpdateException)

Example 15 with RecordStore

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);
            }
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RecordStore(com.revolsys.record.schema.RecordStore) HashMap(java.util.HashMap) Map(java.util.Map)

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