use of com.torodb.core.transaction.metainf.MetaScalar in project torodb by torodb.
the class PostgreSqlWriteInterface method getCopyInsertDocPartDataStatement.
protected String getCopyInsertDocPartDataStatement(String schemaName, DocPartData docPartData, final MetaDocPart metaDocPart, Collection<InternalField<?>> internalFields) {
final StringBuilder copyStatementBuilder = new StringBuilder();
copyStatementBuilder.append("COPY \"").append(schemaName).append("\".\"").append(metaDocPart.getIdentifier()).append("\"").append(" (");
for (InternalField<?> internalField : internalFields) {
copyStatementBuilder.append("\"").append(internalField.getName()).append("\",");
}
Iterator<MetaScalar> metaScalarIterator = docPartData.orderedMetaScalarIterator();
while (metaScalarIterator.hasNext()) {
MetaScalar metaScalar = metaScalarIterator.next();
copyStatementBuilder.append("\"").append(metaScalar.getIdentifier()).append("\",");
}
Iterator<MetaField> metaFieldIterator = docPartData.orderedMetaFieldIterator();
while (metaFieldIterator.hasNext()) {
MetaField metaField = metaFieldIterator.next();
copyStatementBuilder.append("\"").append(metaField.getIdentifier()).append("\",");
}
copyStatementBuilder.setCharAt(copyStatementBuilder.length() - 1, ')');
copyStatementBuilder.append(" FROM STDIN");
final String copyStatement = copyStatementBuilder.toString();
return copyStatement;
}
use of com.torodb.core.transaction.metainf.MetaScalar in project torodb by torodb.
the class R2DTranslatorImpl method readResult.
private void readResult(MetaDocPart metaDocPart, TableRef tableRef, DocPartResult docPartResult, Map<Integer, Map<String, List<KvValue<?>>>> currentFieldDocPartRow, Map<Integer, Map<String, List<KvValue<?>>>> childFieldDocPartRow, ImmutableList.Builder<ToroDocument> readedDocuments) {
while (docPartResult.hasNext()) {
KvDocument.Builder documentBuilder = new KvDocument.Builder();
DocPartResultRow row = docPartResult.next();
Integer did = row.getDid();
Integer rid = row.getRid();
Integer pid = row.getPid();
Integer seq = row.getSeq();
Map<String, List<KvValue<?>>> childFieldDocPartCell = childFieldDocPartRow.get(rid);
//TODO: ensure MetaField order using ResultSet meta data
Iterator<? extends MetaScalar> metaScalarIterator = metaDocPart.streamScalars().iterator();
boolean wasScalar = false;
int fieldIndex = 0;
while (metaScalarIterator.hasNext() && !wasScalar) {
assert seq != null : "found scalar value outside of an array";
MetaScalar metaScalar = metaScalarIterator.next();
KvValue<?> value = row.getUserValue(fieldIndex, metaScalar.getType());
fieldIndex++;
if (value != null) {
if (metaScalar.getType() == FieldType.CHILD) {
value = getChildValue(value, getDocPartCellName(tableRef), childFieldDocPartCell);
}
addValueToDocPartRow(currentFieldDocPartRow, tableRef, pid, seq, value);
wasScalar = true;
}
}
if (wasScalar) {
continue;
}
Iterator<? extends MetaField> metaFieldIterator = metaDocPart.streamFields().iterator();
while (metaFieldIterator.hasNext()) {
MetaField metaField = metaFieldIterator.next();
KvValue<?> value = row.getUserValue(fieldIndex, metaField.getType());
fieldIndex++;
if (value != null) {
if (metaField.getType() == FieldType.CHILD) {
value = getChildValue(value, metaField.getName(), childFieldDocPartCell);
}
documentBuilder.putValue(metaField.getName(), value);
}
}
if (tableRef.isRoot()) {
readedDocuments.add(new ToroDocument(did, documentBuilder.build()));
} else {
addValueToDocPartRow(currentFieldDocPartRow, tableRef, pid, seq, documentBuilder.build());
}
}
}
use of com.torodb.core.transaction.metainf.MetaScalar in project torodb by torodb.
the class TableMetadata method findMetaScalar.
private MetaScalar findMetaScalar(FieldType type) {
MetaScalar metaField = metaDocPart.getScalar(type);
if (metaField == null) {
String identifier = collectionMetaInfo.getScalarIdentifier(type);
metaField = metaDocPart.addMetaScalar(identifier, type);
}
return metaField;
}
Aggregations