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(";");
}
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("/");
}
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);
}
}
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;
}
}
}
}
}
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;
}
}
}
Aggregations