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