Search in sources :

Example 1 with MetaDocPart

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));
}
Also used : EmptyTorodCursor(com.torodb.torod.cursors.EmptyTorodCursor) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) MetaField(com.torodb.core.transaction.metainf.MetaField) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) TableRef(com.torodb.core.TableRef)

Example 2 with MetaDocPart

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());
        };
    });
}
Also used : Function(java.util.function.Function) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) Consumer(java.util.function.Consumer)

Example 3 with MetaDocPart

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);
    }
}
Also used : MutableMetaIndex(com.torodb.core.transaction.metainf.MutableMetaIndex) MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) MutableMetaDocPart(com.torodb.core.transaction.metainf.MutableMetaDocPart) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) MutableMetaDocPart(com.torodb.core.transaction.metainf.MutableMetaDocPart) MutableMetaIndex(com.torodb.core.transaction.metainf.MutableMetaIndex) IdentifierFactory(com.torodb.core.d2r.IdentifierFactory)

Example 4 with MetaDocPart

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);
}
Also used : MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart)

Example 5 with MetaDocPart

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;
}
Also used : ResultSetDocPartResult(com.torodb.backend.d2r.ResultSetDocPartResult) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSetDocPartResult(com.torodb.backend.d2r.ResultSetDocPartResult) DocPartResult(com.torodb.core.d2r.DocPartResult) PreparedStatement(java.sql.PreparedStatement) 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