use of com.torodb.core.transaction.metainf.MutableMetaDatabase in project torodb by torodb.
the class SqlWriteTorodTransaction method dropIndex.
@SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT", justification = "Findbugs thinks MutableMetaCollection#removeMetaIndexByName" + "has no side effect")
@Override
public boolean dropIndex(String dbName, String colName, String indexName) {
MutableMetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
if (db == null) {
return false;
}
MutableMetaCollection col = db.getMetaCollectionByName(colName);
if (col == null) {
return false;
}
MetaIndex index = col.getMetaIndexByName(indexName);
if (index == null) {
return false;
}
col.removeMetaIndexByName(indexName);
getInternalTransaction().getBackendTransaction().dropIndex(db, col, index);
return true;
}
use of com.torodb.core.transaction.metainf.MutableMetaDatabase in project torodb by torodb.
the class SqlWriteTorodTransaction method createIndex.
@Override
public boolean createIndex(String dbName, String colName, String indexName, List<IndexFieldInfo> fields, boolean unique) throws UserException {
if (fields.size() > 1) {
throw new UnsupportedCompoundIndexException(dbName, colName, indexName);
}
MutableMetaDatabase metaDb = getOrCreateMetaDatabase(dbName);
MutableMetaCollection metaColl = getOrCreateMetaCollection(metaDb, colName);
List<Tuple3<TableRef, String, FieldIndexOrdering>> indexFieldDefs = new ArrayList<>(fields.size());
for (IndexFieldInfo field : fields) {
AttributeReference attRef = field.getAttributeReference();
FieldIndexOrdering ordering = field.isAscending() ? FieldIndexOrdering.ASC : FieldIndexOrdering.DESC;
TableRef tableRef = extractTableRef(attRef);
String lastKey = extractKeyName(attRef.getKeys().get(attRef.getKeys().size() - 1));
indexFieldDefs.add(new Tuple3<>(tableRef, lastKey, ordering));
}
if (unique) {
TableRef anyIndexTableRef = indexFieldDefs.stream().findAny().get().v1();
boolean isUniqueIndexWithMutlipleTableRefs = indexFieldDefs.stream().anyMatch(t -> !t.v1().equals(anyIndexTableRef));
if (isUniqueIndexWithMutlipleTableRefs) {
throw new UnsupportedUniqueIndexException(dbName, colName, indexName);
}
}
boolean indexExists = metaColl.streamContainedMetaIndexes().anyMatch(index -> index.getName().equals(indexName) || (index.isUnique() == unique && index.size() == indexFieldDefs.size() && Seq.seq(index.iteratorFields()).allMatch(indexField -> {
Tuple3<TableRef, String, FieldIndexOrdering> indexFieldDef = indexFieldDefs.get(indexField.getPosition());
return indexFieldDef != null && indexFieldDef.v1().equals(indexField.getTableRef()) && indexFieldDef.v2().equals(indexField.getName()) && indexFieldDef.v3() == indexField.getOrdering();
})));
if (!indexExists) {
MutableMetaIndex metaIndex = metaColl.addMetaIndex(indexName, unique);
for (Tuple3<TableRef, String, FieldIndexOrdering> indexFieldDef : indexFieldDefs) {
metaIndex.addMetaIndexField(indexFieldDef.v1(), indexFieldDef.v2(), indexFieldDef.v3());
}
getInternalTransaction().getBackendTransaction().createIndex(metaDb, metaColl, metaIndex);
}
return !indexExists;
}
use of com.torodb.core.transaction.metainf.MutableMetaDatabase in project torodb by torodb.
the class SqlExclusiveWriteTorodTransaction method renameCollection.
@Override
public void renameCollection(String fromDb, String fromCollection, String toDb, String toCollection) throws RollbackException, UserException {
MutableMetaDatabase fromMetaDb = getMetaDatabaseOrThrowException(fromDb);
MetaCollection fromMetaColl = getMetaCollectionOrThrowException(fromMetaDb, fromCollection);
MutableMetaDatabase toMetaDb = getOrCreateMetaDatabase(toDb);
MutableMetaCollection toMetaColl = createMetaCollection(toMetaDb, toCollection);
getInternalTransaction().getBackendTransaction().renameCollection(fromMetaDb, fromMetaColl, toMetaDb, toMetaColl);
fromMetaDb.removeMetaCollectionByName(fromCollection);
}
use of com.torodb.core.transaction.metainf.MutableMetaDatabase in project torodb by torodb.
the class SqlWriteTorodTransaction method dropDatabase.
@Override
public void dropDatabase(String db) throws RollbackException, UserException {
MutableMetaDatabase metaDb = getMetaDatabaseOrThrowException(db);
getInternalTransaction().getBackendTransaction().dropDatabase(metaDb);
getInternalTransaction().getMetaSnapshot().removeMetaDatabaseByName(db);
}
use of com.torodb.core.transaction.metainf.MutableMetaDatabase in project torodb by torodb.
the class SqlWriteTorodTransaction method insert.
@Override
public void insert(String db, String collection, Stream<KvDocument> documents) throws RollbackException, UserException {
Preconditions.checkState(!isClosed());
MutableMetaDatabase metaDb = getOrCreateMetaDatabase(db);
MutableMetaCollection metaCol = getOrCreateMetaCollection(metaDb, collection);
//TODO: here we can not use a pipeline
InsertPipeline pipeline = getConnection().getServer().getInsertPipelineFactory().createInsertPipeline(getConnection().getServer().getD2RTranslatorFactory(), metaDb, metaCol, getInternalTransaction().getBackendTransaction(), concurrent);
pipeline.insert(documents);
}
Aggregations