Search in sources :

Example 21 with OneToManyMapping

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

the class XMLForeignKeyTestSuite method testMapKeyForeignKey.

/**
 * Tests a map key foreign key setting.
 */
public void testMapKeyForeignKey() {
    ClassDescriptor runnerDescriptor = getPersistenceUnitServerSession().getDescriptor(Runner.class);
    OneToManyMapping mapping = (OneToManyMapping) runnerDescriptor.getMappingForAttributeName("shoes");
    OneToOneMapping keyMapping = (OneToOneMapping) ((MappedKeyMapContainerPolicy) mapping.getContainerPolicy()).getKeyMapping();
    DatabaseTable table = keyMapping.getForeignKeyFields().get(0).getTable();
    assertForeignKeyConstraint("FK_JPA21_XMLRunner_ShoeTag", "FOREIGN KEY (TAG_ID) REFERENCES JPA21_XML_DDL_SHOE_TAG (ID)", table);
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) DatabaseTable(org.eclipse.persistence.internal.helper.DatabaseTable) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping)

Example 22 with OneToManyMapping

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

the class EntityMappingsAdvancedJUnitTestCase method testDeleteAll.

public void testDeleteAll() {
    Map<Class<?>, ClassDescriptor> descriptors = getServerSession(m_persistenceUnit).getDescriptors();
    ClassDescriptor descriptor = descriptors.get(Department.class);
    OneToManyMapping mapping = (OneToManyMapping) descriptor.getMappingForAttributeName("equipment");
    assertFalse("<delete-all> xml did not work correctly", mapping.mustDeleteReferenceObjectsOneByOne());
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) ReadOnlyClass(org.eclipse.persistence.testing.models.jpa.xml.advanced.ReadOnlyClass)

Example 23 with OneToManyMapping

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

the class XMLForeignKeyTestSuite method testMapKeyForeignKey.

/**
 * Tests a map key foreign key setting.
 */
public void testMapKeyForeignKey() {
    ClassDescriptor runnerDescriptor = getPersistenceUnitServerSession().getDescriptor(Runner.class);
    OneToManyMapping mapping = (OneToManyMapping) runnerDescriptor.getMappingForAttributeName("shoes");
    OneToOneMapping keyMapping = (OneToOneMapping) ((MappedKeyMapContainerPolicy) mapping.getContainerPolicy()).getKeyMapping();
    DatabaseTable table = keyMapping.getForeignKeyFields().get(0).getTable();
    assertForeignKeyConstraint("FK_JPA22_XMLRunner_ShoeTag", "FOREIGN KEY (TAG_ID) REFERENCES JPA22_XML_DDL_SHOE_TAG (ID)", table);
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) DatabaseTable(org.eclipse.persistence.internal.helper.DatabaseTable) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping)

Example 24 with OneToManyMapping

use of org.eclipse.persistence.mappings.OneToManyMapping in project jmix by jmix-framework.

the class JoinCriteriaMappingProcessor method process.

@Override
public void process(MappingProcessorContext context) {
    DatabaseMapping mapping = context.getMapping();
    Expression expression = beanFactory.getBeansOfType(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 etc
    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 : MappingProcessor(io.jmix.eclipselink.persistence.MappingProcessor) 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) JoinExpressionProvider(io.jmix.eclipselink.persistence.JoinExpressionProvider) MappingProcessorContext(io.jmix.eclipselink.persistence.MappingProcessorContext) Autowired(org.springframework.beans.factory.annotation.Autowired) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) Expression(org.eclipse.persistence.expressions.Expression) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) Objects(java.util.Objects) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Example 25 with OneToManyMapping

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

the class SimpleTypes_OneToMany method verifyConfig.

@Test
public void verifyConfig() throws Exception {
    ClassDescriptor descriptorA = dynamicHelper.getSession().getClassDescriptorForAlias("SimpleA");
    assertNotNull("No descriptor found for alias='SimpleA'", descriptorA);
    DynamicType simpleTypeA = dynamicHelper.getType("SimpleA");
    assertNotNull("'SimpleA' EntityType not found", simpleTypeA);
    assertEquals(descriptorA, simpleTypeA.getDescriptor());
    DirectToFieldMapping a_id = (DirectToFieldMapping) descriptorA.getMappingForAttributeName("id");
    assertEquals(int.class, a_id.getAttributeClassification());
    DirectToFieldMapping a_value1 = (DirectToFieldMapping) descriptorA.getMappingForAttributeName("value1");
    assertEquals(String.class, a_value1.getAttributeClassification());
    ClassDescriptor descriptorB = dynamicHelper.getSession().getClassDescriptorForAlias("SimpleB");
    assertNotNull("No descriptor found for alias='SimpleB'", descriptorB);
    DynamicType simpleTypeB = dynamicHelper.getType("SimpleB");
    assertNotNull("'SimpleB' EntityType not found", simpleTypeB);
    assertEquals(descriptorB, simpleTypeB.getDescriptor());
    DirectToFieldMapping b_id = (DirectToFieldMapping) descriptorB.getMappingForAttributeName("id");
    assertEquals(int.class, b_id.getAttributeClassification());
    DirectToFieldMapping b_value1 = (DirectToFieldMapping) descriptorB.getMappingForAttributeName("value1");
    assertEquals(String.class, b_value1.getAttributeClassification());
    OneToManyMapping a_b = (OneToManyMapping) descriptorA.getMappingForAttributeName("b");
    assertEquals(descriptorB, a_b.getReferenceDescriptor());
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) DynamicType(org.eclipse.persistence.dynamic.DynamicType) Test(org.junit.Test)

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