use of com.torodb.core.transaction.metainf.MetaCollection in project torodb by torodb.
the class SqlTorodTransaction method getCollectionSize.
@Override
public long getCollectionSize(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().getCollectionSize(db, col);
}
use of com.torodb.core.transaction.metainf.MetaCollection 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);
}
use of com.torodb.core.transaction.metainf.MetaCollection in project torodb by torodb.
the class SqlWriteTorodTransaction method deleteByAttRef.
@Override
public long deleteByAttRef(String dbName, String colName, AttributeReference attRef, KvValue<?> value) {
MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
if (db == null) {
return 0;
}
MetaCollection col = db.getMetaCollectionByName(colName);
if (col == null) {
return 0;
}
TableRef tableRef = extractTableRef(attRef);
String lastKey = extractKeyName(attRef.getKeys().get(attRef.getKeys().size() - 1));
MetaDocPart docPart = col.getMetaDocPartByTableRef(tableRef);
if (docPart == null) {
return 0;
}
MetaField field = docPart.getMetaFieldByNameAndType(lastKey, FieldType.from(value.getType()));
if (field == null) {
return 0;
}
Collection<Integer> dids = getInternalTransaction().getBackendTransaction().findByField(db, col, docPart, field, value).asDidCursor().getRemaining();
getInternalTransaction().getBackendTransaction().deleteDids(db, col, dids);
return dids.size();
}
use of com.torodb.core.transaction.metainf.MetaCollection in project torodb by torodb.
the class SqlWriteTorodTransaction method deleteAll.
@Override
public long deleteAll(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;
}
Collection<Integer> dids = getInternalTransaction().getBackendTransaction().findAll(db, col).asDidCursor().getRemaining();
getInternalTransaction().getBackendTransaction().deleteDids(db, col, dids);
return dids.size();
}
Aggregations