Search in sources :

Example 16 with ViewMetamodel

use of com.blazebit.persistence.view.metamodel.ViewMetamodel in project blaze-persistence by Blazebit.

the class EntityViewMetamodelFlatViewTest method updatableMutableFlatView.

@Test
public void updatableMutableFlatView() {
    ViewMetamodel metamodel = build(entityViewConfiguration, DocumentViewWithUpdatableMutableFlatView.class, NameObjectView.class, NameObjectUpdateView.class).getMetamodel();
    ManagedViewType<?> nameObjectViewType = metamodel.managedView(NameObjectUpdateView.class);
    ManagedViewType<?> docViewType = metamodel.managedView(DocumentViewWithUpdatableMutableFlatView.class);
    assertTrue(docViewType.getAttribute("nameObject").isUpdatable());
    assertTrue(docViewType.getAttribute("nameObject").isPersistCascaded());
    assertTrue(docViewType.getAttribute("nameObject").isUpdateCascaded());
    assertTrue(docViewType.getAttribute("nameObject").getPersistCascadeAllowedSubtypes().contains(nameObjectViewType));
    assertTrue(docViewType.getAttribute("nameObject").getUpdateCascadeAllowedSubtypes().contains(nameObjectViewType));
    assertTrue(docViewType.getAttribute("nameObject").isMutable());
}
Also used : ViewMetamodel(com.blazebit.persistence.view.metamodel.ViewMetamodel) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 17 with ViewMetamodel

use of com.blazebit.persistence.view.metamodel.ViewMetamodel in project blaze-persistence by Blazebit.

the class EntityViewMetamodelTest method updatableMutableAndCreatableView.

@Test
public void updatableMutableAndCreatableView() {
    EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration();
    cfg.setProperty(ConfigurationProperties.PROXY_EAGER_LOADING, "true");
    cfg.setProperty(ConfigurationProperties.UPDATER_EAGER_LOADING, "true");
    cfg.setProperty(ConfigurationProperties.UPDATER_DISALLOW_OWNED_UPDATABLE_SUBVIEW, "false");
    ViewMetamodel metamodel = build(cfg, DocumentViewWithUpdatableMutableAndCreatableViewTypes.class, PersonCreateAndUpdateView.class).getMetamodel();
    ManagedViewType<?> docViewType = metamodel.managedView(DocumentViewWithUpdatableMutableAndCreatableViewTypes.class);
    // By default, the collection relations are not updatable
    assertTrue(docViewType.getAttribute("partners").isUpdatable());
    assertTrue(docViewType.getAttribute("owner").isUpdatable());
    assertTrue(docViewType.getAttribute("people").isUpdatable());
    // Updatable attributes with mutable types cascade only UPDATE by default
    assertTrue(docViewType.getAttribute("partners").isPersistCascaded());
    assertTrue(docViewType.getAttribute("owner").isPersistCascaded());
    assertTrue(docViewType.getAttribute("people").isPersistCascaded());
    assertTrue(docViewType.getAttribute("partners").isUpdateCascaded());
    assertTrue(docViewType.getAttribute("owner").isUpdateCascaded());
    assertTrue(docViewType.getAttribute("people").isUpdateCascaded());
    // An attribute is mutable if it's updatable or the type is mutable
    assertTrue(docViewType.getAttribute("partners").isMutable());
    assertTrue(docViewType.getAttribute("owner").isMutable());
    assertTrue(docViewType.getAttribute("people").isMutable());
}
Also used : EntityViewConfiguration(com.blazebit.persistence.view.spi.EntityViewConfiguration) ViewMetamodel(com.blazebit.persistence.view.metamodel.ViewMetamodel) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 18 with ViewMetamodel

use of com.blazebit.persistence.view.metamodel.ViewMetamodel in project blaze-persistence by Blazebit.

the class EntityViewMetamodelTest method nonUpdatableEntityAttributeDefaults.

@Test
public void nonUpdatableEntityAttributeDefaults() {
    ViewMetamodel metamodel = build(entityViewConfiguration, DocumentViewWithEntityTypes.class).getMetamodel();
    ManagedViewType<?> docViewType = metamodel.managedView(DocumentViewWithEntityTypes.class);
    // By default, the collection relations are not updatable
    assertFalse(docViewType.getAttribute("partners").isUpdatable());
    assertFalse(docViewType.getAttribute("owner").isUpdatable());
    // Cascades require the update to be updatable, so they are all disabled
    assertFalse(docViewType.getAttribute("partners").isPersistCascaded());
    assertFalse(docViewType.getAttribute("owner").isPersistCascaded());
    assertTrue(docViewType.getAttribute("partners").isUpdateCascaded());
    assertTrue(docViewType.getAttribute("owner").isUpdateCascaded());
    // Entity types are mutable
    assertTrue(docViewType.getAttribute("partners").isMutable());
    assertTrue(docViewType.getAttribute("owner").isMutable());
}
Also used : ViewMetamodel(com.blazebit.persistence.view.metamodel.ViewMetamodel) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 19 with ViewMetamodel

use of com.blazebit.persistence.view.metamodel.ViewMetamodel in project blaze-persistence by Blazebit.

the class EntityViewMetamodelTest method updatableMutableViewAttributeDefaults.

@Test
public void updatableMutableViewAttributeDefaults() {
    EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration();
    cfg.setProperty(ConfigurationProperties.PROXY_EAGER_LOADING, "true");
    cfg.setProperty(ConfigurationProperties.UPDATER_EAGER_LOADING, "true");
    cfg.setProperty(ConfigurationProperties.UPDATER_DISALLOW_OWNED_UPDATABLE_SUBVIEW, "false");
    ViewMetamodel metamodel = build(cfg, DocumentViewWithUpdatableMutableViewTypes.class, PersonUpdateView.class).getMetamodel();
    ManagedViewType<?> docViewType = metamodel.managedView(DocumentViewWithUpdatableMutableViewTypes.class);
    // By default, the collection relations are not updatable
    assertTrue(docViewType.getAttribute("partners").isUpdatable());
    assertTrue(docViewType.getAttribute("owner").isUpdatable());
    assertTrue(docViewType.getAttribute("people").isUpdatable());
    // Updatable attributes with mutable types cascade only UPDATE by default
    assertFalse(docViewType.getAttribute("partners").isPersistCascaded());
    assertFalse(docViewType.getAttribute("owner").isPersistCascaded());
    assertFalse(docViewType.getAttribute("people").isPersistCascaded());
    assertTrue(docViewType.getAttribute("partners").isUpdateCascaded());
    assertTrue(docViewType.getAttribute("owner").isUpdateCascaded());
    assertTrue(docViewType.getAttribute("people").isUpdateCascaded());
    // An attribute is mutable if it's updatable or the type is mutable
    assertTrue(docViewType.getAttribute("partners").isMutable());
    assertTrue(docViewType.getAttribute("owner").isMutable());
    assertTrue(docViewType.getAttribute("people").isMutable());
}
Also used : EntityViewConfiguration(com.blazebit.persistence.view.spi.EntityViewConfiguration) ViewMetamodel(com.blazebit.persistence.view.metamodel.ViewMetamodel) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 20 with ViewMetamodel

use of com.blazebit.persistence.view.metamodel.ViewMetamodel in project blaze-persistence by Blazebit.

the class ViewMetamodelTest method testMappingAttributeInterfaceInheritedClassView.

@Test
public void testMappingAttributeInterfaceInheritedClassView() throws Exception {
    ViewMetamodel viewMetamodel = getViewMetamodel();
    ViewType<?> viewType = viewMetamodel.view(DocumentViewAbstractClass.class);
    MethodAttribute<?, ?> attribute = viewType.getAttribute("id");
    assertNotNull(attribute);
    assertEquals("id", attribute.getName());
    assertFalse(attribute.isSubquery());
    assertEquals("id", ((MappingAttribute<?, ?>) attribute).getMapping());
    assertFalse(attribute.isCollection());
    assertFalse(((SingularAttribute<?, ?>) attribute).isQueryParameter());
    assertEquals(Long.class, attribute.getJavaType());
    assertEquals(IdHolderView.class.getMethod("getId"), attribute.getJavaMethod());
    assertEquals(viewType, attribute.getDeclaringType());
}
Also used : IdHolderView(com.blazebit.persistence.view.testsuite.basic.model.IdHolderView) ViewMetamodel(com.blazebit.persistence.view.metamodel.ViewMetamodel) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Aggregations

ViewMetamodel (com.blazebit.persistence.view.metamodel.ViewMetamodel)44 AbstractEntityViewTest (com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)44 Test (org.junit.Test)44 DocumentViewInterface (com.blazebit.persistence.view.testsuite.basic.model.DocumentViewInterface)15 EntityViewConfiguration (com.blazebit.persistence.view.spi.EntityViewConfiguration)5 DocumentViewAbstractClass (com.blazebit.persistence.view.testsuite.basic.model.DocumentViewAbstractClass)5 MappingAttribute (com.blazebit.persistence.view.metamodel.MappingAttribute)3 MappingConstructor (com.blazebit.persistence.view.metamodel.MappingConstructor)3 IdHolderView (com.blazebit.persistence.view.testsuite.basic.model.IdHolderView)3 PersonView (com.blazebit.persistence.view.testsuite.basic.model.PersonView)3 MethodAttribute (com.blazebit.persistence.view.metamodel.MethodAttribute)2 Document (com.blazebit.persistence.testsuite.entity.Document)1 Person (com.blazebit.persistence.testsuite.entity.Person)1 FlatViewType (com.blazebit.persistence.view.metamodel.FlatViewType)1 SingularAttribute (com.blazebit.persistence.view.metamodel.SingularAttribute)1 CircularDocument (com.blazebit.persistence.view.testsuite.basic.model.CircularDocument)1 CircularPerson (com.blazebit.persistence.view.testsuite.basic.model.CircularPerson)1 PersonViewWithSingularMapping (com.blazebit.persistence.view.testsuite.basic.model.PersonViewWithSingularMapping)1