use of com.torodb.core.transaction.metainf.MutableMetaSnapshot in project torodb by torodb.
the class SqlWriteTorodTransaction method getOrCreateMetaDatabase.
@Nonnull
protected MutableMetaDatabase getOrCreateMetaDatabase(String dbName) {
MutableMetaSnapshot metaSnapshot = getInternalTransaction().getMetaSnapshot();
MutableMetaDatabase metaDb = metaSnapshot.getMetaDatabaseByName(dbName);
if (metaDb == null) {
metaDb = createMetaDatabase(dbName);
}
return metaDb;
}
use of com.torodb.core.transaction.metainf.MutableMetaSnapshot in project torodb by torodb.
the class SqlWriteTorodTransaction method getMetaDatabaseOrThrowException.
@Nonnull
protected MutableMetaDatabase getMetaDatabaseOrThrowException(@Nonnull String dbName) throws DatabaseNotFoundException {
MutableMetaSnapshot metaSnapshot = getInternalTransaction().getMetaSnapshot();
MutableMetaDatabase metaDb = metaSnapshot.getMetaDatabaseByName(dbName);
if (metaDb == null) {
throw new DatabaseNotFoundException(dbName);
}
return metaDb;
}
use of com.torodb.core.transaction.metainf.MutableMetaSnapshot in project torodb by torodb.
the class SqlWriteTorodTransaction method createMetaDatabase.
private MutableMetaDatabase createMetaDatabase(String dbName) {
Preconditions.checkState(!isClosed());
MutableMetaSnapshot metaSnapshot = getInternalTransaction().getMetaSnapshot();
MutableMetaDatabase metaDb = metaSnapshot.addMetaDatabase(dbName, getConnection().getServer().getIdentifierFactory().toDatabaseIdentifier(metaSnapshot, dbName));
getInternalTransaction().getBackendTransaction().addDatabase(metaDb);
return metaDb;
}
use of com.torodb.core.transaction.metainf.MutableMetaSnapshot in project torodb by torodb.
the class SnapshotUpdaterImpl method updateSnapshot.
@Override
public void updateSnapshot(MetainfoRepository metainfoRepository) throws InvalidDatabaseException {
MutableMetaSnapshot mutableSnapshot;
try (SnapshotStage stage = metainfoRepository.startSnapshotStage()) {
mutableSnapshot = stage.createMutableSnapshot();
}
if (mutableSnapshot.streamMetaDatabases().anyMatch((o) -> true)) {
LOGGER.warn("Trying to update a not empty metainfo repository with information from " + "the database");
}
try (Connection connection = sqlInterface.getDbBackend().createSystemConnection()) {
DSLContext dsl = sqlInterface.getDslContextFactory().createDslContext(connection);
Updater updater = new Updater(dsl, tableRefFactory, sqlInterface);
updater.loadMetaSnapshot(mutableSnapshot);
connection.commit();
} catch (SQLException sqlException) {
throw sqlInterface.getErrorHandler().handleException(Context.UNKNOWN, sqlException);
}
try (MergerStage merge = metainfoRepository.startMerge(mutableSnapshot)) {
merge.commit();
}
}
use of com.torodb.core.transaction.metainf.MutableMetaSnapshot in project torodb by torodb.
the class SnapshotMergerForIndexTest method testNewIndexMultiField.
/**
* Test a new index with multiple fields Case [1&1.OK1|1&2.OK1].2
*
* @throws Exception
*/
@Test
public void testNewIndexMultiField() throws Exception {
MutableMetaSnapshot currentModifiedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
ImmutableMetaSnapshot currentSnapshot = currentModifiedSnapshot.immutableCopy();
MutableMetaSnapshot changedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").addMetaIndex("idxName2", false).addMetaIndexField(tableRefFactory.createRoot(), "fieldName2", FieldIndexOrdering.ASC);
changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaIndexByName("idxName2").addMetaIndexField(tableRefFactory.createRoot(), "fieldName3", FieldIndexOrdering.ASC);
changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaIndexByName("idxName2").addMetaIndexField(tableRefFactory.createRoot(), "fieldName4", FieldIndexOrdering.ASC);
changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaIndexByName("idxName2").addMetaIndexField(tableRefFactory.createRoot(), "fieldName5", FieldIndexOrdering.ASC);
new SnapshotMerger(currentSnapshot, changedSnapshot).merge();
}
Aggregations