Search in sources :

Example 26 with OneToOneMapping

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

the class ParameterAndMappingWithIndirectionMismatchTest method setup.

@Override
protected void setup() {
    expectedException = DescriptorException.parameterAndMappingWithIndirectionMismatch(new OneToOneMapping());
    orgIntegrityChecker = getSession().getIntegrityChecker();
    getSession().setIntegrityChecker(new IntegrityChecker());
    getSession().getIntegrityChecker().dontCatchExceptions();
}
Also used : IntegrityChecker(org.eclipse.persistence.exceptions.IntegrityChecker) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping)

Example 27 with OneToOneMapping

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

the class ParameterAndMappingWithIndirectionMismatchTest 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);
    OneToOneMapping addressMapping = new OneToOneMapping();
    addressMapping.setAttributeName("address");
    addressMapping.setReferenceClass(org.eclipse.persistence.testing.models.employee.domain.Address.class);
    addressMapping.useBasicIndirection();
    addressMapping.setGetMethodName("getAddress");
    addressMapping.setSetMethodName("setAddress");
    addressMapping.addForeignKeyFieldName("EMPLOYEE.ADDR_ID", "ADDRESS.ADDRESS_ID");
    descriptor.addMapping(addressMapping);
    // expectedException = DescriptorException.parameterAndMappingWithIndirectionMismatch(addressMapping);
    return descriptor;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping)

Example 28 with OneToOneMapping

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

the class ParameterAndMappingWithoutIndirectionMismatchTest 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");
    descriptor.addMapping(idMapping);
    OneToOneMapping addressMapping = new OneToOneMapping();
    addressMapping.setAttributeName("address");
    addressMapping.setReferenceClass(org.eclipse.persistence.testing.models.employee.domain.Address.class);
    addressMapping.dontUseIndirection();
    addressMapping.setGetMethodName("getAddressHolder");
    addressMapping.setSetMethodName("setAddressHolder");
    addressMapping.addForeignKeyFieldName("EMPLOYEE.ADDR_ID", "ADDRESS.ADDRESS_ID");
    descriptor.addMapping(addressMapping);
    return descriptor;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping)

Example 29 with OneToOneMapping

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

the class MissingMappingForFieldTest method test.

@Override
public void test() {
    RelationalDescriptor descriptor = descriptor();
    org.eclipse.persistence.testing.tests.validation.EmployeeWithProblems person = new org.eclipse.persistence.testing.tests.validation.EmployeeWithProblems();
    OneToOneMapping dMapping = (OneToOneMapping) descriptor.getMappingForAttributeName("manager");
    DatabaseField dField = dMapping.getForeignKeyFields().firstElement();
    // the following causes the correct error to occure.
    descriptor.getObjectBuilder().getMappingsByField().remove(dField);
    try {
        descriptor.getObjectBuilder().extractValueFromObjectForField(person, dField, (AbstractSession) getSession());
    } catch (EclipseLinkException exception) {
        caughtException = exception;
    }
}
Also used : RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping)

Example 30 with OneToOneMapping

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

the class MissingMappingForFieldTest method descriptor.

public RelationalDescriptor descriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    descriptor.setJavaClass(org.eclipse.persistence.testing.tests.validation.EmployeeWithProblems.class);
    descriptor.addTableName("EMPLOYEE");
    descriptor.addPrimaryKeyFieldName("EMPLOYEE.EMP_ID");
    // Descriptor properties.
    descriptor.useSoftCacheWeakIdentityMap();
    descriptor.setIdentityMapSize(100);
    descriptor.useRemoteSoftCacheWeakIdentityMap();
    descriptor.setRemoteIdentityMapSize(100);
    descriptor.setSequenceNumberFieldName("EMP_ID");
    descriptor.setSequenceNumberName("EMP_SEQ");
    descriptor.setAlias("EMPLOYEE");
    DirectToFieldMapping idMapping = new DirectToFieldMapping();
    idMapping.setAttributeName("id");
    idMapping.setFieldName("EMPLOYEE.EMP_ID");
    descriptor.addMapping(idMapping);
    OneToOneMapping managerMapping = new OneToOneMapping();
    managerMapping.setAttributeName("manager");
    managerMapping.setReferenceClass(org.eclipse.persistence.testing.tests.validation.EmployeeWithProblems.class);
    managerMapping.useBasicIndirection();
    managerMapping.addForeignKeyFieldName("EMPLOYEE.MANAGER_ID", "EMPLOYEE.EMP_ID");
    descriptor.addMapping(managerMapping);
    return descriptor;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping)

Aggregations

OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)97 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)38 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)32 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)27 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)24 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)17 DatabaseTable (org.eclipse.persistence.internal.helper.DatabaseTable)15 ManyToManyMapping (org.eclipse.persistence.mappings.ManyToManyMapping)15 OneToManyMapping (org.eclipse.persistence.mappings.OneToManyMapping)15 Vector (java.util.Vector)11 Expression (org.eclipse.persistence.expressions.Expression)8 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 DirectCollectionMapping (org.eclipse.persistence.mappings.DirectCollectionMapping)5 DirectMapMapping (org.eclipse.persistence.mappings.DirectMapMapping)5 SessionBroker (org.eclipse.persistence.sessions.broker.SessionBroker)5 Test (org.junit.Test)5 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)4 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)4 RelationTableMechanism (org.eclipse.persistence.mappings.RelationTableMechanism)4