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);
}
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());
}
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);
}
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);
}
}
}
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());
}
Aggregations