private AssociationSet clone(AssociationSet set) { if (set == null) { return null; } AssociationSet newSet = new AssociationSet(); newSet.setAnnotationAttributes(set.getAnnotationAttributes()); newSet.setAnnotationElements(set.getAnnotationElements()); newSet.setAssociation(set.getAssociation()); newSet.setDocumentation(set.getDocumentation()); newSet.setEnd1(clone(set.getEnd1())); newSet.setEnd2(clone(set.getEnd2())); newSet.setName(set.getName()); return newSet; }
@Override public EdmAnnotations getAnnotations() throws EdmException { if (annotations == null) { annotations = new EdmAnnotationsImplProv(associationSet.getAnnotationAttributes(), associationSet.getAnnotationElements()); } return annotations; } }
@Override public EdmAssociationSetEnd getEnd(final String role) throws EdmException { AssociationSetEnd end; if (associationSet.getEnd1().getRole().equals(role)) { end = associationSet.getEnd1(); } else if (associationSet.getEnd2().getRole().equals(role)) { end = associationSet.getEnd2(); } else { return null; } EdmEntitySet entitySet = edmEntityContainer.getEntitySet(end.getEntitySet()); if (entitySet == null) { throw new EdmException(EdmException.COMMON); } return new EdmAssociationSetEndImplProv(end, entitySet); }
if (sets != null) { for (AssociationSet set : sets) { if (set.getName().equals(associationSetName)) { throw new ODataException("association set " + associationSetName + " already defined"); AssociationSet set = new AssociationSet(); set.setName(associationSetName); set.setAssociation(new FullQualifiedName(schema.getNamespace(), associationName)); end1.setEntitySet(sourceEntitySetName); end1.setRole(sourceRoleName); set.setEnd1(end1); set.setEnd2(end2);
@Override public AssociationSet getAssociationSet(final String entityContainer, final FullQualifiedName association, final String sourceEntitySetName, final String sourceEntitySetRole) throws ODataException { for (Schema schema : dataServices.getSchemas()) { for (EntityContainer container : schema.getEntityContainers()) { if (container.getName().equals(entityContainer)) { for (AssociationSet associationSet : container.getAssociationSets()) { if (associationSet.getAssociation().equals(association) && ((associationSet.getEnd1().getEntitySet().equals(sourceEntitySetName) && associationSet.getEnd1() .getRole().equals(sourceEntitySetRole)) || (associationSet.getEnd2().getEntitySet().equals(sourceEntitySetName) && associationSet.getEnd2() .getRole().equals(sourceEntitySetRole)))) { return associationSet; } } } } } return null; }
private AssociationSet readAssociationSet(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException { reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ASSOCIATION_SET); AssociationSet associationSet = new AssociationSet(); List<AssociationSetEnd> ends = new ArrayList<AssociationSetEnd>(); List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>(); associationSet.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME)); String association = reader.getAttributeValue(null, XmlMetadataConstants.EDM_ASSOCIATION); if (association != null) { associationSet.setAssociation(extractFQName(association)); } else { throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE .addContent(XmlMetadataConstants.EDM_ASSOCIATION).addContent(XmlMetadataConstants.EDM_ASSOCIATION_SET)); associationSet.setAnnotationAttributes(readAnnotationAttribute(reader)); while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) .addContent("Count of AssociationSet ends should be 2")); } else { associationSet.setEnd1(ends.get(0)).setEnd2(ends.get(1)); associationSet.setAnnotationElements(annotationElements);
for (AssociationSet associationSet : associationSets) { xmlStreamWriter.writeStartElement(XmlMetadataConstants.EDM_ASSOCIATION_SET); xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_NAME, associationSet.getName()); xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_ASSOCIATION, associationSet.getAssociation() .toString()); writeAnnotationAttributes(associationSet.getAnnotationAttributes(), predefinedNamespaces, null, xmlStreamWriter); writeDocumentation(associationSet.getDocumentation(), predefinedNamespaces, xmlStreamWriter); writeAssociationSetEnd(associationSet.getEnd1(), predefinedNamespaces, xmlStreamWriter); writeAssociationSetEnd(associationSet.getEnd2(), predefinedNamespaces, xmlStreamWriter); writeAnnotationElements(associationSet.getAnnotationElements(), predefinedNamespaces, xmlStreamWriter);
private void includeAssociationSet(Schema targetSchema, EntityContainer targetContainer, IServiceInfo service, AssociationSet sourceSet) throws ODataException { List<AssociationSet> sets = targetContainer.getAssociationSets(); if (sets != null) { for (AssociationSet set : sets) { if (set.getName().equals(sourceSet.getName())) { throw new ODataException("association set " + sourceSet.getName() + " already defined"); } } } else { sets = new ArrayList<AssociationSet>(); } AssociationSet newSet = clone(sourceSet); newSet.setAssociation(new FullQualifiedName( targetSchema.getNamespace(), newSet.getAssociation().getName())); sets.add(newSet); targetContainer.setAssociationSets(sets); }
@Override public EdmAssociation getAssociation() throws EdmException { EdmAssociation association = edm.getAssociation(associationSet.getAssociation().getNamespace(), associationSet.getAssociation().getName()); if (association == null) { throw new EdmException(EdmException.COMMON); } return association; }
public static void build(final JPAEdmAssociationSetView view) { AssociationSet associationSet = view.getEdmAssociationSet(); String name = view.getEdmAssociation().getName(); associationSet.setName(name + ASSOCIATIONSET_SUFFIX); }
public void addAssociationSets(final Collection<Association> associations) throws ODataException { for (Association association : associations) { AssociationSet as = new AssociationSet(); as.setName(association.getName()); FullQualifiedName asAssociationFqn = new FullQualifiedName(namespace, association.getName()); as.setAssociation(asAssociationFqn); AssociationSetEnd asEnd1 = new AssociationSetEnd(); asEnd1.setEntitySet(getEntitySetName(association.getEnd1())); asEnd1.setRole(association.getEnd1().getRole()); as.setEnd1(asEnd1); AssociationSetEnd asEnd2 = new AssociationSetEnd(); asEnd2.setEntitySet(getEntitySetName(association.getEnd2())); asEnd2.setRole(association.getEnd2().getRole()); as.setEnd2(asEnd2); associationSets.add(as); } }
@Override public AssociationSet getAssociationSet(final String entityContainer, final FullQualifiedName association, final String sourceEntitySetName, final String sourceEntitySetRole) throws ODataException { for (Schema schema : dataServices.getSchemas()) { for (EntityContainer container : schema.getEntityContainers()) { if (container.getName().equals(entityContainer)) { for (AssociationSet associationSet : container.getAssociationSets()) { if (associationSet.getAssociation().equals(association) && ((associationSet.getEnd1().getEntitySet().equals(sourceEntitySetName) && associationSet.getEnd1() .getRole().equals(sourceEntitySetRole)) || (associationSet.getEnd2().getEntitySet().equals(sourceEntitySetName) && associationSet.getEnd2() .getRole().equals(sourceEntitySetRole)))) { return associationSet; } } } } } return null; }
private AssociationSet readAssociationSet(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException { reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ASSOCIATION_SET); AssociationSet associationSet = new AssociationSet(); List<AssociationSetEnd> ends = new ArrayList<AssociationSetEnd>(); List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>(); associationSet.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME)); String association = reader.getAttributeValue(null, XmlMetadataConstants.EDM_ASSOCIATION); if (association != null) { associationSet.setAssociation(extractFQName(association)); } else { throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE .addContent(XmlMetadataConstants.EDM_ASSOCIATION).addContent(XmlMetadataConstants.EDM_ASSOCIATION_SET)); associationSet.setAnnotationAttributes(readAnnotationAttribute(reader)); while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) .addContent("Count of AssociationSet ends should be 2")); } else { associationSet.setEnd1(ends.get(0)).setEnd2(ends.get(1)); associationSet.setAnnotationElements(annotationElements);
for (AssociationSet associationSet : associationSets) { xmlStreamWriter.writeStartElement(XmlMetadataConstants.EDM_ASSOCIATION_SET); xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_NAME, associationSet.getName()); xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_ASSOCIATION, associationSet.getAssociation() .toString()); writeAnnotationAttributes(associationSet.getAnnotationAttributes(), predefinedNamespaces, null, xmlStreamWriter); writeDocumentation(associationSet.getDocumentation(), predefinedNamespaces, xmlStreamWriter); writeAssociationSetEnd(associationSet.getEnd1(), predefinedNamespaces, xmlStreamWriter); writeAssociationSetEnd(associationSet.getEnd2(), predefinedNamespaces, xmlStreamWriter); writeAnnotationElements(associationSet.getAnnotationElements(), predefinedNamespaces, xmlStreamWriter);
@Override public EdmAssociationSetEnd getEnd(final String role) throws EdmException { AssociationSetEnd end; if (associationSet.getEnd1().getRole().equals(role)) { end = associationSet.getEnd1(); } else if (associationSet.getEnd2().getRole().equals(role)) { end = associationSet.getEnd2(); } else { return null; } EdmEntitySet entitySet = edmEntityContainer.getEntitySet(end.getEntitySet()); if (entitySet == null) { throw new EdmException(EdmException.COMMON); } return new EdmAssociationSetEndImplProv(end, entitySet); }
@Override public EdmAssociation getAssociation() throws EdmException { EdmAssociation association = edm.getAssociation(associationSet.getAssociation().getNamespace(), associationSet.getAssociation().getName()); if (association == null) { throw new EdmException(EdmException.COMMON); } return association; }
@Override public EdmAnnotations getAnnotations() throws EdmException { if (annotations == null) { annotations = new EdmAnnotationsImplProv(associationSet.getAnnotationAttributes(), associationSet.getAnnotationElements()); } return annotations; } }
public static void build(final JPAEdmAssociationSetView view) { AssociationSet associationSet = view.getEdmAssociationSet(); String name = view.getEdmAssociation().getName(); associationSet.setName(name + ASSOCIATIONSET_SUFFIX); }
public void addAssociationSets(final Collection<Association> associations) throws ODataException { for (Association association : associations) { AssociationSet as = new AssociationSet(); as.setName(association.getName()); FullQualifiedName asAssociationFqn = new FullQualifiedName(namespace, association.getName()); as.setAssociation(asAssociationFqn); AssociationSetEnd asEnd1 = new AssociationSetEnd(); asEnd1.setEntitySet(getEntitySetName(association.getEnd1())); asEnd1.setRole(association.getEnd1().getRole()); as.setEnd1(asEnd1); AssociationSetEnd asEnd2 = new AssociationSetEnd(); asEnd2.setEntitySet(getEntitySetName(association.getEnd2())); asEnd2.setRole(association.getEnd2().getRole()); as.setEnd2(asEnd2); associationSets.add(as); } }
@Override public AssociationSet getAssociationSet(final String entityContainer, final FullQualifiedName association, final String sourceEntitySetName, final String sourceEntitySetRole) throws ODataException { for (Schema schema : dataServices.getSchemas()) { for (EntityContainer container : schema.getEntityContainers()) { if (container.getName().equals(entityContainer)) { for (AssociationSet associationSet : container.getAssociationSets()) { if (associationSet.getAssociation().equals(association) && ((associationSet.getEnd1().getEntitySet().equals(sourceEntitySetName) && associationSet.getEnd1() .getRole().equals(sourceEntitySetRole)) || (associationSet.getEnd2().getEntitySet().equals(sourceEntitySetName) && associationSet.getEnd2() .getRole().equals(sourceEntitySetRole)))) { return associationSet; } } } } } return null; }