use of com.torodb.core.transaction.metainf.MetaDocPart in project torodb by torodb.
the class SqlTorodTransaction method findByAttRef.
@Override
public TorodCursor findByAttRef(String dbName, String colName, AttributeReference attRef, KvValue<?> value) {
MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
if (db == null) {
LOGGER.trace("Db with name " + dbName + " does not exist. An empty cursor is returned");
return new EmptyTorodCursor();
}
MetaCollection col = db.getMetaCollectionByName(colName);
if (col == null) {
LOGGER.trace("Collection " + dbName + '.' + colName + " does not exist. An empty cursor is returned");
return new EmptyTorodCursor();
}
TableRef ref = extractTableRef(attRef);
String lastKey = extractKeyName(attRef.getKeys().get(attRef.getKeys().size() - 1));
MetaDocPart docPart = col.getMetaDocPartByTableRef(ref);
if (docPart == null) {
LOGGER.trace("DocPart " + dbName + '.' + colName + '.' + ref + " does not exist. An empty cursor is returned");
return new EmptyTorodCursor();
}
MetaField field = docPart.getMetaFieldByNameAndType(lastKey, FieldType.from(value.getType()));
if (field == null) {
LOGGER.trace("Field " + dbName + '.' + colName + '.' + ref + '.' + lastKey + " does not exist. An empty cursor is returned");
return new EmptyTorodCursor();
}
return toToroCursor(getInternalTransaction().getBackendTransaction().findByField(db, col, docPart, field, value));
}
use of com.torodb.core.transaction.metainf.MetaDocPart in project torodb by torodb.
the class BackendServiceImpl method enableInternalIndexJobs.
private Stream<Consumer<DSLContext>> enableInternalIndexJobs(MetaDatabase db, MetaCollection col, MetaDocPart docPart) {
StructureInterface structureInterface = sqlInterface.getStructureInterface();
Stream<Function<DSLContext, String>> consumerStream;
if (docPart.getTableRef().isRoot()) {
consumerStream = structureInterface.streamRootDocPartTableIndexesCreation(db.getIdentifier(), docPart.getIdentifier(), docPart.getTableRef());
} else {
MetaDocPart parentDocPart = col.getMetaDocPartByTableRef(docPart.getTableRef().getParent().get());
assert parentDocPart != null;
consumerStream = structureInterface.streamDocPartTableIndexesCreation(db.getIdentifier(), docPart.getIdentifier(), docPart.getTableRef(), parentDocPart.getIdentifier());
}
return consumerStream.map(job -> {
return (Consumer<DSLContext>) dsl -> {
String index = job.apply(dsl);
LOGGER.info("Created internal index {} for table {}", index, docPart.getIdentifier());
};
});
}
use of com.torodb.core.transaction.metainf.MetaDocPart in project torodb by torodb.
the class ExclusiveWriteBackendTransactionImpl method copyMetaCollection.
private void copyMetaCollection(MetaDatabase fromDb, MetaCollection fromColl, MutableMetaDatabase toDb, MutableMetaCollection toColl) {
IdentifierFactory identifierFactory = getIdentifierFactory();
Iterator<? extends MetaIndex> fromMetaIndexIterator = fromColl.streamContainedMetaIndexes().iterator();
while (fromMetaIndexIterator.hasNext()) {
MetaIndex fromMetaIndex = fromMetaIndexIterator.next();
MutableMetaIndex toMetaIndex = toColl.addMetaIndex(fromMetaIndex.getName(), fromMetaIndex.isUnique());
getSqlInterface().getMetaDataWriteInterface().addMetaIndex(getDsl(), toDb, toColl, toMetaIndex);
copyIndexFields(fromMetaIndex, toDb, toColl, toMetaIndex);
}
Iterator<? extends MetaDocPart> fromMetaDocPartIterator = fromColl.streamContainedMetaDocParts().iterator();
while (fromMetaDocPartIterator.hasNext()) {
MetaDocPart fromMetaDocPart = fromMetaDocPartIterator.next();
MutableMetaDocPart toMetaDocPart = toColl.addMetaDocPart(fromMetaDocPart.getTableRef(), identifierFactory.toDocPartIdentifier(toDb, toColl.getName(), fromMetaDocPart.getTableRef()));
getSqlInterface().getMetaDataWriteInterface().addMetaDocPart(getDsl(), toDb, toColl, toMetaDocPart);
copyScalar(identifierFactory, fromMetaDocPart, toDb, toColl, toMetaDocPart);
copyFields(identifierFactory, fromMetaDocPart, toDb, toColl, toMetaDocPart);
copyIndexes(identifierFactory, fromMetaDocPart, toDb, toColl, toMetaDocPart);
int nextRid = ridGenerator.getDocPartRidGenerator(fromDb.getName(), fromColl.getName()).nextRid(fromMetaDocPart.getTableRef());
ridGenerator.getDocPartRidGenerator(toDb.getName(), toColl.getName()).setNextRid(toMetaDocPart.getTableRef(), nextRid - 1);
}
}
use of com.torodb.core.transaction.metainf.MetaDocPart in project torodb by torodb.
the class AbstractReadInterface method countAll.
@Override
public long countAll(@Nonnull DSLContext dsl, @Nonnull MetaDatabase database, @Nonnull MetaCollection collection) {
MetaDocPart rootDocPart = collection.getMetaDocPartByTableRef(tableRefFactory.createRoot());
if (rootDocPart == null) {
return 0;
}
String statement = getReadCountAllStatement(database.getIdentifier(), rootDocPart.getIdentifier());
return sqlHelper.executeStatementWithResult(dsl, statement, Context.FETCH).get(0).into(Long.class);
}
use of com.torodb.core.transaction.metainf.MetaDocPart in project torodb by torodb.
the class AbstractReadInterface method getCollectionResultSets.
@Override
@SuppressFBWarnings(value = { "OBL_UNSATISFIED_OBLIGATION", "ODR_OPEN_DATABASE_RESOURCE" }, justification = "ResultSet is wrapped in a DocPartResult. It's iterated and closed in caller code")
public List<DocPartResult> getCollectionResultSets(DSLContext dsl, MetaDatabase metaDatabase, MetaCollection metaCollection, Collection<Integer> dids) throws SQLException {
ArrayList<DocPartResult> result = new ArrayList<>();
Connection connection = dsl.configuration().connectionProvider().acquire();
try {
Iterator<? extends MetaDocPart> metaDocPartIterator = metaCollection.streamContainedMetaDocParts().sorted(TableRefComparator.MetaDocPart.DESC).iterator();
while (metaDocPartIterator.hasNext()) {
MetaDocPart metaDocPart = metaDocPartIterator.next();
String statament = getDocPartStatament(metaDatabase, metaDocPart, dids);
PreparedStatement preparedStatement = connection.prepareStatement(statament);
result.add(new ResultSetDocPartResult(metaDataReadInterface, dataTypeProvider, errorHandler, metaDocPart, preparedStatement.executeQuery(), sqlHelper));
}
} finally {
dsl.configuration().connectionProvider().release(connection);
}
return result;
}
Aggregations