use of com.torodb.core.transaction.metainf.MetaScalar in project torodb by torodb.
the class ExclusiveWriteBackendTransactionImpl method copyScalar.
private void copyScalar(IdentifierFactory identifierFactory, MetaDocPart fromMetaDocPart, MetaDatabase toMetaDb, MetaCollection toMetaColl, MutableMetaDocPart toMetaDocPart) {
Iterator<? extends MetaScalar> fromMetaScalarIterator = fromMetaDocPart.streamScalars().iterator();
while (fromMetaScalarIterator.hasNext()) {
MetaScalar fromMetaScalar = fromMetaScalarIterator.next();
MetaScalar toMetaScalar = toMetaDocPart.addMetaScalar(identifierFactory.toFieldIdentifierForScalar(fromMetaScalar.getType()), fromMetaScalar.getType());
getSqlInterface().getMetaDataWriteInterface().addMetaScalar(getDsl(), toMetaDb, toMetaColl, toMetaDocPart, toMetaScalar);
}
}
use of com.torodb.core.transaction.metainf.MetaScalar in project torodb by torodb.
the class AbstractWriteInterface method insertDocPartData.
@Override
public void insertDocPartData(DSLContext dsl, String schemaName, DocPartData docPartData) throws UserException {
Iterator<DocPartRow> docPartRowIterator = docPartData.iterator();
if (!docPartRowIterator.hasNext()) {
return;
}
try {
MetaDocPart metaDocPart = docPartData.getMetaDocPart();
Iterator<MetaScalar> metaScalarIterator = docPartData.orderedMetaScalarIterator();
Iterator<MetaField> metaFieldIterator = docPartData.orderedMetaFieldIterator();
standardInsertDocPartData(dsl, schemaName, docPartData, metaDocPart, metaScalarIterator, metaFieldIterator, docPartRowIterator);
} catch (DataAccessException ex) {
throw errorHandler.handleUserException(Context.INSERT, ex);
}
}
use of com.torodb.core.transaction.metainf.MetaScalar in project torodb by torodb.
the class PostgreSqlWriteInterface method getInsertDocPartDataStatement.
@Override
protected String getInsertDocPartDataStatement(String schemaName, MetaDocPart metaDocPart, Iterator<MetaField> metaFieldIterator, Iterator<MetaScalar> metaScalarIterator, Collection<InternalField<?>> internalFields, List<FieldType> fieldTypeList) {
final StringBuilder insertStatementBuilder = new StringBuilder(2048);
final StringBuilder insertStatementValuesBuilder = new StringBuilder(1024);
insertStatementBuilder.append("INSERT INTO \"").append(schemaName).append("\".\"").append(metaDocPart.getIdentifier()).append("\" (");
insertStatementValuesBuilder.append(" VALUES (");
for (InternalField<?> internalField : internalFields) {
insertStatementBuilder.append("\"").append(internalField.getName()).append("\",");
insertStatementValuesBuilder.append("?,");
}
while (metaScalarIterator.hasNext()) {
MetaScalar metaScalar = metaScalarIterator.next();
FieldType type = metaScalar.getType();
insertStatementBuilder.append("\"").append(metaScalar.getIdentifier()).append("\",");
insertStatementValuesBuilder.append(sqlHelper.getPlaceholder(type)).append(',');
fieldTypeList.add(type);
}
while (metaFieldIterator.hasNext()) {
MetaField metaField = metaFieldIterator.next();
FieldType type = metaField.getType();
insertStatementBuilder.append("\"").append(metaField.getIdentifier()).append("\",");
insertStatementValuesBuilder.append(sqlHelper.getPlaceholder(type)).append(',');
fieldTypeList.add(type);
}
insertStatementBuilder.setCharAt(insertStatementBuilder.length() - 1, ')');
insertStatementValuesBuilder.setCharAt(insertStatementValuesBuilder.length() - 1, ')');
insertStatementBuilder.append(insertStatementValuesBuilder);
String statement = insertStatementBuilder.toString();
return statement;
}
use of com.torodb.core.transaction.metainf.MetaScalar in project torodb by torodb.
the class SnapshotMerger method merge.
private void merge(MetaDatabase db, MetaCollection col, ImmutableMetaDocPart oldStructure, ImmutableMetaDocPart.Builder parentBuilder, ImmutableMetaScalar changed) {
MetaScalar byId = oldStructure.getScalar(changed.getIdentifier());
MetaScalar byType = oldStructure.getScalar(changed.getType());
if (byType != byId) {
throw createUnmergeableException(db, col, oldStructure, changed, byType, byId);
}
if (byType == null && byId == null) {
parentBuilder.put(changed);
}
}
use of com.torodb.core.transaction.metainf.MetaScalar in project torodb by torodb.
the class DerbyWriteInterface method getInsertDocPartDataStatement.
@Override
protected String getInsertDocPartDataStatement(String schemaName, MetaDocPart metaDocPart, Iterator<MetaField> metaFieldIterator, Iterator<MetaScalar> metaScalarIterator, Collection<InternalField<?>> internalFields, List<FieldType> fieldTypeList) {
final StringBuilder insertStatementBuilder = new StringBuilder(2048);
final StringBuilder insertStatementValuesBuilder = new StringBuilder(1024);
insertStatementBuilder.append("INSERT INTO \"").append(schemaName).append("\".\"").append(metaDocPart.getIdentifier()).append("\" (");
insertStatementValuesBuilder.append(" VALUES (");
for (InternalField<?> internalField : internalFields) {
insertStatementBuilder.append("\"").append(internalField.getName()).append("\",");
insertStatementValuesBuilder.append("?,");
}
while (metaScalarIterator.hasNext()) {
MetaScalar metaScalar = metaScalarIterator.next();
insertStatementBuilder.append("\"").append(metaScalar.getIdentifier()).append("\",");
insertStatementValuesBuilder.append("?,");
fieldTypeList.add(metaScalar.getType());
}
while (metaFieldIterator.hasNext()) {
MetaField metaField = metaFieldIterator.next();
insertStatementBuilder.append("\"").append(metaField.getIdentifier()).append("\",");
insertStatementValuesBuilder.append("?,");
fieldTypeList.add(metaField.getType());
}
insertStatementBuilder.setCharAt(insertStatementBuilder.length() - 1, ')');
insertStatementValuesBuilder.setCharAt(insertStatementValuesBuilder.length() - 1, ')');
insertStatementBuilder.append(insertStatementValuesBuilder);
String statement = insertStatementBuilder.toString();
return statement;
}
Aggregations