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;
}
}
}
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());
}
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());
}
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());
}
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"));
}
}
Aggregations