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