diff --git a/querydsl-jdo/pom.xml b/querydsl-jdo/pom.xml
index f699ba3be..4c38fd895 100644
--- a/querydsl-jdo/pom.xml
+++ b/querydsl-jdo/pom.xml
@@ -16,8 +16,8 @@
jar
- 2.1.2
- 2.0.1
+ 3.2.0-m1
+ 3.2.0-m1
@@ -70,12 +70,18 @@
-
-
- org.datanucleus
- datanucleus-core
- ${dn.version}
- test
+
+
+ org.datanucleus
+ datanucleus-api-jdo
+ ${dn.version}
+ test
+
+
+ org.datanucleus
+ datanucleus-core
+ ${dn.version}
+ test
org.datanucleus
@@ -161,11 +167,11 @@
-
- javax.jdo
- jdo2-api
- 2.3-ec
- runtime
+
+ org.datanucleus
+ datanucleus-api-jdo
+ ${dn.version}
+ runtime
diff --git a/querydsl-jdo/src/main/java/com/mysema/query/jdo/AbstractJDOQLQuery.java b/querydsl-jdo/src/main/java/com/mysema/query/jdo/AbstractJDOQLQuery.java
index fccbda80d..f26a7e58e 100644
--- a/querydsl-jdo/src/main/java/com/mysema/query/jdo/AbstractJDOQLQuery.java
+++ b/querydsl-jdo/src/main/java/com/mysema/query/jdo/AbstractJDOQLQuery.java
@@ -1,6 +1,6 @@
/*
* Copyright 2011, Mysema Ltd
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -29,6 +29,7 @@ import javax.jdo.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.collect.Lists;
import com.mysema.commons.lang.CloseableIterator;
import com.mysema.commons.lang.IteratorAdapter;
import com.mysema.query.DefaultQueryMetadata;
@@ -51,7 +52,7 @@ import com.mysema.query.types.QTuple;
*
* @param
*/
-public abstract class AbstractJDOQLQuery> extends ProjectableQuery{
+public abstract class AbstractJDOQLQuery> extends ProjectableQuery {
private static final Logger logger = LoggerFactory.getLogger(JDOQLQueryImpl.class);
@@ -77,6 +78,9 @@ public abstract class AbstractJDOQLQuery> extend
@Nullable
protected Integer maxFetchDepth;
+
+ @Nullable
+ private FactoryExpression> projection;
public AbstractJDOQLQuery(@Nullable PersistenceManager persistenceManager) {
this(persistenceManager, JDOQLTemplates.DEFAULT, new DefaultQueryMetadata(), false);
@@ -111,7 +115,7 @@ public abstract class AbstractJDOQLQuery> extend
Query query = createQuery(true);
query.setUnique(true);
reset();
- Long rv = (Long) execute(query);
+ Long rv = (Long) execute(query, true);
if (rv != null) {
return rv.longValue();
} else {
@@ -129,7 +133,7 @@ public abstract class AbstractJDOQLQuery> extend
private Expression> getSource() {
return queryMixin.getMetadata().getJoins().get(0).getTarget();
}
-
+
private Query createQuery(boolean forCount) {
Expression> source = getSource();
@@ -146,13 +150,9 @@ public abstract class AbstractJDOQLQuery> extend
if (!forCount) {
List extends Expression>> projection = queryMixin.getMetadata().getProjection();
- Class> exprType = projection.get(0).getClass();
- if (exprType.equals(QTuple.class)) {
- query.setResultClass(JDOTuple.class);
- } else if (FactoryExpression.class.isAssignableFrom(exprType)) {
- query.setResultClass(projection.get(0).getType());
+ if (projection.get(0) instanceof FactoryExpression) {
+ this.projection = (FactoryExpression>)projection.get(0);
}
-
if (!fetchGroups.isEmpty()) {
query.getFetchPlan().setGroups(fetchGroups);
}
@@ -179,8 +179,18 @@ public abstract class AbstractJDOQLQuery> extend
}
}
+ private Object project(FactoryExpression> expr, Object row) {
+ if (row == null) {
+ return null;
+ } else if (row.getClass().isArray()) {
+ return expr.newInstance((Object[])row);
+ } else {
+ return expr.newInstance(new Object[]{row});
+ }
+ }
+
@Nullable
- private Object execute(Query query) {
+ private Object execute(Query query, boolean forCount) {
Object rv;
if (!orderedConstants.isEmpty()) {
rv = query.executeWithArray(orderedConstants.toArray());
@@ -190,6 +200,18 @@ public abstract class AbstractJDOQLQuery> extend
if (isDetach()) {
rv = detach(rv);
}
+ if (projection != null && !forCount) {
+ if (rv instanceof List) {
+ List> original = (List>)rv;
+ rv = Lists.newArrayList();
+ for (Object o : original) {
+ ((List)rv).add(project(projection, o));
+ }
+ } else {
+ rv = project(projection, rv);
+ }
+ }
+
return rv;
}
@@ -226,7 +248,7 @@ public abstract class AbstractJDOQLQuery> extend
@SuppressWarnings("unchecked")
public