Search in sources :

Example 1 with MetaField

use of com.torodb.core.transaction.metainf.MetaField 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 2 with MetaField

use of com.torodb.core.transaction.metainf.MetaField in project torodb by torodb.

the class SqlTorodTransaction method findByAttRef.

@Override
public TorodCursor findByAttRef(String dbName, String colName, AttributeReference attRef, KvValue<?> value) {
    MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
    if (db == null) {
        LOGGER.trace("Db with name " + dbName + " does not exist. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        LOGGER.trace("Collection " + dbName + '.' + colName + " does not exist. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    TableRef ref = extractTableRef(attRef);
    String lastKey = extractKeyName(attRef.getKeys().get(attRef.getKeys().size() - 1));
    MetaDocPart docPart = col.getMetaDocPartByTableRef(ref);
    if (docPart == null) {
        LOGGER.trace("DocPart " + dbName + '.' + colName + '.' + ref + " does not exist. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    MetaField field = docPart.getMetaFieldByNameAndType(lastKey, FieldType.from(value.getType()));
    if (field == null) {
        LOGGER.trace("Field " + dbName + '.' + colName + '.' + ref + '.' + lastKey + " does not exist. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    return toToroCursor(getInternalTransaction().getBackendTransaction().findByField(db, col, docPart, field, value));
}
Also used : EmptyTorodCursor(com.torodb.torod.cursors.EmptyTorodCursor) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) MetaField(com.torodb.core.transaction.metainf.MetaField) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) TableRef(com.torodb.core.TableRef)

Example 3 with MetaField

use of com.torodb.core.transaction.metainf.MetaField in project torodb by torodb.

the class ExclusiveWriteBackendTransactionImpl method copyFields.

private void copyFields(IdentifierFactory identifierFactory, MetaDocPart fromMetaDocPart, MetaDatabase toMetaDb, MetaCollection toMetaColl, MutableMetaDocPart toMetaDocPart) {
    Iterator<? extends MetaField> fromMetaFieldIterator = fromMetaDocPart.streamFields().iterator();
    while (fromMetaFieldIterator.hasNext()) {
        MetaField fromMetaField = fromMetaFieldIterator.next();
        MetaField toMetaField = toMetaDocPart.addMetaField(fromMetaField.getName(), identifierFactory.toFieldIdentifier(toMetaDocPart, fromMetaField.getName(), fromMetaField.getType()), fromMetaField.getType());
        getSqlInterface().getMetaDataWriteInterface().addMetaField(getDsl(), toMetaDb, toMetaColl, toMetaDocPart, toMetaField);
    }
}
Also used : MetaField(com.torodb.core.transaction.metainf.MetaField)

Example 4 with MetaField

use of com.torodb.core.transaction.metainf.MetaField 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 5 with MetaField

use of com.torodb.core.transaction.metainf.MetaField 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

MetaField (com.torodb.core.transaction.metainf.MetaField)12 MetaDocPart (com.torodb.core.transaction.metainf.MetaDocPart)6 TableRef (com.torodb.core.TableRef)5 MetaCollection (com.torodb.core.transaction.metainf.MetaCollection)5 MetaDatabase (com.torodb.core.transaction.metainf.MetaDatabase)5 MetaScalar (com.torodb.core.transaction.metainf.MetaScalar)5 KvValue (com.torodb.kvdocument.values.KvValue)3 EmptyCursor (com.torodb.core.cursors.EmptyCursor)2 EmptyTorodCursor (com.torodb.torod.cursors.EmptyTorodCursor)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 Multimap (com.google.common.collect.Multimap)1 Context (com.torodb.backend.ErrorHandler.Context)1 ResultSetDocPartResult (com.torodb.backend.d2r.ResultSetDocPartResult)1 DocPartTableFields (com.torodb.backend.tables.MetaDocPartTable.DocPartTableFields)1 TableRefFactory (com.torodb.core.TableRefFactory)1 Cursor (com.torodb.core.cursors.Cursor)1 IteratorCursor (com.torodb.core.cursors.IteratorCursor)1