Search in sources :

Example 6 with ImmutableMetaDocPart

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

the class IdentifierFactoryImplTest method longForCounterFieldToIdentifierTest.

@Test
public void longForCounterFieldToIdentifierTest() {
    ImmutableMetaDocPart metaDocPart = new ImmutableMetaDocPart.Builder(createTableRef(), "docpart").build();
    String identifier = identifierFactory.toFieldIdentifier(metaDocPart, "field____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", FieldType.STRING);
    Assert.assertEquals("field____long_long_long_long_long_long_long_long_long_long_lonng_long_long_long_long_long_long_long_long_long_long_long_long_1_s", identifier);
}
Also used : ImmutableMetaDocPart(com.torodb.core.transaction.metainf.ImmutableMetaDocPart) Test(org.junit.Test)

Example 7 with ImmutableMetaDocPart

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

the class IdentifierFactoryImplTest method longForCounterWithCollisionCharacterFieldToIdentifierTest.

@Test
public void longForCounterWithCollisionCharacterFieldToIdentifierTest() {
    ImmutableMetaDocPart metaDocPart = new ImmutableMetaDocPart.Builder(createTableRef(), "docpart").put(new ImmutableMetaField("field_collider", "field____long_long_long_long_long_long_long_long_long_long_lonng_long_long_long_long_long_long_long_long_long_long_long_long_1_s", FieldType.STRING)).build();
    String identifier = identifierFactory.toFieldIdentifier(metaDocPart, "field____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", FieldType.STRING);
    Assert.assertEquals("field____long_long_long_long_long_long_long_long_long_long_lonng_long_long_long_long_long_long_long_long_long_long_long_long_2_s", identifier);
}
Also used : ImmutableMetaDocPart(com.torodb.core.transaction.metainf.ImmutableMetaDocPart) ImmutableMetaField(com.torodb.core.transaction.metainf.ImmutableMetaField) Test(org.junit.Test)

Example 8 with ImmutableMetaDocPart

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

the class IdentifierFactoryImplTest method unallowedFieldToIdentifierTest.

@Test
public void unallowedFieldToIdentifierTest() {
    ImmutableMetaDocPart metaDocPart = new ImmutableMetaDocPart.Builder(createTableRef(), "docpart").build();
    String identifier = identifierFactory.toFieldIdentifier(metaDocPart, "unallowed_column", FieldType.STRING);
    Assert.assertEquals("_unallowed_column_s", identifier);
}
Also used : ImmutableMetaDocPart(com.torodb.core.transaction.metainf.ImmutableMetaDocPart) Test(org.junit.Test)

Example 9 with ImmutableMetaDocPart

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

the class DefaultToBackendFunctionTest method testNoBatchMetaDocPart.

@Test
public void testNoBatchMetaDocPart() {
    CollectionData collectionData = mock(CollectionData.class);
    DocPartData data1 = mock(DocPartData.class);
    given(data1.getMetaDocPart()).willReturn(new WrapperMutableMetaDocPart(new ImmutableMetaDocPart(tableRefFactory.createRoot(), "aDocPartName"), (o) -> {
    }));
    given(collectionData.orderedDocPartData()).willReturn(Collections.singleton(data1));
    //when
    try {
        fun.apply(collectionData);
        //then
        fail("An exception was expected when a metadoc part which is not a " + BatchMetaDocPart.class + " is used");
    } catch (AssertionError | ClassCastException ex) {
    }
}
Also used : CollectionData(com.torodb.core.d2r.CollectionData) Iterables(com.google.common.collect.Iterables) ImmutableMetaScalar(com.torodb.core.transaction.metainf.ImmutableMetaScalar) Mockito.spy(org.mockito.Mockito.spy) MockSettingsImpl(org.mockito.internal.creation.MockSettingsImpl) BackendTransactionJobFactory(com.torodb.core.dsl.backend.BackendTransactionJobFactory) BackendTransactionJob(com.torodb.core.dsl.backend.BackendTransactionJob) RollbackException(com.torodb.core.transaction.RollbackException) ArrayList(java.util.ArrayList) TableRefFactory(com.torodb.core.TableRefFactory) ImmutableMetaDocPart(com.torodb.core.transaction.metainf.ImmutableMetaDocPart) Lists(com.google.common.collect.Lists) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) BDDMockito.given(org.mockito.BDDMockito.given) MetaScalar(com.torodb.core.transaction.metainf.MetaScalar) WriteBackendTransaction(com.torodb.core.backend.WriteBackendTransaction) Assert.fail(org.junit.Assert.fail) CollectionData(com.torodb.core.d2r.CollectionData) Mockito.doReturn(org.mockito.Mockito.doReturn) TableRefFactoryImpl(com.torodb.core.impl.TableRefFactoryImpl) AddCollectionDdlJob(com.torodb.core.dsl.backend.AddCollectionDdlJob) Before(org.junit.Before) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) WrapperMutableMetaDocPart(com.torodb.core.transaction.metainf.WrapperMutableMetaDocPart) MockSettings(org.mockito.MockSettings) Assert.assertTrue(org.junit.Assert.assertTrue) FieldType(com.torodb.core.transaction.metainf.FieldType) ImmutableMetaCollection(com.torodb.core.transaction.metainf.ImmutableMetaCollection) Test(org.junit.Test) UserException(com.torodb.core.exceptions.user.UserException) MutableMetaDocPart(com.torodb.core.transaction.metainf.MutableMetaDocPart) AddFieldDdlJob(com.torodb.core.dsl.backend.AddFieldDdlJob) AddDocPartDdlJob(com.torodb.core.dsl.backend.AddDocPartDdlJob) MetaField(com.torodb.core.transaction.metainf.MetaField) AddScalarDddlJob(com.torodb.core.dsl.backend.AddScalarDddlJob) DocPartData(com.torodb.core.d2r.DocPartData) ImmutableMetaField(com.torodb.core.transaction.metainf.ImmutableMetaField) Optional(java.util.Optional) ImmutableMetaDatabase(com.torodb.core.transaction.metainf.ImmutableMetaDatabase) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) InsertBackendJob(com.torodb.core.dsl.backend.InsertBackendJob) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) Mockito.mock(org.mockito.Mockito.mock) AddDatabaseDdlJob(com.torodb.core.dsl.backend.AddDatabaseDdlJob) DocPartData(com.torodb.core.d2r.DocPartData) WrapperMutableMetaDocPart(com.torodb.core.transaction.metainf.WrapperMutableMetaDocPart) ImmutableMetaDocPart(com.torodb.core.transaction.metainf.ImmutableMetaDocPart) Test(org.junit.Test)

Example 10 with ImmutableMetaDocPart

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

the class SnapshotMerger method merge.

@SuppressWarnings("checkstyle:LineLength")
private void merge(MetaDatabase newDb, MetaDatabase oldDb, MutableMetaCollection newStructure, ImmutableMetaCollection oldStructure, ImmutableMetaCollection.Builder parentBuilder, MutableMetaDocPart changed) throws UnmergeableException {
    ImmutableMetaDocPart byRef = oldStructure.getMetaDocPartByTableRef(changed.getTableRef());
    ImmutableMetaDocPart byId = oldStructure.getMetaDocPartByIdentifier(changed.getIdentifier());
    if (byRef != byId) {
        throw createUnmergeableException(oldDb, oldStructure, changed, byRef, byId);
    }
    if (byRef == null && byId == null) {
        parentBuilder.put(changed.immutableCopy());
        return;
    }
    assert byRef != null;
    assert byId != null;
    ImmutableMetaDocPart.Builder childBuilder = new ImmutableMetaDocPart.Builder(byId);
    for (ImmutableMetaField addedMetaField : changed.getAddedMetaFields()) {
        merge(oldDb, newStructure, oldStructure, changed, byId, childBuilder, addedMetaField);
    }
    for (ImmutableMetaScalar addedMetaScalar : changed.getAddedMetaScalars()) {
        merge(oldDb, oldStructure, byId, childBuilder, addedMetaScalar);
    }
    for (Tuple2<ImmutableMetaIdentifiedDocPartIndex, MetaElementState> addedMetaDocPartIndex : changed.getModifiedMetaDocPartIndexes()) {
        merge(oldDb, newStructure, oldStructure, changed, byId, childBuilder, addedMetaDocPartIndex.v1(), addedMetaDocPartIndex.v2());
    }
    parentBuilder.put(childBuilder);
}
Also used : ImmutableMetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.ImmutableMetaIdentifiedDocPartIndex) ImmutableMetaDocPart(com.torodb.core.transaction.metainf.ImmutableMetaDocPart) MetaElementState(com.torodb.core.transaction.metainf.MetaElementState) ImmutableMetaField(com.torodb.core.transaction.metainf.ImmutableMetaField) ImmutableMetaScalar(com.torodb.core.transaction.metainf.ImmutableMetaScalar)

Aggregations

ImmutableMetaDocPart (com.torodb.core.transaction.metainf.ImmutableMetaDocPart)10 Test (org.junit.Test)7 ImmutableMetaField (com.torodb.core.transaction.metainf.ImmutableMetaField)3 Before (org.junit.Before)3 ImmutableMetaCollection (com.torodb.core.transaction.metainf.ImmutableMetaCollection)2 ImmutableMetaScalar (com.torodb.core.transaction.metainf.ImmutableMetaScalar)2 WrapperMutableMetaDocPart (com.torodb.core.transaction.metainf.WrapperMutableMetaDocPart)2 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 TableRefFactory (com.torodb.core.TableRefFactory)1 WriteBackendTransaction (com.torodb.core.backend.WriteBackendTransaction)1 CollectionData (com.torodb.core.d2r.CollectionData)1 DocPartData (com.torodb.core.d2r.DocPartData)1 AddCollectionDdlJob (com.torodb.core.dsl.backend.AddCollectionDdlJob)1 AddDatabaseDdlJob (com.torodb.core.dsl.backend.AddDatabaseDdlJob)1 AddDocPartDdlJob (com.torodb.core.dsl.backend.AddDocPartDdlJob)1 AddFieldDdlJob (com.torodb.core.dsl.backend.AddFieldDdlJob)1 AddScalarDddlJob (com.torodb.core.dsl.backend.AddScalarDddlJob)1 BackendTransactionJob (com.torodb.core.dsl.backend.BackendTransactionJob)1 BackendTransactionJobFactory (com.torodb.core.dsl.backend.BackendTransactionJobFactory)1