From cd23b435686872ea0abd59568be5bd2bd1994858 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Thu, 28 May 2009 02:57:33 +0000 Subject: [PATCH] add initial test for reading queries; add support for multicolumn joins git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@393 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/query/Query.java | 58 +++++++++++++++++- test/data/queryTest.mdb | Bin 0 -> 163840 bytes .../jackcess/DatabaseTest.java | 14 +++-- .../jackcess/query/QueryTest.java | 48 +++++++++++++++ 4 files changed, 111 insertions(+), 9 deletions(-) create mode 100755 test/data/queryTest.mdb diff --git a/src/java/com/healthmarketscience/jackcess/query/Query.java b/src/java/com/healthmarketscience/jackcess/query/Query.java index 7853859..08f6f48 100644 --- a/src/java/com/healthmarketscience/jackcess/query/Query.java +++ b/src/java/com/healthmarketscience/jackcess/query/Query.java @@ -28,10 +28,12 @@ King of Prussia, PA 19406 package com.healthmarketscience.jackcess.query; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -224,7 +226,31 @@ public abstract class Query List joins = getJoinRows(); if(!joins.isEmpty()) { - for(Row join : joins) { + // combine any multi-column joins + Collection> comboJoins = combineJoins(joins); + + for(List comboJoin : comboJoins) { + + Row join = comboJoin.get(0); + String joinExpr = join.expression; + + if(comboJoin.size() > 1) { + + // combine all the join expressions with "AND" + AppendableList comboExprs = new AppendableList() { + private static final long serialVersionUID = 0L; + @Override + protected String getSeparator() { + return ") AND ("; + } + }; + for(Row tmpJoin : comboJoin) { + comboExprs.add(tmpJoin.expression); + } + + joinExpr = new StringBuilder().append("(") + .append(comboExprs).append(")").toString(); + } String fromTable = join.name1; String toTable = join.name2; @@ -238,7 +264,7 @@ public abstract class Query String expr = new StringBuilder().append(fromExpr) .append(joinType).append(toExpr).append(" ON ") - .append(join.expression).toString(); + .append(joinExpr).toString(); fromExpr.join(toExpr, expr); joinExprs.add(fromExpr); @@ -265,6 +291,28 @@ public abstract class Query throw new IllegalStateException("Cannot find join table " + table); } + private Collection> combineJoins(List joins) + { + // combine joins with the same to/from tables + Map,List> comboJoinMap = + new LinkedHashMap,List>(); + for(Row join : joins) { + List key = Arrays.asList(join.name1, join.name2); + List comboJoins = comboJoinMap.get(key); + if(comboJoins == null) { + comboJoins = new ArrayList(); + comboJoinMap.put(key, comboJoins); + } else { + if(comboJoins.get(0).flag != join.flag) { + throw new IllegalStateException( + "Mismatched join flags for combo joins"); + } + } + comboJoins.add(join); + } + return comboJoinMap.values(); + } + protected String getFromRemoteDbPath() { return getRemoteDatabaseRow().name1; @@ -610,13 +658,17 @@ public abstract class Query super(c); } + protected String getSeparator() { + return ", "; + } + @Override public String toString() { StringBuilder builder = new StringBuilder(); for(Iterator iter = iterator(); iter.hasNext(); ) { builder.append(iter.next().toString()); if(iter.hasNext()) { - builder.append(", "); + builder.append(getSeparator()); } } return builder.toString(); diff --git a/test/data/queryTest.mdb b/test/data/queryTest.mdb new file mode 100755 index 0000000000000000000000000000000000000000..5bb6b28d70adb933073c1232297387dd0c1bb0bb GIT binary patch literal 163840 zcmeHw3w%`7x$oLDlVl#rObEzJ9%JwURA4fJ02VOGBoSglfFOvXl8^*q9)rn%P;HYU z__MY}t3Btc^{BPSw)XbcYOOze)XGs079W-N_O$kOYOQUxt<|=-=bqDB$^Cz8?KQLa zo|%w@7!ba-v$MbX)>_~C)_*Xq5`ZL@9u(pE!H}wnH<|tNQ*QUuk`NAn*B_&+nd?|Mpw+nt!l9SBQo4BhZ8mBftnS z0*nA7zz8q`i~u9R2rvSSz-S;a%g8s-;p6KxMZhpxLe$?U;}TDVc7+tp{}};BfDvE> z7y(9r5nu!u0Y-okU<4QeM&RT^VD7-kjm!9t0L5miM~F?BbDwHPO^*ram^O|R0Wl6k z1T;(l1E&UVGTMuk&L>$u;ReqK$wg!*jkNGe8FmXV`S8fK2V^l`y7mjNkQO-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1)H(PJ z?i`<<|HoPa`ThT~|L-l>`?B>q5{To|IyQ^|BftnS0*nA7zz8q`X$a5<+WWvA{m<&D zNjUV~ijI4)l)-jAi99<)OtWnsq}K&Fzv(4>^f&P7zVyx#&K)1fm)ZiHOFo>a*nK#6X2>1}#r$O7x1oq8tL17``Ejh6l?>+v}%`>)*<>4Vtr*lSaBuO7}JLI%)X%)wx?u_WFWy zIM4s7y(9r5nu!u0Y-okU<4QeMqn%uI8pQeJ#Ib!Pv8I71?pa`d+}zy zy}(#R{3HtFc)rBpFIP{Zg!}-i!h2~ACDEv2(tBw&Vvk`UbL^YmSQ>I?fh_$t2w2gFy&uk$neqp$gwi51cxod&!e6n%+*V&?z< EKPw4~?EnA( literal 0 HcmV?d00001 diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java index aedf3e7..5b5d343 100644 --- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -66,27 +66,29 @@ public class DatabaseTest extends TestCase { super(name); } - static Database open() throws Exception { + public static Database open() throws Exception { return open(new File("test/data/test.mdb")); } - static Database open(File file) throws Exception { + public static Database open(File file) throws Exception { return Database.open(file, true, _autoSync); } - static Database create() throws Exception { + public static Database create() throws Exception { return create(false); } - static Database create(boolean keep) throws Exception { + public static Database create(boolean keep) throws Exception { return Database.create(createTempFile(keep), _autoSync); } - static Database openCopy(File srcFile) throws Exception { + public static Database openCopy(File srcFile) throws Exception { return openCopy(srcFile, false); } - static Database openCopy(File srcFile, boolean keep) throws Exception { + public static Database openCopy(File srcFile, boolean keep) + throws Exception + { File tmp = createTempFile(keep); copyFile(srcFile, tmp); return Database.open(tmp, false, _autoSync); diff --git a/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java b/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java index 10d976c..5d24307 100644 --- a/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java @@ -27,12 +27,17 @@ King of Prussia, PA 19406 package com.healthmarketscience.jackcess.query; +import java.io.File; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import com.healthmarketscience.jackcess.DataType; +import com.healthmarketscience.jackcess.Database; +import com.healthmarketscience.jackcess.DatabaseTest; import com.healthmarketscience.jackcess.query.Query.Row; import junit.framework.TestCase; import org.apache.commons.lang.StringUtils; @@ -192,6 +197,49 @@ public class QueryTest extends TestCase } + public void testReadQueries() throws Exception + { + Map expectedQueries = new HashMap(); + expectedQueries.put( + "SelectQuery", multiline( + "SELECT Table1.*, Table2.col1, Table2.col2, Table3.col3", + "FROM (Table1 LEFT OUTER JOIN Table3 ON Table1.col1 = Table3.col1) INNER JOIN Table2 ON (Table3.col1 = Table2.col1) AND (Table3.col1 = Table2.col2)", + "WHERE (((Table2.col2)=\"foo\" Or (Table2.col2) In (\"buzz\",\"bazz\")))", + "ORDER BY Table2.col1;")); + expectedQueries.put( + "DeleteQuery", multiline( + "DELETE Table1.col1, Table1.col2, Table1.col3", + "FROM Table1", + "WHERE (((Table1.col1)>\"blah\"));")); + expectedQueries.put( + "AppendQuery",multiline( + "INSERT INTO Table3", + "SELECT [Table1].[col2], [Table2].[col2], [Table2].[col3]", + "FROM Table3, Table1 INNER JOIN Table2 ON [Table1].[col1]=[Table2].[col1];")); + expectedQueries.put( + "UpdateQuery",multiline( + "UPDATE Table1", + "SET Table1.col1 = \"foo\", Table1.col2 = [Table2].[col3]", + "WHERE (([Table2].[col1] Is Not Null));")); + expectedQueries.put( + "MakeTableQuery",multiline( + "SELECT Max(Table2.col1) AS MaxOfcol1, Table2.col2, Table3.col2 INTO Table4", + "FROM (Table2 INNER JOIN Table1 ON Table2.col1 = Table1.col2) RIGHT OUTER JOIN Table3 ON Table1.col2 = Table3.col3", + "GROUP BY Table2.col2, Table3.col2", + "HAVING (((Max(Table2.col1))=\"buzz\") AND ((Table2.col2)<>\"blah\"));")); + + Database db = DatabaseTest.open(new File("test/data/queryTest.mdb")); + + Map foundQueries = new HashMap(); + for(Query q : db.getQueries()) { + assertNull(foundQueries.put(q.getName(), q.toSQLString())); + } + + assertEquals(expectedQueries, foundQueries); + + db.close(); + } + private void doTestColumns(SelectQuery query) throws Exception { addRows(query, newRow(COLUMN_ATTRIBUTE, "Table1.id", null, null)); -- 2.39.5