@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) { boolean end1EqCurEnd2 = end1.getMultiplicity().equals(currentAssociationEnd2.getMultiplicity()); boolean end2EqCurEnd1 = end2.getMultiplicity().equals(currentAssociationEnd1.getMultiplicity()); if(end1Type.equals(currentAssociationEnd2Type) && end2Type.equals(currentAssociationEnd1Type) && end1EqCurEnd2 && end2EqCurEnd1) { 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 ((end1IsZeroToOne && currentAssociationEnd1.getMultiplicity() == EdmMultiplicity.ONE || end1IsOne && currentAssociationEnd1.getMultiplicity() == EdmMultiplicity.ZERO_TO_ONE)
private Association mergeAssociations(final Association associationOne, final Association associationTwo) { AssociationEnd oneEnd1 = associationOne.getEnd1(); AssociationEnd oneEnd2 = associationOne.getEnd2(); AssociationEnd twoEnd1 = associationTwo.getEnd1(); AssociationEnd twoEnd2 = associationTwo.getEnd2(); AssociationEnd[] oneEnds = new AssociationEnd[] { oneEnd1, oneEnd2 }; for (AssociationEnd associationEnd : oneEnds) { if (associationEnd.getRole().equals(twoEnd1.getRole())) { if (twoEnd1.getMultiplicity() == EdmMultiplicity.MANY) { associationEnd.setMultiplicity(EdmMultiplicity.MANY); } } else if (associationEnd.getRole().equals(twoEnd2.getRole())) { if (twoEnd2.getMultiplicity() == EdmMultiplicity.MANY) { associationEnd.setMultiplicity(EdmMultiplicity.MANY); } } } return associationOne; }
@Override public EdmAnnotations getAnnotations() throws EdmException { if (annotations == null) { annotations = new EdmAnnotationsImplProv(associationEnd.getAnnotationAttributes(), associationEnd.getAnnotationElements()); } return annotations; } }
public EdmMultiplicity getEndMultiplicity(final String role) { if (association.getEnd1().getRole().equals(role)) { return association.getEnd1().getMultiplicity(); } if (association.getEnd2().getRole().equals(role)) { return association.getEnd2().getMultiplicity(); } return null; }
reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ASSOCIATION_END); AssociationEnd associationEnd = new AssociationEnd(); List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>(); associationEnd.setRole(reader.getAttributeValue(null, XmlMetadataConstants.EDM_ROLE)); associationEnd.setMultiplicity(EdmMultiplicity.fromLiteral(reader.getAttributeValue(null, XmlMetadataConstants.EDM_ASSOCIATION_MULTIPLICITY))); String type = reader.getAttributeValue(null, XmlMetadataConstants.EDM_TYPE); .addContent(XmlMetadataConstants.EDM_TYPE).addContent(XmlMetadataConstants.EDM_ASSOCIATION_END)); associationEnd.setType(extractFQName(type)); associationEnd.setAnnotationAttributes(readAnnotationAttribute(reader)); while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && XmlMetadataConstants.EDM_ASSOCIATION_END.equals(reader.getLocalName()))) { associationEnd.setOnDelete(onDelete); } else { annotationElements.add(readAnnotationElement(reader)); associationEnd.setAnnotationElements(annotationElements);
private Association createAssociation(final AnnotationHelper.AnnotatedNavInfo info) { Association association = new Association(); AssociationEnd fromEnd = new AssociationEnd(); fromEnd.setRole(info.getFromRoleName()); fromEnd.setType(new FullQualifiedName(namespace, info.getFromTypeName())); fromEnd.setMultiplicity(info.getFromMultiplicity()); association.setEnd1(fromEnd); AssociationEnd toEnd = new AssociationEnd(); toEnd.setRole(info.getToRoleName()); toEnd.setType(new FullQualifiedName(namespace, info.getToTypeName())); toEnd.setMultiplicity(info.getToMultiplicity()); association.setEnd2(toEnd); String associationName = info.getRelationshipName(); association.setName(associationName); return association; }
private static void writeAssociationEnd(final AssociationEnd end, final Map<String, String> predefinedNamespaces, final XMLStreamWriter xmlStreamWriter) throws XMLStreamException { xmlStreamWriter.writeStartElement(XmlMetadataConstants.EDM_ASSOCIATION_END); xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_TYPE, end.getType().toString()); xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_ASSOCIATION_MULTIPLICITY, end.getMultiplicity().toString()); if (end.getRole() != null) { xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_ROLE, end.getRole()); } writeAnnotationAttributes(end.getAnnotationAttributes(), predefinedNamespaces, null, xmlStreamWriter); writeDocumentation(end.getDocumentation(), predefinedNamespaces, xmlStreamWriter); OnDelete onDelete = end.getOnDelete(); if (onDelete != null) { xmlStreamWriter.writeStartElement(XmlMetadataConstants.EDM_ASSOCIATION_ONDELETE); xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_ONDELETE_ACTION, onDelete.getAction().toString()); writeAnnotationAttributes(onDelete.getAnnotationAttributes(), predefinedNamespaces, null, xmlStreamWriter); writeDocumentation(onDelete.getDocumentation(), predefinedNamespaces, xmlStreamWriter); writeAnnotationElements(onDelete.getAnnotationElements(), predefinedNamespaces, xmlStreamWriter); xmlStreamWriter.writeEndElement(); } writeAnnotationElements(end.getAnnotationElements(), predefinedNamespaces, xmlStreamWriter); xmlStreamWriter.writeEndElement(); }
private void validateRelationship() throws EntityProviderException { for (NavigationProperty navProperty : navProperties) { if (associationsMap.containsKey(navProperty.getRelationship())) { Association assoc = associationsMap.get(navProperty.getRelationship()); if (!(assoc.getEnd1().getRole().equals(navProperty.getFromRole()) ^ assoc.getEnd1().getRole().equals(navProperty.getToRole()) && (assoc.getEnd2().getRole().equals(navProperty.getFromRole()) ^ assoc.getEnd2().getRole().equals( navProperty.getToRole())))) { throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT .addContent("Invalid end of association")); } if (!entityTypesMap.containsKey(assoc.getEnd1().getType())) { validateEntityTypeWithAlias(assoc.getEnd1().getType()); } if (!entityTypesMap.containsKey(assoc.getEnd2().getType())) { validateEntityTypeWithAlias(assoc.getEnd2().getType()); } } else { throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT.addContent("Invalid Relationship")); } } }
@Override public void build() throws ODataJPAModelException { currentAssociationEnd1 = new AssociationEnd(); currentAssociationEnd2 = new AssociationEnd(); JPAEdmNameBuilder.build(JPAEdmAssociationEnd.this, entityTypeView, propertyView); currentAssociationEnd1.setRole(currentAssociationEnd1.getType().getName()); if (currentAssociationEnd1.getType().getName().equals(currentAssociationEnd2.getType().getName())) { currentAssociationEnd2.setRole(currentAssociationEnd2.getType().getName() + "2"); } else { currentAssociationEnd2.setRole(currentAssociationEnd2.getType().getName()); } setEdmMultiplicity(propertyView.getJPAAttribute().getPersistentAttributeType()); List<String[]> joinColumnNames = propertyView.getJPAJoinColumns(); if (joinColumnNames != null) { int i = 0; columnNames = (String[]) Array.newInstance(String.class, joinColumnNames.size()); referencedColumnNames = (String[]) Array.newInstance(String.class, joinColumnNames.size()); for (String[] jc : joinColumnNames) { columnNames[i] = jc[0]; referencedColumnNames[i++] = jc[1]; } } ownerPropertyName = propertyView.getJPAAttribute().getName(); }
.getType(); FullQualifiedName associationEndTypeTwo = association.getEnd2() .getType(); if (association.getEnd2().getMultiplicity().equals(EdmMultiplicity.MANY)) { navProp.setToRole(association.getEnd2().getRole()); navProp.setFromRole(association.getEnd1().getRole()); } else { navProp.setToRole(association.getEnd1().getRole()); navProp.setFromRole(association.getEnd2().getRole()); if (association.getEnd2().getMultiplicity().equals(EdmMultiplicity.ONE) || association.getEnd2().getMultiplicity().equals(EdmMultiplicity.ZERO_TO_ONE)) { navProp.setToRole(association.getEnd2().getRole()); navProp.setFromRole(association.getEnd1().getRole()); } else { navProp.setToRole(association.getEnd1().getRole()); navProp.setFromRole(association.getEnd2().getRole()); navProp.setFromRole(association.getEnd2().getRole()); navProp.setToRole(association.getEnd1().getRole()); } else if (toName.equals(associationEndTypeTwo.getName())) { navProp.setToRole(association.getEnd2().getRole()); navProp.setFromRole(association.getEnd1().getRole());
@Override public String getRole() { return associationEnd.getRole(); }
private void includeAssociation(Schema targetSchema, IServiceInfo service, Association sourceAssociation) throws ODataException { List<Association> associations = targetSchema.getAssociations(); if (associations != null) { for (Association type : associations) { if (type.getName().equals(sourceAssociation.getName())) { throw new ODataException("association " + sourceAssociation.getName() + " already defined"); } } } else { associations = new ArrayList<Association>(); } Association newAssociation = clone(sourceAssociation); newAssociation.getEnd1().setType( new FullQualifiedName(targetSchema.getNamespace(), newAssociation.getEnd1().getType().getName())); newAssociation.getEnd2().setType( new FullQualifiedName(targetSchema.getNamespace(), newAssociation.getEnd2().getType().getName())); associations.add(newAssociation); targetSchema.setAssociations(associations); }
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); } }
@Override public EdmMultiplicity getMultiplicity() { return associationEnd.getMultiplicity(); }
public static void build(final JPAEdmAssociationEndView assocaitionEndView, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView) { String namespace = buildNamespace(assocaitionEndView); String name = entityTypeView.getEdmEntityType().getName(); FullQualifiedName fQName = new FullQualifiedName(namespace, name); assocaitionEndView.getEdmAssociationEnd1().setType(fQName); name = null; String jpaEntityTypeName = null; Attribute<?, ?> jpaAttribute = propertyView.getJPAAttribute(); if (jpaAttribute.isCollection()) { jpaEntityTypeName = ((PluralAttribute<?, ?, ?>) jpaAttribute).getElementType().getJavaType() .getSimpleName(); } else { jpaEntityTypeName = propertyView.getJPAAttribute().getJavaType() .getSimpleName(); } JPAEdmMappingModelAccess mappingModelAccess = assocaitionEndView.getJPAEdmMappingModelAccess(); if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) { name = mappingModelAccess.mapJPAEntityType(jpaEntityTypeName); } if (name == null) { name = jpaEntityTypeName; } fQName = new FullQualifiedName(namespace, name); assocaitionEndView.getEdmAssociationEnd2().setType(fQName); }
switch (type) { case ONE_TO_MANY: currentAssociationEnd1.setMultiplicity(EdmMultiplicity.ONE); currentAssociationEnd2.setMultiplicity(EdmMultiplicity.MANY); if (annotatedElement != null) { OneToMany reln = annotatedElement.getAnnotation(OneToMany.class); currentAssociationEnd1.setMultiplicity(EdmMultiplicity.MANY); currentAssociationEnd2.setMultiplicity(EdmMultiplicity.MANY); if (annotatedElement != null) { ManyToMany reln = annotatedElement.getAnnotation(ManyToMany.class); currentAssociationEnd1.setMultiplicity(EdmMultiplicity.MANY); currentAssociationEnd2.setMultiplicity(EdmMultiplicity.ONE); if (annotatedElement != null) { ManyToOne reln = annotatedElement.getAnnotation(ManyToOne.class); if (reln != null && reln.optional()) { currentAssociationEnd2.setMultiplicity(EdmMultiplicity.ZERO_TO_ONE); currentAssociationEnd1.setMultiplicity(EdmMultiplicity.ONE); currentAssociationEnd2.setMultiplicity(EdmMultiplicity.ONE); if (annotatedElement != null) { OneToOne reln = annotatedElement.getAnnotation(OneToOne.class); mappedBy = reln.mappedBy(); if(reln.optional()) { currentAssociationEnd2.setMultiplicity(EdmMultiplicity.ZERO_TO_ONE);
reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ASSOCIATION_END); AssociationEnd associationEnd = new AssociationEnd(); List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>(); associationEnd.setRole(reader.getAttributeValue(null, XmlMetadataConstants.EDM_ROLE)); associationEnd.setMultiplicity(EdmMultiplicity.fromLiteral(reader.getAttributeValue(null, XmlMetadataConstants.EDM_ASSOCIATION_MULTIPLICITY))); String type = reader.getAttributeValue(null, XmlMetadataConstants.EDM_TYPE); .addContent(XmlMetadataConstants.EDM_TYPE).addContent(XmlMetadataConstants.EDM_ASSOCIATION_END)); associationEnd.setType(extractFQName(type)); associationEnd.setAnnotationAttributes(readAnnotationAttribute(reader)); while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && XmlMetadataConstants.EDM_ASSOCIATION_END.equals(reader.getLocalName()))) { associationEnd.setOnDelete(onDelete); } else { annotationElements.add(readAnnotationElement(reader)); associationEnd.setAnnotationElements(annotationElements);
private Association createAssociation(final AnnotationHelper.AnnotatedNavInfo info) { Association association = new Association(); AssociationEnd fromEnd = new AssociationEnd(); fromEnd.setRole(info.getFromRoleName()); fromEnd.setType(new FullQualifiedName(namespace, info.getFromTypeName())); fromEnd.setMultiplicity(info.getFromMultiplicity()); association.setEnd1(fromEnd); AssociationEnd toEnd = new AssociationEnd(); toEnd.setRole(info.getToRoleName()); toEnd.setType(new FullQualifiedName(namespace, info.getToTypeName())); toEnd.setMultiplicity(info.getToMultiplicity()); association.setEnd2(toEnd); String associationName = info.getRelationshipName(); association.setName(associationName); return association; }
private static void writeAssociationEnd(final AssociationEnd end, final Map<String, String> predefinedNamespaces, final XMLStreamWriter xmlStreamWriter) throws XMLStreamException { xmlStreamWriter.writeStartElement(XmlMetadataConstants.EDM_ASSOCIATION_END); xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_TYPE, end.getType().toString()); xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_ASSOCIATION_MULTIPLICITY, end.getMultiplicity().toString()); if (end.getRole() != null) { xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_ROLE, end.getRole()); } writeAnnotationAttributes(end.getAnnotationAttributes(), predefinedNamespaces, null, xmlStreamWriter); writeDocumentation(end.getDocumentation(), predefinedNamespaces, xmlStreamWriter); OnDelete onDelete = end.getOnDelete(); if (onDelete != null) { xmlStreamWriter.writeStartElement(XmlMetadataConstants.EDM_ASSOCIATION_ONDELETE); xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_ONDELETE_ACTION, onDelete.getAction().toString()); writeAnnotationAttributes(onDelete.getAnnotationAttributes(), predefinedNamespaces, null, xmlStreamWriter); writeDocumentation(onDelete.getDocumentation(), predefinedNamespaces, xmlStreamWriter); writeAnnotationElements(onDelete.getAnnotationElements(), predefinedNamespaces, xmlStreamWriter); xmlStreamWriter.writeEndElement(); } writeAnnotationElements(end.getAnnotationElements(), predefinedNamespaces, xmlStreamWriter); xmlStreamWriter.writeEndElement(); }