jochen 2005/03/02 05:35:32
Modified: src/js/org/apache/ws/jaxme/sqls/impl SQLGeneratorImpl.java
BooleanConstraintImpl.java StatementMetaData.java
CombinedConstraintImpl.java
src/js/org/apache/ws/jaxme/sqls CombinedConstraint.java
BooleanConstraint.java
src/js/org/apache/ws/jaxme/sqls/junit CreateTest.java
Log:
Added support for the BETWEEN operator.
Revision Changes Path
1.26 +12 -3
ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/SQLGeneratorImpl.java
Index: SQLGeneratorImpl.java
===================================================================
RCS file:
/home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/SQLGeneratorImpl.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- SQLGeneratorImpl.java 20 Dec 2004 11:08:16 -0000 1.25
+++ SQLGeneratorImpl.java 2 Mar 2005 13:35:32 -0000 1.26
@@ -719,6 +719,15 @@
result.append(getSelectQuery(selectStatement, pData));
result.append(")");
expected = 1;
+ } else if (BooleanConstraint.Type.BETWEEN.equals(type)) {
+ expected = 3;
+ if (pConstraint.getNumParts() >= 3) {
+ result.append(getBooleanConstraintPart(pData,
parts.next()));
+ result.append(" BETWEEN ");
+ result.append(getBooleanConstraintPart(pData,
parts.next()));
+ result.append(" AND ");
+ result.append(getBooleanConstraintPart(pData,
parts.next()));
+ }
} else {
result.append(getBooleanConstraintPart(pData, parts.next()));
if (BooleanConstraint.Type.EQ.equals(type) ||
@@ -731,7 +740,7 @@
expected = 2;
if (!parts.hasNext()) {
throw new NullPointerException("The boolean constraint "
+ type +
- " must have exactly two parts set.");
+ "
must have exactly two parts set.");
}
result.append(getBooleanConstraintType(type));
result.append(getBooleanConstraintPart(pData, parts.next()));
@@ -744,8 +753,8 @@
}
if (expected != 0 && parts.hasNext()) {
throw new NullPointerException("The boolean constraint " + type +
- " must have exactly " + expected +
- " parts set, but has " + pConstraint.getNumParts());
+ " must have exactly
" + expected +
+ " parts set, but has
" + pConstraint.getNumParts());
}
return result.toString();
}
1.5 +21 -15
ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/BooleanConstraintImpl.java
Index: BooleanConstraintImpl.java
===================================================================
RCS file:
/home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/BooleanConstraintImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BooleanConstraintImpl.java 16 Feb 2004 23:39:49 -0000 1.4
+++ BooleanConstraintImpl.java 2 Mar 2005 13:35:32 -0000 1.5
@@ -47,21 +47,27 @@
}
protected void add(Object pPart) {
- if (getType().equals(BooleanConstraint.Type.IN)) {
- // Arbitrary number of parts
- } else if (getType().equals(BooleanConstraint.Type.ISNULL)) {
- // Exactly one part
- if (getNumParts() == 1) {
- throw new IllegalStateException("An IS NULL clause cannot have more
than one part.");
- }
- } else {
- // Exactly two parts
- if (getNumParts() == 2) {
- throw new IllegalStateException("An " + getType() + " clause cannot
have more than two parts.");
- }
- }
- super.add(pPart);
- }
+ Type type = getType();
+ if (BooleanConstraint.Type.IN.equals(type)) {
+ // Arbitrary number of parts
+ } else if (BooleanConstraint.Type.ISNULL.equals(type)) {
+ // Exactly one part
+ if (getNumParts() == 1) {
+ throw new IllegalStateException("An IS NULL
clause cannot have more than one part.");
+ }
+ } else if (BooleanConstraint.Type.BETWEEN.equals(type)) {
+ // Exactly three parts
+ if (getNumParts() == 3) {
+ throw new IllegalStateException("A BETWEEN
clause cannot have more than three parts.");
+ }
+ } else {
+ // Exactly two parts
+ if (getNumParts() == 2) {
+ throw new IllegalStateException("An " +
getType() + " clause cannot have more than two parts.");
+ }
+ }
+ super.add(pPart);
+ }
public ConstrainedStatement getConstrainedStatement() {
return (ConstrainedStatement) getStatement();
1.6 +2 -1
ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/StatementMetaData.java
Index: StatementMetaData.java
===================================================================
RCS file:
/home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/StatementMetaData.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StatementMetaData.java 22 Sep 2004 10:05:53 -0000 1.5
+++ StatementMetaData.java 2 Mar 2005 13:35:32 -0000 1.6
@@ -229,7 +229,8 @@
|| BooleanConstraint.Type.LE.equals(type)
|| BooleanConstraint.Type.LIKE.equals(type)
|| BooleanConstraint.Type.LT.equals(type)
- || BooleanConstraint.Type.NE.equals(type)) {
+ || BooleanConstraint.Type.NE.equals(type)
+ || BooleanConstraint.Type.BETWEEN.equals(type)) {
addParts(pConstraint);
} else {
throw new IllegalStateException("Invalid part type in
BooleanConstraint: " + type);
1.7 +7 -1
ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/CombinedConstraintImpl.java
Index: CombinedConstraintImpl.java
===================================================================
RCS file:
/home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/CombinedConstraintImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CombinedConstraintImpl.java 17 Feb 2005 16:07:43 -0000 1.6
+++ CombinedConstraintImpl.java 2 Mar 2005 13:35:32 -0000 1.7
@@ -139,7 +139,13 @@
parts.add(bc);
bc.addPart(pStatement);
}
-
+
+ public BooleanConstraint createBETWEEN() {
+ BooleanConstraint result = new BooleanConstraintImpl(this,
BooleanConstraint.Type.BETWEEN);
+ parts.add(result);
+ return result;
+ }
+
public void addColumnSetQuery(ColumnSet pSet, TableReference
pTableReference) {
if (!pTableReference.getTable().equals(pSet.getTable())) {
throw new IllegalStateException("The foreign keys referencing
table is " +
1.6 +5 -0
ws-jaxme/src/js/org/apache/ws/jaxme/sqls/CombinedConstraint.java
Index: CombinedConstraint.java
===================================================================
RCS file:
/home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/sqls/CombinedConstraint.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CombinedConstraint.java 7 Oct 2004 22:12:13 -0000 1.5
+++ CombinedConstraint.java 2 Mar 2005 13:35:32 -0000 1.6
@@ -95,6 +95,11 @@
*/
public void createEXISTS(SelectStatement pStatement);
+ /** Creates a "BETWEEN" condition with the given select
+ * statement and inserts it at the current position.
+ */
+ public BooleanConstraint createBETWEEN();
+
/** Creates a JOIN condition matching the given foreign key. In other
* words, if the foreign key consists of the columns <code>A</code> and
* <code>B</code> referencing the columns <code>X</code> and
<code>Y</code>,
1.8 +3 -0
ws-jaxme/src/js/org/apache/ws/jaxme/sqls/BooleanConstraint.java
Index: BooleanConstraint.java
===================================================================
RCS file:
/home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/sqls/BooleanConstraint.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- BooleanConstraint.java 2 Dec 2004 20:41:13 -0000 1.7
+++ BooleanConstraint.java 2 Mar 2005 13:35:32 -0000 1.8
@@ -54,6 +54,9 @@
/** A boolean constraint matching the "EXISTS" condition.
*/
public static final Type EXISTS = new
BooleanConstraintImpl.TypeImpl("EXISTS");
+ /** A boolean constraint matching the "BETWEEN" condition.
+ */
+ public static final Type BETWEEN = new
BooleanConstraintImpl.TypeImpl("BETWEEN");
}
/** <p>Returns the boolean constraints type.</p>
1.11 +18 -1
ws-jaxme/src/js/org/apache/ws/jaxme/sqls/junit/CreateTest.java
Index: CreateTest.java
===================================================================
RCS file:
/home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/sqls/junit/CreateTest.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- CreateTest.java 28 Jun 2004 07:19:05 -0000 1.10
+++ CreateTest.java 2 Mar 2005 13:35:32 -0000 1.11
@@ -299,7 +299,24 @@
" FROM MySchema.OtherTable WHERE RefIndex=MyTable.MyIndex)";
assertEquals(expect, got);
}
-
+
+ /** <p>Test for a BETWEEN clause.</p>
+ */
+ public void testBetween() {
+ Table table = getBasicTable();
+ SelectStatement statement = table.getSelectStatement();
+ BooleanConstraint between =
statement.getWhere().createBETWEEN();
+
between.addPart(statement.getTableReference().newColumnReference("MyIndex"));
+ between.addPart(3);
+ between.addPart(5);
+
+ SQLGenerator generator = getSQLGenerator();
+ generator.setLineTerminator("\n");
+ String got = generator.getQuery(statement);
+ String expect = "SELECT MyIndex, MyName, MyDate FROM
MySchema.MyTable WHERE MyIndex BETWEEN 3 AND 5";
+ assertEquals(expect, got);
+ }
+
/** <p>Creates a table with a composed primary key.</p>
*/
protected Table getComposedKeyTable() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]