Search in sources :

Example 11 with DynamicType

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

the class SimpleTypes_OneToMany method createSimpleA.

@Test
public void createSimpleA() {
    DynamicType simpleTypeA = dynamicHelper.getType("SimpleA");
    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();
    assertEquals(1, simpleCount);
    session.release();
}
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 12 with DynamicType

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

the class SimpleTypeTestSuite 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 13 with DynamicType

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

the class SimpleTypeWithEnumTestSuite method verifyDefaultValuesFromEntityType.

@Test
public void verifyDefaultValuesFromEntityType() throws Exception {
    DynamicType type = dynamicHelper.getType("Simple");
    assertNotNull(type);
    DynamicEntity simpleInstance = type.newDynamicEntity();
    assertDefaultValues(simpleInstance);
}
Also used : DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) DynamicType(org.eclipse.persistence.dynamic.DynamicType) Test(org.junit.Test)

Example 14 with DynamicType

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

the class SimpleTypeWithEnumTestSuite method createSimpleInstance.

public DynamicEntity createSimpleInstance(Session session, int id) {
    DynamicType simpleEntityType = dynamicHelper.getType("Simple");
    Assert.assertNotNull(simpleEntityType);
    DynamicEntity simpleInstance = simpleEntityType.newDynamicEntity();
    simpleInstance.set("id", id);
    simpleInstance.set("value2", true);
    Enum blue = Enum.valueOf(simpleEnum.getClass(), "BLUE");
    simpleInstance.set("color", blue);
    ReportQuery countQuery = dynamicHelper.newReportQuery("Simple", new ExpressionBuilder());
    countQuery.addCount();
    countQuery.setShouldReturnSingleValue(true);
    assertEquals(0, ((Number) session.executeQuery(countQuery)).intValue());
    UnitOfWork uow = session.acquireUnitOfWork();
    uow.registerNewObject(simpleInstance);
    uow.commit();
    assertEquals(1, ((Number) session.executeQuery(countQuery)).intValue());
    DynamicEntity foundEntity = find(dynamicHelper, session, 1);
    assertNotNull(foundEntity);
    assertEquals(simpleInstance.<Integer>get("id"), foundEntity.<Integer>get("id"));
    assertEquals(simpleInstance.<String>get("value1"), foundEntity.<String>get("value1"));
    assertEquals(simpleInstance.<Boolean>get("value2"), foundEntity.<Boolean>get("value2"));
    assertSame(simpleInstance.<Enum>get("color"), foundEntity.<Enum>get("color"));
    session.release();
    return simpleInstance;
}
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)

Example 15 with DynamicType

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

the class SimpleTypeWithEnumTestSuite method invalidDirectMappingSet_id.

@Test(expected = DynamicException.class)
public void invalidDirectMappingSet_id() throws Exception {
    DynamicType type = dynamicHelper.getType("Simple");
    DynamicEntity entity = type.newDynamicEntity();
    entity.set("id", 1l);
}
Also used : DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) DynamicType(org.eclipse.persistence.dynamic.DynamicType) 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