Search in sources :

Example 36 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class PostgreSQLDdlWriter method writeResetSequence.

@Override
public void writeResetSequence(final RecordDefinition recordDefinition, final List<Record> values) {
    final PrintWriter out = getOut();
    Long nextValue = 0L;
    for (final Record object : values) {
        final Identifier id = object.getIdentifier();
        for (final Object value : id.getValues()) {
            if (value instanceof Number) {
                final Number number = (Number) value;
                final long longValue = number.longValue();
                if (longValue > nextValue) {
                    nextValue = longValue;
                }
            }
        }
    }
    nextValue++;
    final String sequeneName = getSequenceName(recordDefinition);
    out.print("ALTER SEQUENCE ");
    out.print(sequeneName);
    out.print(" RESTART WITH ");
    out.print(nextValue);
    out.println(";");
}
Also used : Identifier(com.revolsys.identifier.Identifier) Record(com.revolsys.record.Record) PrintWriter(java.io.PrintWriter)

Example 37 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class OracleDdlWriter method writeResetSequence.

@Override
public void writeResetSequence(final RecordDefinition recordDefinition, final List<Record> values) {
    final PrintWriter out = getOut();
    Long nextValue = 0L;
    for (final Record object : values) {
        final Identifier id = object.getIdentifier();
        for (final Object value : id.getValues()) {
            if (value instanceof Number) {
                final Number number = (Number) value;
                final long longValue = number.longValue();
                if (longValue > nextValue) {
                    nextValue = longValue;
                }
            }
        }
    }
    nextValue++;
    final String sequeneName = getSequenceName(recordDefinition);
    out.println("DECLARE");
    out.println("  cur_val NUMBER;");
    out.println("BEGIN");
    out.print("  SELECT ");
    out.print(sequeneName);
    out.println(".NEXTVAL INTO cur_val FROM DUAL;");
    out.print("  IF cur_val + 1 <> ");
    out.print(nextValue);
    out.println(" THEN");
    out.print("    EXECUTE IMMEDIATE 'ALTER SEQUENCE ");
    out.print(sequeneName);
    out.print(" INCREMENT BY ' || (");
    out.print(nextValue);
    out.println(" -  cur_val -1) || ' MINVALUE 1';");
    out.print("    SELECT ");
    out.print(sequeneName);
    out.println(".NEXTVAL INTO cur_val FROM DUAL;");
    out.print("    EXECUTE IMMEDIATE 'ALTER SEQUENCE ");
    out.print(sequeneName);
    out.println(" INCREMENT BY 1';");
    out.println("  END IF;");
    out.println("END;");
    out.println("/");
}
Also used : Identifier(com.revolsys.identifier.Identifier) Record(com.revolsys.record.Record) PrintWriter(java.io.PrintWriter)

Example 38 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class CopyRecords method run.

@Override
public void run() {
    try {
        final Query query = this.sourceRecordStore.newQuery(this.typePath);
        query.setOrderBy(this.orderBy);
        try (final RecordReader reader = this.sourceRecordStore.getRecords(query);
            final RecordWriter targetWriter = this.targetRecordStore.newRecordWriter()) {
            final RecordDefinition targetRecordDefinition = this.targetRecordStore.getRecordDefinition(this.typePath);
            if (targetRecordDefinition == null) {
                Logs.error(this, "Cannot find target table: " + this.typePath);
            } else {
                if (this.hasSequence) {
                    final String idFieldName = targetRecordDefinition.getIdFieldName();
                    Identifier maxId = this.targetRecordStore.newPrimaryIdentifier(this.typePath);
                    for (final Record sourceRecord : reader) {
                        final Record targetRecord = this.targetRecordStore.newRecord(this.typePath, sourceRecord);
                        final Identifier sourceId = sourceRecord.getIdentifier(idFieldName);
                        while (CompareUtil.compare(maxId, sourceId) < 0) {
                            maxId = this.targetRecordStore.newPrimaryIdentifier(this.typePath);
                        }
                        targetWriter.write(targetRecord);
                    }
                } else {
                    for (final Record sourceRecord : reader) {
                        final Record targetRecord = this.targetRecordStore.newRecord(this.typePath, sourceRecord);
                        targetWriter.write(targetRecord);
                    }
                }
            }
        }
    } catch (final Throwable e) {
        throw new RuntimeException("Unable to copy records for " + this.typePath, e);
    }
}
Also used : RecordWriter(com.revolsys.record.io.RecordWriter) Identifier(com.revolsys.identifier.Identifier) Query(com.revolsys.record.query.Query) RecordReader(com.revolsys.record.io.RecordReader) Record(com.revolsys.record.Record) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 39 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class LayerRecord method isSame.

@Override
default boolean isSame(Record record) {
    if (record == null) {
        return false;
    } else {
        if (record instanceof AbstractProxyLayerRecord) {
            final AbstractProxyLayerRecord proxyRecord = (AbstractProxyLayerRecord) record;
            record = proxyRecord.getRecordProxied();
        }
        if (this == record) {
            return true;
        } else {
            synchronized (this) {
                if (isLayerRecord(record)) {
                    final Identifier id = getIdentifier();
                    final Identifier otherId = record.getIdentifier();
                    if (id == null || otherId == null) {
                        return false;
                    } else if (DataType.equal(id, otherId)) {
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }
            }
        }
    }
}
Also used : Identifier(com.revolsys.identifier.Identifier)

Example 40 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class RecordStoreLayer method forEachRecordInternal.

@Override
protected void forEachRecordInternal(Query query, final Consumer<? super LayerRecord> consumer) {
    if (isExists()) {
        try {
            final RecordStore recordStore = getRecordStore();
            if (recordStore != null && query != null) {
                final Predicate<Record> filter = query.getWhereCondition();
                final Map<? extends CharSequence, Boolean> orderBy = query.getOrderBy();
                final List<LayerRecord> changedRecords = new ArrayList<>();
                changedRecords.addAll(getRecordsNew());
                changedRecords.addAll(getRecordsModified());
                Records.filterAndSort(changedRecords, filter, orderBy);
                final Iterator<LayerRecord> changedIterator = changedRecords.iterator();
                LayerRecord currentChangedRecord = Iterators.next(changedIterator);
                final RecordDefinition internalRecordDefinition = getInternalRecordDefinition();
                query = query.newQuery(internalRecordDefinition);
                final Comparator<Record> comparator = Records.newComparatorOrderBy(orderBy);
                try (final BaseCloseable booleanValueCloseable = eventsDisabled();
                    Transaction transaction = recordStore.newTransaction(Propagation.REQUIRES_NEW);
                    final RecordReader reader = newRecordStoreRecordReader(query)) {
                    for (LayerRecord record : reader.<LayerRecord>i()) {
                        boolean write = true;
                        final Identifier identifier = getId(record);
                        if (identifier == null) {
                            record = newProxyLayerRecordNoId(record);
                        } else {
                            final LayerRecord cachedRecord = this.recordsByIdentifier.get(identifier);
                            if (cachedRecord != null) {
                                record = cachedRecord;
                                if (record.isChanged() || isDeleted(record)) {
                                    write = false;
                                }
                            }
                        }
                        if (!isDeleted(record) && write) {
                            while (currentChangedRecord != null && comparator.compare(currentChangedRecord, record) < 0) {
                                consumer.accept(currentChangedRecord);
                                currentChangedRecord = Iterators.next(changedIterator);
                            }
                            consumer.accept(record);
                        }
                    }
                    while (currentChangedRecord != null) {
                        consumer.accept(currentChangedRecord);
                        currentChangedRecord = Iterators.next(changedIterator);
                    }
                }
            }
        } catch (final CancellationException e) {
        } catch (final RuntimeException e) {
            Logs.error(this, "Error executing query: " + query, e);
            throw e;
        }
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) RecordReader(com.revolsys.record.io.RecordReader) ArrayList(java.util.ArrayList) RecordDefinition(com.revolsys.record.schema.RecordDefinition) Identifier(com.revolsys.identifier.Identifier) Transaction(com.revolsys.transaction.Transaction) CancellationException(java.util.concurrent.CancellationException) RecordStore(com.revolsys.record.schema.RecordStore) Record(com.revolsys.record.Record)

Aggregations

Identifier (com.revolsys.identifier.Identifier)56 Record (com.revolsys.record.Record)17 ArrayList (java.util.ArrayList)12 RecordDefinition (com.revolsys.record.schema.RecordDefinition)11 SingleIdentifier (com.revolsys.identifier.SingleIdentifier)8 ListIdentifier (com.revolsys.identifier.ListIdentifier)7 TypedIdentifier (com.revolsys.identifier.TypedIdentifier)6 CodeTable (com.revolsys.record.code.CodeTable)6 RecordReader (com.revolsys.record.io.RecordReader)5 RecordStore (com.revolsys.record.schema.RecordStore)5 Transaction (com.revolsys.transaction.Transaction)5 List (java.util.List)5 Geometry (com.revolsys.geometry.model.Geometry)4 BaseCloseable (com.revolsys.io.BaseCloseable)4 PathName (com.revolsys.io.PathName)4 ArrayRecord (com.revolsys.record.ArrayRecord)4 Query (com.revolsys.record.query.Query)4 OsmElement (com.revolsys.record.io.format.openstreetmap.model.OsmElement)3 FieldDefinition (com.revolsys.record.schema.FieldDefinition)3 CompoundCoordinateSystem (com.revolsys.geometry.cs.CompoundCoordinateSystem)2