Revision: 10565
http://datanucleus.svn.sourceforge.net/datanucleus/?rev=10565&view=rev
Author: andy_jefferson
Date: 2010-10-04 08:10:13 +0000 (Mon, 04 Oct 2010)
Log Message:
-----------
more work around typesafe queries ... start to implement PersistableExpression in annotation processor
Modified Paths:
--------------
platform/core/trunk/src/java/org/datanucleus/query/typesafe/Query.java
platform/core/trunk/src/java/org/datanucleus/query/typesafe/impl/JDOQueryProcessor.java
platform/core/trunk/src/java/org/datanucleus/query/typesafe/impl/TypesafeQueryImpl.java
Modified: platform/core/trunk/src/java/org/datanucleus/query/typesafe/Query.java
===================================================================
--- platform/core/trunk/src/java/org/datanucleus/query/typesafe/Query.java 2010-10-04 07:04:46 UTC (rev 10564)
+++ platform/core/trunk/src/java/org/datanucleus/query/typesafe/Query.java 2010-10-04 08:10:13 UTC (rev 10565)
@@ -133,30 +133,32 @@
*/
Query setParameter(String paramName, Object value);
+ // TODO Methods to execute and return instances of candidate type T
+
/**
* Method to execute the query where there are (potentially) multiple rows and we are returning either a
* result type or the candidate type.
* @param resultCls Result class
* @return The results
*/
- <T> List<T> executeList(T resultCls);
+ <R> List<R> executeList(R resultCls);
/**
- * Method to execute the query where there are (potentially) multiple rows and we have a result defined
- * but no result class.
- * @return The results
- */
- Object[] executeList();
-
- /**
* Method to execute the query where there is a single row and we are returning either a result type
* or the candidate type.
* @param resultCls Result class
* @return The result
*/
- <T> T executeUnique(T resultCls);
+ <R> R executeUnique(R resultCls);
/**
+ * Method to execute the query where there are (potentially) multiple rows and we have a result defined
+ * but no result class.
+ * @return The results
+ */
+ List<Object[]> executeList();
+
+ /**
* Method to execute the query where there is a single row and we have a result defined
* but no result class.
* @return The results
Modified: platform/core/trunk/src/java/org/datanucleus/query/typesafe/impl/JDOQueryProcessor.java
===================================================================
--- platform/core/trunk/src/java/org/datanucleus/query/typesafe/impl/JDOQueryProcessor.java 2010-10-04 07:04:46 UTC (rev 10564)
+++ platform/core/trunk/src/java/org/datanucleus/query/typesafe/impl/JDOQueryProcessor.java 2010-10-04 08:10:13 UTC (rev 10565)
@@ -34,6 +34,8 @@
import javax.lang.model.util.Types;
import javax.tools.JavaFileObject;
+import org.datanucleus.query.typesafe.PersistableExpression;
+
/**
* Annotation processor for JDO to generate "dummy" classes for all persistable classes for use with the
* Typesafe Query API. Any class ({MyClass}) that has a JDO "class" annotation will have a stub class
@@ -90,7 +92,7 @@
String className = elementUtils.getBinaryName(el).toString();
String pkgName = className.substring(0, className.lastIndexOf('.'));
String classSimpleName = className.substring(className.lastIndexOf('.') + 1);
- String classNameNew = prefix + className;
+ String classNameNew = pkgName + "." + prefix + classSimpleName;
System.out.println("JDO QueryProcessor orig=" + className + " new=" + classNameNew);
TypeElement superEl = getPersistentSupertype(el);
@@ -100,20 +102,44 @@
Writer w = javaFile.openWriter();
try
{
+ // Package declaration
w.append("package " + pkgName + ";\n");
w.append("\n");
+
+ // Imports
+ String typesafeCls = PersistableExpression.class.getName();
+ String typesafePkg = typesafeCls.substring(0, typesafeCls.lastIndexOf('.'));
+ w.append("import " + typesafePkg + ".*;\n");
+ w.append("\n");
+
+ // Class declaration
w.append("public class " + prefix + classSimpleName);
if (superEl != null)
{
String superClassName = elementUtils.getBinaryName(superEl).toString();
w.append(" extends ").append(prefix + superClassName);
}
- // TODO implements PathExpression
+ w.append(" implements ").append(PersistableExpression.class.getSimpleName());
w.append("\n");
w.append("{\n");
+ String indent = " ";
+
// Find the members to use for persistence processing
+ // TODO Add field for each persistable member
+ // Implement PersistableExpression
+ w.append(indent).append("public Expression jdoObjectId()\n");
+ w.append(indent).append("{\n");
+ w.append(indent).append(" return null;\n"); // TODO Implement this
+ w.append(indent).append("}\n");
+ w.append(indent).append("public Expression jdoVersion()\n");
+ w.append(indent).append("{\n");
+ w.append(indent).append(" return null;\n"); // TODO Implement this
+ w.append(indent).append("}\n");
+
+ // Implement Expression TODO Add these methods
+
w.append("}\n");
w.flush();
}
Modified: platform/core/trunk/src/java/org/datanucleus/query/typesafe/impl/TypesafeQueryImpl.java
===================================================================
--- platform/core/trunk/src/java/org/datanucleus/query/typesafe/impl/TypesafeQueryImpl.java 2010-10-04 07:04:46 UTC (rev 10564)
+++ platform/core/trunk/src/java/org/datanucleus/query/typesafe/impl/TypesafeQueryImpl.java 2010-10-04 08:10:13 UTC (rev 10565)
@@ -20,8 +20,12 @@
import java.util.List;
import javax.jdo.FetchPlan;
+import javax.jdo.JDOUserException;
+import org.datanucleus.ClassLoaderResolver;
import org.datanucleus.ObjectManager;
+import org.datanucleus.metadata.MetaDataManager;
+import org.datanucleus.query.compiler.QueryCompilation;
import org.datanucleus.query.typesafe.BooleanExpression;
import org.datanucleus.query.typesafe.Expression;
import org.datanucleus.query.typesafe.NumericExpression;
@@ -47,14 +51,21 @@
Expression rangeLowerExpr;
Expression rangeUpperExpr;
+ /** The single-string query that this equates to (cached). */
+ String queryString = null;
+
+ /** The generic query compilation that this equates to (cached). */
+ QueryCompilation compilation = null;
+
/**
* Constructor for a typesafe query.
* @param om Object Manager
+ * @param candidateClass The candidate class
*/
- public TypesafeQueryImpl(ObjectManager om, Class cls)
+ public TypesafeQueryImpl(ObjectManager om, Class candidateClass)
{
this.om = om;
- this.candidateCls = cls;
+ this.candidateCls = candidateClass;
}
/* (non-Javadoc)
@@ -71,6 +82,7 @@
*/
public Expression parameter(String name, Class type)
{
+ discardCompiled();
// TODO Auto-generated method stub
return null;
}
@@ -80,6 +92,7 @@
*/
public Expression variable(String name, Class type)
{
+ discardCompiled();
// TODO Auto-generated method stub
return null;
}
@@ -89,6 +102,7 @@
*/
public Query filter(BooleanExpression expr)
{
+ discardCompiled();
this.filterExpr = expr;
return this;
}
@@ -98,6 +112,7 @@
*/
public Query groupBy(Expression... exprs)
{
+ discardCompiled();
this.groupingExprs = exprs;
return this;
}
@@ -107,6 +122,7 @@
*/
public Query having(Expression expr)
{
+ discardCompiled();
this.havingExpr = expr;
return this;
}
@@ -116,6 +132,7 @@
*/
public Query orderBy(OrderExpression... orderExprs)
{
+ discardCompiled();
this.orderExprs = orderExprs;
return this;
}
@@ -125,6 +142,7 @@
*/
public Query range(long lowerIncl, long upperExcl)
{
+ discardCompiled();
// TODO Auto-generated method stub - create NumericExpressions internally
return this;
}
@@ -134,6 +152,7 @@
*/
public Query range(NumericExpression lowerInclExpr, NumericExpression upperExclExpr)
{
+ discardCompiled();
this.rangeLowerExpr = lowerInclExpr;
this.rangeUpperExpr = upperExclExpr;
return this;
@@ -144,6 +163,15 @@
*/
public Query range(Expression paramLowerInclExpr, Expression paramUpperExclExpr)
{
+ discardCompiled();
+ if (!paramLowerInclExpr.isParameter())
+ {
+ throw new JDOUserException("lower inclusive expression should be a parameter");
+ }
+ else if (!paramUpperExclExpr.isParameter())
+ {
+ throw new JDOUserException("upper exclusive expression should be a parameter");
+ }
this.rangeLowerExpr = paramLowerInclExpr;
this.rangeUpperExpr = paramUpperExclExpr;
return this;
@@ -154,6 +182,7 @@
*/
public Query result(Expression... exprs)
{
+ discardCompiled();
this.resultExprs = exprs;
return this;
}
@@ -163,6 +192,7 @@
*/
public Query setFetchPlan(FetchPlan fp)
{
+ discardCompiled();
this.fp = fp;
return this;
}
@@ -172,6 +202,7 @@
*/
public Query setParameter(Expression paramExpr, Object value)
{
+ discardCompiled();
// TODO Auto-generated method stub
return this;
}
@@ -181,6 +212,7 @@
*/
public Query setParameter(String paramName, Object value)
{
+ discardCompiled();
// TODO Auto-generated method stub
return this;
}
@@ -188,7 +220,7 @@
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.Query#executeList()
*/
- public Object[] executeList()
+ public List<Object[]> executeList()
{
// TODO Auto-generated method stub
return null;
@@ -231,12 +263,37 @@
}
/**
+ * Called when something is set on the query making any compilation invalid.
+ */
+ protected void discardCompiled()
+ {
+ compilation = null;
+ queryString = null;
+ }
+
+ /**
+ * Accessor for the generic compilation that this criteria query equates to.
+ * @return The generic compilation
+ */
+ public QueryCompilation getCompilation(MetaDataManager mmgr, ClassLoaderResolver clr)
+ {
+ if (compilation == null)
+ {
+ // TODO Implement this
+ }
+ return compilation;
+ }
+
+ /**
* Method to return the single-string form of this JDOQL query.
* @return Single-string form of the query
*/
public String toString()
{
- // TODO Implement this
- return null;
+ if (queryString == null)
+ {
+ // TODO Implement this
+ }
+ return queryString;
}
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|