Return-Path: X-Original-To: apmail-olingo-commits-archive@minotaur.apache.org Delivered-To: apmail-olingo-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3DAEE10C12 for ; Mon, 24 Feb 2014 11:18:23 +0000 (UTC) Received: (qmail 51575 invoked by uid 500); 24 Feb 2014 11:18:23 -0000 Delivered-To: apmail-olingo-commits-archive@olingo.apache.org Received: (qmail 50825 invoked by uid 500); 24 Feb 2014 11:18:21 -0000 Mailing-List: contact commits-help@olingo.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@olingo.incubator.apache.org Delivered-To: mailing list commits@olingo.incubator.apache.org Received: (qmail 50815 invoked by uid 99); 24 Feb 2014 11:18:21 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Feb 2014 11:18:21 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Feb 2014 11:18:19 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 99B2A2388994; Mon, 24 Feb 2014 11:17:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1571244 - /incubator/olingo/site/trunk/content/doc/tutorials/jpafunctionimport.mdtext Date: Mon, 24 Feb 2014 11:17:59 -0000 To: commits@olingo.incubator.apache.org From: deepa@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140224111759.99B2A2388994@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: deepa Date: Mon Feb 24 11:17:59 2014 New Revision: 1571244 URL: http://svn.apache.org/r1571244 Log: CMS commit to olingo by deepa Modified: incubator/olingo/site/trunk/content/doc/tutorials/jpafunctionimport.mdtext Modified: incubator/olingo/site/trunk/content/doc/tutorials/jpafunctionimport.mdtext URL: http://svn.apache.org/viewvc/incubator/olingo/site/trunk/content/doc/tutorials/jpafunctionimport.mdtext?rev=1571244&r1=1571243&r2=1571244&view=diff ============================================================================== --- incubator/olingo/site/trunk/content/doc/tutorials/jpafunctionimport.mdtext (original) +++ incubator/olingo/site/trunk/content/doc/tutorials/jpafunctionimport.mdtext Mon Feb 24 11:17:59 2014 @@ -48,106 +48,7 @@ Enable ##### Sample Code - :::java - package org.apache.olingo.odata2.jpa.processor.ref.extension; - - import java.util.List; - - import javax.persistence.EntityManager; - import javax.persistence.Persistence; - import javax.persistence.Query; - - import org.apache.olingo.odata2.api.annotation.edm.Facets; - import org.apache.olingo.odata2.api.annotation.edm.FunctionImport; - import org.apache.olingo.odata2.api.annotation.edm.Parameter; - import org.apache.olingo.odata2.api.annotation.edm.Parameter.Mode; - import org.apache.olingo.odata2.api.annotation.edmx.HttpMethod.Name; - import org.apache.olingo.odata2.api.annotation.edmx.HttpMethod; - import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.ReturnType; - import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.Multiplicity; - import org.apache.olingo.odata2.api.exception.ODataException; - import org.apache.olingo.odata2.jpa.processor.ref.model.Address; - import org.apache.olingo.odata2.jpa.processor.ref.model.SalesOrderHeader; - import org.apache.olingo.odata2.jpa.processor.ref.model.SalesOrderItem; - - public class SalesOrderHeaderProcessor { - - private EntityManager em; - - public SalesOrderHeaderProcessor() - em = Persistence.createEntityManagerFactory("salesorderprocessing") - .createEntityManager(); - } - - @SuppressWarnings("unchecked") - @FunctionImport(name = "FindAllSalesOrders", entitySet = "SalesOrders", returnType = ReturnType.ENTITY_TYPE, multiplicity = Multiplicity.MANY) - public List findAllSalesOrders( - @Parameter(name = "DeliveryStatusCode", facets = @Facets(maxLength = 2)) final String status) { - - Query q = em.createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.deliveryStatus = '"+ status + "'"); - List soList = (List) q.getResultList(); - return soList; - } - - @FunctionImport(name = "CheckATP", returnType = ReturnType.SCALAR, multiplicity = Multiplicity.ONE, httpMethod = @HttpMethod(name = Name.GET)) - public boolean checkATP( - @Parameter(name = "SoID", facets = @Facets(nullable = false), mode = Mode.IN) final Long soID, - @Parameter(name = "LiId", facets = @Facets(nullable = false), mode = Mode.IN) final Long lineItemID) { - if (soID == 2L) { - return false; - } else { - return true; - } - } - - @FunctionImport(returnType = ReturnType.ENTITY_TYPE, entitySet = "SalesOrders") - public SalesOrderHeader calculateNetAmount( - @Parameter(name = "SoID", facets = @Facets(nullable = false)) final Long soID) - throws ODataException { - - if (soID <= 0L) { - throw new ODataException("Invalid SoID"); - } - - Query q = em.createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.soId = "+ soID + "l"); - if (q.getResultList().isEmpty()) { - return null; - } - SalesOrderHeader so = (SalesOrderHeader) q.getResultList().get(0); - double amount = 0; - for (SalesOrderItem soi : so.getSalesOrderItem()) { - amount = amount + (soi.getAmount() * soi.getDiscount() * soi.getQuantity()); - } - so.setNetAmount(amount); - return so; - } - - @SuppressWarnings("unchecked") - @FunctionImport(returnType = ReturnType.COMPLEX_TYPE) - public Address getAddress( - @Parameter(name = "SoID", facets = @Facets(nullable = false)) final Long soID) { - Query q = em.createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.soId = " + soID + "l"); - List soList = (List) q.getResultList(); - if (!soList.isEmpty()) { - return soList.get(0).getBuyerAddress(); - } else { - return null; - } - } - - /* - * This method will not be transformed into Function - * Import. Function Import with return type as void is not - * supported yet. - */ - @FunctionImport(returnType = ReturnType.NONE) - public void process( - @Parameter(name = "SoID", facets = @Facets(nullable = false)) final Long soID) { - return; - } - } - - + package org.apache.olingo.odata2.jpa.processor.ref.extension; import java.util.List;