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());
}
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);
}
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);
}
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;
}
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);
}
Aggregations