Search in sources :

Example 1 with OneToManyMapping

use of org.eclipse.persistence.mappings.OneToManyMapping in project cuba by cuba-platform.

the class JoinCriteriaMappingProcessor method process.

@Override
public void process(MappingProcessorContext context) {
    DatabaseMapping mapping = context.getMapping();
    Expression expression = AppBeans.getAll(JoinExpressionProvider.class).values().stream().map(provider -> provider.getJoinCriteriaExpression(mapping)).filter(Objects::nonNull).reduce(Expression::and).orElse(null);
    // Applying additional join criteria, e.g. for soft delete or multitenancy -> move to mapping processor
    if (mapping.isOneToManyMapping() || mapping.isOneToOneMapping()) {
        // Apply expression to mappings
        if (mapping.isOneToManyMapping()) {
            ((OneToManyMapping) mapping).setAdditionalJoinCriteria(expression);
        } else if (mapping.isOneToOneMapping()) {
            ((OneToOneMapping) mapping).setAdditionalJoinCriteria(expression);
        }
    }
}
Also used : Objects(java.util.Objects) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping) Component(org.springframework.stereotype.Component) Expression(org.eclipse.persistence.expressions.Expression) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) AppBeans(com.haulmont.cuba.core.global.AppBeans) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) Expression(org.eclipse.persistence.expressions.Expression) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) Objects(java.util.Objects) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Example 2 with OneToManyMapping

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

the class BidirectionalRelationshipProject method buildTeamDescriptor.

public RelationalDescriptor buildTeamDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    descriptor.setJavaClass(Team.class);
    descriptor.addTableName("TEAM");
    descriptor.addPrimaryKeyFieldName("TEAM.ID");
    // RelationalDescriptor properties.
    descriptor.useFullIdentityMap();
    descriptor.setIdentityMapSize(100);
    descriptor.setSequenceNumberFieldName("TEAM.ID");
    descriptor.setSequenceNumberName("team_seq");
    descriptor.setAlias("Team");
    // Query manager.
    descriptor.getQueryManager().checkCacheForDoesExist();
    // Mappings.
    DirectToFieldMapping idMapping = new DirectToFieldMapping();
    idMapping.setAttributeName("m_id");
    idMapping.setFieldName("TEAM.ID");
    descriptor.addMapping(idMapping);
    OneToManyMapping onetomanymapping = new OneToManyMapping();
    onetomanymapping.setAttributeName("m_players");
    onetomanymapping.setReferenceClass(Player.class);
    onetomanymapping.useTransparentMap("getId");
    onetomanymapping.addTargetForeignKeyFieldName("PLAYER.TEAM_ID", "TEAM.ID");
    descriptor.addMapping(onetomanymapping);
    return descriptor;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping)

Example 3 with OneToManyMapping

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

the class SimpleTypes_OneToMany method removeAwithB_PrivateOwned.

@Test
public void removeAwithB_PrivateOwned() {
    createAwithB();
    DynamicType simpleAType = dynamicHelper.getType("SimpleA");
    ((OneToManyMapping) simpleAType.getDescriptor().getMappingForAttributeName("b")).setIsPrivateOwned(true);
    UnitOfWork uow = session.acquireUnitOfWork();
    ReadObjectQuery findQuery = dynamicHelper.newReadObjectQuery("SimpleA");
    findQuery.setSelectionCriteria(findQuery.getExpressionBuilder().get("id").equal(1));
    DynamicEntity a = (DynamicEntity) uow.executeQuery(findQuery);
    assertNotNull(a);
    ReportQuery countQuery = dynamicHelper.newReportQuery("SimpleB", new ExpressionBuilder());
    countQuery.addCount();
    countQuery.setShouldReturnSingleValue(true);
    int simpleCountB = ((Number) session.executeQuery(countQuery)).intValue();
    assertEquals(1, simpleCountB);
    countQuery = dynamicHelper.newReportQuery("SimpleA", new ExpressionBuilder());
    countQuery.addCount();
    countQuery.setShouldReturnSingleValue(true);
    int simpleCountA = ((Number) session.executeQuery(countQuery)).intValue();
    assertEquals(1, simpleCountA);
    uow.deleteObject(a);
    // em.remove(a.get("b", List.class).get(0));
    uow.commit();
    countQuery = dynamicHelper.newReportQuery("SimpleB", new ExpressionBuilder());
    countQuery.addCount();
    countQuery.setShouldReturnSingleValue(true);
    simpleCountB = ((Number) session.executeQuery(countQuery)).intValue();
    assertEquals(0, simpleCountB);
    countQuery = dynamicHelper.newReportQuery("SimpleA", new ExpressionBuilder());
    countQuery.addCount();
    countQuery.setShouldReturnSingleValue(true);
    simpleCountA = ((Number) session.executeQuery(countQuery)).intValue();
    assertEquals(0, simpleCountA);
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) ReportQuery(org.eclipse.persistence.queries.ReportQuery) DynamicType(org.eclipse.persistence.dynamic.DynamicType) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) Test(org.junit.Test)

Example 4 with OneToManyMapping

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

the class BidirectionWithHashtableTest method descriptor.

public RelationalDescriptor descriptor() {
    RelationalDescriptor employeeDescriptor = new RelationalDescriptor();
    employeeDescriptor.setJavaClass(Employee.class);
    employeeDescriptor.setTableName("VAL_EMP");
    employeeDescriptor.setPrimaryKeyFieldName("ID");
    OneToManyMapping phoneNumbersMapping = new OneToManyMapping();
    phoneNumbersMapping.setAttributeName("phoneNumbers");
    phoneNumbersMapping.setReferenceClass(org.eclipse.persistence.testing.models.employee.domain.PhoneNumber.class);
    phoneNumbersMapping.useTransparentCollection();
    phoneNumbersMapping.useMapClass(org.eclipse.persistence.indirection.IndirectMap.class, "getNumber");
    phoneNumbersMapping.privateOwnedRelationship();
    phoneNumbersMapping.addTargetForeignKeyFieldName("PHONE.EMP_ID", "EMPLOYEE.EMP_ID");
    phoneNumbersMapping.setRelationshipPartnerAttributeName("employee");
    employeeDescriptor.addMapping(phoneNumbersMapping);
    return employeeDescriptor;
}
Also used : RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping)

Example 5 with OneToManyMapping

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

the class GetMethodReturnTypeNotValidTest 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