You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2008/01/05 16:47:23 UTC
svn commit: r609157 - in
/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src:
main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
test/java/org/apache/cayenne/access/DataContextFlattenedAttributesTest.java
Author: aadamchik
Date: Sat Jan 5 07:46:16 2008
New Revision: 609157
URL: http://svn.apache.org/viewvc?rev=609157&view=rev
Log:
CAY-948 Implement flattened attributes in Cayenne
(support for flattened attributes in the where clause translation)
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesTest.java
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java?rev=609157&r1=609156&r2=609157&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java Sat Jan 5 07:46:16 2008
@@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -184,8 +185,15 @@
}
protected void processTerminatingAttribute(ObjAttribute attribute) {
-
- DbEntity table = currentEntity.getDbEntity();
+
+ DbEntity table = null;
+ Iterator<?> it = attribute.getDbPathIterator();
+ while (it.hasNext()) {
+ Object pathComponent = it.next();
+ if (pathComponent instanceof DbAttribute) {
+ table = (DbEntity) ((DbAttribute) pathComponent).getEntity();
+ }
+ }
if (isUsingAliases()) {
String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesTest.java?rev=609157&r1=609156&r2=609157&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesTest.java Sat Jan 5 07:46:16 2008
@@ -29,6 +29,7 @@
import org.apache.art.Artist;
import org.apache.art.CompoundPainting;
import org.apache.cayenne.DataObjectUtils;
+import org.apache.cayenne.PersistenceState;
import org.apache.cayenne.exp.ExpressionFactory;
import org.apache.cayenne.query.EJBQLQuery;
import org.apache.cayenne.query.SelectQuery;
@@ -67,6 +68,7 @@
long dateBase = System.currentTimeMillis();
for (int i = 1; i <= artistCount; i++) {
stmt.setInt(1, i + 1);
+ System.out.println("artist real id: " + (i + 1));
stmt.setString(2, "artist" + i);
stmt.setDate(3, new java.sql.Date(dateBase + 1000 * 60 * 60 * 24 * i));
stmt.executeUpdate();
@@ -85,6 +87,7 @@
for (int i = 1; i <= paintCount; i++) {
stmt.setInt(1, i);
stmt.setString(2, "painting" + i);
+ System.out.println("artist id: " + ((i - 1) % artistCount + 2));
stmt.setInt(3, (i - 1) % artistCount + 2);
stmt.setBigDecimal(4, new BigDecimal(1000d));
if (i == 3)
@@ -144,6 +147,8 @@
}
}
+ // TODO: andrus 1/5/2007 - CAY-952: SelectQuery uses INNER JOIN for flattened attributes, while
+ // EJBQLQuery does an OUTER JOIN... which seems like a better idea...
public void testSelectCompound2() throws Exception {
populateTables();
SelectQuery query = new SelectQuery(CompoundPainting.class, ExpressionFactory
@@ -179,40 +184,22 @@
painting.getGalleryName());
}
}
-
+
public void testSelectEJQBQL() throws Exception {
-// populateTables();
-// EJBQLQuery query = new EJBQLQuery("SELECT a FROM CompoundPainting a WHERE a.artistName = 'artist2'");
-// List<?> objects = context.performQuery(query);
-//
-// assertNotNull(objects);
-// assertEquals(1, objects.size());
-// assertTrue("CompoundPainting expected, got " + objects.get(0).getClass(), objects
-// .get(0) instanceof CompoundPainting);
-//
-// for (Iterator<?> i = objects.iterator(); i.hasNext();) {
-// CompoundPainting painting = (CompoundPainting) i.next();
-// Number id = (Number) painting
-// .getObjectId()
-// .getIdSnapshot()
-// .get("PAINTING_ID");
-// assertEquals("CompoundPainting.getObjectId(): " + id, id.intValue(), 2);
-// assertEquals("CompoundPainting.getPaintingTitle(): "
-// + painting.getPaintingTitle(), "painting" + id, painting
-// .getPaintingTitle());
-// assertEquals(
-// "CompoundPainting.getTextReview(): " + painting.getTextReview(),
-// "painting review" + id,
-// painting.getTextReview());
-// assertEquals(
-// "CompoundPainting.getArtistName(): " + painting.getArtistName(),
-// "artist2",
-// painting.getArtistName());
-// assertEquals(
-// "CompoundPainting.getArtistName(): " + painting.getGalleryName(),
-// painting.getToGallery().getGalleryName(),
-// painting.getGalleryName());
-// }
+ populateTables();
+ EJBQLQuery query = new EJBQLQuery(
+ "SELECT a FROM CompoundPainting a WHERE a.artistName = 'artist2'");
+ List<?> objects = context.performQuery(query);
+
+ assertNotNull(objects);
+ assertEquals(2, objects.size());
+ assertTrue("CompoundPainting expected, got " + objects.get(0).getClass(), objects
+ .get(0) instanceof CompoundPainting);
+ Iterator<?> i = objects.iterator();
+ while (i.hasNext()) {
+ CompoundPainting painting = (CompoundPainting) i.next();
+ // assertEquals(PersistenceState.COMMITTED, painting.getPersistenceState());
+ }
}
public void testInsert() {