private void appendAtomContentLink(final XMLStreamWriter writer, final EntityInfoAggregator eia, final Map<String, Object> data, final String selfLink) throws EntityProviderException, EdmException { try { String mediaResourceMimeType = null; EdmMapping entityTypeMapping = eia.getEntityType().getMapping(); if (entityTypeMapping != null) { String mediaResourceMimeTypeKey = entityTypeMapping.getMediaResourceMimeTypeKey(); if (mediaResourceMimeTypeKey != null) { mediaResourceMimeType = (String) data.get(mediaResourceMimeTypeKey); } } if (mediaResourceMimeType == null) { mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString(); } writer.writeStartElement(FormatXml.ATOM_LINK); writer.writeAttribute(FormatXml.ATOM_HREF, selfLink + "/$value"); writer.writeAttribute(FormatXml.ATOM_REL, Edm.LINK_REL_EDIT_MEDIA); writer.writeAttribute(FormatXml.ATOM_TYPE, mediaResourceMimeType); writer.writeEndElement(); } catch (XMLStreamException e) { throw new EntityProviderProducerException(EntityProviderException.COMMON, e); } }
private void appendAtomContentLink(final XMLStreamWriter writer, final EntityInfoAggregator eia, final Map<String, Object> data, final String selfLink) throws EntityProviderException, EdmException { try { String mediaResourceMimeType = null; EdmMapping entityTypeMapping = eia.getEntityType().getMapping(); if (entityTypeMapping != null) { String mediaResourceMimeTypeKey = entityTypeMapping.getMediaResourceMimeTypeKey(); if (mediaResourceMimeTypeKey != null) { mediaResourceMimeType = (String) data.get(mediaResourceMimeTypeKey); } } if (mediaResourceMimeType == null) { mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString(); } writer.writeStartElement(FormatXml.ATOM_LINK); writer.writeAttribute(FormatXml.ATOM_HREF, selfLink + VALUE); writer.writeAttribute(FormatXml.ATOM_REL, Edm.LINK_REL_EDIT_MEDIA); writer.writeAttribute(FormatXml.ATOM_TYPE, mediaResourceMimeType); writer.writeEndElement(); } catch (XMLStreamException e) { throw new EntityProviderProducerException(EntityProviderException.COMMON, e); } }
private void appendAtomContentLink(final XMLStreamWriter writer, final EntityInfoAggregator eia, final Map<String, Object> data, final String selfLink) throws EntityProviderException, EdmException { try { String mediaResourceMimeType = null; EdmMapping entityTypeMapping = eia.getEntityType().getMapping(); if (entityTypeMapping != null) { String mediaResourceMimeTypeKey = entityTypeMapping.getMediaResourceMimeTypeKey(); if (mediaResourceMimeTypeKey != null) { mediaResourceMimeType = (String) data.get(mediaResourceMimeTypeKey); } } if (mediaResourceMimeType == null) { mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString(); } writer.writeStartElement(FormatXml.ATOM_LINK); writer.writeAttribute(FormatXml.ATOM_HREF, selfLink + "/$value"); writer.writeAttribute(FormatXml.ATOM_REL, Edm.LINK_REL_EDIT_MEDIA); writer.writeAttribute(FormatXml.ATOM_TYPE, mediaResourceMimeType); writer.writeEndElement(); } catch (XMLStreamException e) { throw new EntityProviderProducerException(EntityProviderException.COMMON, e); } }
private void appendAtomContentLink(final XMLStreamWriter writer, final EntityInfoAggregator eia, final Map<String, Object> data, final String selfLink) throws EntityProviderException, EdmException { try { String mediaResourceMimeType = properties.getMediaResourceMimeType(); if (mediaResourceMimeType == null) { EdmMapping entityTypeMapping = eia.getEntityType().getMapping(); if (entityTypeMapping != null) { String mediaResourceMimeTypeKey = entityTypeMapping.getMediaResourceMimeTypeKey(); if (mediaResourceMimeTypeKey != null) { mediaResourceMimeType = (String) data.get(mediaResourceMimeTypeKey); } } if (mediaResourceMimeType == null) { mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString(); } } writer.writeStartElement(FormatXml.ATOM_LINK); writer.writeAttribute(FormatXml.ATOM_HREF, selfLink + "/$value"); writer.writeAttribute(FormatXml.ATOM_REL, Edm.LINK_REL_EDIT_MEDIA); writer.writeAttribute(FormatXml.ATOM_TYPE, mediaResourceMimeType); writer.writeEndElement(); } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.COMMON, e); } }
public ODataJPATombstoneEntityListener getODataJPATombstoneEntityListener(UriInfo uriParserResultView) throws InstantiationException, IllegalAccessException, EdmException { JPAEdmMapping mapping = (JPAEdmMapping) uriParserResultView.getTargetEntitySet().getEntityType().getMapping(); if (mapping.getODataJPATombstoneEntityListener() != null) { return (ODataJPATombstoneEntityListener) mapping.getODataJPATombstoneEntityListener().newInstance(); } return null; }
public ODataJPATombstoneEntityListener getODataJPATombstoneEntityListener(UriInfo uriParserResultView) throws InstantiationException, IllegalAccessException, EdmException { JPAEdmMapping mapping = (JPAEdmMapping) uriParserResultView.getTargetEntitySet().getEntityType().getMapping(); if (mapping.getODataJPATombstoneEntityListener() != null) { return (ODataJPATombstoneEntityListener) mapping.getODataJPATombstoneEntityListener().newInstance(); } return odataJPAContext.getODataJPAQueryExtensionEntityListener(); }
private Object processNew(final UriInfo newView) throws ODataJPAModelException, ODataJPARuntimeException { Object jpaEntity = null; try { final EdmEntitySet oDataEntitySet = newView.getTargetEntitySet(); final EdmEntityType oDataEntityType = oDataEntitySet.getEntityType(); jpaEntity = ((JPAEdmMappingImpl) oDataEntityType.getMapping()).getJPAType().newInstance(); if (((JPAEdmMappingImpl) oDataEntityType.getMapping()).isVirtualAccess()) { JPAQueryBuilder queryBuilder = new JPAQueryBuilder(oDataJPAContext); ODataJPAQueryExtensionEntityListener listener = null; try { listener = queryBuilder.getODataJPAQueryEntityListener((UriInfo) newView); } catch (Exception e) { e.printStackTrace(); } if (listener != null) { Object newObj = listener.processNew(newView); if (newObj != null) { jpaEntity = newObj; } } } } catch (Exception e) { throw new RuntimeException(e); } return jpaEntity; }
public Query build(PutMergePatchUriInfo uriInfo) throws ODataJPARuntimeException { Query query = null; try { if (uriInfo.getTargetEntitySet().getEntityType().getMapping() != null) { if (!((JPAEdmMappingImpl)uriInfo.getTargetEntitySet().getEntityType().getMapping()).canEdit()) { throw new RuntimeException("Entity is Read Only"); } } ODataJPAQueryExtensionEntityListener listener = getODataJPAQueryEntityListener((UriInfo) uriInfo); if (listener != null && !ignoreListener) { query = listener.getQuery(uriInfo, em); } if (query == null) { query = buildQuery((UriInfo) uriInfo, UriInfoType.PutMergePatch); } } catch (Exception e) { throw new RuntimeException(e); } return query; }
public Query build(DeleteUriInfo uriInfo) throws ODataJPARuntimeException { Query query = null; try { if (uriInfo.getTargetEntitySet().getEntityType().getMapping() != null) { if (!((JPAEdmMappingImpl)uriInfo.getTargetEntitySet().getEntityType().getMapping()).canEdit()) { throw new RuntimeException("Entity is Read Only"); } } ODataJPAQueryExtensionEntityListener listener = getODataJPAQueryEntityListener((UriInfo) uriInfo); if (listener != null && !ignoreListener) { query = listener.getQuery(uriInfo, em); } if (query == null) { query = buildQuery((UriInfo) uriInfo, UriInfoType.Delete); } } catch (Exception e) { throw new RuntimeException(e); } return query; }
public JPAEntity(final EdmEntityType oDataEntityType, final EdmEntitySet oDataEntitySet, final ODataJPAContext context) { this.oDataEntityType = oDataEntityType; this.oDataEntitySet = oDataEntitySet; oDataJPAContext = context; try { JPAEdmMapping mapping = (JPAEdmMapping) oDataEntityType.getMapping(); jpaType = mapping.getJPAType(); } catch (EdmException e) { return; } jpaEntityParser = new JPAEntityParser(oDataJPAContext, null); onJPAWriteContent = oDataJPAContext.getODataContext().getServiceFactory().getCallback(OnJPAWriteContent.class); }
public JPAEntity(final EdmEntityType oDataEntityType, final EdmEntitySet oDataEntitySet, final ODataJPAContext context) { this.oDataEntityType = oDataEntityType; this.oDataEntitySet = oDataEntitySet; oDataJPAContext = context; try { JPAEdmMapping mapping = (JPAEdmMapping) oDataEntityType.getMapping(); jpaType = mapping.getJPAType(); } catch (EdmException e) { return; } jpaEntityParser = new JPAEntityParser(); onJPAWriteContent = oDataJPAContext.getODataContext().getServiceFactory().getCallback(OnJPAWriteContent.class); }
private String getFromEntityName(final EdmNavigationProperty navigationProperty) throws EdmException { String fromRole = navigationProperty.getFromRole(); EdmEntityType fromEntityType = navigationProperty.getRelationship().getEnd(fromRole).getEntityType(); EdmMapping mapping = fromEntityType.getMapping(); String entityName = null; if (mapping != null) { entityName = mapping.getInternalName(); } else { entityName = fromEntityType.getName(); } return entityName; }
private String getFromEntityName(final EdmNavigationProperty navigationProperty) throws EdmException { String fromRole = navigationProperty.getFromRole(); EdmEntityType fromEntityType = navigationProperty.getRelationship().getEnd(fromRole).getEntityType(); EdmMapping mapping = fromEntityType.getMapping(); String entityName = null; if (mapping != null) { entityName = mapping.getInternalName(); } else { entityName = fromEntityType.getName(); } return entityName; }
private String getFromEntityName(final EdmNavigationProperty navigationProperty) throws EdmException { String fromRole = navigationProperty.getFromRole(); EdmEntityType toEntityType = navigationProperty.getRelationship().getEnd(fromRole).getEntityType(); EdmMapping mapping = toEntityType.getMapping(); String entityName = null; if (mapping != null) { entityName = mapping.getInternalName(); } else { entityName = toEntityType.getName(); } return entityName; }
private String getFromEntityName(final EdmNavigationProperty navigationProperty) throws EdmException { String fromRole = navigationProperty.getFromRole(); EdmEntityType toEntityType = navigationProperty.getRelationship().getEnd(fromRole).getEntityType(); EdmMapping mapping = toEntityType.getMapping(); String entityName = null; if (mapping != null) { entityName = mapping.getInternalName(); } else { entityName = toEntityType.getName(); } return entityName; }
protected List<JPAJoinClause> generateJoinClauses() throws ODataJPARuntimeException, EdmException { List<JPAJoinClause> jpaOuterJoinClauses = new ArrayList<JPAJoinClause>(); JPAJoinClause jpaOuterJoinClause = null; String joinCondition = null; String entityAlias = generateJPAEntityAlias(); joinCondition = ODataExpressionParser.parseKeyPredicates(entitySetView.getKeyPredicates(), entityAlias); EdmEntityType entityType = entitySetView.getStartEntitySet().getEntityType(); Mapping mapping = (Mapping) entityType.getMapping(); String entityTypeName = null; if (mapping != null) { entityTypeName = mapping.getInternalName(); } else { entityTypeName = entityType.getName(); } jpaOuterJoinClause = new JPAJoinClause(entityTypeName, entityAlias, null, null, joinCondition, JPAJoinClause.JOIN.INNER); jpaOuterJoinClauses.add(jpaOuterJoinClause); for (NavigationSegment navigationSegment : entitySetView.getNavigationSegments()) { EdmNavigationProperty navigationProperty = navigationSegment.getNavigationProperty(); String relationShipAlias = generateRelationShipAlias(); joinCondition = ODataExpressionParser.parseKeyPredicates(navigationSegment.getKeyPredicates(), relationShipAlias); jpaOuterJoinClause = new JPAJoinClause(getFromEntityName(navigationProperty), entityAlias, getRelationShipName(navigationProperty), relationShipAlias, joinCondition, JPAJoinClause.JOIN.INNER); jpaOuterJoinClauses.add(jpaOuterJoinClause); } return jpaOuterJoinClauses; }
protected List<JPAJoinClause> generateJoinClauses() throws ODataJPARuntimeException, EdmException { List<JPAJoinClause> jpaOuterJoinClauses = new ArrayList<JPAJoinClause>(); JPAJoinClause jpaOuterJoinClause = null; String joinCondition = null; String entityAlias = generateJPAEntityAlias(); joinCondition = ODataExpressionParser.parseKeyPredicates(entitySetView.getKeyPredicates(), entityAlias); EdmEntityType entityType = entitySetView.getStartEntitySet().getEntityType(); Mapping mapping = (Mapping) entityType.getMapping(); String entityTypeName = null; if (mapping != null) { entityTypeName = mapping.getInternalName(); } else { entityTypeName = entityType.getName(); } jpaOuterJoinClause = new JPAJoinClause(entityTypeName, entityAlias, null, null, joinCondition, JPAJoinClause.JOIN.INNER); jpaOuterJoinClauses.add(jpaOuterJoinClause); for (NavigationSegment navigationSegment : entitySetView.getNavigationSegments()) { EdmNavigationProperty navigationProperty = navigationSegment.getNavigationProperty(); String relationShipAlias = generateRelationShipAlias(); joinCondition = ODataExpressionParser.parseKeyPredicates(navigationSegment.getKeyPredicates(), relationShipAlias); jpaOuterJoinClause = new JPAJoinClause(getFromEntityName(navigationProperty), entityAlias, getRelationShipName(navigationProperty), relationShipAlias, joinCondition, JPAJoinClause.JOIN.INNER); jpaOuterJoinClauses.add(jpaOuterJoinClause); } return jpaOuterJoinClauses; }
@Override public JPQLContext build() throws ODataJPAModelException, ODataJPARuntimeException { if (entityView != null) { try { setType(JPQLContextType.SELECT_SINGLE); EdmEntityType entityType = entityView.getTargetEntitySet().getEntityType(); EdmMapping mapping = entityType.getMapping(); if (mapping != null) { setJPAEntityName(mapping.getInternalName()); } else { setJPAEntityName(entityType.getName()); } setJPAEntityAlias(generateJPAEntityAlias()); setKeyPredicates(entityView.getKeyPredicates()); setSelectExpression(generateSelectExpression()); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } } return JPQLSelectSingleContext.this; }
@Override public JPQLContext build() throws ODataJPAModelException, ODataJPARuntimeException { if (entityView != null) { try { setType(JPQLContextType.SELECT_SINGLE); EdmEntityType entityType = entityView.getTargetEntitySet().getEntityType(); EdmMapping mapping = entityType.getMapping(); if (mapping != null) { setJPAEntityName(mapping.getInternalName()); } else { setJPAEntityName(entityType.getName()); } setJPAEntityAlias(generateJPAEntityAlias()); setKeyPredicates(entityView.getKeyPredicates()); setSelectExpression(generateSelectExpression()); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } } return JPQLSelectSingleContext.this; }
@Override public JPQLContext build() throws ODataJPAModelException, ODataJPARuntimeException { if (entitySetView != null) { try { if (isCountOnly) { setType(JPQLContextType.SELECT_COUNT); } else { setType(JPQLContextType.SELECT); } if (withPaging) { isPagingRequested(withPaging); } EdmEntityType entityType = entitySetView.getTargetEntitySet().getEntityType(); EdmMapping mapping = entityType.getMapping(); if (mapping != null) { setJPAEntityName(mapping.getInternalName()); } else { setJPAEntityName(entityType.getName()); } setJPAEntityAlias(generateJPAEntityAlias()); setOrderByCollection(generateOrderByFileds()); setSelectExpression(generateSelectExpression()); setWhereExpression(generateWhereExpression()); } catch (ODataException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } } return JPQLSelectContext.this; }