Search in sources :

Example 1 with MetaCollection

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

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

the class SqlTorodTransaction method getDocumentsSize.

@Override
public long getDocumentsSize(String dbName, String colName) {
    MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
    if (db == null) {
        return 0;
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        return 0;
    }
    return getInternalTransaction().getBackendTransaction().getDocumentsSize(db, col);
}
Also used : MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection)

Example 3 with MetaCollection

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

the class SqlTorodTransaction method getIndexesInfo.

@Override
public Stream<IndexInfo> getIndexesInfo(String dbName, String colName) {
    MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
    if (db == null) {
        return Stream.empty();
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        return Stream.empty();
    }
    return col.streamContainedMetaIndexes().map(metaIdx -> createIndexInfo(metaIdx));
}
Also used : MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection)

Example 4 with MetaCollection

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

the class SqlTorodTransaction method getCollectionInfo.

@Override
public CollectionInfo getCollectionInfo(String dbName, String colName) throws CollectionNotFoundException {
    MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
    if (db == null) {
        throw new CollectionNotFoundException(dbName, colName);
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        throw new CollectionNotFoundException(dbName, colName);
    }
    return new CollectionInfo(db.getMetaCollectionByName(colName).getName(), Json.createObjectBuilder().build());
}
Also used : MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) CollectionInfo(com.torodb.torod.CollectionInfo) CollectionNotFoundException(com.torodb.core.exceptions.user.CollectionNotFoundException)

Example 5 with MetaCollection

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

the class SqlTorodTransaction method getIndexInfo.

@Override
public IndexInfo getIndexInfo(String dbName, String colName, String idxName) throws IndexNotFoundException {
    MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
    if (db == null) {
        throw new IndexNotFoundException(dbName, colName, idxName);
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        throw new IndexNotFoundException(dbName, colName, idxName);
    }
    MetaIndex idx = col.getMetaIndexByName(idxName);
    if (idx == null) {
        throw new IndexNotFoundException(dbName, colName, idxName);
    }
    return createIndexInfo(idx);
}
Also used : MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) IndexNotFoundException(com.torodb.core.exceptions.user.IndexNotFoundException)

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