private EntitySet clone(EntitySet set) { if (set == null) { return null; } EntitySet newSet = new EntitySet(); newSet.setAnnotationAttributes(set.getAnnotationAttributes()); newSet.setAnnotationElements(set.getAnnotationElements()); newSet.setDocumentation(set.getDocumentation()); newSet.setEntityType(set.getEntityType()); newSet.setMapping(set.getMapping()); newSet.setName(set.getName()); return newSet; }
private EntitySet createEntitySet(final FullQualifiedName typeName, final Class<?> entitySetClass) { String entitySetName = ANNOTATION_HELPER.extractEntitySetName(entitySetClass); return new EntitySet().setName(entitySetName).setEntityType(typeName); }
@Override public EdmAnnotations getAnnotations() throws EdmException { if (annotations == null) { annotations = new EdmAnnotationsImplProv(entitySet.getAnnotationAttributes(), entitySet.getAnnotationElements()); } return annotations; }
private EntitySet readEntitySet(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException { reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ENTITY_SET); EntitySet entitySet = new EntitySet(); List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>(); entitySet.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME)); String entityType = reader.getAttributeValue(null, XmlMetadataConstants.EDM_ENTITY_TYPE); if (entityType != null) { FullQualifiedName fqName = extractFQName(entityType); entitySet.setEntityType(fqName); } else { throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE .addContent(XmlMetadataConstants.EDM_ENTITY_TYPE).addContent(XmlMetadataConstants.EDM_ENTITY_SET)); } entitySet.setAnnotationAttributes(readAnnotationAttribute(reader)); while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && XmlMetadataConstants.EDM_ENTITY_SET.equals(reader.getLocalName()))) { reader.next(); if (reader.isStartElement()) { extractNamespaces(reader); annotationElements.add(readAnnotationElement(reader)); } } if (!annotationElements.isEmpty()) { entitySet.setAnnotationElements(annotationElements); } return entitySet; }
for (EntitySet entitySet : entitySets) { xmlStreamWriter.writeStartElement(XmlMetadataConstants.EDM_ENTITY_SET); xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_NAME, entitySet.getName()); xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_ENTITY_TYPE, entitySet.getEntityType() .toString()); writeAnnotationAttributes(entitySet.getAnnotationAttributes(), predefinedNamespaces, null, xmlStreamWriter); writeDocumentation(entitySet.getDocumentation(), predefinedNamespaces, xmlStreamWriter); writeAnnotationElements(entitySet.getAnnotationElements(), predefinedNamespaces, xmlStreamWriter);
public EdmEntitySetImplProv(final EdmImplProv edm, final EntitySet entitySet, final EdmEntityContainer edmEntityContainer) throws EdmException { super(edm, entitySet.getName()); this.entitySet = entitySet; this.edmEntityContainer = edmEntityContainer; }
private void readEntitySets(final JsonReader reader) throws IOException, EntityProviderException, EdmException { while (reader.hasNext()) { currentHandledObjectName = reader.nextString(); if (currentHandledObjectName != null) { // Looking for the last dot: "\\.(?=[^.]+$)" String[] names = currentHandledObjectName.split("\\" + Edm.DELIMITER + "(?=[^" + Edm.DELIMITER + "]+$)"); if (names.length == 1) { EntitySet entitySet = new EntitySet().setName(names[0]); EntityContainerInfo container = new EntityContainerInfo().setDefaultEntityContainer(true); EdmEntitySetInfo entitySetInfo = new EdmEntitySetInfoImplProv(entitySet, container); entitySets.add(entitySetInfo); } else { EntitySet entitySet = new EntitySet().setName(names[1]); EntityContainerInfo container = new EntityContainerInfo().setName(names[0]).setDefaultEntityContainer(false); EdmEntitySetInfo entitySetInfo = new EdmEntitySetInfoImplProv(entitySet, container); entitySets.add(entitySetInfo); } } } }
private String getEntitySetName(final AssociationEnd end) { for (EntitySet entitySet : entitySets) { if (entitySet.getEntityType().equals(end.getType())) { return entitySet.getName(); } } throw new ODataRuntimeException("No entity set found for " + end.getType()); } }
private void includeEntitySet(Schema targetSchema, EntityContainer targetContainer, IServiceInfo service, EntitySet sourceSet) throws ODataException { List<EntitySet> targetEntitySets = targetContainer.getEntitySets(); if (targetEntitySets != null) { for (EntitySet set : targetEntitySets) { if (set.getName().equals(sourceSet.getName())) { throw new ODataException("entity set " + sourceSet.getName() + " already defined"); } } } else { targetEntitySets = new ArrayList<EntitySet>(); } EntitySet newSet = clone(sourceSet); newSet.setEntityType(new FullQualifiedName(targetSchema.getNamespace(), newSet.getEntityType().getName())); targetEntitySets.add(newSet); targetContainer.setEntitySets(targetEntitySets); MashServiceRegistry.setTargetService(_service, targetSchema, targetContainer, newSet, service); }
public static void build(final JPAEdmEntitySetView view, final JPAEdmEntityTypeView entityTypeView) { FullQualifiedName fQname = view.getEdmEntitySet().getEntityType(); JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess(); String entitySetName = null; if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) { Mapping mapping = entityTypeView.getEdmEntityType().getMapping(); if (mapping != null) { entitySetName = mappingModelAccess.mapJPAEntitySet(mapping.getInternalName()); } } if (entitySetName == null) { entitySetName = fQname.getName(); } view.getEdmEntitySet().setName(entitySetName); }
@Override public void build() throws ODataJPAModelException, ODataJPARuntimeException { if (consistentEntitySetList == null) { consistentEntitySetList = new ArrayList<EntitySet>(); } entityTypeView = new JPAEdmEntityType(schemaView); entityTypeView.getBuilder().build(); if (entityTypeView.isConsistent() && entityTypeView.getConsistentEdmEntityTypes() != null) { String nameSpace = schemaView.getEdmSchema().getNamespace(); for (EntityType entityType : entityTypeView.getConsistentEdmEntityTypes()) { currentEntitySet = new EntitySet(); currentEntitySet.setEntityType(new FullQualifiedName(nameSpace, entityType.getName())); JPAEdmNameBuilder.build(JPAEdmEntitySet.this, entityTypeView); consistentEntitySetList.add(currentEntitySet); } isConsistent = true; } else { isConsistent = false; return; } }
private void validateEntitySet() throws EntityProviderException { for (Map.Entry<FullQualifiedName, EntityContainer> container : containerMap.entrySet()) { for (EntitySet entitySet : container.getValue().getEntitySets()) { FullQualifiedName entityType = entitySet.getEntityType(); if (!(entityTypesMap.containsKey(entityType))) { validateEntityTypeWithAlias(entityType); } } } }
@Override public EdmMapping getMapping() throws EdmException { return entitySet.getMapping(); } }
private EntitySet readEntitySet(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException { reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ENTITY_SET); EntitySet entitySet = new EntitySet(); List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>(); entitySet.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME)); String entityType = reader.getAttributeValue(null, XmlMetadataConstants.EDM_ENTITY_TYPE); if (entityType != null) { FullQualifiedName fqName = extractFQName(entityType); entitySet.setEntityType(fqName); } else { throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE .addContent(XmlMetadataConstants.EDM_ENTITY_TYPE).addContent(XmlMetadataConstants.EDM_ENTITY_SET)); } entitySet.setAnnotationAttributes(readAnnotationAttribute(reader)); while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && XmlMetadataConstants.EDM_ENTITY_SET.equals(reader.getLocalName()))) { reader.next(); if (reader.isStartElement()) { extractNamespaces(reader); annotationElements.add(readAnnotationElement(reader)); } } if (!annotationElements.isEmpty()) { entitySet.setAnnotationElements(annotationElements); } return entitySet; }
for (EntitySet entitySet : entitySets) { xmlStreamWriter.writeStartElement(XmlMetadataConstants.EDM_ENTITY_SET); xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_NAME, entitySet.getName()); xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_ENTITY_TYPE, entitySet.getEntityType() .toString()); writeAnnotationAttributes(entitySet.getAnnotationAttributes(), predefinedNamespaces, null, xmlStreamWriter); writeDocumentation(entitySet.getDocumentation(), predefinedNamespaces, xmlStreamWriter); writeAnnotationElements(entitySet.getAnnotationElements(), predefinedNamespaces, xmlStreamWriter);
private EntitySet createEntitySet(final FullQualifiedName typeName, final Class<?> entitySetClass) { String entitySetName = ANNOTATION_HELPER.extractEntitySetName(entitySetClass); return new EntitySet().setName(entitySetName).setEntityType(typeName); }
public EdmEntitySetImplProv(final EdmImplProv edm, final EntitySet entitySet, final EdmEntityContainer edmEntityContainer) throws EdmException { super(edm, entitySet.getName()); this.entitySet = entitySet; this.edmEntityContainer = edmEntityContainer; }
private void readEntitySets(final JsonReader reader) throws IOException, EntityProviderException, EdmException { while (reader.hasNext()) { currentHandledObjectName = reader.nextString(); if (currentHandledObjectName != null) { // Looking for the last dot: "\\.(?=[^.]+$)" String[] names = currentHandledObjectName.split("\\" + Edm.DELIMITER + "(?=[^" + Edm.DELIMITER + "]+$)"); if (names.length == 1) { EntitySet entitySet = new EntitySet().setName(Decoder.decode(names[0])); EntityContainerInfo container = new EntityContainerInfo().setDefaultEntityContainer(true); EdmEntitySetInfo entitySetInfo = new EdmEntitySetInfoImplProv(entitySet, container); entitySets.add(entitySetInfo); } else { EntitySet entitySet = new EntitySet().setName(Decoder.decode(names[1])); EntityContainerInfo container = new EntityContainerInfo().setName(Decoder.decode(names[0])).setDefaultEntityContainer(false); EdmEntitySetInfo entitySetInfo = new EdmEntitySetInfoImplProv(entitySet, container); entitySets.add(entitySetInfo); } } } }
private String getEntitySetName(final AssociationEnd end) throws ODataException { for (EntitySet entitySet : entitySets) { if (entitySet.getEntityType().equals(end.getType())) { return entitySet.getName(); } } throw new ODataException("No entity set found for " + end.getType()); } }
public static void build(final JPAEdmEntitySetView view, final JPAEdmEntityTypeView entityTypeView) { FullQualifiedName fQname = view.getEdmEntitySet().getEntityType(); JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess(); String entitySetName = null; if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) { Mapping mapping = entityTypeView.getEdmEntityType().getMapping(); if (mapping != null) { entitySetName = mappingModelAccess.mapJPAEntitySet(mapping.getInternalName()); } } if (entitySetName == null) { entitySetName = fQname.getName() + ENTITY_SET_SUFFIX; } view.getEdmEntitySet().setName(entitySetName); }