Search in sources :

Example 1 with MutableMetaSnapshot

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;
}
Also used : MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) MutableMetaDatabase(com.torodb.core.transaction.metainf.MutableMetaDatabase) Nonnull(javax.annotation.Nonnull)

Example 2 with MutableMetaSnapshot

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;
}
Also used : MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) DatabaseNotFoundException(com.torodb.core.exceptions.user.DatabaseNotFoundException) MutableMetaDatabase(com.torodb.core.transaction.metainf.MutableMetaDatabase) Nonnull(javax.annotation.Nonnull)

Example 3 with MutableMetaSnapshot

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;
}
Also used : MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) MutableMetaDatabase(com.torodb.core.transaction.metainf.MutableMetaDatabase)

Example 4 with MutableMetaSnapshot

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();
    }
}
Also used : MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) SnapshotStage(com.torodb.core.transaction.metainf.MetainfoRepository.SnapshotStage) SQLException(java.sql.SQLException) SnapshotUpdater(com.torodb.core.backend.SnapshotUpdater) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext) MergerStage(com.torodb.core.transaction.metainf.MetainfoRepository.MergerStage)

Example 5 with MutableMetaSnapshot

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();
}
Also used : WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) ImmutableMetaSnapshot(com.torodb.core.transaction.metainf.ImmutableMetaSnapshot) WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) Test(org.junit.Test)

Aggregations

MutableMetaSnapshot (com.torodb.core.transaction.metainf.MutableMetaSnapshot)74 Test (org.junit.Test)70 WrapperMutableMetaSnapshot (com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot)69 ImmutableMetaSnapshot (com.torodb.core.transaction.metainf.ImmutableMetaSnapshot)56 UnmergeableException (com.torodb.core.transaction.metainf.UnmergeableException)34 MutableMetaDatabase (com.torodb.core.transaction.metainf.MutableMetaDatabase)3 MergerStage (com.torodb.core.transaction.metainf.MetainfoRepository.MergerStage)2 SnapshotStage (com.torodb.core.transaction.metainf.MetainfoRepository.SnapshotStage)2 Nonnull (javax.annotation.Nonnull)2 SnapshotUpdater (com.torodb.core.backend.SnapshotUpdater)1 DatabaseNotFoundException (com.torodb.core.exceptions.user.DatabaseNotFoundException)1 MutableMetaDocPart (com.torodb.core.transaction.metainf.MutableMetaDocPart)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 DSLContext (org.jooq.DSLContext)1