Search in sources :

Example 6 with MetaCollection

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

the class SqlWriteTorodTransaction method delete.

@Override
public void delete(String dbName, String colName, Cursor<Integer> cursor) {
    MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
    if (db == null) {
        return;
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        return;
    }
    getInternalTransaction().getBackendTransaction().deleteDids(db, col, cursor.getRemaining());
}
Also used : MutableMetaDatabase(com.torodb.core.transaction.metainf.MutableMetaDatabase) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) MutableMetaCollection(com.torodb.core.transaction.metainf.MutableMetaCollection) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection)

Example 7 with MetaCollection

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

the class SharedWriteBackendTransactionImpl method dropDatabase.

@Override
public void dropDatabase(MetaDatabase db) {
    Preconditions.checkState(!isClosed(), "This transaction is closed");
    Iterator<? extends MetaCollection> metaCollectionIterator = db.streamMetaCollections().iterator();
    while (metaCollectionIterator.hasNext()) {
        MetaCollection metaCollection = metaCollectionIterator.next();
        dropMetaCollection(db, metaCollection);
    }
    getSqlInterface().getMetaDataWriteInterface().deleteMetaDatabase(getDsl(), db);
    getSqlInterface().getStructureInterface().dropDatabase(getDsl(), db);
}
Also used : MutableMetaCollection(com.torodb.core.transaction.metainf.MutableMetaCollection) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection)

Example 8 with MetaCollection

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

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

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

the class SqlExclusiveWriteTorodTransaction method renameCollection.

@Override
public void renameCollection(String fromDb, String fromCollection, String toDb, String toCollection) throws RollbackException, UserException {
    MutableMetaDatabase fromMetaDb = getMetaDatabaseOrThrowException(fromDb);
    MetaCollection fromMetaColl = getMetaCollectionOrThrowException(fromMetaDb, fromCollection);
    MutableMetaDatabase toMetaDb = getOrCreateMetaDatabase(toDb);
    MutableMetaCollection toMetaColl = createMetaCollection(toMetaDb, toCollection);
    getInternalTransaction().getBackendTransaction().renameCollection(fromMetaDb, fromMetaColl, toMetaDb, toMetaColl);
    fromMetaDb.removeMetaCollectionByName(fromCollection);
}
Also used : MutableMetaCollection(com.torodb.core.transaction.metainf.MutableMetaCollection) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) MutableMetaCollection(com.torodb.core.transaction.metainf.MutableMetaCollection) MutableMetaDatabase(com.torodb.core.transaction.metainf.MutableMetaDatabase)

Aggregations

MetaCollection (com.torodb.core.transaction.metainf.MetaCollection)19 MetaDatabase (com.torodb.core.transaction.metainf.MetaDatabase)16 MetaDocPart (com.torodb.core.transaction.metainf.MetaDocPart)7 TableRef (com.torodb.core.TableRef)6 MetaField (com.torodb.core.transaction.metainf.MetaField)5 MutableMetaCollection (com.torodb.core.transaction.metainf.MutableMetaCollection)5 MutableMetaDatabase (com.torodb.core.transaction.metainf.MutableMetaDatabase)4 EmptyTorodCursor (com.torodb.torod.cursors.EmptyTorodCursor)4 KvValue (com.torodb.kvdocument.values.KvValue)3 Context (com.torodb.backend.ErrorHandler.Context)2 EmptyCursor (com.torodb.core.cursors.EmptyCursor)2 MetaIndex (com.torodb.core.transaction.metainf.MetaIndex)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 Stream (java.util.stream.Stream)2 Nonnull (javax.annotation.Nonnull)2 Singleton (javax.inject.Singleton)2 DSLContext (org.jooq.DSLContext)2 Preconditions (com.google.common.base.Preconditions)1