Search in sources :

Example 1 with MetaScalar

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);
    }
}
Also used : MetaScalar(com.torodb.core.transaction.metainf.MetaScalar)

Example 2 with MetaScalar

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);
    }
}
Also used : MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) MetaField(com.torodb.core.transaction.metainf.MetaField) DocPartRow(com.torodb.core.d2r.DocPartRow) DataAccessException(org.jooq.exception.DataAccessException) MetaScalar(com.torodb.core.transaction.metainf.MetaScalar)

Example 3 with MetaScalar

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;
}
Also used : MetaField(com.torodb.core.transaction.metainf.MetaField) MetaScalar(com.torodb.core.transaction.metainf.MetaScalar) FieldType(com.torodb.core.transaction.metainf.FieldType)

Example 4 with MetaScalar

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);
    }
}
Also used : ImmutableMetaScalar(com.torodb.core.transaction.metainf.ImmutableMetaScalar) MetaScalar(com.torodb.core.transaction.metainf.MetaScalar)

Example 5 with MetaScalar

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;
}
Also used : MetaField(com.torodb.core.transaction.metainf.MetaField) MetaScalar(com.torodb.core.transaction.metainf.MetaScalar)

Aggregations

MetaScalar (com.torodb.core.transaction.metainf.MetaScalar)8 MetaField (com.torodb.core.transaction.metainf.MetaField)5 ImmutableList (com.google.common.collect.ImmutableList)1 DocPartResultRow (com.torodb.core.d2r.DocPartResultRow)1 DocPartRow (com.torodb.core.d2r.DocPartRow)1 ToroDocument (com.torodb.core.document.ToroDocument)1 FieldType (com.torodb.core.transaction.metainf.FieldType)1 ImmutableMetaScalar (com.torodb.core.transaction.metainf.ImmutableMetaScalar)1 MetaDocPart (com.torodb.core.transaction.metainf.MetaDocPart)1 KvDocument (com.torodb.kvdocument.values.KvDocument)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DataAccessException (org.jooq.exception.DataAccessException)1