Search in sources :

Example 1 with EntityViewConfiguration

use of com.blazebit.persistence.view.spi.EntityViewConfiguration in project blaze-persistence by Blazebit.

the class CreatableAbstractEntityTest method tesValidationAbstractEntityMapping.

@Test
public void tesValidationAbstractEntityMapping() {
    EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration();
    cfg.addEntityView(SingleTableBaseAbstractEntityMappingValidationView.class);
    try {
        cfg.createEntityViewManager(cbf);
        Assert.fail("Expected validation exception!");
    } catch (IllegalArgumentException ex) {
        if (!ex.getMessage().contains("@CreatableEntityView but refers to an abstract entity")) {
            throw ex;
        }
    }
}
Also used : EntityViewConfiguration(com.blazebit.persistence.view.spi.EntityViewConfiguration) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 2 with EntityViewConfiguration

use of com.blazebit.persistence.view.spi.EntityViewConfiguration in project blaze-persistence by Blazebit.

the class ViewMetamodelTest method testResolveConflictingMapping.

@Test
public void testResolveConflictingMapping() {
    EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration();
    cfg.addEntityView(ResolveConflictingDoc.class);
    ViewMetamodel metamodel = build(ResolveConflictingDoc.class).getMetamodel();
    MappingAttribute<?, ?> mappingAttribute = (MappingAttribute<?, ?>) metamodel.view(ResolveConflictingDoc.class).getAttribute("name");
    assertEquals("UPPER(name)", mappingAttribute.getMapping());
}
Also used : EntityViewConfiguration(com.blazebit.persistence.view.spi.EntityViewConfiguration) ViewMetamodel(com.blazebit.persistence.view.metamodel.ViewMetamodel) MappingAttribute(com.blazebit.persistence.view.metamodel.MappingAttribute) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 3 with EntityViewConfiguration

use of com.blazebit.persistence.view.spi.EntityViewConfiguration in project blaze-persistence by Blazebit.

the class EntityViewBuilderTest method testBuilder.

@Test
public void testBuilder() {
    Object global = new Object();
    EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration();
    cfg.setOptionalParameter("test", global);
    EntityViewManager evm = build(cfg, DocumentBuilderView.class, PersonView.class);
    EntityViewBuilder<DocumentBuilderView> builder = evm.createBuilder(DocumentBuilderView.class);
    DocumentBuilderView view = builder.with("id", 10L).with("name", "Test").withSingularBuilder("owner").with("id", 100L).with("name", "Owner").build().withMapBuilder("contacts", 1).with("id", 100L).with("name", "Owner").build().withListBuilder("people", 1).with("id", 100L).with("name", "Owner").build().withCollectionBuilder("peopleListBag").with("id", 100L).with("name", "Owner").build().withCollectionBuilder("partners").with("id", 100L).with("name", "Owner").build().withElement("strings", "Test").build();
    assertView(view);
    Assert.assertEquals(global, view.getTest());
    Object overridden = new Object();
    DocumentBuilderView view2 = evm.createBuilder(view, Collections.singletonMap("test", overridden)).withListBuilder("people", 0).with("id", 100L).with("name", "Owner").build().build();
    assertView(view2);
    Assert.assertEquals(overridden, view2.getTest());
    Assert.assertNull(view.getPeople().get(0));
    assertOwner(view2.getPeople().get(0));
    DocumentBuilderView view3 = evm.createBuilder(view).with(0, "Test").build();
    Assert.assertEquals("Test", view3.getTest());
}
Also used : DocumentBuilderView(com.blazebit.persistence.view.testsuite.builder.model.DocumentBuilderView) EntityViewConfiguration(com.blazebit.persistence.view.spi.EntityViewConfiguration) EntityViewManager(com.blazebit.persistence.view.EntityViewManager) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest) Test(org.junit.Test)

Example 4 with EntityViewConfiguration

use of com.blazebit.persistence.view.spi.EntityViewConfiguration in project blaze-persistence by Blazebit.

the class MappingIndexTest method test.

private <T extends DocumentViewWithMappingIndex> void test(Class<T> clazz, Integer batchSize) {
    EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration();
    cfg.setProperty(ConfigurationProperties.PROXY_EAGER_LOADING, "true");
    cfg.setProperty(ConfigurationProperties.UPDATER_EAGER_LOADING, "true");
    build(cfg, clazz, VersionViewWithMappingIndex.class, VersionKeyView.class, VersionStaticKeyView.class);
    CriteriaBuilder<Document> criteria = cbf.create(em, Document.class, "d").orderByAsc("id");
    EntityViewSetting<T, CriteriaBuilder<T>> setting = EntityViewSetting.create(clazz);
    if (batchSize != null) {
        setting.setProperty(ConfigurationProperties.DEFAULT_BATCH_SIZE + ".versions", batchSize);
        setting.setProperty(ConfigurationProperties.DEFAULT_BATCH_SIZE + ".versionMap", batchSize);
        setting.setProperty(ConfigurationProperties.DEFAULT_BATCH_SIZE + ".versionMap2", batchSize);
        setting.setProperty(ConfigurationProperties.DEFAULT_BATCH_SIZE + ".multiVersions", batchSize);
        setting.setProperty(ConfigurationProperties.DEFAULT_BATCH_SIZE + ".multiVersionMap", batchSize);
        setting.setProperty(ConfigurationProperties.DEFAULT_BATCH_SIZE + ".multiVersionMap2", batchSize);
    }
    CriteriaBuilder<T> cb = evm.applySetting(setting, criteria);
    List<T> results = cb.getResultList();
    List<Version> versions = new ArrayList<>(doc1.getVersions());
    versions.sort(Comparator.comparing(Version::getIdx));
    List<Version> versionsIdSorted = new ArrayList<>(doc1.getVersions());
    versionsIdSorted.sort(Comparator.comparing(Version::getId));
    assertEquals(2, results.size());
    assertEquals("doc1", results.get(0).getName());
    assertEquals(2, results.get(0).getVersions().size());
    assertEquals(2, results.get(0).getVersionMap().size());
    assertEquals(2, results.get(0).getVersionMap2().size());
    assertEquals(1, results.get(0).getMultiVersions().size());
    assertEquals(1, results.get(0).getMultiVersionMap().size());
    assertEquals(1, results.get(0).getMultiVersionMap2().size());
    assertEquals(versions.get(0).getId(), results.get(0).getVersions().get(0).getId());
    assertEquals(versions.get(1).getId(), results.get(0).getVersions().get(1).getId());
    assertEquals(versions.get(0).getId(), results.get(0).getVersionMap().get(1).getId());
    assertEquals(versions.get(1).getId(), results.get(0).getVersionMap().get(2).getId());
    assertEquals(versions.get(0).getId(), results.get(0).getVersionMap2().get(VersionKeyView.of(1)).getId());
    assertEquals(versions.get(1).getId(), results.get(0).getVersionMap2().get(VersionKeyView.of(2)).getId());
    assertEquals(versionsIdSorted.get(0).getId(), results.get(0).getMultiVersions().get(0).first().getId());
    assertEquals(versionsIdSorted.get(1).getId(), results.get(0).getMultiVersions().get(0).last().getId());
    assertEquals(versionsIdSorted.get(0).getId(), results.get(0).getMultiVersionMap().get(0).first().getId());
    assertEquals(versionsIdSorted.get(1).getId(), results.get(0).getMultiVersionMap().get(0).last().getId());
    assertEquals(versionsIdSorted.get(0).getId(), results.get(0).getMultiVersionMap2().get(VersionStaticKeyView.of(0)).first().getId());
    assertEquals(versionsIdSorted.get(1).getId(), results.get(0).getMultiVersionMap2().get(VersionStaticKeyView.of(0)).last().getId());
    assertEquals("doc2", results.get(1).getName());
    assertEquals(0, results.get(1).getVersions().size());
    assertEquals(0, results.get(1).getVersionMap().size());
    assertEquals(0, results.get(1).getVersionMap2().size());
    assertEquals(0, results.get(1).getMultiVersions().size());
    assertEquals(0, results.get(1).getMultiVersionMap().size());
    assertEquals(0, results.get(1).getMultiVersionMap2().size());
}
Also used : CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) EntityViewConfiguration(com.blazebit.persistence.view.spi.EntityViewConfiguration) Version(com.blazebit.persistence.testsuite.entity.Version) ArrayList(java.util.ArrayList) Document(com.blazebit.persistence.testsuite.entity.Document)

Example 5 with EntityViewConfiguration

use of com.blazebit.persistence.view.spi.EntityViewConfiguration in project blaze-persistence by Blazebit.

the class ProxyFactoryEmeddableTest method testCreatableEmbeddableWithEmbeddableContainingConstructor.

@Test
public void testCreatableEmbeddableWithEmbeddableContainingConstructor() {
    EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration();
    cfg.setProperty(ConfigurationProperties.PROXY_EAGER_LOADING, "true");
    try {
        build(cfg, EmbeddableTestEntityView.class, EmbeddableTestEntityView.Id.class, CreatableEmbeddableTestEntityViewWithEmbeddableContainingConstructor.class, CreatableEmbeddableTestEntityViewWithEmbeddableContainingConstructor.ReadOnlyEmbeddableTestEntityEmbeddableView.class);
    } catch (IllegalArgumentException ex) {
        assertTrue(ex.getMessage().contains("empty constructor"));
    }
}
Also used : EntityViewConfiguration(com.blazebit.persistence.view.spi.EntityViewConfiguration) CreatableEmbeddableTestEntityViewWithEmbeddableContainingConstructor(com.blazebit.persistence.view.testsuite.proxy.model.CreatableEmbeddableTestEntityViewWithEmbeddableContainingConstructor) UpdatableEmbeddableTestEntityView(com.blazebit.persistence.view.testsuite.proxy.model.UpdatableEmbeddableTestEntityView) EmbeddableTestEntityView(com.blazebit.persistence.view.testsuite.proxy.model.EmbeddableTestEntityView) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Aggregations

EntityViewConfiguration (com.blazebit.persistence.view.spi.EntityViewConfiguration)21 AbstractEntityViewTest (com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)13 Test (org.junit.Test)13 Document (com.blazebit.persistence.testsuite.entity.Document)5 ViewMetamodel (com.blazebit.persistence.view.metamodel.ViewMetamodel)5 EntityViewManager (com.blazebit.persistence.view.EntityViewManager)3 Type (java.lang.reflect.Type)3 EntityViewMapping (com.blazebit.persistence.view.spi.EntityViewMapping)2 DocumentTypeConverterView (com.blazebit.persistence.view.testsuite.convert.type.model.DocumentTypeConverterView)2 EmbeddableTestEntityView (com.blazebit.persistence.view.testsuite.proxy.model.EmbeddableTestEntityView)2 UpdatableEmbeddableTestEntityView (com.blazebit.persistence.view.testsuite.proxy.model.UpdatableEmbeddableTestEntityView)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Produces (javax.enterprise.inject.Produces)2 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)1 Restricted (com.blazebit.persistence.deltaspike.data.testsuite.qualifier.Restricted)1 ValuesEntity (com.blazebit.persistence.impl.function.entity.ValuesEntity)1 ConcurrentHashMapExpressionCache (com.blazebit.persistence.parser.expression.ConcurrentHashMapExpressionCache)1 Version (com.blazebit.persistence.testsuite.entity.Version)1 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)1 MappingAttribute (com.blazebit.persistence.view.metamodel.MappingAttribute)1