Search in sources :

Example 6 with OneToManyMapping

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

the class GetMethodReturnTypeNotValidTest method setup.

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

Example 7 with OneToManyMapping

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

the class DistributedProject method buildCompanyDescriptor.

public RelationalDescriptor buildCompanyDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    descriptor.setJavaClass(org.eclipse.persistence.testing.tests.distributedservers.Company.class);
    descriptor.addTableName("DIST_COMPANY");
    descriptor.addPrimaryKeyFieldName("DIST_COMPANY.ID");
    // Descriptor properties.
    descriptor.useSoftCacheWeakIdentityMap();
    descriptor.setIdentityMapSize(100);
    descriptor.useRemoteSoftCacheWeakIdentityMap();
    descriptor.setRemoteIdentityMapSize(100);
    descriptor.setSequenceNumberFieldName("DIST_COMPANY.ID");
    descriptor.setSequenceNumberName("COMAPNY_SEQ");
    descriptor.setAlias("Company");
    // Query manager.
    descriptor.getQueryManager().checkCacheForDoesExist();
    // Named Queries
    // Event manager.
    // Mappings.
    DirectToFieldMapping idMapping = new DirectToFieldMapping();
    idMapping.setAttributeName("id");
    idMapping.setFieldName("DIST_COMPANY.ID");
    descriptor.addMapping(idMapping);
    DirectToFieldMapping nameMapping = new DirectToFieldMapping();
    nameMapping.setAttributeName("name");
    nameMapping.setFieldName("DIST_COMPANY.NAME");
    descriptor.addMapping(nameMapping);
    OneToManyMapping ownedItemsMapping = new OneToManyMapping();
    ownedItemsMapping.setAttributeName("ownedItems");
    ownedItemsMapping.setReferenceClass(org.eclipse.persistence.testing.tests.distributedservers.Item.class);
    ownedItemsMapping.dontUseIndirection();
    ownedItemsMapping.useCollectionClass(java.util.Vector.class);
    ownedItemsMapping.addTargetForeignKeyFieldName("DIST_ITEM.COMPANYOWNER", "DIST_COMPANY.ID");
    descriptor.addMapping(ownedItemsMapping);
    return descriptor;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping)

Example 8 with OneToManyMapping

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

the class DistributedProject method buildDist_EmployeeDescriptor.

public RelationalDescriptor buildDist_EmployeeDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    descriptor.setJavaClass(org.eclipse.persistence.testing.tests.distributedservers.Dist_Employee.class);
    descriptor.addTableName("DIST_EMPLOYEE");
    descriptor.addPrimaryKeyFieldName("DIST_EMPLOYEE.ID");
    // Descriptor properties.
    descriptor.useSoftCacheWeakIdentityMap();
    descriptor.setIdentityMapSize(100);
    descriptor.useRemoteSoftCacheWeakIdentityMap();
    descriptor.setRemoteIdentityMapSize(100);
    descriptor.setSequenceNumberFieldName("DIST_EMPLOYEE.ID");
    descriptor.setSequenceNumberName("EMPLOYEE_SEQ");
    descriptor.setAlias("Dist_Employee");
    // Query manager.
    descriptor.getQueryManager().checkCacheForDoesExist();
    // Named Queries
    // Event manager.
    // Mappings.
    DirectToFieldMapping idMapping = new DirectToFieldMapping();
    idMapping.setAttributeName("id");
    idMapping.setFieldName("DIST_EMPLOYEE.ID");
    descriptor.addMapping(idMapping);
    DirectToFieldMapping nameMapping = new DirectToFieldMapping();
    nameMapping.setAttributeName("name");
    nameMapping.setFieldName("DIST_EMPLOYEE.NAME");
    descriptor.addMapping(nameMapping);
    OneToManyMapping heldItemsMapping = new OneToManyMapping();
    heldItemsMapping.setAttributeName("heldItems");
    heldItemsMapping.setReferenceClass(org.eclipse.persistence.testing.tests.distributedservers.Item.class);
    heldItemsMapping.dontUseIndirection();
    heldItemsMapping.useCollectionClass(java.util.Vector.class);
    heldItemsMapping.addTargetForeignKeyFieldName("DIST_ITEM.EMPLOYEEHOLDER", "DIST_EMPLOYEE.ID");
    descriptor.addMapping(heldItemsMapping);
    return descriptor;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping)

Example 9 with OneToManyMapping

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

the class IsolatedEmployeeProject method buildIsolatedParentDescriptor.

public RelationalDescriptor buildIsolatedParentDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    descriptor.setJavaClass(IsolatedParent.class);
    descriptor.addTableName("ISOLATED_PARENT");
    descriptor.addPrimaryKeyFieldName("ISOLATED_PARENT.ID");
    // ClassDescriptor Properties.
    descriptor.useFullIdentityMap();
    descriptor.setIdentityMapSize(100);
    descriptor.useRemoteFullIdentityMap();
    descriptor.setRemoteIdentityMapSize(100);
    descriptor.setSequenceNumberFieldName("ISOLATED_PARENT.ID");
    descriptor.setSequenceNumberName("PARENT_SEQ");
    // IMPORTANT!
    descriptor.alwaysConformResultsInUnitOfWork();
    descriptor.setCacheIsolation(CacheIsolationType.ISOLATED);
    descriptor.setAlias("IsolatedParent");
    descriptor.setCacheSynchronizationType(ClassDescriptor.DO_NOT_SEND_CHANGES);
    descriptor.setAmendmentClass(IsolatedParent.class);
    descriptor.setAmendmentMethodName("afterLoad");
    // Query Manager.
    descriptor.getQueryManager().checkCacheForDoesExist();
    // Named Queries.
    // Named Query -- findParentBySerial
    ReadObjectQuery namedQuery0 = new ReadObjectQuery(IsolatedParent.class);
    namedQuery0.setName("findParentBySerial");
    namedQuery0.setShouldBindAllParameters(true);
    ExpressionBuilder expBuilder0 = namedQuery0.getExpressionBuilder();
    namedQuery0.setSelectionCriteria(expBuilder0.get("serial").equal(expBuilder0.getParameter("serial_p")));
    namedQuery0.addArgument("serial_p", java.lang.String.class);
    descriptor.getQueryManager().addQuery("findParentBySerial", namedQuery0);
    // Event Manager.
    // Mappings.
    DirectToFieldMapping idMapping = new DirectToFieldMapping();
    idMapping.setAttributeName("id");
    idMapping.setFieldName("ISOLATED_PARENT.ID");
    descriptor.addMapping(idMapping);
    DirectToFieldMapping serialMapping = new DirectToFieldMapping();
    serialMapping.setAttributeName("serial");
    serialMapping.setFieldName("ISOLATED_PARENT.SERIAL");
    descriptor.addMapping(serialMapping);
    OneToManyMapping childrenMapping = new OneToManyMapping();
    childrenMapping.setAttributeName("children");
    childrenMapping.setReferenceClass(IsolatedChild.class);
    childrenMapping.useTransparentCollection();
    childrenMapping.useCollectionClass(org.eclipse.persistence.indirection.IndirectList.class);
    childrenMapping.addTargetForeignKeyFieldName("ISOLATED_CHILD.PARENT_ID", "ISOLATED_PARENT.ID");
    childrenMapping.privateOwnedRelationship();
    descriptor.addMapping(childrenMapping);
    return descriptor;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 10 with OneToManyMapping

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

the class IsolatedParent method afterLoad.

public static void afterLoad(ClassDescriptor descriptor) {
    OneToManyMapping childrenMapping = (OneToManyMapping) descriptor.getMappingForAttributeName("children");
    Expression selectionCriteria = childrenMapping.buildSelectionCriteria();
    ExpressionBuilder builder = new ExpressionBuilder();
    childrenMapping.setSelectionCriteria(selectionCriteria.and(builder.get("deleted").equal("N")));
}
Also used : Expression(org.eclipse.persistence.expressions.Expression) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

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