Repository: olingo-odata2 Updated Branches: refs/heads/master 5a416b9e6 -> 28e28212f
[OLINGO-458] - JPA Batch requests are not executed in a single database transaction Fixed - Handling of all requests in a changeset as one single database transaction. Fixed - Issue with Default Naming when there is no Join Column/Column Name specified. Signed-off-by: Chandan V A <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/28e28212 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/28e28212 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/28e28212 Branch: refs/heads/master Commit: 28e28212f386c8f19feb9321d770c7683d09788a Parents: 5a416b9 Author: Chandan V A <[email protected]> Authored: Sat Oct 18 15:35:21 2014 +0530 Committer: Chandan V A <[email protected]> Committed: Sat Oct 18 15:35:21 2014 +0530 ---------------------------------------------------------------------- .../core/ODataJPAProcessorDefault.java | 32 +- .../core/access/data/JPAProcessorImpl.java | 300 ++++++++++--------- .../core/access/model/JPAEdmNameBuilder.java | 12 +- .../processor/core/model/JPAEdmProperty.java | 11 +- .../model/JPAEdmReferentialConstraintRole.java | 6 +- .../core/ODataJPAProcessorDefaultTest.java | 1 + .../core/access/data/JPAProcessorImplTest.java | 1 + .../jpa/processor/ref/model/SalesOrderItem.java | 4 +- .../src/main/resources/META-INF/persistence.xml | 4 +- .../ref/web/JPAReferenceServiceFactory.java | 2 +- .../jpa-web/src/main/webapp/index.jsp | 6 +- 11 files changed, 211 insertions(+), 168 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/28e28212/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java index 6512b79..bc820ba 100644 --- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java +++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java @@ -219,27 +219,41 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor { PathInfo pathInfo = getContext().getPathInfo(); EntityProviderBatchProperties batchProperties = EntityProviderBatchProperties.init().pathInfo(pathInfo).build(); List<BatchRequestPart> batchParts = EntityProvider.parseBatchRequest(contentType, content, batchProperties); + for (BatchRequestPart batchPart : batchParts) { batchResponseParts.add(handler.handleBatchPart(batchPart)); } batchResponse = EntityProvider.writeBatchResponse(batchResponseParts); return batchResponse; + } @Override public BatchResponsePart executeChangeSet(final BatchHandler handler, final List<ODataRequest> requests) throws ODataException { List<ODataResponse> responses = new ArrayList<ODataResponse>(); - for (ODataRequest request : requests) { - ODataResponse response = handler.handleRequest(request); - if (response.getStatus().getStatusCode() >= HttpStatusCodes.BAD_REQUEST.getStatusCode()) { - // Rollback - List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1); - errorResponses.add(response); - return BatchResponsePart.responses(errorResponses).changeSet(false).build(); + try { + oDataJPAContext.getEntityManager().getTransaction().begin(); + + for (ODataRequest request : requests) { + ODataResponse response = handler.handleRequest(request); + if (response.getStatus().getStatusCode() >= HttpStatusCodes.BAD_REQUEST.getStatusCode()) { + // Rollback + oDataJPAContext.getEntityManager().getTransaction().rollback(); + List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1); + errorResponses.add(response); + return BatchResponsePart.responses(errorResponses).changeSet(false).build(); + } + responses.add(response); } - responses.add(response); + oDataJPAContext.getEntityManager().getTransaction().commit(); + + return BatchResponsePart.responses(responses).changeSet(true).build(); + } catch (Exception e) { + + List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1); + errorResponses.add(ODataResponse.entity(e).status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build()); + return BatchResponsePart.responses(errorResponses).changeSet(false).build(); } - return BatchResponsePart.responses(responses).changeSet(true).build(); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/28e28212/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java index 8c497d3..814a053 100644 --- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java +++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import javax.persistence.EntityManager; +import javax.persistence.EntityTransaction; import javax.persistence.Query; import org.apache.olingo.odata2.api.commons.InlineCount; @@ -203,53 +204,6 @@ public class JPAProcessorImpl implements JPAProcessor { } } - private List<Object> handlePaging(final List<Object> result, final GetEntitySetUriInfo uriParserResultView) { - if (result == null) { - return null; - } - JPAPageBuilder pageBuilder = new JPAPageBuilder(); - pageBuilder.pageSize(oDataJPAContext.getPageSize()) - .entities(result) - .skipToken(uriParserResultView.getSkipToken()); - - // $top/$skip with $inlinecount case handled in response builder to avoid multiple DB call - if (uriParserResultView.getSkip() != null && uriParserResultView.getInlineCount() == null) { - pageBuilder.skip(uriParserResultView.getSkip().intValue()); - } - - if (uriParserResultView.getTop() != null && uriParserResultView.getInlineCount() == null) { - pageBuilder.top(uriParserResultView.getTop().intValue()); - } - - JPAPage page = pageBuilder.build(); - oDataJPAContext.setPaging(page); - - return page.getPagedEntities(); - } - - private List<Object> handlePaging(final Query query, final GetEntitySetUriInfo uriParserResultView) { - - JPAPageBuilder pageBuilder = new JPAPageBuilder(); - pageBuilder.pageSize(oDataJPAContext.getPageSize()) - .query(query) - .skipToken(uriParserResultView.getSkipToken()); - - // $top/$skip with $inlinecount case handled in response builder to avoid multiple DB call - if (uriParserResultView.getSkip() != null && uriParserResultView.getInlineCount() == null) { - pageBuilder.skip(uriParserResultView.getSkip().intValue()); - } - - if (uriParserResultView.getTop() != null && uriParserResultView.getInlineCount() == null) { - pageBuilder.top(uriParserResultView.getTop().intValue()); - } - - JPAPage page = pageBuilder.build(); - oDataJPAContext.setPaging(page); - - return page.getPagedEntities(); - - } - /* Process Get Entity Request (Read) */ @Override public <T> Object process(GetEntityUriInfo uriParserResultView) @@ -378,12 +332,115 @@ public class JPAProcessorImpl implements JPAProcessor { return processUpdate(updateView, null, content, null); } + /* Process Delete Entity Request */ + @Override + public Object process(DeleteUriInfo uriParserResultView, final String contentType) + throws ODataJPAModelException, ODataJPARuntimeException { + JPQLContextType contextType = null; + try { + if (uriParserResultView instanceof DeleteUriInfo) { + if (((UriInfo) uriParserResultView).isLinks()) { + return deleteLink(uriParserResultView); + } + uriParserResultView = ((DeleteUriInfo) uriParserResultView); + if (!((DeleteUriInfo) uriParserResultView).getStartEntitySet().getName() + .equals(((DeleteUriInfo) uriParserResultView).getTargetEntitySet().getName())) { + contextType = JPQLContextType.JOIN_SINGLE; + } else { + contextType = JPQLContextType.SELECT_SINGLE; + } + } + } catch (EdmException e) { + ODataJPARuntimeException.throwException( + ODataJPARuntimeException.GENERAL, e); + } + + Object selectedObject = readEntity(uriParserResultView, contextType); + if (selectedObject != null) { + try { + boolean isLocalTransaction = setTransaction(); + em.remove(selectedObject); + em.flush(); + if (isLocalTransaction) { + em.getTransaction().commit(); + } + + } catch (Exception e) { + throw ODataJPARuntimeException.throwException( + ODataJPARuntimeException.ERROR_JPQL_DELETE_REQUEST, e); + } + } + return selectedObject; + } + + /* Process Get Entity Link Request */ + @Override + public Object process(final GetEntityLinkUriInfo uriParserResultView) + throws ODataJPAModelException, ODataJPARuntimeException { + + return this.process((GetEntityUriInfo) uriParserResultView); + } + + /* Process Get Entity Set Link Request */ + @Override + public List<Object> process(final GetEntitySetLinksUriInfo uriParserResultView) + throws ODataJPAModelException, ODataJPARuntimeException { + return this.process((GetEntitySetUriInfo) uriParserResultView); + } + + @Override + public void process(final PostUriInfo uriInfo, + final InputStream content, final String requestContentType, final String contentType) + throws ODataJPARuntimeException, ODataJPAModelException { + JPALink link = new JPALink(oDataJPAContext); + link.create(uriInfo, content, requestContentType, contentType); + link.save(); + } + + @Override + public void process(final PutMergePatchUriInfo putUriInfo, + final InputStream content, final String requestContentType, final String contentType) + throws ODataJPARuntimeException, ODataJPAModelException { + + JPALink link = new JPALink(oDataJPAContext); + link.update(putUriInfo, content, requestContentType, contentType); + link.save(); + + } + + /* Common method for Read and Delete */ + private Object readEntity(final Object uriParserResultView, final JPQLContextType contextType) + throws ODataJPAModelException, ODataJPARuntimeException { + + Object selectedObject = null; + + if (uriParserResultView instanceof DeleteUriInfo || uriParserResultView instanceof GetEntityUriInfo + || uriParserResultView instanceof PutMergePatchUriInfo) { + + JPQLContext selectJPQLContext = JPQLContext.createBuilder( + contextType, uriParserResultView).build(); + + JPQLStatement selectJPQLStatement = JPQLStatement.createBuilder( + selectJPQLContext).build(); + Query query = null; + try { + query = em.createQuery(selectJPQLStatement.toString()); + if (!query.getResultList().isEmpty()) { + selectedObject = query.getResultList().get(0); + } + } catch (IllegalArgumentException e) { + throw ODataJPARuntimeException.throwException( + ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e); + } + } + return selectedObject; + } + private Object processCreate(final PostUriInfo createView, final InputStream content, final Map<String, Object> properties, final String requestedContentType) throws ODataJPAModelException, ODataJPARuntimeException { try { - final EdmEntitySet oDataEntitySet = createView.getTargetEntitySet(); final EdmEntityType oDataEntityType = oDataEntitySet.getEntityType(); final JPAEntity virtualJPAEntity = new JPAEntity(oDataEntityType, oDataEntitySet, oDataJPAContext); @@ -400,15 +457,15 @@ public class JPAProcessorImpl implements JPAProcessor { return null; } - em.getTransaction().begin(); + boolean isLocalTransaction = setTransaction(); jpaEntity = virtualJPAEntity.getJPAEntity(); em.persist(jpaEntity); if (em.contains(jpaEntity)) { - em.getTransaction().commit(); - + if (isLocalTransaction) { + em.getTransaction().commit(); + } return jpaEntity; - } } catch (Exception e) { throw ODataJPARuntimeException.throwException( @@ -417,13 +474,13 @@ public class JPAProcessorImpl implements JPAProcessor { return null; } - public <T> Object processUpdate(PutMergePatchUriInfo updateView, + private <T> Object processUpdate(PutMergePatchUriInfo updateView, final InputStream content, final Map<String, Object> properties, final String requestContentType) throws ODataJPAModelException, ODataJPARuntimeException { JPQLContextType contextType = null; Object jpaEntity = null; try { - em.getTransaction().begin(); + boolean isLocalTransaction = setTransaction(); if (updateView instanceof PutMergePatchUriInfo) { updateView = ((PutMergePatchUriInfo) updateView); if (!((PutMergePatchUriInfo) updateView).getStartEntitySet().getName() @@ -456,7 +513,9 @@ public class JPAProcessorImpl implements JPAProcessor { return null; } em.flush(); - em.getTransaction().commit(); + if (isLocalTransaction) { + em.getTransaction().commit(); + } } catch (Exception e) { throw ODataJPARuntimeException.throwException( ODataJPARuntimeException.ERROR_JPQL_UPDATE_REQUEST, e); @@ -465,45 +524,6 @@ public class JPAProcessorImpl implements JPAProcessor { return jpaEntity; } - /* Process Delete Entity Request */ - @Override - public Object process(DeleteUriInfo uriParserResultView, final String contentType) - throws ODataJPAModelException, ODataJPARuntimeException { - JPQLContextType contextType = null; - try { - if (uriParserResultView instanceof DeleteUriInfo) { - if (((UriInfo) uriParserResultView).isLinks()) { - return deleteLink(uriParserResultView); - } - uriParserResultView = ((DeleteUriInfo) uriParserResultView); - if (!((DeleteUriInfo) uriParserResultView).getStartEntitySet().getName() - .equals(((DeleteUriInfo) uriParserResultView).getTargetEntitySet().getName())) { - contextType = JPQLContextType.JOIN_SINGLE; - } else { - contextType = JPQLContextType.SELECT_SINGLE; - } - } - } catch (EdmException e) { - ODataJPARuntimeException.throwException( - ODataJPARuntimeException.GENERAL, e); - } - - Object selectedObject = readEntity(uriParserResultView, contextType); - if (selectedObject != null) { - try { - em.getTransaction().begin(); - em.remove(selectedObject); - em.flush(); - em.getTransaction().commit(); - - } catch (Exception e) { - throw ODataJPARuntimeException.throwException( - ODataJPARuntimeException.ERROR_JPQL_DELETE_REQUEST, e); - } - } - return selectedObject; - } - private Object deleteLink(final DeleteUriInfo uriParserResultView) throws ODataJPARuntimeException { JPALink link = new JPALink(oDataJPAContext); link.delete(uriParserResultView); @@ -511,66 +531,60 @@ public class JPAProcessorImpl implements JPAProcessor { return link.getTargetJPAEntity(); } - /* Process Get Entity Link Request */ - @Override - public Object process(final GetEntityLinkUriInfo uriParserResultView) - throws ODataJPAModelException, ODataJPARuntimeException { + private List<Object> handlePaging(final List<Object> result, final GetEntitySetUriInfo uriParserResultView) { + if (result == null) { + return null; + } + JPAPageBuilder pageBuilder = new JPAPageBuilder(); + pageBuilder.pageSize(oDataJPAContext.getPageSize()) + .entities(result) + .skipToken(uriParserResultView.getSkipToken()); - return this.process((GetEntityUriInfo) uriParserResultView); - } + // $top/$skip with $inlinecount case handled in response builder to avoid multiple DB call + if (uriParserResultView.getSkip() != null && uriParserResultView.getInlineCount() == null) { + pageBuilder.skip(uriParserResultView.getSkip().intValue()); + } - /* Process Get Entity Set Link Request */ - @Override - public List<Object> process(final GetEntitySetLinksUriInfo uriParserResultView) - throws ODataJPAModelException, ODataJPARuntimeException { - return this.process((GetEntitySetUriInfo) uriParserResultView); - } + if (uriParserResultView.getTop() != null && uriParserResultView.getInlineCount() == null) { + pageBuilder.top(uriParserResultView.getTop().intValue()); + } - @Override - public void process(final PostUriInfo uriInfo, - final InputStream content, final String requestContentType, final String contentType) - throws ODataJPARuntimeException, ODataJPAModelException { - JPALink link = new JPALink(oDataJPAContext); - link.create(uriInfo, content, requestContentType, contentType); - link.save(); - } + JPAPage page = pageBuilder.build(); + oDataJPAContext.setPaging(page); - /* Common method for Read and Delete */ - private Object readEntity(final Object uriParserResultView, final JPQLContextType contextType) - throws ODataJPAModelException, ODataJPARuntimeException { + return page.getPagedEntities(); + } - Object selectedObject = null; + private List<Object> handlePaging(final Query query, final GetEntitySetUriInfo uriParserResultView) { - if (uriParserResultView instanceof DeleteUriInfo || uriParserResultView instanceof GetEntityUriInfo - || uriParserResultView instanceof PutMergePatchUriInfo) { + JPAPageBuilder pageBuilder = new JPAPageBuilder(); + pageBuilder.pageSize(oDataJPAContext.getPageSize()) + .query(query) + .skipToken(uriParserResultView.getSkipToken()); - JPQLContext selectJPQLContext = JPQLContext.createBuilder( - contextType, uriParserResultView).build(); + // $top/$skip with $inlinecount case handled in response builder to avoid multiple DB call + if (uriParserResultView.getSkip() != null && uriParserResultView.getInlineCount() == null) { + pageBuilder.skip(uriParserResultView.getSkip().intValue()); + } - JPQLStatement selectJPQLStatement = JPQLStatement.createBuilder( - selectJPQLContext).build(); - Query query = null; - try { - query = em.createQuery(selectJPQLStatement.toString()); - if (!query.getResultList().isEmpty()) { - selectedObject = query.getResultList().get(0); - } - } catch (IllegalArgumentException e) { - throw ODataJPARuntimeException.throwException( - ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e); - } + if (uriParserResultView.getTop() != null && uriParserResultView.getInlineCount() == null) { + pageBuilder.top(uriParserResultView.getTop().intValue()); } - return selectedObject; - } - @Override - public void process(final PutMergePatchUriInfo putUriInfo, - final InputStream content, final String requestContentType, final String contentType) - throws ODataJPARuntimeException, ODataJPAModelException { + JPAPage page = pageBuilder.build(); + oDataJPAContext.setPaging(page); - JPALink link = new JPALink(oDataJPAContext); - link.update(putUriInfo, content, requestContentType, contentType); - link.save(); + return page.getPagedEntities(); + + } + + private boolean setTransaction() { + final EntityTransaction transaction = em.getTransaction(); + if (!transaction.isActive()) { + em.getTransaction().begin(); + return true; + } + return false; } } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/28e28212/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java index edd4bb9..1016f9e 100644 --- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java +++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java @@ -148,7 +148,7 @@ public class JPAEdmNameBuilder { propertyName = jpaAttributeName; if (isForeignKey == true) { joinColumnNames = view.getJPAJoinColumns().get(view.getJPAJoinColumns().size() - 1); - propertyName = mappingModelAccess.mapJPAAttribute(view.getJPAEdmEntityTypeView().getJPAEntityType().getName(), + propertyName = mappingModelAccess.mapJPAAttribute(view.getJPAEdmEntityTypeView().getJPAEntityType().getName(), joinColumnNames[0]); if (propertyName == null) { propertyName = FK_PREFIX + UNDERSCORE + joinColumnNames[0]; @@ -166,11 +166,13 @@ public class JPAEdmNameBuilder { Column column = annotatedElement.getAnnotation(Column.class); if (column != null) { mapping.setJPAColumnName(column.name()); + } else if (joinColumnNames != null) { + mapping.setJPAColumnName(joinColumnNames[0]); } else { - if (joinColumnNames != null) { - mapping.setJPAColumnName(joinColumnNames[0]); - jpaAttributeName += "." + view.getJPAReferencedAttribute().getName(); - } + mapping.setJPAColumnName(jpaAttributeName); + } + if (isForeignKey) { + jpaAttributeName += "." + view.getJPAReferencedAttribute().getName(); } } else { ManagedType<?> managedType = jpaAttribute.getDeclaringType(); http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/28e28212/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java index fd14794..33f0c93 100644 --- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java +++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java @@ -377,7 +377,16 @@ public class JPAEdmProperty extends JPAEdmBaseViewImpl implements for (Attribute<?, ?> referencedAttribute : referencedEntityType.getAttributes()) { if (referencedAttribute.getPersistentAttributeType() == PersistentAttributeType.BASIC && ((SingularAttribute<?, ?>) referencedAttribute).isId()) { - name[1] = referencedAttribute.getName(); + AnnotatedElement annotatedElement = (AnnotatedElement) referencedAttribute.getJavaMember(); + Column referencedColumn = null; + if (annotatedElement != null) { + referencedColumn = annotatedElement.getAnnotation(Column.class); + } + if (referencedColumn != null) { + name[1] = referencedColumn.name(); + } else { + name[1] = referencedAttribute.getName(); + } joinColumnNames.add(name); currentRefAttribute = referencedAttribute; break; http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/28e28212/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java index 94905e9..eeaaefa 100644 --- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java +++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java @@ -144,6 +144,7 @@ public class JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implemen if (currentRole == null) { currentRole = new ReferentialConstraintRole(); String jpaAttributeType = null; + String jpaColumnName = null; EntityType edmEntityType = null; if (roleType == RoleType.PRINCIPAL) { @@ -165,9 +166,10 @@ public class JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implemen if (edmEntityType != null) { for (String[] columnName : jpaColumnNames) { for (Property property : edmEntityType.getProperties()) { - if (columnName[0].equals(((JPAEdmMapping) property.getMapping()).getJPAColumnName()) || + jpaColumnName = ((JPAEdmMapping) property.getMapping()).getJPAColumnName(); + if (columnName[0].equals(jpaColumnName) || columnName[0].equals(property.getName()) || - columnName[1].equals(((JPAEdmMapping) property.getMapping()).getJPAColumnName()) || + columnName[1].equals(jpaColumnName) || columnName[1].equals(property.getName())) { PropertyRef propertyRef = new PropertyRef(); propertyRef.setName(property.getName()); http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/28e28212/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java index 6317a4b..dc90021 100644 --- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java +++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java @@ -360,6 +360,7 @@ public class ODataJPAProcessorDefaultTest extends JPAEdmTestModelView { entityTransaction.begin(); // testing void method entityTransaction.commit();// testing void method entityTransaction.rollback();// testing void method + EasyMock.expect(entityTransaction.isActive()).andReturn(false); EasyMock.replay(entityTransaction); return entityTransaction; } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/28e28212/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java index e74dc52..b79fac4 100644 --- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java +++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java @@ -321,6 +321,7 @@ public class JPAProcessorImplTest { entityTransaction.begin(); // testing void method entityTransaction.commit();// testing void method entityTransaction.commit();// testing void method + EasyMock.expect(entityTransaction.isActive()).andReturn(false).anyTimes(); EasyMock.replay(entityTransaction); return entityTransaction; } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/28e28212/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderItem.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderItem.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderItem.java index 6da7a3c..35482ad 100644 --- a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderItem.java +++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderItem.java @@ -61,11 +61,11 @@ public class SalesOrderItem { @Column private boolean delivered; - public Boolean isDelivered() { + public boolean isDelivered() { return delivered; } - public void setDelivered(final Boolean deliveryStatus) { + public void setDelivered(final boolean deliveryStatus) { delivered = deliveryStatus; } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/28e28212/odata2-jpa-processor/jpa-ref/src/main/resources/META-INF/persistence.xml ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-ref/src/main/resources/META-INF/persistence.xml b/odata2-jpa-processor/jpa-ref/src/main/resources/META-INF/persistence.xml index 023aee1..450c73b 100644 --- a/odata2-jpa-processor/jpa-ref/src/main/resources/META-INF/persistence.xml +++ b/odata2-jpa-processor/jpa-ref/src/main/resources/META-INF/persistence.xml @@ -22,9 +22,9 @@ <class>org.apache.olingo.odata2.jpa.processor.ref.model.Customer</class> <class>org.apache.olingo.odata2.jpa.processor.ref.model.Category</class> <class>org.apache.olingo.odata2.jpa.processor.ref.model.Material</class> - <class>org.apache.olingo.odata2.jpa.processor.ref.model.AppointmentActivity</class> + <!-- <class>org.apache.olingo.odata2.jpa.processor.ref.model.AppointmentActivity</class> <class>org.apache.olingo.odata2.jpa.processor.ref.model.Activity</class> - <class>org.apache.olingo.odata2.jpa.processor.ref.model.ActivityParty</class> + <class>org.apache.olingo.odata2.jpa.processor.ref.model.ActivityParty</class> --> <class>org.apache.olingo.odata2.jpa.processor.ref.converter.BlobToByteConverter</class> <properties> <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" /> http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/28e28212/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java index 256ffdd..60679f8 100644 --- a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java +++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java @@ -47,7 +47,7 @@ public class JPAReferenceServiceFactory extends ODataJPAServiceFactory { oDataJPAContext .setJPAEdmExtension((JPAEdmExtension) new SalesOrderProcessingExtension()); oDataJPAContext.setPageSize(PAGE_SIZE); - oDataJPAContext.setDefaultNaming(false); + oDataJPAContext.setDefaultNaming(true); setErrorLevel(); setOnWriteJPAContent(onDBWriteContent); http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/28e28212/odata2-jpa-processor/jpa-web/src/main/webapp/index.jsp ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-web/src/main/webapp/index.jsp b/odata2-jpa-processor/jpa-web/src/main/webapp/index.jsp index 0885ad0..c261c16 100644 --- a/odata2-jpa-processor/jpa-web/src/main/webapp/index.jsp +++ b/odata2-jpa-processor/jpa-web/src/main/webapp/index.jsp @@ -297,13 +297,13 @@ th,td { <ul> <li><a href="SalesOrderProcessing.svc/SalesOrders?$top=1&$inlinecount=allpages" - target="_blank">SalesOrderProcessing.svc/SalesOrders?$top=1&$inlinecount=allpages"</a></li> + target="_blank">SalesOrderProcessing.svc/SalesOrders?$top=1&$inlinecount=allpages"</a></li> <li><a href="SalesOrderProcessing.svc/SalesOrders?$top=1&$inlinecount=allpages&$skiptoken=5" - target="_blank">SalesOrderProcessing.svc/SalesOrders?$top=1&$inlinecount=allpages&$skiptoken=5</a></li> + target="_blank">SalesOrderProcessing.svc/SalesOrders?$top=1&$inlinecount=allpages&$skiptoken=5</a></li> <li><a href="SalesOrderProcessing.svc/SalesOrders?$top=1&$skip=4&$inlinecount=allpages&$skiptoken=5" - target="_blank">SalesOrderProcessing.svc/SalesOrders?$top=1&$skip=4&$inlinecount=allpages&$skiptoken=5</a></li> + target="_blank">SalesOrderProcessing.svc/SalesOrders?$top=1&$skip=4&$inlinecount=allpages&$skiptoken=5</a></li> </ul> </td> <td valign="top"> </td>
