Search in sources :

Example 31 with OneToManyMapping

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

the class CascadeNoBindingOnQuery method setup.

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

Example 32 with OneToManyMapping

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

the class NoTargetForeignKeysSpecifiedTest method descriptor.

public RelationalDescriptor descriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    descriptor.setJavaClass(org.eclipse.persistence.testing.models.employee.domain.Employee.class);
    descriptor.addTableName("EMPLOYEE");
    // descriptor.addTableName("SALARY");
    descriptor.addPrimaryKeyFieldName("EMPLOYEE.EMP_ID");
    // Descriptor properties.
    descriptor.useFullIdentityMap();
    descriptor.setIdentityMapSize(100);
    descriptor.useRemoteFullIdentityMap();
    descriptor.setRemoteIdentityMapSize(100);
    descriptor.setSequenceNumberFieldName("EMP_ID");
    descriptor.setSequenceNumberName("EMP_SEQ");
    DirectToFieldMapping idMapping = new DirectToFieldMapping();
    idMapping.setAttributeName("id");
    idMapping.setFieldName("EMPLOYEE.EMP_ID");
    descriptor.addMapping(idMapping);
    OneToManyMapping managedEmployeesMapping = new OneToManyMapping();
    managedEmployeesMapping.setAttributeName("managedEmployees");
    managedEmployeesMapping.setReferenceClass(org.eclipse.persistence.testing.models.employee.domain.Employee.class);
    managedEmployeesMapping.useBasicIndirection();
    // if the following is missing then the correct error will occure.
    // managedEmployeesMapping.addTargetForeignKeyFieldName("EMPLOYEE.MANAGER_ID", "EMPLOYEE.EMP_ID");
    // managedEmployeesMapping.setTargetForeignKeyFieldName();
    descriptor.addMapping(managedEmployeesMapping);
    return descriptor;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping)

Example 33 with OneToManyMapping

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

the class InvalidContainerPolicyWithTransparentIndirectionTest method test.

@Override
public void test() {
    TransparentIndirectionPolicy policy = new TransparentIndirectionPolicy();
    OneToManyMapping mapping = new OneToManyMapping();
    mapping.setAttributeName("manager");
    mapping.setReferenceClass(org.eclipse.persistence.testing.models.employee.domain.Employee.class);
    mapping.addTargetForeignKeyFieldName("EMPLOYEE.MANAGER_ID", "EMPLOYEE.EMP_ID");
    policy.setMapping(mapping);
    try {
        policy.validateContainerPolicy(getSession().getIntegrityChecker());
    } catch (EclipseLinkException exception) {
        caughtException = exception;
    }
}
Also used : TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException)

Example 34 with OneToManyMapping

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

the class ReturnAndMappingWithTransparentIndirectionMismatchTest method descriptor.

public RelationalDescriptor descriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    descriptor.setJavaClass(org.eclipse.persistence.testing.tests.validation.PersonWithValueHolder.class);
    descriptor.addTableName("EMPLOYEE");
    descriptor.addPrimaryKeyFieldName("EMPLOYEE.EMP_ID");
    // Descriptor properties.
    DirectToFieldMapping idMapping = new DirectToFieldMapping();
    idMapping.setAttributeName("p_id");
    idMapping.setFieldName("EMPLOYEE.EMP_ID");
    descriptor.addMapping(idMapping);
    OneToManyMapping phoneNumbersMapping = new OneToManyMapping();
    phoneNumbersMapping.setAttributeName("phoneNumbers");
    phoneNumbersMapping.setReferenceClass(org.eclipse.persistence.testing.models.employee.domain.PhoneNumber.class);
    phoneNumbersMapping.dontUseIndirection();
    phoneNumbersMapping.useTransparentCollection();
    phoneNumbersMapping.setSetMethodName("setPhones");
    phoneNumbersMapping.setGetMethodName("getPhones");
    // phoneNumbersMapping.privateOwnedRelationship();
    phoneNumbersMapping.addTargetForeignKeyFieldName("PHONE.EMP_ID", "EMPLOYEE.EMP_ID");
    descriptor.addMapping(phoneNumbersMapping);
    return descriptor;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping)

Example 35 with OneToManyMapping

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

the class ParameterAndMappingWithTransparentIndirectionMismatchTest method descriptor.

public RelationalDescriptor descriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    descriptor.setJavaClass(org.eclipse.persistence.testing.tests.validation.PersonWithValueHolder.class);
    descriptor.addTableName("EMPLOYEE");
    descriptor.addPrimaryKeyFieldName("EMPLOYEE.EMP_ID");
    // Descriptor properties.
    DirectToFieldMapping idMapping = new DirectToFieldMapping();
    idMapping.setAttributeName("p_id");
    idMapping.setFieldName("EMPLOYEE.EMP_ID");
    idMapping.setGetMethodName("getId");
    idMapping.setSetMethodName("setId");
    idMapping.getAttributeAccessor().initializeAttributes(PersonWithValueHolder.class);
    descriptor.addMapping(idMapping);
    OneToManyMapping phoneNumbersMapping = new OneToManyMapping();
    phoneNumbersMapping.setAttributeName("phoneNumbers");
    phoneNumbersMapping.setReferenceClass(org.eclipse.persistence.testing.models.employee.domain.PhoneNumber.class);
    phoneNumbersMapping.dontUseIndirection();
    phoneNumbersMapping.useTransparentCollection();
    phoneNumbersMapping.setSetMethodName("setPhones");
    phoneNumbersMapping.setGetMethodName("getPhones");
    phoneNumbersMapping.addTargetForeignKeyFieldName("PHONE.EMP_ID", "EMPLOYEE.EMP_ID");
    phoneNumbersMapping.getAttributeAccessor().initializeAttributes(PersonWithValueHolder.class);
    descriptor.addMapping(phoneNumbersMapping);
    return descriptor;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) 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