Search in sources :

Example 6 with DynamicType

use of org.eclipse.persistence.dynamic.DynamicType in project eclipselink by eclipse-ee4j.

the class SimpleTypes_MultiTable method verifyProperties.

@Test
public void verifyProperties() {
    DynamicType simpleTypeA = dynamicHelper.getType("SimpleA");
    Assert.assertNotNull(simpleTypeA);
    assertEquals(6, simpleTypeA.getNumberOfProperties());
    assertTrue(simpleTypeA.getPropertiesNames().contains("id"));
    assertEquals(int.class, simpleTypeA.getPropertyType("id"));
    assertTrue("value1", simpleTypeA.getPropertiesNames().contains("value1"));
    assertEquals(String.class, simpleTypeA.getPropertyType("value1"));
    assertTrue("value2", simpleTypeA.getPropertiesNames().contains("value2"));
    assertEquals(boolean.class, simpleTypeA.getPropertyType("value2"));
    assertTrue("value3", simpleTypeA.getPropertiesNames().contains("value3"));
    assertEquals(String.class, simpleTypeA.getPropertyType("value3"));
    assertTrue("value4", simpleTypeA.getPropertiesNames().contains("value4"));
    assertEquals(double.class, simpleTypeA.getPropertyType("value4"));
    assertTrue("value5", simpleTypeA.getPropertiesNames().contains("value5"));
    assertEquals(String.class, simpleTypeA.getPropertyType("value5"));
}
Also used : DynamicType(org.eclipse.persistence.dynamic.DynamicType) Test(org.junit.Test)

Example 7 with DynamicType

use of org.eclipse.persistence.dynamic.DynamicType in project eclipselink by eclipse-ee4j.

the class SimpleTypes_MultiTable method verifyConfig.

@Test
public void verifyConfig() throws Exception {
    ClassDescriptor descriptorA = dynamicHelper.getSession().getClassDescriptorForAlias("SimpleA");
    assertNotNull("No descriptor found for alias='SimpleA'", descriptorA);
    DynamicType simpleTypeA = dynamicHelper.getType("SimpleA");
    assertNotNull("'SimpleA' EntityType not found", simpleTypeA);
    assertEquals(descriptorA, simpleTypeA.getDescriptor());
    assertTrue(descriptorA.hasMultipleTables());
    assertEquals(3, descriptorA.getTables().size());
    DirectToFieldMapping a_id = (DirectToFieldMapping) descriptorA.getMappingForAttributeName("id");
    assertEquals(int.class, a_id.getAttributeClassification());
    DirectToFieldMapping a_value1 = (DirectToFieldMapping) descriptorA.getMappingForAttributeName("value1");
    assertEquals(String.class, a_value1.getAttributeClassification());
    DirectToFieldMapping a_value2 = (DirectToFieldMapping) descriptorA.getMappingForAttributeName("value2");
    assertEquals(boolean.class, a_value2.getAttributeClassification());
    DirectToFieldMapping a_value3 = (DirectToFieldMapping) descriptorA.getMappingForAttributeName("value3");
    assertEquals(String.class, a_value3.getAttributeClassification());
    DirectToFieldMapping a_value4 = (DirectToFieldMapping) descriptorA.getMappingForAttributeName("value4");
    assertEquals(double.class, a_value4.getAttributeClassification());
    DirectToFieldMapping a_value5 = (DirectToFieldMapping) descriptorA.getMappingForAttributeName("value5");
    assertEquals(String.class, a_value5.getAttributeClassification());
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DynamicType(org.eclipse.persistence.dynamic.DynamicType) Test(org.junit.Test)

Example 8 with DynamicType

use of org.eclipse.persistence.dynamic.DynamicType in project eclipselink by eclipse-ee4j.

the class SimpleTypes_MultiTable method verifyChangeTracking.

@Test
public void verifyChangeTracking() {
    persistSimpleA();
    DynamicType simpleTypeA = dynamicHelper.getType("SimpleA");
    Assert.assertNotNull(simpleTypeA);
    UnitOfWork uow = session.acquireUnitOfWork();
    ReadObjectQuery findQuery = dynamicHelper.newReadObjectQuery("SimpleA");
    findQuery.setSelectionCriteria(findQuery.getExpressionBuilder().get("id").equal(1));
    DynamicEntityImpl a = (DynamicEntityImpl) uow.executeQuery(findQuery);
    assertNotNull(a);
    assertNotNull(a._persistence_getPropertyChangeListener());
    uow.release();
    session.release();
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) DynamicEntityImpl(org.eclipse.persistence.internal.dynamic.DynamicEntityImpl) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) DynamicType(org.eclipse.persistence.dynamic.DynamicType) Test(org.junit.Test)

Example 9 with DynamicType

use of org.eclipse.persistence.dynamic.DynamicType in project eclipselink by eclipse-ee4j.

the class SimpleTypes_OneToMany method removeAwithB_PrivateOwned.

@Test
public void removeAwithB_PrivateOwned() {
    createAwithB();
    DynamicType simpleAType = dynamicHelper.getType("SimpleA");
    ((OneToManyMapping) simpleAType.getDescriptor().getMappingForAttributeName("b")).setIsPrivateOwned(true);
    UnitOfWork uow = session.acquireUnitOfWork();
    ReadObjectQuery findQuery = dynamicHelper.newReadObjectQuery("SimpleA");
    findQuery.setSelectionCriteria(findQuery.getExpressionBuilder().get("id").equal(1));
    DynamicEntity a = (DynamicEntity) uow.executeQuery(findQuery);
    assertNotNull(a);
    ReportQuery countQuery = dynamicHelper.newReportQuery("SimpleB", new ExpressionBuilder());
    countQuery.addCount();
    countQuery.setShouldReturnSingleValue(true);
    int simpleCountB = ((Number) session.executeQuery(countQuery)).intValue();
    assertEquals(1, simpleCountB);
    countQuery = dynamicHelper.newReportQuery("SimpleA", new ExpressionBuilder());
    countQuery.addCount();
    countQuery.setShouldReturnSingleValue(true);
    int simpleCountA = ((Number) session.executeQuery(countQuery)).intValue();
    assertEquals(1, simpleCountA);
    uow.deleteObject(a);
    // em.remove(a.get("b", List.class).get(0));
    uow.commit();
    countQuery = dynamicHelper.newReportQuery("SimpleB", new ExpressionBuilder());
    countQuery.addCount();
    countQuery.setShouldReturnSingleValue(true);
    simpleCountB = ((Number) session.executeQuery(countQuery)).intValue();
    assertEquals(0, simpleCountB);
    countQuery = dynamicHelper.newReportQuery("SimpleA", new ExpressionBuilder());
    countQuery.addCount();
    countQuery.setShouldReturnSingleValue(true);
    simpleCountA = ((Number) session.executeQuery(countQuery)).intValue();
    assertEquals(0, simpleCountA);
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) ReportQuery(org.eclipse.persistence.queries.ReportQuery) DynamicType(org.eclipse.persistence.dynamic.DynamicType) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) Test(org.junit.Test)

Example 10 with DynamicType

use of org.eclipse.persistence.dynamic.DynamicType in project eclipselink by eclipse-ee4j.

the class SimpleTypes_OneToMany method createSimpleB.

@Test
public void createSimpleB() {
    DynamicType simpleTypeB = dynamicHelper.getType("SimpleB");
    assertNotNull(simpleTypeB);
    DynamicEntity simpleInstance = simpleTypeB.newDynamicEntity();
    simpleInstance.set("id", 1);
    simpleInstance.set("value1", "B1");
    UnitOfWork uow = session.acquireUnitOfWork();
    uow.registerNewObject(simpleInstance);
    uow.commit();
    ReportQuery countQuery = dynamicHelper.newReportQuery("SimpleB", new ExpressionBuilder());
    countQuery.addCount();
    countQuery.setShouldReturnSingleValue(true);
    int simpleCount = ((Number) session.executeQuery(countQuery)).intValue();
    assertEquals(1, simpleCount);
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) ReportQuery(org.eclipse.persistence.queries.ReportQuery) DynamicType(org.eclipse.persistence.dynamic.DynamicType) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) Test(org.junit.Test)

Aggregations

DynamicType (org.eclipse.persistence.dynamic.DynamicType)76 Test (org.junit.Test)57 DynamicEntity (org.eclipse.persistence.dynamic.DynamicEntity)56 EntityManager (jakarta.persistence.EntityManager)20 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)19 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)15 ReportQuery (org.eclipse.persistence.queries.ReportQuery)15 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)13 JPADynamicHelper (org.eclipse.persistence.jpa.dynamic.JPADynamicHelper)8 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)8 HashMap (java.util.HashMap)7 DynamicClassLoader (org.eclipse.persistence.dynamic.DynamicClassLoader)5 OneToManyMapping (org.eclipse.persistence.mappings.OneToManyMapping)4 BufferedReader (java.io.BufferedReader)3 IOException (java.io.IOException)3 InputStreamReader (java.io.InputStreamReader)3 DynamicTypeBuilder (org.eclipse.persistence.dynamic.DynamicTypeBuilder)3 DynamicEntityImpl (org.eclipse.persistence.internal.dynamic.DynamicEntityImpl)3 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)3 DynamicHelper (org.eclipse.persistence.dynamic.DynamicHelper)2