Java Code Examples for org.apache.olingo.odata2.api.edm.EdmMultiplicity#ONE
The following examples show how to use
org.apache.olingo.odata2.api.edm.EdmMultiplicity#ONE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationHelper.java From olingo-odata2 with Apache License 2.0 | 5 votes |
public EdmMultiplicity extractMultiplicity(final EdmNavigationProperty enp, final Field field) { EdmMultiplicity multiplicity = mapMultiplicity(enp.toMultiplicity()); final boolean isCollectionType = field.getType().isArray() || Collection.class.isAssignableFrom(field.getType()); if (multiplicity == EdmMultiplicity.ONE && isCollectionType) { return EdmMultiplicity.MANY; } return multiplicity; }
Example 2
Source File: AnnotationHelper.java From olingo-odata2 with Apache License 2.0 | 5 votes |
public EdmMultiplicity mapMultiplicity(final Multiplicity multiplicity) { switch (multiplicity) { case ZERO_OR_ONE: return EdmMultiplicity.ZERO_TO_ONE; case ONE: return EdmMultiplicity.ONE; case MANY: return EdmMultiplicity.MANY; default: throw new AnnotationRuntimeException("Unknown type '" + multiplicity + "' for mapping to EdmMultiplicity."); } }
Example 3
Source File: JPAEdmAssociation.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private void updateAssociationEndMultiplicity(JPAEdmAssociationEndView view, Association association) { if (view.getEdmAssociationEnd1().getMultiplicity() == EdmMultiplicity.ZERO_TO_ONE && association.getEnd1().getMultiplicity() == EdmMultiplicity.ONE) { association.getEnd1().setMultiplicity(EdmMultiplicity.ZERO_TO_ONE); } else if (view.getEdmAssociationEnd2().getMultiplicity() == EdmMultiplicity.ZERO_TO_ONE && association.getEnd2().getMultiplicity() == EdmMultiplicity.ONE) { association.getEnd2().setMultiplicity(EdmMultiplicity.ZERO_TO_ONE); } else if (view.getEdmAssociationEnd1().getMultiplicity() == EdmMultiplicity.ZERO_TO_ONE && association.getEnd2().getMultiplicity() == EdmMultiplicity.ONE) { association.getEnd2().setMultiplicity(EdmMultiplicity.ZERO_TO_ONE); } else if (view.getEdmAssociationEnd2().getMultiplicity() == EdmMultiplicity.ZERO_TO_ONE && association.getEnd1().getMultiplicity() == EdmMultiplicity.ONE) { association.getEnd1().setMultiplicity(EdmMultiplicity.ZERO_TO_ONE); } }
Example 4
Source File: EdmElementImplProv.java From olingo-odata2 with Apache License 2.0 | 5 votes |
public EdmElementImplProv(final EdmImplProv edm, final String name, final FullQualifiedName typeName, final EdmFacets edmFacets, final EdmMapping edmMapping) throws EdmException { super(edm, name, typeName, (edmFacets == null || edmFacets.isNullable() == null) || edmFacets.isNullable() ? EdmMultiplicity.ZERO_TO_ONE : EdmMultiplicity.ONE); this.edmFacets = edmFacets; this.edmMapping = edmMapping; }
Example 5
Source File: AnnotationHelper.java From olingo-odata2 with Apache License 2.0 | 4 votes |
public EdmMultiplicity getFromMultiplicity() { if(isBiDirectional()) { return EdmMultiplicity.ONE; } return extractMultiplicity(toNavigation, toField); }
Example 6
Source File: JPAEdmAssociationEnd.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public boolean compare(final AssociationEnd end1, final AssociationEnd end2) { FullQualifiedName end1Type = end1.getType(); FullQualifiedName currentAssociationEnd1Type = currentAssociationEnd1.getType(); FullQualifiedName end2Type = end2.getType(); FullQualifiedName currentAssociationEnd2Type = currentAssociationEnd2.getType(); if(end1.getMultiplicity() == null || currentAssociationEnd1.getMultiplicity() == null) { return false; } if(end2.getMultiplicity() == null || currentAssociationEnd2.getMultiplicity() == null) { return false; } boolean end1eqCurEnd1 = end1.getMultiplicity().equals(currentAssociationEnd1.getMultiplicity()); boolean end2eqCurEnd2 = end2.getMultiplicity().equals(currentAssociationEnd2.getMultiplicity()); if(end1Type.equals(currentAssociationEnd1Type) && end2Type.equals(currentAssociationEnd2Type) && end1eqCurEnd1 && end2eqCurEnd2) { return true; } boolean end1EqCurEnd2 = end1.getMultiplicity().equals(currentAssociationEnd2.getMultiplicity()); boolean end2EqCurEnd1 = end2.getMultiplicity().equals(currentAssociationEnd1.getMultiplicity()); if(end1Type.equals(currentAssociationEnd2Type) && end2Type.equals(currentAssociationEnd1Type) && end1EqCurEnd2 && end2EqCurEnd1) { return true; } boolean end1IsZeroToOne = end1.getMultiplicity() == EdmMultiplicity.ZERO_TO_ONE; boolean end1IsOne = end1.getMultiplicity() == EdmMultiplicity.ONE; boolean end2IsZeroToOne = end2.getMultiplicity() == EdmMultiplicity.ZERO_TO_ONE; boolean end2IsOne = end2.getMultiplicity() == EdmMultiplicity.ONE; if (end1Type.equals(currentAssociationEnd1Type) && end2Type.equals(currentAssociationEnd2Type)) { if ((end1IsZeroToOne && currentAssociationEnd1.getMultiplicity() == EdmMultiplicity.ONE || end1IsOne && currentAssociationEnd1.getMultiplicity() == EdmMultiplicity.ZERO_TO_ONE) && end2eqCurEnd2) { return true; } if ((end2IsZeroToOne && currentAssociationEnd2.getMultiplicity() == EdmMultiplicity.ONE || end2IsOne && currentAssociationEnd2.getMultiplicity() == EdmMultiplicity.ZERO_TO_ONE) && end1eqCurEnd1) { return true; } } if (end2Type.equals(currentAssociationEnd1Type) && end1Type.equals(currentAssociationEnd2Type)) { if ((end1IsZeroToOne && currentAssociationEnd2.getMultiplicity() == EdmMultiplicity.ONE || end1IsOne && currentAssociationEnd2.getMultiplicity() == EdmMultiplicity.ZERO_TO_ONE) && end2EqCurEnd1) { return true; } if ((end2IsZeroToOne && currentAssociationEnd1.getMultiplicity() == EdmMultiplicity.ONE || end2IsOne && currentAssociationEnd1.getMultiplicity() == EdmMultiplicity.ZERO_TO_ONE) && end1EqCurEnd2) { return true; } } return false; }
Example 7
Source File: JPALinkTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
private List<NavigationSegment> mockNavigationSegments(boolean isReverse) throws EdmException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { Class<?> type = null; String entityTypeName = null; String keyLiteral = null; EdmMultiplicity multiplicity = null; String navPropertyName = null; String toRole = null; String associationName = null; if (isReverse) { type = SalesOrderHeader.class; entityTypeName = "SalesOrder"; keyLiteral = "1"; multiplicity = EdmMultiplicity.ONE; navPropertyName = "salesOrderHeader"; toRole = "SalesOrder"; associationName = "Note_SalesOrder"; } else { type = List.class; entityTypeName = "Note"; keyLiteral = "2"; multiplicity = EdmMultiplicity.MANY; navPropertyName = "NotesDetails"; toRole = "Note"; associationName = "Note_SalesOrder"; } JPAEdmMapping mapping = new JPAEdmMappingImpl(); mapping.setJPAType(type); KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class); EasyMock.expect(keyPredicate.getProperty()).andReturn( edm.getEntityType("SalesOrderProcessing", entityTypeName).getKeyProperties().get(0)).anyTimes(); EasyMock.expect(keyPredicate.getLiteral()).andReturn(keyLiteral); EasyMock.replay(keyPredicate); List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>(); keyPredicates.add(keyPredicate); NavigationSegment navigationSegment = EasyMock.createMock(NavigationSegment.class); EasyMock.expect(navigationSegment.getKeyPredicates()).andReturn(keyPredicates); EdmNavigationProperty navProperty = EasyMock.createMock(EdmNavigationProperty.class); EasyMock.expect(navProperty.getMapping()).andReturn((EdmMapping) mapping).anyTimes(); EasyMock.expect(navProperty.getMultiplicity()).andReturn(multiplicity).anyTimes(); EasyMock.expect(navProperty.getName()).andReturn(navPropertyName).anyTimes(); EasyMock.expect(navProperty.getToRole()).andReturn(toRole).anyTimes(); EasyMock.expect(navProperty.getRelationship()).andReturn( edm.getAssociation("SalesOrderProcessing", associationName)); EasyMock.replay(navProperty); EdmEntityType edmEntityType = edm.getAssociation("SalesOrderProcessing", associationName).getEnd(toRole).getEntityType(); Field field = EdmEntityTypeImplProv.class.getDeclaredField("entityType"); field.setAccessible(true); EntityType entityType = (EntityType) field.get(edmEntityType); entityType.setMapping((Mapping) mapping); EasyMock.expect(navigationSegment.getNavigationProperty()).andReturn(navProperty).anyTimes(); EasyMock.replay(navigationSegment); List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>(); navigationSegments.add(navigationSegment); return navigationSegments; }