aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-10-22 20:40:52 -0400
committerJames Moger <james.moger@gitblit.com>2014-10-22 22:29:05 -0400
commit1e4fc9cc867b925d82410f5ab3d5091987d60c4a (patch)
tree5ccb73a6da0d805354259f17264e4d3972b38332 /src
parent18bc0518a7b5f7e97dc54413120cb108d934b0a2 (diff)
downloadiciql-1e4fc9cc867b925d82410f5ab3d5091987d60c4a.tar.gz
iciql-1e4fc9cc867b925d82410f5ab3d5091987d60c4a.zip
Implement execution tests of nested conditions and documentation
Diffstat (limited to 'src')
-rw-r--r--src/site/model_classes.mkd4
-rw-r--r--src/site/usage.mkd40
-rw-r--r--src/test/java/com/iciql/test/IciqlSuite.java2
-rw-r--r--src/test/java/com/iciql/test/NestedConditionsTest.java (renamed from src/test/java/com/iciql/test/StackableConditionsTest.java)33
-rw-r--r--src/test/java/com/iciql/test/OneOfTest.java32
-rw-r--r--src/test/java/com/iciql/test/models/Customer.java12
6 files changed, 110 insertions, 13 deletions
diff --git a/src/site/model_classes.mkd b/src/site/model_classes.mkd
index ea91bb0..cb21dcd 100644
--- a/src/site/model_classes.mkd
+++ b/src/site/model_classes.mkd
@@ -67,7 +67,7 @@ can be used for all iciql expressions
<td>INT<br/><em>EnumType.ORDINAL</em><br/><i>can only <b>declare and explicitly reference</b> one instance of <u>each enum type</u> per model<br/>multiple instances of an enum type within a model is allowed if not using where/set/on/and/or/groupBy/orderBy(enum)</i></td></tr>
<tr><td>java.lang.Enum implements<br/><em>com.iciql.Iciql.EnumId.enumId()</em></td><td> </td>
-<td>INT<br/><em>EnumType.ENUMID</em><br/><i>can only <b>declare and explicitly reference</b> one instance of <u>each enum type</u> per model<br/>multiple instances of an enum type within a model is allowed if not using where/set/on/and/or/groupBy/orderBy(enum)</i></td></tr>
+<td><i>variable</i><br/><em>EnumType.ENUMID</em><br/><i>can only <b>declare and explicitly reference</b> one instance of <u>each enum type</u> per model<br/>multiple instances of an enum type within a model is allowed if not using where/set/on/and/or/groupBy/orderBy(enum)</i></td></tr>
<tr><td colspan="3"><b>Partially Supported Types</b><br/>
can not be directly referenced in an expression</td></tr>
@@ -383,4 +383,4 @@ public class Product {
public Product() {
}
}
----JAVA--- \ No newline at end of file
+---JAVA---
diff --git a/src/site/usage.mkd b/src/site/usage.mkd
index b1f4c48..8b54dce 100644
--- a/src/site/usage.mkd
+++ b/src/site/usage.mkd
@@ -69,6 +69,44 @@ List<Product> allProducts = db.buildObjects(Product.class, rs);
JdbcUtils.closeSilently(rs, true);
---JAVA---
+### Compound Conditions
+
+It is possible to specify type-safe compound where clauses using nested `And` and `Or` statements.
+
+---JAVA---
+final Customer model = new Customer();
+
+List<Customer> regionals =
+ db.from(model).where(model.customerId).isNotNull()
+ .and(model.region).isNotNull()
+ .and(new Or<Customer>(db, model) {{
+ or(model.region).is("LA");
+ or(model.region).is("CA");
+ }});
+
+List<Customer> regionalType1s =
+ db.from(model).where(new And<Customer>(db, model) {{
+ and(model.type).is(1);
+ and(new Or<Customer>(db, model) {{
+ or(model.region).is("CA");
+ or(model.region).is("LA");
+ }});
+ }});
+
+---JAVA---
+
+### Finding Matches for a List of Values
+
+You can use SQL's *IN* WHERE clause with the `oneOf` or `noneOf` conditions.
+
+---JAVA---
+final Customer model = new Customer();
+
+List<Customer> regionals = db.from(model).where(model.region).oneOf("CA", "LA");
+List<Customer> others = db.from(model).where(model.region).noneOf("CA", "LA");
+
+---JAVA---
+
### Read-only Views
View model classes can inherit their field definitions from a parent table model class.
@@ -232,4 +270,4 @@ for (int i = 0; i < 5; i++) {
---JAVA---
</td></tr>
-</table> \ No newline at end of file
+</table>
diff --git a/src/test/java/com/iciql/test/IciqlSuite.java b/src/test/java/com/iciql/test/IciqlSuite.java
index 0273399..c5d7ce8 100644
--- a/src/test/java/com/iciql/test/IciqlSuite.java
+++ b/src/test/java/com/iciql/test/IciqlSuite.java
@@ -93,7 +93,7 @@ import com.iciql.util.Utils;
@SuiteClasses({ AliasMapTest.class, AnnotationsTest.class, BooleanModelTest.class, ClobTest.class,
ConcurrencyTest.class, EnumsTest.class, ModelsTest.class, PrimitivesTest.class, OneOfTest.class,
RuntimeQueryTest.class, SamplesTest.class, UpdateTest.class, UpgradesTest.class, JoinTest.class,
- UUIDTest.class, ViewsTest.class, ForeignKeyTest.class, TransactionTest.class, StackableConditionsTest.class })
+ UUIDTest.class, ViewsTest.class, ForeignKeyTest.class, TransactionTest.class, NestedConditionsTest.class })
public class IciqlSuite {
private static final TestDb[] TEST_DBS = {
diff --git a/src/test/java/com/iciql/test/StackableConditionsTest.java b/src/test/java/com/iciql/test/NestedConditionsTest.java
index f812339..48bcfb3 100644
--- a/src/test/java/com/iciql/test/StackableConditionsTest.java
+++ b/src/test/java/com/iciql/test/NestedConditionsTest.java
@@ -20,6 +20,10 @@ package com.iciql.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -31,7 +35,7 @@ import com.iciql.IciqlException;
import com.iciql.QueryWhere;
import com.iciql.test.models.Customer;
-public class StackableConditionsTest {
+public class NestedConditionsTest {
enum Region {
JP, FR
@@ -42,6 +46,7 @@ public class StackableConditionsTest {
@Before
public void setUp() {
db = IciqlSuite.openNewDb();
+ db.insertAll(Customer.getList());
}
@After
@@ -68,9 +73,8 @@ public class StackableConditionsTest {
return query.toSQL();
}
- @SuppressWarnings("serial")
@Test
- public void andOrTest() {
+ public void andOrSyntaxTest() {
String Customer = db.getDialect().prepareTableName(null, "Customer");
String customerId = db.getDialect().prepareColumnName("customerId");
String region = db.getDialect().prepareColumnName("region");
@@ -155,7 +159,7 @@ public class StackableConditionsTest {
}
@Test
- public void fluentTest() {
+ public void fluentSyntaxTest() {
String Customer = db.getDialect().prepareTableName(null, "Customer");
String customerId = db.getDialect().prepareColumnName("customerId");
String region = db.getDialect().prepareColumnName("region");
@@ -194,4 +198,25 @@ public class StackableConditionsTest {
Customer, customerId, region, region, region));
}
+ @Test
+ public void compoundConditionsTest() {
+ final Customer c = new Customer();
+ List<Customer> matches = db.from(c)
+ .where(c.customerId).like("A%")
+ .and(c.region).isNotNull()
+ .and(new Or<Customer>(db, c) {{
+ or(c.region).is("LA");
+ or(c.region).is("CA");
+ }}).select();
+
+ assertEquals(2, matches.size());
+
+ Set<String> ids = new TreeSet<String>();
+ for (Customer customer : matches) {
+ ids.add(customer.customerId);
+ }
+ assertEquals("[ANTON, ASLAN]", ids.toString());
+
+ }
+
}
diff --git a/src/test/java/com/iciql/test/OneOfTest.java b/src/test/java/com/iciql/test/OneOfTest.java
index e534262..c4aa90b 100644
--- a/src/test/java/com/iciql/test/OneOfTest.java
+++ b/src/test/java/com/iciql/test/OneOfTest.java
@@ -20,6 +20,9 @@ package com.iciql.test;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
import org.junit.After;
import org.junit.Before;
@@ -36,6 +39,7 @@ public class OneOfTest {
@Before
public void setUp() {
db = IciqlSuite.openNewDb();
+ db.insertAll(Customer.getList());
}
@After
@@ -45,7 +49,7 @@ public class OneOfTest {
@SuppressWarnings("serial")
@Test
- public void oneOfTest() {
+ public void oneOfSyntaxTest() {
String PrimitivesTest = db.getDialect().prepareTableName(null, "PrimitivesTest");
String Customer = db.getDialect().prepareTableName(null, "Customer");
String myInteger = db.getDialect().prepareColumnName("myInteger");
@@ -82,7 +86,7 @@ public class OneOfTest {
@SuppressWarnings("serial")
@Test
- public void noneOfTest() {
+ public void noneOfSyntaxTest() {
String PrimitivesTest = db.getDialect().prepareTableName(null, "PrimitivesTest");
String Customer = db.getDialect().prepareTableName(null, "Customer");
String myInteger = db.getDialect().prepareColumnName("myInteger");
@@ -117,4 +121,28 @@ public class OneOfTest {
.toSQL());
}
+ public void noneOfTest() {
+ Customer c = new Customer();
+ List<Customer> meAndny = db.from(c).where(c.region).noneOf("WA", "CA", "LA").select();
+ assertEquals(2, meAndny.size());
+
+ Set<String> regions = new TreeSet<String>();
+ for (Customer customer : meAndny) {
+ regions.add(customer.region);
+ }
+ assertEquals("[ME, NY]", regions.toString());
+ }
+
+ public void oneOfTest() {
+ Customer c = new Customer();
+ List<Customer> meAndny = db.from(c).where(c.region).oneOf("ME", "NY").select();
+ assertEquals(2, meAndny.size());
+
+ Set<String> regions = new TreeSet<String>();
+ for (Customer customer : meAndny) {
+ regions.add(customer.region);
+ }
+ assertEquals("[ME, NY]", regions.toString());
+ }
+
}
diff --git a/src/test/java/com/iciql/test/models/Customer.java b/src/test/java/com/iciql/test/models/Customer.java
index ae8e40d..4270623 100644
--- a/src/test/java/com/iciql/test/models/Customer.java
+++ b/src/test/java/com/iciql/test/models/Customer.java
@@ -44,14 +44,20 @@ public class Customer {
this.region = region;
}
+ @Override
public String toString() {
return customerId;
}
public static List<Customer> getList() {
- Customer[] list = { new Customer("ALFKI", "WA"), new Customer("ANATR", "WA"),
- new Customer("ANTON", "CA") };
- return Arrays.asList(list);
+ return Arrays.asList(
+ new Customer("ALFKI", "WA"),
+ new Customer("ANATR", "WA"),
+ new Customer("ASLAN", "CA"),
+ new Customer("ANTON", "CA"),
+ new Customer("BROWN", "LA"),
+ new Customer("SMITH", "NY"),
+ new Customer("JONES", "ME"));
}
}