openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r1042370 - in /openjpa/sandboxes/jest/openjpa-persistence/src/main: java/org/apache/openjpa/persistence/jest/ resources/org/apache/openjpa/persistence/jest/
Date Sun, 05 Dec 2010 15:09:32 GMT
Author: ppoddar
Date: Sun Dec  5 15:09:31 2010
New Revision: 1042370

URL: http://svn.apache.org/viewvc?rev=1042370&view=rev
Log:
OPENJPA-1851: Support FetchPlan in JEST

Modified:
    openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/AbstractCommand.java
    openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/FindCommand.java
    openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ProcessingException.java
    openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/PropertiesCommand.java
    openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/QueryCommand.java
    openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/XMLFormatter.java
    openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.css
    openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.html
    openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.js

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/AbstractCommand.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/AbstractCommand.java?rev=1042370&r1=1042369&r2=1042370&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/AbstractCommand.java
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/AbstractCommand.java
Sun Dec  5 15:09:31 2010
@@ -21,6 +21,7 @@ package org.apache.openjpa.persistence.j
 
 import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
 import static org.apache.openjpa.persistence.jest.Constants.QUALIFIER_FORMAT;
+import static org.apache.openjpa.persistence.jest.Constants.QUALIFIER_PLAN;
 import static org.apache.openjpa.persistence.jest.Constants._loc;
 
 import java.io.IOException;
@@ -38,7 +39,12 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.openjpa.enhance.PersistenceCapable;
+import org.apache.openjpa.kernel.BrokerImpl;
 import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.persistence.FetchPlan;
+import org.apache.openjpa.persistence.JPAFacadeHelper;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAQuery;
 
 /**
  * The abstract base class for all commands available to JEST.
@@ -266,7 +272,40 @@ abstract class AbstractCommand implement
         return sms;
     }
     
+    protected void pushFetchPlan(Object target) {
+        if (!hasQualifier(QUALIFIER_PLAN))
+            return;
+        OpenJPAEntityManager em = ctx.getPersistenceContext();
+        FetchPlan plan = em.pushFetchPlan();
+        BrokerImpl broker = (BrokerImpl)JPAFacadeHelper.toBroker(em);
+        if (target instanceof OpenJPAEntityManager) {
+            broker.setCacheFinderQuery(false);
+        } else if (target instanceof OpenJPAQuery) {
+            broker.setCachePreparedQuery(false);
+        }
+        
+        String[] plans = getQualifier(QUALIFIER_PLAN).split(",");
+        for (String p : plans) {
+            p = p.trim();
+            if (p.charAt(0) == '-') {
+                plan.removeFetchGroup(p.substring(1));
+            } else {
+                plan.addFetchGroup(p);
+            }
+        }
+    }
     
+    protected void popFetchPlan(boolean finder) {
+        if (!hasQualifier(QUALIFIER_PLAN))
+            return;
+        OpenJPAEntityManager em = ctx.getPersistenceContext();
+        BrokerImpl broker = (BrokerImpl)JPAFacadeHelper.toBroker(em);
+        if (finder) {
+            broker.setCacheFinderQuery(false);
+        } else {
+            broker.setCachePreparedQuery(false);
+        }
+    }
 
     protected void debug(HttpServletRequest request, HttpServletResponse response, JPAServletContext
ctx) 
         throws IOException {

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/FindCommand.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/FindCommand.java?rev=1042370&r1=1042369&r2=1042370&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/FindCommand.java
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/FindCommand.java
Sun Dec  5 15:09:31 2010
@@ -33,6 +33,7 @@ import javax.persistence.EntityManager;
 
 import org.apache.openjpa.kernel.OpenJPAStateManager;
 import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
 import org.apache.openjpa.util.ApplicationIds;
 
 
@@ -64,7 +65,7 @@ class FindCommand extends AbstractComman
 
     @Override
     public void process() throws ProcessingException {
-        EntityManager em = ctx.getPersistenceContext();
+        OpenJPAEntityManager em = ctx.getPersistenceContext();
         String type = getMandatoryArgument(ARG_TYPE);
         ClassMetaData meta = ctx.resolve(type);
         Map<String,String> parameters = getArguments();
@@ -74,21 +75,26 @@ class FindCommand extends AbstractComman
             pks[i] = params.next().getKey();
         }
         Object oid = ApplicationIds.fromPKValues(pks, meta);
-        Object pc = em.find(meta.getDescribedType(), oid); 
-        if (pc != null) {
-            OpenJPAStateManager sm = toStateManager(pc);
-            ObjectFormatter<?> formatter = getObjectFormatter();
-            ctx.getResponse().setContentType(formatter.getMimeType());
-            try {
-                formatter.writeOut(Collections.singleton(sm), em.getMetamodel(), 
-                    _loc.get("find-title").toString(), _loc.get("find-desc").toString(),
ctx.getRequestURI(), 
-                    ctx.getResponse().getOutputStream());
-            } catch (IOException e) {
-                throw new ProcessingException(ctx, e);
+        pushFetchPlan(em);
+        try {
+            Object pc = em.find(meta.getDescribedType(), oid); 
+            if (pc != null) {
+                OpenJPAStateManager sm = toStateManager(pc);
+                ObjectFormatter<?> formatter = getObjectFormatter();
+                ctx.getResponse().setContentType(formatter.getMimeType());
+                try {
+                    formatter.writeOut(Collections.singleton(sm), em.getMetamodel(), 
+                        _loc.get("find-title").toString(), _loc.get("find-desc").toString(),
ctx.getRequestURI(), 
+                        ctx.getResponse().getOutputStream());
+                } catch (IOException e) {
+                    throw new ProcessingException(ctx, e);
+                }
+            } else {
+                throw new ProcessingException(ctx, _loc.get("entity-not-found", type, Arrays.toString(pks)),

+                    HttpURLConnection.HTTP_NOT_FOUND);
             }
-        } else {
-            throw new ProcessingException(ctx, _loc.get("entity-not-found", type, Arrays.toString(pks)),

-                HttpURLConnection.HTTP_NOT_FOUND);
+        } finally {
+            popFetchPlan(true);
         }
     }
 }

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ProcessingException.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ProcessingException.java?rev=1042370&r1=1042369&r2=1042370&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ProcessingException.java
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ProcessingException.java
Sun Dec  5 15:09:31 2010
@@ -88,7 +88,7 @@ public class ProcessingException extends
         ExceptionFormatter formatter = new ExceptionFormatter();
         Document xml = formatter.createXML("Request URI: " + uri, t);
         try {
-            formatter.write(xml, response.getOutputStream(), false);
+            formatter.write(xml, response.getOutputStream());
         } catch (IOException e) {
             e.printStackTrace();
             throw new RuntimeException("Request URI: " + uri, e);

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/PropertiesCommand.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/PropertiesCommand.java?rev=1042370&r1=1042369&r2=1042370&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/PropertiesCommand.java
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/PropertiesCommand.java
Sun Dec  5 15:09:31 2010
@@ -59,7 +59,7 @@ public class PropertiesCommand extends A
         PropertiesFormatter formatter = new PropertiesFormatter();
         String caption = _loc.get("properties-caption", ctx.getPersistenceUnitName()).toString();
         Document xml = formatter.createXML(caption, "", "", properties);
-        formatter.write(xml, response.getOutputStream(), false);
+        formatter.write(xml, response.getOutputStream());
         response.setStatus(HttpURLConnection.HTTP_OK);
     }
     

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/QueryCommand.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/QueryCommand.java?rev=1042370&r1=1042369&r2=1042370&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/QueryCommand.java
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/QueryCommand.java
Sun Dec  5 15:09:31 2010
@@ -30,6 +30,8 @@ import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
 import org.apache.openjpa.persistence.ArgumentException;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
 import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;;
 
 /**
@@ -65,13 +67,14 @@ class QueryCommand extends AbstractComma
     @Override
     public void process() throws ProcessingException {
         String spec = getMandatoryArgument(ARG_QUERY);
+        OpenJPAEntityManager em = ctx.getPersistenceContext();
         try {
-            EntityManager em = ctx.getPersistenceContext();
             Query query = isBooleanQualifier(QUALIFIER_NAMED) ? em.createNamedQuery(spec)
: em.createQuery(spec);
             if (hasQualifier(QUALIFIER_FIRSTRESULT)) 
                 query.setFirstResult(Integer.parseInt(getQualifier(QUALIFIER_FIRSTRESULT)));
             if (hasQualifier(QUALIFIER_MAXRESULT)) 
                 query.setMaxResults(Integer.parseInt(getQualifier(QUALIFIER_MAXRESULT)));
+            pushFetchPlan(query);
             
             Map<String, String> args = getArguments();
             for (Map.Entry<String, String> entry : args.entrySet()) {
@@ -87,6 +90,8 @@ class QueryCommand extends AbstractComma
             throw new ProcessingException(ctx, e1, _loc.get("query-execution-error", spec),
HTTP_BAD_REQUEST);
         } catch (Exception e) {
             throw new ProcessingException(ctx, e, _loc.get("query-execution-error", spec));
+        } finally {
+            popFetchPlan(false);
         }
     }
 }

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/XMLFormatter.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/XMLFormatter.java?rev=1042370&r1=1042369&r2=1042370&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/XMLFormatter.java
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/XMLFormatter.java
Sun Dec  5 15:09:31 2010
@@ -98,7 +98,7 @@ public class XMLFormatter implements Obj
             _xsd = factory.newSchema(new StreamSource(xsd));
 
             _transformer.setOutputProperty(OutputKeys.METHOD,     "xml");
-            _transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+            _transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
             _transformer.setOutputProperty(OutputKeys.INDENT,     "yes");
             _transformer.setOutputProperty(OutputKeys.STANDALONE, "no");
             _transformer.setOutputProperty(OutputKeys.ENCODING,   "UTF-8");
@@ -169,7 +169,7 @@ public class XMLFormatter implements Obj
         URI uri, OutputStream out) throws IOException {
         Document doc = encode(objs, model);
         decorate(doc, title, desc, uri);
-        write(doc, out, true);
+        write(doc, out);
         return doc;
     }
     
@@ -178,7 +178,7 @@ public class XMLFormatter implements Obj
         throws IOException {
         Document doc = encode(model);
         decorate(doc, title, desc, uri);
-        write(doc, out, true);
+        write(doc, out);
         return doc;
     }
     
@@ -194,18 +194,16 @@ public class XMLFormatter implements Obj
         return doc;
     }
     
-    public void write(Document doc, OutputStream out, boolean standalone) throws IOException
{
+    public void write(Document doc, OutputStream out) throws IOException {
         try {
-            _transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, standalone ?
"yes" : "no");
             _transformer.transform(new DOMSource(doc), new StreamResult(out));
         } catch (Exception e) {
             throw new IOException(e);
         }
     }
     
-    public void write(Document doc, Writer writer, boolean standalone) throws IOException
{
+    public void write(Document doc, Writer writer) throws IOException {
         try {
-            _transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, standalone ?
"yes" : "no");
             _transformer.transform(new DOMSource(doc), new StreamResult(writer));
         } catch (Exception e) {
             throw new IOException(e);

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.css
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.css?rev=1042370&r1=1042369&r2=1042370&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.css
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.css
Sun Dec  5 15:09:31 2010
@@ -201,6 +201,10 @@ p.small {
 .ref {
 	color : blue;
 }
+.null {
+	color : red;
+}
+
 .delimiter {
   color:lightgray;
   font-weight:bold;

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.html
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.html?rev=1042370&r1=1042369&r2=1042370&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.html
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.html
Sun Dec  5 15:09:31 2010
@@ -185,13 +185,13 @@ The response always contains the <em>clo
 	<tr>
 	  <th width="30%" class="mandatory" title="Name of a persistent entity to find.">Entity
Name</th>
 	  <th width="30%" class="mandatory" title="Primary Key of the entity.">Identifier</th>
-	  <th width="30%" title="Fetch Plan to use.">Fetch Plan</th>
+	  <th width="30%" title="Fetch Plan(s) to use. Separate each plan with comma.">Fetch
Plan</th>
 	  <th width="10%" title="Format of the response.">Format</th>
 	</tr>
 	<tr>
 	  <td><input id="find.type"                      onblur="javascript:toURI('find');"></td>
 	  <td><input id="find.pk"                        onblur="javascript:toURI('find');"></td>
-	  <td><input id="find.plan" disabled="disabled"  onblur="javascript:toURI('find');"
></td>
+	  <td><input id="find.plan"   onblur="javascript:toURI('find');" ></td>
 	  <td>
 	    <select id="find.format" onchange="javascript:toURI('find');" >
 	    <option value=""></option>
@@ -236,14 +236,14 @@ The response always contains the <em>clo
       <th width="10%"style="display: hidden"></th>
 	  <th width="5%" title="Is it a named query?">Single</th>
 	  <th width="5%" title="Returns single result?">Named</th>
-	  <th width="30%" title="Fetch Plan to use.">Fetch Plan</th>
+	  <th width="30%" title="Fetch Plan(s) to use. Separate each plan with comma.">Fetch
Plan</th>
 	  <th width="10%" title="Format of the response.">Format</th>
 	</tr>
 	<tr>
 	  <td colspan="4"><input id="query.q"                         onblur="javascript:toURI('query');"></td>
 	  <td><input id="query.single" type="checkbox" value="true"   onblur="javascript:toURI('query');"></td>
 	  <td><input id="query.named"  type="checkbox" value="true"   onblur="javascript:toURI('query');"></td>
-	  <td><input id="query.plan"   disabled="disabled"            onblur="javascript:toURI('query');"
></td>
+	  <td><input id="query.plan"               onblur="javascript:toURI('query');"
></td>
 	  <td>
 	    <select id="query.format" onchange="javascript:toURI('query');" >
 	    <option value=""></option>

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.js
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.js?rev=1042370&r1=1042369&r2=1042370&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.js
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.js
Sun Dec  5 15:09:31 2010
@@ -795,9 +795,7 @@ function renderDomainFromXMLAsDojo(/*XML
  * @returns a div with zero or more tables.
  */
 function renderInstancesFromXMLAsHTML(/* XML DOM */data) {
-	var empty = document.createElement('div');
-	empty.innerHTML = "<b>renderInstancesFromXMLAsHTML</b> not implemented";
-	return empty;
+	return unimplemented("Rendering Instances as HTML is not implemented");
 }
 
 /**
@@ -808,8 +806,13 @@ function renderInstancesFromXMLAsHTML(/*
  * @returns a div with zero or more tables.
  */
 function renderDomainFromXMLAsHTML(/* XML DOM */data) {
-	var empty = document.createElement('div');
-	empty.innerHTML = "<b>renderDomainFromXMLAsHTML</b> not implemented";
+	return unimplemented("Rendering Domain as HTML is not implemented");
+}
+
+function unimplemented(/*string*/message) {
+	var empty = document.createElement('img');
+	empty.setAttribute("src", "images/underconstruction.jpg");
+	empty.setAttribute("alt", message);
 	return empty;
 }
 
@@ -902,14 +905,30 @@ function createInstanceDojoWidget(/*XML 
 		var valueColumn = document.createElement("td");
 		nameColumn.className = item.nodeName.toLowerCase(); /* May be cross-browser trouble */
 		nameColumn.innerHTML = item.getAttribute("name");
-		var ref = item.getElementsByTagName("ref");
-		if (ref.length > 0) {
-			valueColumn.innerHTML = ref[0].getAttribute("id");
-			valueColumn.className = ref[0].nodeName.toLowerCase();
-			attrRow.appendChild(nameColumn);
-			attrRow.appendChild(valueColumn);
-			instanceTable.appendChild(attrRow);
-		}
+//		var ref = item.getElementsByTagName("ref");
+//		if (ref.length > 0) {
+//			valueColumn.innerHTML = ref[0].getAttribute("id");
+//			valueColumn.className = ref[0].nodeName.toLowerCase();
+//			attrRow.appendChild(nameColumn);
+//			attrRow.appendChild(valueColumn);
+//			instanceTable.appendChild(attrRow);
+//		}
+//		var nulls = item.getElementsByTagName("null");
+//		if (nulls.length > 0) {
+//			valueColumn.innerHTML = 'null';
+//			valueColumn.className = 'null';
+//			attrRow.appendChild(nameColumn);
+//			attrRow.appendChild(valueColumn);
+//			instanceTable.appendChild(attrRow);
+//		}
+		dojo.query('ref, null', instanceNode)
+		    .forEach(function(ref) {
+				valueColumn.innerHTML = ref.nodeName == 'null' ? 'null' : ref.getAttribute("id");
+				valueColumn.className = ref.nodeName.toLowerCase();
+				attrRow.appendChild(nameColumn);
+				attrRow.appendChild(valueColumn);
+				instanceTable.appendChild(attrRow);
+		    });
     });
 	dojo.query('one-to-many, many-to-many', instanceNode).forEach(function(item) { 
 		var attrRow     = document.createElement("tr");



Mime
View raw message