Search in sources :

Example 1 with EmptyCursor

use of com.torodb.core.cursors.EmptyCursor 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);
    }
}
Also used : MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) EmptyCursor(com.torodb.core.cursors.EmptyCursor) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with EmptyCursor

use of com.torodb.core.cursors.EmptyCursor in project torodb by torodb.

the class SqlTorodTransaction method findByAttRefInProjection.

@Override
public Cursor<Tuple2<Integer, KvValue<?>>> findByAttRefInProjection(String dbName, String colName, AttributeReference attRef, Collection<KvValue<?>> values) {
    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 EmptyCursor<>();
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        LOGGER.trace("Collection " + dbName + '.' + colName + " does not exist. An empty cursor is returned");
        return new EmptyCursor<>();
    }
    if (values.isEmpty()) {
        LOGGER.trace("An empty list of values have been given as in condition. An empty cursor is returned");
        return new EmptyCursor<>();
    }
    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 EmptyCursor<>();
    }
    Multimap<MetaField, KvValue<?>> valuesMap = ArrayListMultimap.create();
    for (KvValue<?> value : values) {
        MetaField field = docPart.getMetaFieldByNameAndType(lastKey, FieldType.from(value.getType()));
        if (field != null) {
            valuesMap.put(field, value);
        }
    }
    return getInternalTransaction().getBackendTransaction().findByFieldInProjection(db, col, docPart, valuesMap);
}
Also used : 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) EmptyCursor(com.torodb.core.cursors.EmptyCursor) TableRef(com.torodb.core.TableRef) KvValue(com.torodb.kvdocument.values.KvValue)

Aggregations

EmptyCursor (com.torodb.core.cursors.EmptyCursor)2 MetaDocPart (com.torodb.core.transaction.metainf.MetaDocPart)2 TableRef (com.torodb.core.TableRef)1 MetaCollection (com.torodb.core.transaction.metainf.MetaCollection)1 MetaDatabase (com.torodb.core.transaction.metainf.MetaDatabase)1 MetaField (com.torodb.core.transaction.metainf.MetaField)1 KvValue (com.torodb.kvdocument.values.KvValue)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1