use of com.blazebit.persistence.view.EntityViewManager in project blaze-persistence by Blazebit.
the class EntityViewSettingTest method testEntityViewSettingCustomRoot.
@Test
public void testEntityViewSettingCustomRoot() {
EntityViewManager evm = build(CustomRootPersonView.class);
// Base setting
EntityViewSetting<CustomRootPersonView, CriteriaBuilder<CustomRootPersonView>> setting = EntityViewSetting.create(CustomRootPersonView.class);
// Query
CriteriaBuilder<Document> cb = cbf.create(em, Document.class);
setting.addAttributeFilter("name", "pers1");
CriteriaBuilder<CustomRootPersonView> criteriaBuilder = evm.applySetting(setting, cb, "owner");
assertEquals("SELECT " + singleValuedAssociationIdPath("owner_1.id", "owner_1") + " AS CustomRootPersonView_id, owner_1.name AS CustomRootPersonView_name " + "FROM Document document JOIN document.owner owner_1 " + "WHERE owner_1.name <> :param_0", criteriaBuilder.getQueryString());
List<CustomRootPersonView> result = criteriaBuilder.getResultList();
assertEquals(2, result.size());
assertEquals("pers2", result.get(0).getName());
assertEquals("pers2", result.get(1).getName());
}
use of com.blazebit.persistence.view.EntityViewManager in project blaze-persistence by Blazebit.
the class AbstractEntityViewTest method build.
public EntityViewManager build(EntityViewConfiguration cfg, Class<?>... classes) {
for (Class<?> c : classes) {
cfg.addEntityView(c);
}
EntityViewManagerFactoryCacheKey cacheKey = new EntityViewManagerFactoryCacheKey(cbf, cfg);
EntityViewManager evm;
if ((evm = evmCache.get(cacheKey)) == null) {
evm = build0(cfg, classes);
evmCache.put(cacheKey, evm);
}
AbstractEntityViewTest.evm = evm;
PackageOpener packageOpener = cbf.getService(PackageOpener.class);
boolean unsafeDisabled = !Boolean.valueOf(String.valueOf(cfg.getProperty(ConfigurationProperties.PROXY_UNSAFE_ALLOWED)));
boolean strictCascadingCheck = Boolean.valueOf(String.valueOf(cfg.getProperty(ConfigurationProperties.UPDATER_STRICT_CASCADING_CHECK)));
ProxyFactoryCacheKey proxyFactoryCacheKey = new ProxyFactoryCacheKey(unsafeDisabled, strictCascadingCheck, packageOpener);
ProxyFactory proxyFactory;
if ((proxyFactory = proxyFactoryCache.get(proxyFactoryCacheKey)) == null) {
proxyFactoryCache.put(proxyFactoryCacheKey, ((EntityViewManagerImpl) evm).getProxyFactory());
} else {
try {
Field proxyFactoryField = EntityViewManagerImpl.class.getDeclaredField("proxyFactory");
proxyFactoryField.setAccessible(true);
proxyFactoryField.set(evm, proxyFactory);
boolean scanStaticImplementations = !Boolean.valueOf(String.valueOf(cfg.getProperty(ConfigurationProperties.STATIC_IMPLEMENTATION_SCANNING_DISABLED)));
for (ManagedViewType<?> managedView : evm.getMetamodel().getManagedViews()) {
Class<?> javaType = managedView.getJavaType();
if (!javaType.isInterface() && !Modifier.isAbstract(javaType.getModifiers())) {
proxyFactory.setImplementation(javaType);
} else if (scanStaticImplementations) {
proxyFactory.loadImplementation(new HashSet<>(), managedView, evm);
}
}
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return evm;
}
use of com.blazebit.persistence.view.EntityViewManager in project blaze-persistence by Blazebit.
the class WithCTEMappingTest method testCteBinding.
@Test
public void testCteBinding() {
EntityViewManager evm = build(DocumentWithCTE.class);
CriteriaBuilder<Document> cb = cbf.create(em, Document.class).orderByAsc("id");
EntityViewSetting<DocumentWithCTE, CriteriaBuilder<DocumentWithCTE>> setting;
setting = EntityViewSetting.create(DocumentWithCTE.class);
setting.addOptionalParameter("ownerMaxAge", 63L);
List<DocumentWithCTE> list = evm.applySetting(setting, cb).getResultList();
assertEquals(2, list.size());
assertEquals("doc1", list.get(0).getName());
assertEquals("doc2", list.get(1).getName());
assertNull(list.get(0).getOwnedDocumentCount());
assertEquals(Long.valueOf(1), list.get(1).getOwnedDocumentCount());
}
use of com.blazebit.persistence.view.EntityViewManager in project blaze-persistence by Blazebit.
the class WithCTEMappingTest method testCteBindingWithSubview.
@Test
public void testCteBindingWithSubview() {
EntityViewManager evm = build(DocumentWithCTE.class, PersonWithPartnerDocument.class, PersonWithPartnerDocumentFullAged.class, PersonWithPartnerDocumentUnderAged.class);
CriteriaBuilder<Person> cb = cbf.create(em, Person.class).orderByAsc("id");
EntityViewSetting<PersonWithPartnerDocument, CriteriaBuilder<PersonWithPartnerDocument>> setting;
setting = EntityViewSetting.create(PersonWithPartnerDocument.class);
List<PersonWithPartnerDocument> list = evm.applySetting(setting, cb).getResultList();
assertEquals(3, list.size());
assertEquals("doc1", list.get(0).getPartnerDocument().getName());
assertEquals(Long.valueOf(1), list.get(0).getPartnerDocument().getOwnedDocumentCount());
boolean containsProvider = false;
ManagedViewType<?> viewType = evm.getMetamodel().managedView(PersonWithPartnerDocumentFullAged.class);
for (CTEProvider provider : viewType.getCteProviders()) {
if (provider instanceof FullAgedCTEProvider) {
containsProvider = true;
}
}
assertTrue(containsProvider);
}
use of com.blazebit.persistence.view.EntityViewManager in project blaze-persistence by Blazebit.
the class AttributeFilterTest method testViewFilter.
@Test
public void testViewFilter() {
EntityViewManager evm = build(ViewFilterPrimitiveDocumentView.class);
EntityViewSetting<ViewFilterPrimitiveDocumentView, CriteriaBuilder<ViewFilterPrimitiveDocumentView>> setting = EntityViewSetting.create(ViewFilterPrimitiveDocumentView.class);
setting.addViewFilter("viewFilter1");
List<ViewFilterPrimitiveDocumentView> results = evm.applySetting(setting, cbf.create(em, PrimitiveDocument.class)).getResultList();
assertEquals(1, results.size());
Assert.assertEquals(Long.valueOf(doc1.getId()), results.get(0).getId());
}
Aggregations