Search in sources :

Example 6 with ImmutableMetaDatabase

use of com.torodb.core.transaction.metainf.ImmutableMetaDatabase in project torodb by torodb.

the class IdentifierFactoryImplTest method emptyCollectionDocPartRootToIdentifierTest.

@Test
public void emptyCollectionDocPartRootToIdentifierTest() {
    ImmutableMetaDatabase metaDatabase = new ImmutableMetaDatabase.Builder("database", "database").build();
    String identifier = identifierFactory.toDocPartIdentifier(metaDatabase, "", createTableRef());
    Assert.assertEquals("", identifier);
}
Also used : ImmutableMetaDatabase(com.torodb.core.transaction.metainf.ImmutableMetaDatabase) Test(org.junit.Test)

Example 7 with ImmutableMetaDatabase

use of com.torodb.core.transaction.metainf.ImmutableMetaDatabase in project torodb by torodb.

the class SnapshotMerger method merge.

private void merge(ImmutableMetaSnapshot.Builder parentBuilder, MutableMetaDatabase newDb, MetaElementState newState) throws UnmergeableException {
    ImmutableMetaDatabase byName = oldSnapshot.getMetaDatabaseByName(newDb.getName());
    ImmutableMetaDatabase byId = oldSnapshot.getMetaDatabaseByIdentifier(newDb.getIdentifier());
    switch(newState) {
        default:
        case NOT_CHANGED:
        case NOT_EXISTENT:
            throw new AssertionError("A modification was expected, but the new state is " + newState);
        case ADDED:
        case MODIFIED:
            {
                if (byName != byId) {
                    throw createUnmergeableException(newDb, byName, byId);
                }
                if (byName == null && byId == null) {
                    parentBuilder.put(newDb.immutableCopy());
                    return;
                }
                assert byName != null;
                assert byId != null;
                ImmutableMetaDatabase.Builder childBuilder = new ImmutableMetaDatabase.Builder(byId);
                for (Tuple2<MutableMetaCollection, MetaElementState> modifiedCollection : newDb.getModifiedCollections()) {
                    merge(newDb, byId, childBuilder, modifiedCollection.v1(), modifiedCollection.v2());
                }
                parentBuilder.put(childBuilder);
                break;
            }
        case REMOVED:
            {
                if (byName != byId) {
                    /*
           * The backend transaction will remove by id, but it is referencing another name on the
           * current snapshot, so the final state will be inconsistent. It is better to fail.
           */
                    throw createUnmergeableException(newDb, byName, byId);
                }
                if (byName == null && byId == null) {
                    /*
           * it has been removed on another transaction or created and removed on the current one.
           * No change must be done
           */
                    return;
                }
                assert byName != null;
                assert byId != null;
                /*
         * In this case, we can delegate on the backend transaction check. If it thinks everything
         * is fine, we can remove the element. If it thinks there is an error, then we have to
         * rollback the transaction.
         */
                parentBuilder.remove(byName);
            }
    }
}
Also used : Tuple2(org.jooq.lambda.tuple.Tuple2) ImmutableMetaDatabase(com.torodb.core.transaction.metainf.ImmutableMetaDatabase)

Example 8 with ImmutableMetaDatabase

use of com.torodb.core.transaction.metainf.ImmutableMetaDatabase in project torodb by torodb.

the class IdentifierFactoryImplTest method longForCounterWithCollisionCharacterDocPartToIdentifierTest.

@Test
public void longForCounterWithCollisionCharacterDocPartToIdentifierTest() {
    ImmutableMetaDatabase metaDatabase = new ImmutableMetaDatabase.Builder("database", "database").put(new ImmutableMetaCollection.Builder("collecti", "collecti").put(new ImmutableMetaDocPart.Builder(createTableRef(), "collecti_long_long_long_long_long_long_long_long_long_long_longong_long_long_long_long_long_long_long_long_long_long_long_long_1").build()).build()).build();
    String identifier = identifierFactory.toDocPartIdentifier(metaDatabase, "collecti", createTableRef("long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long"));
    Assert.assertEquals("collecti_long_long_long_long_long_long_long_long_long_long_longong_long_long_long_long_long_long_long_long_long_long_long_long_2", identifier);
}
Also used : ImmutableMetaDocPart(com.torodb.core.transaction.metainf.ImmutableMetaDocPart) ImmutableMetaDatabase(com.torodb.core.transaction.metainf.ImmutableMetaDatabase) Test(org.junit.Test)

Example 9 with ImmutableMetaDatabase

use of com.torodb.core.transaction.metainf.ImmutableMetaDatabase in project torodb by torodb.

the class IdentifierFactoryImplTest method docPartArrayInArrayChildToIdentifierTest.

@Test
public void docPartArrayInArrayChildToIdentifierTest() {
    ImmutableMetaDatabase metaDatabase = new ImmutableMetaDatabase.Builder("database", "database").build();
    String identifier = identifierFactory.toDocPartIdentifier(metaDatabase, "collecti", createTableRef("array", "2"));
    Assert.assertEquals("collecti_array$2", identifier);
}
Also used : ImmutableMetaDatabase(com.torodb.core.transaction.metainf.ImmutableMetaDatabase) Test(org.junit.Test)

Example 10 with ImmutableMetaDatabase

use of com.torodb.core.transaction.metainf.ImmutableMetaDatabase in project torodb by torodb.

the class IdentifierFactoryImplTest method docPartObjectChildToIdentifierTest.

@Test
public void docPartObjectChildToIdentifierTest() {
    ImmutableMetaDatabase metaDatabase = new ImmutableMetaDatabase.Builder("database", "database").build();
    String identifier = identifierFactory.toDocPartIdentifier(metaDatabase, "collecti", createTableRef("object"));
    Assert.assertEquals("collecti_object", identifier);
}
Also used : ImmutableMetaDatabase(com.torodb.core.transaction.metainf.ImmutableMetaDatabase) Test(org.junit.Test)

Aggregations

ImmutableMetaDatabase (com.torodb.core.transaction.metainf.ImmutableMetaDatabase)13 Test (org.junit.Test)12 Lists (com.google.common.collect.Lists)1 CollectionData (com.torodb.core.d2r.CollectionData)1 D2RTranslator (com.torodb.core.d2r.D2RTranslator)1 D2RTranslatorFactory (com.torodb.core.d2r.D2RTranslatorFactory)1 ImmutableMetaDocPart (com.torodb.core.transaction.metainf.ImmutableMetaDocPart)1 MutableMetaCollection (com.torodb.core.transaction.metainf.MutableMetaCollection)1 WrapperMutableMetaCollection (com.torodb.core.transaction.metainf.WrapperMutableMetaCollection)1 WrapperMutableMetaDatabase (com.torodb.core.transaction.metainf.WrapperMutableMetaDatabase)1 KvDocument (com.torodb.kvdocument.values.KvDocument)1 Collections (java.util.Collections)1 List (java.util.List)1 Tuple2 (org.jooq.lambda.tuple.Tuple2)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Before (org.junit.Before)1 BDDMockito.given (org.mockito.BDDMockito.given)1 Mockito (org.mockito.Mockito)1