Search in sources :

Example 11 with OneToManyMapping

use of org.eclipse.persistence.mappings.OneToManyMapping in project eclipselink by eclipse-ee4j.

the class CascadeNoBindingOnQuery method reset.

@Override
public void reset() {
    getSession().getLogin().setShouldBindAllParameters(this.shouldBindParameters);
    OneToManyMapping mapping = (OneToManyMapping) getSession().getDescriptor(Employee.class).getMappingForAttributeName("phoneNumbers");
    mapping.setUsesBatchReading(this.usesBatchReading);
}
Also used : OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping)

Example 12 with OneToManyMapping

use of org.eclipse.persistence.mappings.OneToManyMapping in project eclipselink by eclipse-ee4j.

the class DynamicEmployeeSystem method configureEmployee.

private static void configureEmployee(DynamicTypeBuilder employee, DynamicTypeBuilder address, DynamicTypeBuilder phone, DynamicTypeBuilder period, DynamicTypeBuilder project) {
    employee.setPrimaryKeyFields("EMP_ID");
    employee.addDirectMapping("id", int.class, "D_EMPLOYEE.EMP_ID");
    employee.addDirectMapping("firstName", String.class, "D_EMPLOYEE.F_NAME");
    employee.addDirectMapping("lastName", String.class, "D_EMPLOYEE.L_NAME");
    employee.addDirectMapping("gender", String.class, "D_EMPLOYEE.GENDER");
    employee.addDirectMapping("salary", int.class, "D_SALARY.SALARY");
    OneToOneMapping addressMapping = employee.addOneToOneMapping("address", address.getType(), "ADDR_ID");
    addressMapping.setCascadeAll(true);
    addressMapping.setIsPrivateOwned(true);
    employee.addOneToOneMapping("manager", employee.getType(), "MANAGER_ID");
    OneToManyMapping phoneMapping = employee.addOneToManyMapping("phoneNumbers", phone.getType(), "EMP_ID");
    phoneMapping.setCascadeAll(true);
    phoneMapping.setIsPrivateOwned(true);
    employee.addAggregateObjectMapping("period", period.getType(), true);
    employee.addOneToManyMapping("managedEmployees", employee.getType(), "MANAGER_ID");
    employee.configureSequencing("EMP_SEQ", "EMP_ID");
}
Also used : OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping)

Example 13 with OneToManyMapping

use of org.eclipse.persistence.mappings.OneToManyMapping in project eclipselink by eclipse-ee4j.

the class MappingConfigTestSuite method verifyEmployeeDescriptor.

@Test
public void verifyEmployeeDescriptor() {
    ClassDescriptor descriptor = session.getDescriptorForAlias("Employee");
    assertNotNull(descriptor);
    assertEquals("Employee", descriptor.getAlias());
    assertNull(descriptor.getInheritancePolicyOrNull());
    // Address Mapping
    OneToOneMapping addrMapping = (OneToOneMapping) descriptor.getMappingForAttributeName("address");
    assertNotNull(addrMapping);
    assertTrue(addrMapping.isPrivateOwned());
    assertEquals(session.getDescriptorForAlias("Address"), addrMapping.getReferenceDescriptor());
    // PhoneNumber Mapping
    OneToManyMapping phoneMapping = (OneToManyMapping) descriptor.getMappingForAttributeName("phoneNumbers");
    assertNotNull(phoneMapping);
    assertTrue(phoneMapping.isPrivateOwned());
    assertEquals(session.getDescriptorForAlias("PhoneNumber"), phoneMapping.getReferenceDescriptor());
    // Manager Mapping
    OneToOneMapping managerMapping = (OneToOneMapping) descriptor.getMappingForAttributeName("manager");
    assertNotNull(managerMapping);
    assertFalse(managerMapping.isPrivateOwned());
    assertEquals(descriptor, managerMapping.getReferenceDescriptor());
    // Managed Employees Mapping
    OneToManyMapping managedEmployeesMapping = (OneToManyMapping) descriptor.getMappingForAttributeName("managedEmployees");
    assertNotNull(managedEmployeesMapping);
    assertFalse(managedEmployeesMapping.isPrivateOwned());
    assertEquals(descriptor, managedEmployeesMapping.getReferenceDescriptor());
    // Projects Mapping
    ManyToManyMapping projectsMapping = (ManyToManyMapping) descriptor.getMappingForAttributeName("projects");
    assertNotNull(projectsMapping);
    assertFalse(projectsMapping.isPrivateOwned());
    assertEquals(session.getDescriptorForAlias("Project"), projectsMapping.getReferenceDescriptor());
}
Also used : ManyToManyMapping(org.eclipse.persistence.mappings.ManyToManyMapping) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping) Test(org.junit.Test)

Example 14 with OneToManyMapping

use of org.eclipse.persistence.mappings.OneToManyMapping in project eclipselink by eclipse-ee4j.

the class SetMethodParameterTypeNotValidTest method test.

@Override
public void test() {
    try {
        getSession().setIntegrityChecker(new IntegrityChecker());
        getSession().getIntegrityChecker().dontCatchExceptions();
        // the following causes the correct error to occure.
        RelationalDescriptor descriptor = descriptor();
        OneToManyMapping dMapping = (OneToManyMapping) descriptor.getMappingForAttributeName("managedEmployeesWithProblems");
        org.eclipse.persistence.testing.tests.validation.EmployeeWithProblems person = new org.eclipse.persistence.testing.tests.validation.EmployeeWithProblems();
        NoIndirectionPolicy indirectionPolicy = (NoIndirectionPolicy) dMapping.getIndirectionPolicy();
        indirectionPolicy.validateSetMethodParameterTypeForCollection(org.eclipse.persistence.testing.tests.validation.EmployeeWithProblems.class, getSession().getIntegrityChecker());
    } catch (EclipseLinkException exception) {
        caughtException = exception;
    }
}
Also used : IntegrityChecker(org.eclipse.persistence.exceptions.IntegrityChecker) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) NoIndirectionPolicy(org.eclipse.persistence.internal.indirection.NoIndirectionPolicy)

Example 15 with OneToManyMapping

use of org.eclipse.persistence.mappings.OneToManyMapping in project eclipselink by eclipse-ee4j.

the class EmployeeSubProject method buildEmployeeDescriptor.

@Override
public ClassDescriptor buildEmployeeDescriptor() {
    ClassDescriptor descriptor = super.buildEmployeeDescriptor();
    DirectToFieldMapping lastNameMapping = (DirectToFieldMapping) descriptor.getMappingForAttributeName("lastName");
    lastNameMapping.setNullValue(null);
    OneToManyMapping addressMapping = (OneToManyMapping) descriptor.getMappingForAttributeName("phoneNumbers");
    addressMapping.addAscendingOrdering("id");
    OneToManyMapping managedEmployeeMapping = (OneToManyMapping) descriptor.getMappingForAttributeName("managedEmployees");
    managedEmployeeMapping.addDescendingOrdering("id");
    TransformationMapping normalHoursMapping = (TransformationMapping) descriptor.getMappingForAttributeName("normalHours");
    normalHoursMapping.useContainerIndirection(Vector.class);
    return descriptor;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) TransformationMapping(org.eclipse.persistence.mappings.TransformationMapping) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping)

Aggregations

OneToManyMapping (org.eclipse.persistence.mappings.OneToManyMapping)50 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)18 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)18 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)16 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)13 Expression (org.eclipse.persistence.expressions.Expression)6 TransparentIndirectionPolicy (org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)6 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)6 UnidirectionalOneToManyMapping (org.eclipse.persistence.mappings.UnidirectionalOneToManyMapping)6 Test (org.junit.Test)6 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)5 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)5 TransformationMapping (org.eclipse.persistence.mappings.TransformationMapping)5 DynamicType (org.eclipse.persistence.dynamic.DynamicType)4 DatabaseTable (org.eclipse.persistence.internal.helper.DatabaseTable)4 ManyToManyMapping (org.eclipse.persistence.mappings.ManyToManyMapping)4 EntityManager (jakarta.persistence.EntityManager)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)3