Search in sources :

Example 6 with MetaDocPart

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

the class AbstractStructureInterface method dropCollection.

@Override
public void dropCollection(DSLContext dsl, String schemaName, MetaCollection metaCollection) {
    Iterator<? extends MetaDocPart> metaDocPartIterator = metaCollection.streamContainedMetaDocParts().sorted(TableRefComparator.MetaDocPart.DESC).iterator();
    while (metaDocPartIterator.hasNext()) {
        MetaDocPart metaDocPart = metaDocPartIterator.next();
        String statement = getDropTableStatement(schemaName, metaDocPart.getIdentifier());
        sqlHelper.executeUpdate(dsl, statement, Context.DROP_TABLE);
    }
}
Also used : MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart)

Example 7 with MetaDocPart

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

the class AbstractStructureInterface method dropDatabase.

@Override
public void dropDatabase(DSLContext dsl, MetaDatabase metaDatabase) {
    Iterator<? extends MetaCollection> metaCollectionIterator = metaDatabase.streamMetaCollections().iterator();
    while (metaCollectionIterator.hasNext()) {
        MetaCollection metaCollection = metaCollectionIterator.next();
        Iterator<? extends MetaDocPart> metaDocPartIterator = metaCollection.streamContainedMetaDocParts().sorted(TableRefComparator.MetaDocPart.DESC).iterator();
        while (metaDocPartIterator.hasNext()) {
            MetaDocPart metaDocPart = metaDocPartIterator.next();
            String statement = getDropTableStatement(metaDatabase.getIdentifier(), metaDocPart.getIdentifier());
            sqlHelper.executeUpdate(dsl, statement, Context.DROP_TABLE);
        }
    }
    String statement = getDropSchemaStatement(metaDatabase.getIdentifier());
    sqlHelper.executeUpdate(dsl, statement, Context.DROP_SCHEMA);
}
Also used : MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection)

Example 8 with MetaDocPart

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

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

the class AbstractMetaDataReadInterface method getIndexSize.

@Override
public Long getIndexSize(@Nonnull DSLContext dsl, @Nonnull MetaDatabase database, @Nonnull MetaCollection collection, @Nonnull String indexName) {
    long result = 0;
    MetaIndex index = collection.getMetaIndexByName(indexName);
    Iterator<TableRef> tableRefIterator = index.streamTableRefs().iterator();
    while (tableRefIterator.hasNext()) {
        TableRef tableRef = tableRefIterator.next();
        MetaDocPart docPart = collection.getMetaDocPartByTableRef(tableRef);
        Iterator<? extends MetaIdentifiedDocPartIndex> docPartIndexIterator = docPart.streamIndexes().iterator();
        while (docPartIndexIterator.hasNext()) {
            MetaIdentifiedDocPartIndex docPartIndex = docPartIndexIterator.next();
            if (index.isCompatible(docPart, docPartIndex)) {
                long relatedIndexCount = collection.streamContainedMetaIndexes().filter(i -> i.isCompatible(docPart, docPartIndex)).count();
                String statement = getReadIndexSizeStatement(database.getIdentifier(), docPart.getIdentifier(), docPartIndex.getIdentifier());
                result += sqlHelper.executeStatementWithResult(dsl, statement, Context.FETCH).get(0).into(Long.class) / relatedIndexCount;
            }
        }
    }
    return result;
}
Also used : MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) KvTable(com.torodb.backend.tables.KvTable) Singleton(javax.inject.Singleton) Condition(org.jooq.Condition) MetaDocPartTable(com.torodb.backend.tables.MetaDocPartTable) MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) Inject(javax.inject.Inject) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) Record1(org.jooq.Record1) DSLContext(org.jooq.DSLContext) Context(com.torodb.backend.ErrorHandler.Context) Nonnull(javax.annotation.Nonnull) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) Record(org.jooq.Record) Iterator(java.util.Iterator) KvRecord(com.torodb.backend.tables.records.KvRecord) Collection(java.util.Collection) MetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex) Result(org.jooq.Result) TableRef(com.torodb.core.TableRef) Stream(java.util.stream.Stream) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) MetaInfoKey(com.torodb.core.backend.MetaInfoKey) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) MetaDatabaseRecord(com.torodb.backend.tables.records.MetaDatabaseRecord) MetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) TableRef(com.torodb.core.TableRef)

Example 10 with MetaDocPart

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

the class AbstractReadInterface method getAllCollectionDids.

@Override
@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")
public Cursor<Integer> getAllCollectionDids(DSLContext dsl, MetaDatabase metaDatabase, MetaCollection metaCollection) throws SQLException {
    MetaDocPart rootDocPart = metaCollection.getMetaDocPartByTableRef(tableRefFactory.createRoot());
    if (rootDocPart == null) {
        return new EmptyCursor<>();
    }
    String statement = getReadAllCollectionDidsStatement(metaDatabase.getIdentifier(), rootDocPart.getIdentifier());
    Connection connection = dsl.configuration().connectionProvider().acquire();
    try {
        PreparedStatement preparedStatement = connection.prepareStatement(statement);
        return new DefaultDidCursor(errorHandler, preparedStatement.executeQuery());
    } finally {
        dsl.configuration().connectionProvider().release(connection);
    }
}
Also used : MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) EmptyCursor(com.torodb.core.cursors.EmptyCursor) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

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