Search in sources :

Example 16 with DynamicType

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

the class SimpleTypeWithEnumTestSuite method verifyDefaultValuesFromDescriptor.

@Test
public void verifyDefaultValuesFromDescriptor() throws Exception {
    DynamicType simpleType = dynamicHelper.getType("Simple");
    assertNotNull(simpleType);
    DynamicEntity simpleInstance = (DynamicEntity) simpleType.getDescriptor().getObjectBuilder().buildNewInstance();
    assertDefaultValues(simpleInstance);
}
Also used : DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) DynamicType(org.eclipse.persistence.dynamic.DynamicType) Test(org.junit.Test)

Example 17 with DynamicType

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

the class SimpleTypes_AggregateObject method verifyChangTracking.

@Test
public void verifyChangTracking() {
    persistSimpleA();
    DynamicType simpleTypeA = dynamicHelper.getType("SimpleA");
    Assert.assertNotNull(simpleTypeA);
    UnitOfWork uow = session.acquireUnitOfWork();
    ReadObjectQuery roq = dynamicHelper.newReadObjectQuery("SimpleA");
    roq.setSelectionCriteria(roq.getExpressionBuilder().get("id").equal(1));
    DynamicEntityImpl sharedA = (DynamicEntityImpl) session.executeQuery(roq);
    assertNotNull(sharedA);
    assertNull(sharedA._persistence_getPropertyChangeListener());
    DynamicEntityImpl a = (DynamicEntityImpl) uow.executeQuery(roq);
    assertNotNull(a);
    assertNotNull(a._persistence_getPropertyChangeListener());
    DynamicEntityImpl c = a.<DynamicEntityImpl>get("c");
    assertNotNull(c);
    assertNotNull(c._persistence_getPropertyChangeListener());
    assertTrue(c._persistence_getPropertyChangeListener() instanceof AggregateAttributeChangeListener);
    uow.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) AggregateAttributeChangeListener(org.eclipse.persistence.internal.descriptors.changetracking.AggregateAttributeChangeListener) Test(org.junit.Test)

Example 18 with DynamicType

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

the class SimpleTypes_AggregateObject method createSimpleA.

@Test
public void createSimpleA() {
    DynamicType simpleTypeA = dynamicHelper.getType("SimpleA");
    Assert.assertNotNull(simpleTypeA);
    DynamicEntity a = simpleTypeA.newDynamicEntity();
    assertNotNull(a);
    assertEquals(((Number) a.get("id")).intValue(), 0);
    assertFalse(a.isSet("id"));
    assertFalse(a.isSet("value1"));
    assertFalse(a.isSet("b"));
    DynamicType typeC = dynamicHelper.getType("SimpleC");
    assertEquals(a.get("c").getClass(), typeC.newDynamicEntity().getClass());
    DynamicEntity c = a.get("c");
    assertNotNull(c);
    assertEquals(((Number) c.get("value4")).doubleValue(), 0.0, 0.01);
    assertFalse(c.isSet("value5"));
}
Also used : DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) DynamicType(org.eclipse.persistence.dynamic.DynamicType) Test(org.junit.Test)

Example 19 with DynamicType

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

the class SimpleTypes_AggregateObject method persistSimpleA.

@Test
public void persistSimpleA() {
    DynamicType simpleTypeA = dynamicHelper.getType("SimpleA");
    Assert.assertNotNull(simpleTypeA);
    DynamicEntity simpleInstance = simpleTypeA.newDynamicEntity();
    simpleInstance.set("id", 1);
    simpleInstance.set("value1", "A1");
    UnitOfWork uow = session.acquireUnitOfWork();
    uow.registerNewObject(simpleInstance);
    uow.commit();
    ReportQuery countQuery = dynamicHelper.newReportQuery("SimpleA", new ExpressionBuilder());
    countQuery.addCount();
    countQuery.setShouldReturnSingleValue(true);
    int simpleCount = ((Number) session.executeQuery(countQuery)).intValue();
    Assert.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)

Example 20 with DynamicType

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

the class ComicsPopulateAndQueryTestSuite method loadPublishers.

protected Map<Integer, DynamicEntity> loadPublishers(Session server, URL fileURL) {
    DynamicType type = dynamicHelper.getType("Publisher");
    Map<Integer, DynamicEntity> publishers = new HashMap<Integer, DynamicEntity>();
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(fileURL.openStream()));
        String nextLine = null;
        while ((nextLine = reader.readLine()) != null) {
            DynamicEntity publisher = buildPublisher(type, nextLine);
            publishers.put(publisher.<Integer>get("id"), publisher);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
            // ignoree
            }
        }
    }
    return publishers;
}
Also used : InputStreamReader(java.io.InputStreamReader) DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) HashMap(java.util.HashMap) DynamicType(org.eclipse.persistence.dynamic.DynamicType) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

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