use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class RecordConverterProcess method preRun.
@Override
protected void preRun(final Channel<Record> in, final Channel<Record> out) {
this.labelCountMap.connect();
// ignoredStatistics.connect();
if (this.simpleMapping != null) {
for (final Entry<Object, Map<String, Object>> entry : this.simpleMapping.entrySet()) {
final Object key = entry.getKey();
String sourceTypeName;
if (key instanceof String) {
sourceTypeName = (String) key;
} else {
sourceTypeName = String.valueOf(key.toString());
}
final Map<String, Object> map = entry.getValue();
final Object targetName = map.get("typePath");
String targetTypeName;
if (key instanceof String) {
targetTypeName = (String) targetName;
} else {
targetTypeName = String.valueOf(targetName.toString());
}
@SuppressWarnings("unchecked") final Map<String, String> attributeMapping = (Map<String, String>) map.get("attributeMapping");
final RecordDefinition targetRecordDefinition = getTargetRecordDefinition(targetTypeName);
final SimpleRecordConveter converter = new SimpleRecordConveter(targetRecordDefinition);
converter.addProcessor(new CopyValues(attributeMapping));
addTypeConverter(sourceTypeName, converter);
}
}
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class AbstractMergeProcess method addSavedObjects.
private RecordDefinition addSavedObjects(final RecordDefinition currentType, final String currentTypeName, final Channel<Record> out, final boolean[] guard, final Record[] objects) {
final Record sourceObject = objects[SOURCE_INDEX];
final Record otherObject = objects[OTHER_INDEX];
if (sourceObject == null) {
if (otherObject == null) {
return null;
} else {
addOtherObject(otherObject);
objects[OTHER_INDEX] = null;
guard[OTHER_INDEX] = true;
return otherObject.getRecordDefinition();
}
} else if (otherObject == null) {
if (sourceObject == null) {
return null;
} else {
addSourceObject(sourceObject);
objects[SOURCE_INDEX] = null;
guard[SOURCE_INDEX] = true;
return sourceObject.getRecordDefinition();
}
} else {
final RecordDefinition sourceType = sourceObject.getRecordDefinition();
final String sourceTypeName = sourceType.getPath();
final RecordDefinition otherType = otherObject.getRecordDefinition();
final String otherTypeName = otherType.getPath();
if (sourceTypeName.equals(currentTypeName)) {
addSourceObject(sourceObject);
objects[SOURCE_INDEX] = null;
guard[SOURCE_INDEX] = true;
objects[OTHER_INDEX] = otherObject;
guard[OTHER_INDEX] = false;
return currentType;
} else if (otherTypeName.equals(currentTypeName)) {
addOtherObject(otherObject);
objects[SOURCE_INDEX] = sourceObject;
guard[SOURCE_INDEX] = false;
objects[OTHER_INDEX] = null;
guard[OTHER_INDEX] = true;
return currentType;
} else {
processObjects(currentType, out);
final int nameCompare = sourceTypeName.toString().compareTo(otherTypeName.toString());
if (nameCompare < 0) {
// If the first feature type name is < second feature type
// name
// then add the first feature and save the second feature
// for later
addSourceObject(sourceObject);
objects[SOURCE_INDEX] = null;
guard[SOURCE_INDEX] = true;
objects[OTHER_INDEX] = otherObject;
guard[OTHER_INDEX] = false;
return sourceType;
} else if (nameCompare == 0) {
// If both features have the same type them add them
addSourceObject(sourceObject);
addOtherObject(otherObject);
objects[SOURCE_INDEX] = null;
guard[SOURCE_INDEX] = true;
objects[OTHER_INDEX] = null;
guard[OTHER_INDEX] = true;
return sourceType;
} else {
// If the first feature type name is > second feature type
// name
// then add the second feature and save the first feature
// for later
addOtherObject(otherObject);
objects[SOURCE_INDEX] = sourceObject;
guard[SOURCE_INDEX] = false;
objects[OTHER_INDEX] = null;
guard[OTHER_INDEX] = true;
return otherType;
}
}
}
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class AbstractMergeProcess method run.
@Override
@SuppressWarnings("unchecked")
protected void run(final Channel<Record> in, final Channel<Record> out) {
setUp();
try {
RecordDefinition currentType = null;
String currentTypeName = null;
final Channel<Record>[] channels = ArrayUtil.newArray(in, this.otherIn);
final boolean[] guard = new boolean[] { true, true };
final Record[] objects = new Record[2];
final String[] typePaths = new String[2];
for (int i = 0; i < 2; i++) {
try {
final Channel<Record> channel = channels[i];
if (channel == null) {
guard[i] = false;
} else {
Record object = null;
boolean test = false;
do {
object = channel.read();
test = testObject(object);
} while (!test);
if (test) {
objects[i] = object;
typePaths[i] = objects[i].getRecordDefinition().getPath();
}
}
} catch (final ClosedException e) {
guard[i] = false;
}
}
final Record otherObject = objects[OTHER_INDEX];
if (typePaths[SOURCE_INDEX] != null) {
final Record sourceObject = objects[SOURCE_INDEX];
if (typePaths[OTHER_INDEX] != null) {
final int nameCompare = typePaths[SOURCE_INDEX].toString().compareTo(typePaths[OTHER_INDEX].toString());
if (nameCompare <= 0) {
currentType = sourceObject.getRecordDefinition();
currentTypeName = typePaths[SOURCE_INDEX];
addSourceObject(sourceObject);
objects[SOURCE_INDEX] = null;
if (nameCompare != 0) {
guard[OTHER_INDEX] = false;
}
}
if (nameCompare >= 0) {
currentType = otherObject.getRecordDefinition();
currentTypeName = typePaths[OTHER_INDEX];
addOtherObject(otherObject);
objects[OTHER_INDEX] = null;
if (nameCompare != 0) {
guard[SOURCE_INDEX] = false;
}
}
} else {
currentType = sourceObject.getRecordDefinition();
currentTypeName = typePaths[SOURCE_INDEX];
if (otherObject != null) {
addSourceObject(otherObject);
}
}
} else {
currentType = otherObject.getRecordDefinition();
currentTypeName = typePaths[OTHER_INDEX];
if (otherObject != null) {
addOtherObject(otherObject);
}
objects[OTHER_INDEX] = null;
}
try {
final MultiInputSelector alt = new MultiInputSelector();
final boolean running = true;
while (running) {
final int channelIndex = alt.select(channels, guard, 1000);
if (channelIndex >= 0) {
final Record object = channels[channelIndex].read();
if (testObject(object)) {
final RecordDefinition recordDefinition = object.getRecordDefinition();
final String typePath = recordDefinition.getPath();
if (currentTypeName == null) {
currentTypeName = typePath;
currentType = recordDefinition;
init(recordDefinition);
}
if (typePath.equals(currentTypeName)) {
currentTypeName = typePath;
currentType = recordDefinition;
if (channelIndex == SOURCE_INDEX) {
addSourceObject(object);
} else {
addOtherObject(object);
}
} else {
objects[channelIndex] = object;
addObjectFromOtherChannel(channels, guard, objects, channelIndex);
currentType = addSavedObjects(currentType, currentTypeName, out, guard, objects);
if (currentType != null) {
currentTypeName = currentType.getPath();
}
}
}
} else {
if (channels[0].isClosed()) {
guard[1] = true;
} else if (channels[1].isClosed()) {
guard[0] = true;
}
}
}
} finally {
try {
while (addSavedObjects(currentType, currentTypeName, out, guard, objects) != null) {
}
processObjects(currentType, out);
} finally {
}
}
} finally {
this.otherIn.readDisconnect();
tearDown();
}
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class AddDefaultValuesProcess method process.
private void process(final Record record) {
final RecordDefinition type = record.getRecordDefinition();
boolean process = true;
if (this.schemaName != null) {
if (!PathUtil.getPath(type.getPath()).equals(this.schemaName)) {
process = false;
}
}
if (process) {
processDefaultValues(record, getDefaultValues(type));
}
for (int i = 0; i < type.getFieldCount(); i++) {
final Object value = record.getValue(i);
if (value instanceof Record) {
process((Record) value);
}
}
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class Record method getValues.
default List<Object> getValues() {
final RecordDefinition recordDefinition = getRecordDefinition();
final List<Object> values = new ArrayList<>();
for (int i = 0; i < recordDefinition.getFieldCount(); i++) {
final Object value = getValue(i);
values.add(value);
}
return values;
}
Aggregations