Search in sources :

Example 11 with MetaDocPart

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

the class InsertBackendJobImpl method toString.

@Override
public String toString() {
    MetaDocPart docPart = data.getMetaDocPart();
    int rowCount = data.rowCount();
    return "insert{db:" + db + ", col:" + col + ", docPart:" + docPart + ", rows:" + rowCount + '}';
}
Also used : MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart)

Example 12 with MetaDocPart

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

the class R2DTranslatorImpl method translate.

@Override
public List<ToroDocument> translate(Iterator<DocPartResult> docPartResultIt) {
    ImmutableList.Builder<ToroDocument> readedDocuments = ImmutableList.builder();
    Table<TableRef, Integer, Map<String, List<KvValue<?>>>> currentFieldDocPartTable = HashBasedTable.<TableRef, Integer, Map<String, List<KvValue<?>>>>create();
    Table<TableRef, Integer, Map<String, List<KvValue<?>>>> childFieldDocPartTable = HashBasedTable.<TableRef, Integer, Map<String, List<KvValue<?>>>>create();
    int previousDepth = -1;
    while (docPartResultIt.hasNext()) {
        DocPartResult docPartResult = docPartResultIt.next();
        MetaDocPart metaDocPart = docPartResult.getMetaDocPart();
        TableRef tableRef = metaDocPart.getTableRef();
        if (previousDepth != -1 && previousDepth != tableRef.getDepth()) {
            Table<TableRef, Integer, Map<String, List<KvValue<?>>>> previousFieldChildDocPartTable = childFieldDocPartTable;
            childFieldDocPartTable = currentFieldDocPartTable;
            currentFieldDocPartTable = previousFieldChildDocPartTable;
            if (!tableRef.isRoot()) {
                currentFieldDocPartTable.clear();
            }
        }
        previousDepth = tableRef.getDepth();
        Map<Integer, Map<String, List<KvValue<?>>>> childFieldDocPartRow = childFieldDocPartTable.row(tableRef);
        Map<Integer, Map<String, List<KvValue<?>>>> currentFieldDocPartRow;
        if (tableRef.isRoot()) {
            currentFieldDocPartRow = null;
        } else {
            currentFieldDocPartRow = currentFieldDocPartTable.row(tableRef.getParent().get());
        }
        readResult(metaDocPart, tableRef, docPartResult, currentFieldDocPartRow, childFieldDocPartRow, readedDocuments);
    }
    return readedDocuments.build();
}
Also used : MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) ImmutableList(com.google.common.collect.ImmutableList) ToroDocument(com.torodb.core.document.ToroDocument) DocPartResult(com.torodb.core.d2r.DocPartResult) HashMap(java.util.HashMap) Map(java.util.Map) TableRef(com.torodb.core.TableRef) KvValue(com.torodb.kvdocument.values.KvValue)

Example 13 with MetaDocPart

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

the class AbstractReadInterface method getCollectionDidsWithFieldsInBatch.

@SuppressFBWarnings(value = { "OBL_UNSATISFIED_OBLIGATION", "ODR_OPEN_DATABASE_RESOURCE" }, justification = "ResultSet is wrapped in a Cursor<Integer>. It's iterated and closed in caller code")
private Cursor<Integer> getCollectionDidsWithFieldsInBatch(DSLContext dsl, MetaDatabase metaDatabase, MetaCollection metaCol, MetaDocPart metaDocPart, Multimap<MetaField, KvValue<?>> valuesMultimap) throws SQLException {
    @SuppressWarnings("checkstyle:LineLength") Provider<Stream<Map.Entry<MetaField, Collection<KvValue<?>>>>> valuesMultimapSortedStreamProvider = () -> valuesMultimap.asMap().entrySet().stream().sorted((e1, e2) -> e1.getKey().getIdentifier().compareTo(e2.getKey().getIdentifier()));
    String statement = getReadCollectionDidsWithFieldInStatement(metaDatabase.getIdentifier(), metaDocPart.getIdentifier(), valuesMultimapSortedStreamProvider.get().map(e -> new Tuple2<String, Integer>(e.getKey().getIdentifier(), e.getValue().size())));
    Connection connection = dsl.configuration().connectionProvider().acquire();
    try {
        PreparedStatement preparedStatement = connection.prepareStatement(statement);
        int parameterIndex = 1;
        Iterator<Map.Entry<MetaField, Collection<KvValue<?>>>> valuesMultimapSortedIterator = valuesMultimapSortedStreamProvider.get().iterator();
        while (valuesMultimapSortedIterator.hasNext()) {
            Map.Entry<MetaField, Collection<KvValue<?>>> valuesMultimapEntry = valuesMultimapSortedIterator.next();
            for (KvValue<?> value : valuesMultimapEntry.getValue()) {
                sqlHelper.setPreparedStatementValue(preparedStatement, parameterIndex, valuesMultimapEntry.getKey().getType(), value);
                parameterIndex++;
            }
        }
        return new DefaultDidCursor(errorHandler, preparedStatement.executeQuery());
    } finally {
        dsl.configuration().connectionProvider().release(connection);
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Connection(java.sql.Connection) Provider(javax.inject.Provider) IteratorCursor(com.torodb.core.cursors.IteratorCursor) Multimap(com.google.common.collect.Multimap) Seq(org.jooq.lambda.Seq) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) TableRefFactory(com.torodb.core.TableRefFactory) KvValue(com.torodb.kvdocument.values.KvValue) Tuple2(org.jooq.lambda.tuple.Tuple2) SQLException(java.sql.SQLException) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) ResultSetDocPartResult(com.torodb.backend.d2r.ResultSetDocPartResult) ResultSet(java.sql.ResultSet) Map(java.util.Map) DSLContext(org.jooq.DSLContext) Context(com.torodb.backend.ErrorHandler.Context) Nonnull(javax.annotation.Nonnull) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) Unchecked(org.jooq.lambda.Unchecked) Iterator(java.util.Iterator) Cursor(com.torodb.core.cursors.Cursor) Collection(java.util.Collection) EmptyCursor(com.torodb.core.cursors.EmptyCursor) DocPartTableFields(com.torodb.backend.tables.MetaDocPartTable.DocPartTableFields) PreparedStatement(java.sql.PreparedStatement) Collectors(java.util.stream.Collectors) TableRef(com.torodb.core.TableRef) List(java.util.List) MetaField(com.torodb.core.transaction.metainf.MetaField) Stream(java.util.stream.Stream) DocPartResult(com.torodb.core.d2r.DocPartResult) Entry(java.util.Map.Entry) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) MetaField(com.torodb.core.transaction.metainf.MetaField) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Entry(java.util.Map.Entry) Tuple2(org.jooq.lambda.tuple.Tuple2) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) Collection(java.util.Collection) Stream(java.util.stream.Stream) Map(java.util.Map) KvValue(com.torodb.kvdocument.values.KvValue) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 14 with MetaDocPart

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

the class AbstractStructureInterface method renameCollection.

@Override
public void renameCollection(DSLContext dsl, String fromSchemaName, MetaCollection fromCollection, String toSchemaName, MetaCollection toCollection) {
    Iterator<? extends MetaDocPart> metaDocPartIterator = fromCollection.streamContainedMetaDocParts().iterator();
    while (metaDocPartIterator.hasNext()) {
        MetaDocPart fromMetaDocPart = metaDocPartIterator.next();
        MetaDocPart toMetaDocPart = toCollection.getMetaDocPartByTableRef(fromMetaDocPart.getTableRef());
        String renameStatement = getRenameTableStatement(fromSchemaName, fromMetaDocPart.getIdentifier(), toMetaDocPart.getIdentifier());
        sqlHelper.executeUpdate(dsl, renameStatement, Context.RENAME_TABLE);
        Iterator<? extends MetaIdentifiedDocPartIndex> metaDocPartIndexIterator = fromMetaDocPart.streamIndexes().iterator();
        while (metaDocPartIndexIterator.hasNext()) {
            MetaIdentifiedDocPartIndex fromMetaIndex = metaDocPartIndexIterator.next();
            MetaIdentifiedDocPartIndex toMetaIndex = toMetaDocPart.streamIndexes().filter(index -> index.hasSameColumns(fromMetaIndex)).findAny().get();
            String renameIndexStatement = getRenameIndexStatement(fromSchemaName, fromMetaIndex.getIdentifier(), toMetaIndex.getIdentifier());
            sqlHelper.executeUpdate(dsl, renameIndexStatement, Context.RENAME_INDEX);
        }
        if (!fromSchemaName.equals(toSchemaName)) {
            String setSchemaStatement = getSetTableSchemaStatement(fromSchemaName, fromMetaDocPart.getIdentifier(), toSchemaName);
            sqlHelper.executeUpdate(dsl, setSchemaStatement, Context.SET_TABLE_SCHEMA);
        }
    }
}
Also used : MetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart)

Example 15 with MetaDocPart

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

the class AbstractWriteInterface method deleteCollectionDocParts.

private void deleteCollectionDocParts(Connection c, String schemaName, MetaCollection metaCollection, Collection<Integer> dids) {
    Iterator<? extends MetaDocPart> iterator = metaCollection.streamContainedMetaDocParts().sorted(TableRefComparator.MetaDocPart.DESC).iterator();
    while (iterator.hasNext()) {
        MetaDocPart metaDocPart = iterator.next();
        String statement = getDeleteDocPartsStatement(schemaName, metaDocPart.getIdentifier(), dids);
        sqlHelper.executeUpdate(c, statement, Context.DELETE);
        LOGGER.trace("Executed {}", statement);
    }
}
Also used : MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart)

Aggregations

MetaDocPart (com.torodb.core.transaction.metainf.MetaDocPart)20 TableRef (com.torodb.core.TableRef)7 MetaCollection (com.torodb.core.transaction.metainf.MetaCollection)7 MetaDatabase (com.torodb.core.transaction.metainf.MetaDatabase)6 MetaField (com.torodb.core.transaction.metainf.MetaField)6 KvValue (com.torodb.kvdocument.values.KvValue)4 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)4 EmptyCursor (com.torodb.core.cursors.EmptyCursor)3 DocPartResult (com.torodb.core.d2r.DocPartResult)3 MetaIdentifiedDocPartIndex (com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex)3 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ArrayList (java.util.ArrayList)3 Context (com.torodb.backend.ErrorHandler.Context)2 ResultSetDocPartResult (com.torodb.backend.d2r.ResultSetDocPartResult)2 DocPartRow (com.torodb.core.d2r.DocPartRow)2 MetaIndex (com.torodb.core.transaction.metainf.MetaIndex)2 EmptyTorodCursor (com.torodb.torod.cursors.EmptyTorodCursor)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2