You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pp...@apache.org on 2008/12/01 13:34:19 UTC
svn commit: r722059 - in /openjpa/trunk/openjpa-slice/src:
main/java/org/apache/openjpa/slice/jdbc/ test/java/org/apache/openjpa/slice/
Author: ppoddar
Date: Mon Dec 1 04:34:17 2008
New Revision: 722059
URL: http://svn.apache.org/viewvc?rev=722059&view=rev
Log:
OPENJPA-787,OPENJPA-799: getSingleResult() and multiple aggregate projections
Modified:
openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedResultSet.java
openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/UniqueResultObjectProvider.java
openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestBasic.java
openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java
Modified: openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedResultSet.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedResultSet.java?rev=722059&r1=722058&r2=722059&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedResultSet.java (original)
+++ openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedResultSet.java Mon Dec 1 04:34:17 2008
@@ -40,22 +40,26 @@
/**
* A chain of ResultSet.
+ * Assumes added ResultSet are identical in structure and fetches forward.
+ * Can not move absolutely or change fetch direction.
*
* @author Pinaki Poddar
*
*/
class DistributedResultSet implements ResultSet {
- LinkedList<ResultSet> comps = new LinkedList<ResultSet>();
- ResultSet current;
- int cursor = -1;
+ private LinkedList<ResultSet> comps = new LinkedList<ResultSet>();
+ private ResultSet current;
+ private int cursor = -1;
/**
* Adds the ResultSet only if it has rows.
*/
public void add(ResultSet rs) {
try {
- if (rs.first())
+ if (rs.first()) {
comps.add(rs);
+ rs.beforeFirst();
+ }
} catch (SQLException e) {
// ignore
}
@@ -76,31 +80,32 @@
}
public void cancelRowUpdates() throws SQLException {
- throw new UnsupportedOperationException();
+ current.cancelRowUpdates();
}
public void clearWarnings() throws SQLException {
- for (ResultSet rs:comps)
+ for (ResultSet rs : comps)
rs.clearWarnings();
}
public void close() throws SQLException {
- for (ResultSet rs:comps)
+ for (ResultSet rs : comps)
rs.close();
}
-
+
public void deleteRow() throws SQLException {
- current.deleteRow();
+ throw new UnsupportedOperationException();
}
public int findColumn(String arg0) throws SQLException {
- return 0;
+ return current.findColumn(arg0);
}
public boolean first() throws SQLException {
- if (comps.isEmpty()) return false;
+ if (comps.isEmpty())
+ return false;
cursor = 0;
- current = comps.get(0);
+ current = comps.getFirst();
return true;
}
@@ -149,281 +154,226 @@
}
public Blob getBlob(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getBlob(arg0);
}
public boolean getBoolean(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return false;
+ return current.getBoolean(arg0);
}
public boolean getBoolean(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return false;
+ return current.getBoolean(arg0);
}
public byte getByte(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return current.getByte(arg0);
}
public byte getByte(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return current.getByte(arg0);
}
public byte[] getBytes(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getBytes(arg0);
}
public byte[] getBytes(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getBytes(arg0);
}
public Reader getCharacterStream(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getCharacterStream(arg0);
}
public Reader getCharacterStream(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getCharacterStream(arg0);
}
public Clob getClob(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getClob(arg0);
}
public Clob getClob(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getClob(arg0);
}
public int getConcurrency() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return current.getConcurrency();
}
public String getCursorName() throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getCursorName();
}
public Date getDate(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getDate(arg0);
}
public Date getDate(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getDate(arg0);
}
public Date getDate(int arg0, Calendar arg1) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getDate(arg0, arg1);
}
public Date getDate(String arg0, Calendar arg1) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getDate(arg0, arg1);
}
public double getDouble(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return current.getDouble(arg0);
}
public double getDouble(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return current.getDouble(arg0);
}
public int getFetchDirection() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return current.getFetchDirection();
}
public int getFetchSize() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return current.getFetchSize();
}
public float getFloat(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return current.getFloat(arg0);
}
public float getFloat(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return current.getFloat(arg0);
}
public int getInt(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return current.getInt(arg0);
}
public int getInt(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return current.getInt(arg0);
}
public long getLong(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return current.getLong(arg0);
}
public long getLong(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return current.getLong(arg0);
}
public ResultSetMetaData getMetaData() throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getMetaData();
}
public Object getObject(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getObject(arg0);
}
public Object getObject(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getObject(arg0);
}
public Object getObject(int arg0, Map<String, Class<?>> arg1)
throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getObject(arg0, arg1);
}
public Object getObject(String arg0, Map<String, Class<?>> arg1)
throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getObject(arg0, arg1);
}
public Ref getRef(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getRef(arg0);
}
public Ref getRef(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getRef(arg0);
}
public int getRow() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ throw new UnsupportedOperationException();
}
public short getShort(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return current.getShort(arg0);
}
public short getShort(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return current.getShort(arg0);
}
public Statement getStatement() throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getStatement();
}
public String getString(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getString(arg0);
}
public String getString(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getString(arg0);
}
public Time getTime(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getTime(arg0);
}
public Time getTime(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getTime(arg0);
}
public Time getTime(int arg0, Calendar arg1) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getTime(arg0, arg1);
}
public Time getTime(String arg0, Calendar arg1) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getTime(arg0, arg1);
}
public Timestamp getTimestamp(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getTimestamp(arg0);
}
public Timestamp getTimestamp(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getTimestamp(arg0);
}
public Timestamp getTimestamp(int arg0, Calendar arg1) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getTimestamp(arg0, arg1);
}
public Timestamp getTimestamp(String arg0, Calendar arg1)
throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getTimestamp(arg0, arg1);
}
public int getType() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return current.getType();
}
public URL getURL(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getURL(arg0);
}
public URL getURL(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getURL(arg0);
}
public InputStream getUnicodeStream(int arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getUnicodeStream(arg0);
}
public InputStream getUnicodeStream(String arg0) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getUnicodeStream(arg0);
}
public SQLWarning getWarnings() throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return current.getWarnings();
}
public void insertRow() throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public boolean isAfterLast() throws SQLException {
@@ -431,333 +381,305 @@
}
public boolean isBeforeFirst() throws SQLException {
- return current == null && cursor<0;
+ return current == null && cursor < 0;
}
public boolean isFirst() throws SQLException {
- return current != null && current.isFirst() && cursor==0;
+ return current != null && current.isFirst() && cursor == 0;
}
public boolean isLast() throws SQLException {
- return current != null && current.isLast() && cursor==comps.size()-1;
+ return current != null && current.isLast() && cursor == comps.size()-1;
}
public boolean last() throws SQLException {
- if (comps.isEmpty()) return false;
+ if (comps.isEmpty())
+ return false;
cursor = comps.size()-1;
- return false;
+ current = comps.getLast();
+ return current.last();
}
public void moveToCurrentRow() throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void moveToInsertRow() throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public boolean next() throws SQLException {
+ if (comps.isEmpty())
+ return false;
if (current == null) {
- current = comps.get(0);
+ current = comps.getFirst();
cursor = 0;
}
if (current.next())
return true;
cursor++;
- if (cursor<comps.size())
+ if (cursor < comps.size()) {
current = comps.get(cursor);
- return cursor<comps.size();
+ return current.first();
+ }
+ return false;
}
public boolean previous() throws SQLException {
- return current.previous();
+ if (comps.isEmpty())
+ return false;
+ if (current.previous())
+ return true;
+ cursor--;
+ if (cursor >= 0) {
+ current = comps.get(cursor);
+ return current.last();
+ }
+ return false;
}
public void refreshRow() throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public boolean relative(int arg0) throws SQLException {
- // TODO Auto-generated method stub
+ if (arg0 == 0)
+ return current != null;
+ boolean forward = arg0 > 0;
+ for (int i = 0; i < arg0; i++) {
+ if (forward) {
+ if (!next()) {
+ return false;
+ }
+ } else {
+ if (!previous()) {
+ return false;
+ }
+ }
+ }
return false;
}
public boolean rowDeleted() throws SQLException {
- // TODO Auto-generated method stub
- return false;
+ throw new UnsupportedOperationException();
}
public boolean rowInserted() throws SQLException {
- // TODO Auto-generated method stub
- return false;
+ throw new UnsupportedOperationException();
}
public boolean rowUpdated() throws SQLException {
- // TODO Auto-generated method stub
- return false;
+ throw new UnsupportedOperationException();
}
public void setFetchDirection(int arg0) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void setFetchSize(int arg0) throws SQLException {
- // TODO Auto-generated method stub
-
+ for (ResultSet rs : comps)
+ rs.setFetchSize(arg0);
}
public void updateArray(int arg0, Array arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateArray(String arg0, Array arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateAsciiStream(int arg0, InputStream arg1, int arg2)
throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateAsciiStream(String arg0, InputStream arg1, int arg2)
throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateBigDecimal(int arg0, BigDecimal arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateBigDecimal(String arg0, BigDecimal arg1)
throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateBinaryStream(int arg0, InputStream arg1, int arg2)
throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateBinaryStream(String arg0, InputStream arg1, int arg2)
throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateBlob(int arg0, Blob arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateBlob(String arg0, Blob arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateBoolean(int arg0, boolean arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateBoolean(String arg0, boolean arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateByte(int arg0, byte arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateByte(String arg0, byte arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateBytes(int arg0, byte[] arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateBytes(String arg0, byte[] arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateCharacterStream(int arg0, Reader arg1, int arg2)
throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateCharacterStream(String arg0, Reader arg1, int arg2)
throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateClob(int arg0, Clob arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateClob(String arg0, Clob arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateDate(int arg0, Date arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateDate(String arg0, Date arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateDouble(int arg0, double arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateDouble(String arg0, double arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateFloat(int arg0, float arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateFloat(String arg0, float arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateInt(int arg0, int arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateInt(String arg0, int arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateLong(int arg0, long arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateLong(String arg0, long arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateNull(int arg0) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateNull(String arg0) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateObject(int arg0, Object arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateObject(String arg0, Object arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateObject(int arg0, Object arg1, int arg2)
throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateObject(String arg0, Object arg1, int arg2)
throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateRef(int arg0, Ref arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateRef(String arg0, Ref arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateRow() throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateShort(int arg0, short arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateShort(String arg0, short arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateString(int arg0, String arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateString(String arg0, String arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateTime(int arg0, Time arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateTime(String arg0, Time arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateTimestamp(int arg0, Timestamp arg1) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void updateTimestamp(String arg0, Timestamp arg1)
throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public boolean wasNull() throws SQLException {
- // TODO Auto-generated method stub
- return false;
+ return current.wasNull();
}
-
}
Modified: openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java?rev=722059&r1=722058&r2=722059&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java (original)
+++ openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java Mon Dec 1 04:34:17 2008
@@ -147,10 +147,10 @@
}
boolean[] ascending = getAscending(q);
boolean isAscending = ascending.length > 0;
- boolean isUnique = q.getContext().isUnique();
+ boolean isAggregate = q.getContext().isAggregate();
boolean hasRange = q.getContext().getEndRange() != Long.MAX_VALUE;
ResultObjectProvider result = null;
- if (isUnique) {
+ if (isAggregate) {
result = new UniqueResultObjectProvider(tmp, q,
getQueryExpressions());
} else if (isAscending) {
Modified: openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/UniqueResultObjectProvider.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/UniqueResultObjectProvider.java?rev=722059&r1=722058&r2=722059&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/UniqueResultObjectProvider.java (original)
+++ openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/UniqueResultObjectProvider.java Mon Dec 1 04:34:17 2008
@@ -88,7 +88,8 @@
boolean isAggregate = v.isAggregate();
String op = v.getClass().getSimpleName();
for (ResultObjectProvider rop:_rops) {
- rop.next();
+ if (i == 0)
+ rop.next();
Object[] row = (Object[]) rop.getResultObject();
if (isAggregate) {
if (COUNT.equals(op)) {
Modified: openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestBasic.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestBasic.java?rev=722059&r1=722058&r2=722059&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestBasic.java (original)
+++ openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestBasic.java Mon Dec 1 04:34:17 2008
@@ -47,7 +47,7 @@
/**
* Persist N independent objects.
*/
- List<PObject> create(int N) {
+ List<PObject> createIndependentObjects(int N) {
List<PObject> pcs = new ArrayList<PObject>();
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
@@ -65,8 +65,8 @@
/**
* Create a single object.
*/
- PObject create() {
- return create(1).get(0);
+ PObject createIndependentObject() {
+ return createIndependentObjects(1).get(0);
}
/**
@@ -74,7 +74,7 @@
*/
public void testDelete() {
int N = 10;
- create(N);
+ createIndependentObjects(N);
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
int before = count(PObject.class);
@@ -106,7 +106,7 @@
* Store and find the same object.
*/
public void testFind() {
- PObject pc = create();
+ PObject pc = createIndependentObject();
int value = pc.getValue();
EntityManager em = emf.createEntityManager();
@@ -181,7 +181,7 @@
* from which the instance was fetched.
*/
public void testMerge() {
- PObject pc = create(1).get(0);
+ PObject pc = createIndependentObjects(1).get(0);
int value = pc.getValue();
pc.setValue(value + 1);
assertNotNull(pc);
@@ -237,5 +237,21 @@
em.merge(india);
em.getTransaction().commit();
}
+
+ public void testQuerySingleObject() {
+ PObject pc = createIndependentObject();
+ long pid = pc.getId();
+ int value = pc.getValue();
+
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+ String jpql = "select p from PObject p where p.id=:id";
+ PObject pc2 = (PObject)em.createQuery(jpql).setParameter("id", pid)
+ .getSingleResult();
+ assertNotNull(pc2);
+ assertNotEquals(pc, pc2);
+ assertEquals(pc.getId(), pc2.getId());
+ assertEquals(value, pc2.getValue());
+ }
}
Modified: openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java?rev=722059&r1=722058&r2=722059&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java (original)
+++ openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java Mon Dec 1 04:34:17 2008
@@ -85,12 +85,17 @@
Object max = em.createQuery("SELECT MAX(p.value) FROM PObject p").getSingleResult();
Object min = em.createQuery("SELECT MIN(p.value) FROM PObject p").getSingleResult();
Object sum = em.createQuery("SELECT SUM(p.value) FROM PObject p").getSingleResult();
+ Object minmax = em.createQuery("SELECT MIN(p.value),MAX(p.value) FROM PObject p").getSingleResult();
+ Object min1 = ((Object[])minmax)[0];
+ Object max1 = ((Object[])minmax)[1];
em.getTransaction().rollback();
assertEquals(POBJECT_COUNT, ((Number)count).intValue());
assertEquals(VALUE_MAX, ((Number)max).intValue());
assertEquals(VALUE_MIN, ((Number)min).intValue());
assertEquals((VALUE_MIN+VALUE_MAX)*POBJECT_COUNT, 2*((Number)sum).intValue());
+ assertEquals(min, min1);
+ assertEquals(max, max1);
}
public void testSetMaxResult() {