summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--sqlelements/pom.xml169
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/AbstractAliasedSQLElement.java64
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/AbstractCommand.java56
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/AbstractJoin.java57
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/AbstractParameterizedCommand.java80
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/AbstractStatement.java68
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/AbstractTable.java48
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/AliasedSQLElement.java42
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/Column.java45
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/Command.java42
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/Delete.java79
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/InnerJoin.java73
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/Join.java45
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/LeftOuterJoin.java56
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/LiteralColumn.java71
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/ParameterizedCommand.java44
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/Query.java55
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/SQLElement.java40
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/SQLParameter.java59
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/Select.java177
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/SelectTable.java82
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/SimpleColumn.java101
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/SimpleTable.java76
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/Statement.java51
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/Table.java41
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/Update.java81
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/constraints/And.java51
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/constraints/ArbitraryStringConstraint.java57
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/constraints/BetweenRange.java86
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/constraints/BinaryConstraint.java62
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/constraints/ColumnConstraint.java65
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/constraints/ComplexConstraint.java43
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/constraints/Constraint.java42
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/constraints/ConstraintUtils.java48
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/constraints/Equals.java45
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/constraints/JoinConstraint.java56
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/constraints/NaryConstraint.java93
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/constraints/Not.java53
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/constraints/NotEquals.java46
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/constraints/Or.java51
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/constraints/SimpleConstraint.java42
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/render/CommandRenderer.java44
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/render/DatabaseType.java119
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/render/DateRenderer.java42
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/render/DelegatedSQLRenderEngine.java73
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/render/GenericSQLRenderEngine.java94
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/render/MockSQLRenderEngine.java60
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/render/MySqlSQLRenderEngine.java40
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/render/OracleSQLRenderEngine.java97
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/render/QueryRenderer.java44
-rw-r--r--sqlelements/src/main/java/org/israfil/sqlelements/render/SQLRenderContext.java97
-rw-r--r--sqlelements/src/site/apt/index.apt14
-rw-r--r--sqlelements/src/site/apt/license.apt48
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/AbstractAliasedSQLElementTest.java88
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/AllTests.java64
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/ColumnTest.java89
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/ComplexSampleQueriesTest.java145
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/DatabaseTypeTest.java60
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/DeleteTest.java94
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/JoinTest.java74
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/ParameterizedCommandTest.java70
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/QueryTest.java209
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/SimpleTableTest.java106
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/UpdateTest.java89
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/constraints/AllTests.java59
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/constraints/BetweenRangeConstraintTest.java63
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/constraints/ColumnConstraintTest.java76
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/constraints/EqualsConstraintTest.java62
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/constraints/LogicalConstraintsTest.java119
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/constraints/MockConstraintTest.java61
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/constraints/NaryConstraintTest.java142
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/constraints/NotEqualsConstraintTest.java62
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/mock/MockAliasedElement.java56
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/mock/MockConstraint.java64
-rw-r--r--sqlelements/src/test/java/org/israfil/sqlelements/mock/MockNaryConstraint.java57
76 files changed, 5328 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a21c345
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+.svn
+.classpath
+.project
+.settings
+target
diff --git a/sqlelements/pom.xml b/sqlelements/pom.xml
new file mode 100644
index 0000000..6c25526
--- /dev/null
+++ b/sqlelements/pom.xml
@@ -0,0 +1,169 @@
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.israfil</groupId>
+ <artifactId>sqlelements</artifactId>
+ <packaging>jar</packaging>
+ <version>0.9-SNAPSHOT</version>
+ <name>SQLElements</name>
+ <url>http://sqlelements.sourceforge.net</url>
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <!--
+ <plugin>
+ <artifactId>maven-release-plugin</artifactId>
+ <configuration>
+ <tagBase>svn+ssh://source.israfil.net/repos/svn/israfil.foundation/tags</tagBase>
+ </configuration>
+ </plugin>
+ -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>11</source>
+ <target>11</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.israfil.foundation</groupId>
+ <artifactId>israfil-foundation-cache</artifactId>
+ <version>1.0.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>net.israfil.foundation</groupId>
+ <artifactId>israfil-foundation-collections</artifactId>
+ <version>1.0.3-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+ <issueManagement>
+ <system>SourceForge</system>
+ <url>http://sourceforge.net/tracker/?group_id=139021</url>
+ </issueManagement>
+ <ciManagement>
+ <system>continuum</system>
+ <url/>
+ <notifiers>
+ <notifier>
+ <type/>
+ <sendOnError/>
+ <sendOnFailure/>
+ <sendOnSuccess/>
+ <sendOnWarning/>
+ <address/>
+ <configuration/>
+ </notifier>
+ </notifiers>
+ </ciManagement>
+ <inceptionYear>2005</inceptionYear>
+ <mailingLists>
+ <mailingList>
+ <name>sqlelements-cvs</name>
+ <subscribe>http://lists.sourceforge.net/lists/listinfo/sqlelements-cvs</subscribe>
+ <post>sqlelements-cvs@lists.sourceforge.net</post>
+ <!-- <archive/><otherArchives/> -->
+ </mailingList>
+ <mailingList>
+ <name>sqlelements-devel</name>
+ <subscribe>http://lists.sourceforge.net/lists/listinfo/sqlelements-devel</subscribe>
+ <post>sqlelements-devel@lists.sourceforge.net</post>
+ <!-- <archive/><otherArchives/> -->
+ </mailingList>
+ </mailingLists>
+ <developers>
+ <developer>
+ <!--<id>cgruber</id>-->
+ <name>Christian Gruber</name>
+ <email>cgruber@israfil.net</email>
+ <organization>Israfil Consulting Services Corporation</organization>
+ <url>http://www.israfil.net/</url>
+ <timezone>-5</timezone>
+ <roles>
+ <role>Admin</role>
+ <role>Architect</role>
+ <role>Developer</role>
+ <role>Build Manager</role>
+ </roles>
+ </developer>
+ <developer>
+ <!--<id>under_score</id>-->
+ <name>Miskhin Berteig</name>
+ <email>mishkin@berteigconsulting.com</email>
+ <organization>Berteig Consulting, Inc.</organization>
+ <url>http://www.berteigconsulting.com/</url>
+ <timezone>-5</timezone>
+ <roles>
+ <role>Developer</role>
+ <role>Test Auditor</role>
+ </roles>
+ </developer>
+ </developers>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <configuration>
+ <targetJdk>1.5</targetJdk>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>surefire-report-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
+ <scm>
+ <connection>
+ scm:cvs:pserver:anonymous@anoncvs.sourceforge.net:/cvsroot/sqlelements:sqlelements
+ </connection>
+ <developerConnection>
+ scm:cvs:extssh:username@cvs.sourceforge.net:/cvsroot/sqlelements:sqlelements
+ </developerConnection>
+ <url>http://cvs.sourceforge.net/viewcvs.py/sqlelements</url>
+ </scm>
+ <repositories>
+ <repository>
+ <id>ibiblio</id>
+ <name>iBiblio Mojo</name>
+ <url>http://www.ibiblio.org/maven2</url>
+ </repository>
+ </repositories>
+ <distributionManagement>
+ <!-- use the following if you're not using a snapshot version. -->
+ <repository>
+ <id>local</id>
+ <name>Local Deploy</name>
+ <url>ftp://uploads.sourceforge.net/incoming</url>
+ <!--<url>file:///E:/tmp/i-deploy</url>-->
+ </repository>
+ <!-- use the following if you ARE using a snapshot version. -->
+ <snapshotRepository>
+ <id>local</id>
+ <name>Local Snapshot</name>
+ <url>ftp://uploads.sourceforge.net/incoming</url>
+ <!--<url>file:///E:/tmp/i-deploy</url>-->
+ </snapshotRepository>
+ <site>
+ <id>website</id>
+ <url>scp://cgruber@shell.sourceforge.net/home/groups/s/sq/sqlelements/htdocs</url>
+ </site>
+ </distributionManagement>
+</project>
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/AbstractAliasedSQLElement.java b/sqlelements/src/main/java/org/israfil/sqlelements/AbstractAliasedSQLElement.java
new file mode 100644
index 0000000..e534187
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/AbstractAliasedSQLElement.java
@@ -0,0 +1,64 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: AbstractAliasedSQLElement.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public abstract class AbstractAliasedSQLElement implements AliasedSQLElement {
+ protected String alias;
+
+ public String getAlias() {
+ return alias;
+ }
+
+ public void setAlias(String value) {
+ alias = value;
+ }
+
+ public boolean hasAlias() {
+ return (alias != null && !alias.equals(""));
+ }
+
+ public AbstractAliasedSQLElement() {
+ }
+
+ public AbstractAliasedSQLElement(String alias) {
+ this.alias = alias;
+ }
+
+ public void finalize() throws Throwable {
+ alias = null;
+ }
+
+}
+
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/AbstractCommand.java b/sqlelements/src/main/java/org/israfil/sqlelements/AbstractCommand.java
new file mode 100644
index 0000000..2f8b412
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/AbstractCommand.java
@@ -0,0 +1,56 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: AbstractCommand.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import java.util.List;
+
+import org.israfil.sqlelements.constraints.Constraint;
+
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 25 $
+ */
+public abstract class AbstractCommand extends AbstractStatement implements Command {
+
+ protected Table table = null;
+ public Table getTable() { return table; }
+
+ public List<Column> getColumns() { return null; }
+
+ protected AbstractCommand() {
+ super();
+ }
+
+ public AbstractCommand (Constraint constraint) {
+ super(constraint);
+ }
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/AbstractJoin.java b/sqlelements/src/main/java/org/israfil/sqlelements/AbstractJoin.java
new file mode 100644
index 0000000..ffc0db8
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/AbstractJoin.java
@@ -0,0 +1,57 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: AbstractJoin.java 22 2005-12-11 15:08:56Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+
+/**
+ * Represents a single column from a single (physical or virtual) table.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 22 $
+ */
+public abstract class AbstractJoin implements Join {
+ protected Column left;
+ protected Column right;
+
+ public Column getLeftColumn() { return this.left; }
+ public Column getRightColumn() { return this.right; }
+
+ public AbstractJoin(Column left, Column right)
+ {
+ if (left.getTable() == null || right.getTable() == null)
+ throw new IllegalArgumentException("Cannot assign a Column with no Table to a Join");
+ this.left = left;
+ this.right = right;
+ }
+
+ public abstract String render(SQLRenderContext context);
+} \ No newline at end of file
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/AbstractParameterizedCommand.java b/sqlelements/src/main/java/org/israfil/sqlelements/AbstractParameterizedCommand.java
new file mode 100644
index 0000000..6ba7d60
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/AbstractParameterizedCommand.java
@@ -0,0 +1,80 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: AbstractParameterizedCommand.java 27 2006-01-14 12:50:08Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import java.util.Set;
+
+import net.israfil.foundation.collections.ArraySet;
+
+import org.israfil.sqlelements.constraints.Constraint;
+
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 27 $
+ */
+public abstract class AbstractParameterizedCommand extends AbstractCommand implements ParameterizedCommand {
+
+ protected Set<SQLParameter> parameters = new ArraySet<SQLParameter>();
+ public Set<SQLParameter> getParameters() { return parameters; }
+
+ protected AbstractParameterizedCommand() {
+ super();
+ }
+
+ public AbstractParameterizedCommand (Constraint constraint, SQLParameter ... parameters) {
+ super(constraint);
+ setParameters(parameters);
+ }
+
+ public void setParameters(SQLParameter ... parameters)
+ {
+ for (SQLParameter p : parameters) setParameter(p);
+ }
+
+ public void setParameter(SQLParameter parameter)
+ {
+ if (parameter.column.getTable() == null) throw new IllegalArgumentException("Must supply column in parameters that contain a table.");
+ if (table == null) table = parameter.column.getTable();
+ if (!table.equals(parameter.column.getTable())) throw new IllegalArgumentException("Must supply columns only from the same table.");
+ for (SQLParameter current : parameters)
+ if (current.column == parameter.column) parameters.remove(current);
+ parameters.add(parameter);
+ }
+
+ public void setParameter(Column c,Object v) {
+ setParameter(new SQLParameter(c,v));
+ }
+
+ public Object getParameterValue(Column c) {
+ for (SQLParameter p : parameters) if (p.column == c) return p.value;
+ return null;
+ }
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/AbstractStatement.java b/sqlelements/src/main/java/org/israfil/sqlelements/AbstractStatement.java
new file mode 100644
index 0000000..6f8890b
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/AbstractStatement.java
@@ -0,0 +1,68 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: AbstractStatement.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import org.israfil.sqlelements.constraints.Constraint;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ * Abstract Superclass containing some shared infrastructure for queries and
+ * commands.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 25 $
+ */
+public abstract class AbstractStatement implements Statement {
+
+ protected Constraint constraint;
+
+ public boolean hasConstraint() {
+ return (constraint != null);
+ }
+
+ public Constraint getConstraint() {
+ return this.constraint;
+ }
+
+ public void setConstraint(Constraint value) {
+ this.constraint = value;
+ }
+
+ protected AbstractStatement() {
+ }
+
+ protected AbstractStatement(Constraint constraint) {
+ this.constraint = constraint;
+ }
+
+ public abstract String render(SQLRenderContext context);
+
+ public abstract Object clone() throws CloneNotSupportedException;
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/AbstractTable.java b/sqlelements/src/main/java/org/israfil/sqlelements/AbstractTable.java
new file mode 100644
index 0000000..a3b8f07
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/AbstractTable.java
@@ -0,0 +1,48 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: AbstractTable.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+/**
+ * Abstract Superclass containing some shared infrastructure Table objects.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public abstract class AbstractTable extends AbstractAliasedSQLElement implements Table {
+
+ public AbstractTable(String alias) {
+ super(alias);
+ }
+
+ public void setAlias(String value) {
+ this.alias = value;
+ }
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/AliasedSQLElement.java b/sqlelements/src/main/java/org/israfil/sqlelements/AliasedSQLElement.java
new file mode 100644
index 0000000..f0828dd
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/AliasedSQLElement.java
@@ -0,0 +1,42 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: AliasedSQLElement.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+/**
+ *
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public interface AliasedSQLElement extends SQLElement {
+ public String getAlias();
+
+ public boolean hasAlias();
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/Column.java b/sqlelements/src/main/java/org/israfil/sqlelements/Column.java
new file mode 100644
index 0000000..7f63664
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/Column.java
@@ -0,0 +1,45 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: Column.java 27 2006-01-14 12:50:08Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+
+/**
+ * Represents a single column from a single (physical or virtual) table.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 27 $
+ */
+public interface Column extends AliasedSQLElement
+{
+ public String getName();
+
+ public Table getTable();
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/Command.java b/sqlelements/src/main/java/org/israfil/sqlelements/Command.java
new file mode 100644
index 0000000..0ed6e69
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/Command.java
@@ -0,0 +1,42 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: Command.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 25 $
+ */
+public interface Command extends Statement {
+
+ public Table getTable();
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/Delete.java b/sqlelements/src/main/java/org/israfil/sqlelements/Delete.java
new file mode 100644
index 0000000..234dfce
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/Delete.java
@@ -0,0 +1,79 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: Delete.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import org.israfil.sqlelements.constraints.Constraint;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 25 $
+ */
+public class Delete extends AbstractStatement implements Command
+{
+ protected Table table;
+ public Table getTable() { return table; }
+
+ //public CommandType CommandType { get { return System.Data.CommandType.Text; } }
+
+ public Delete() {
+ super();
+ }
+
+ public Delete (Table table, Constraint constraint)
+ {
+ super(constraint);
+ this.table = table;
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ Delete delete = new Delete();
+ delete.table = this.table;
+ delete.constraint = this.constraint;
+ return delete;
+ }
+
+ public String render(SQLRenderContext context)
+ {
+ if (table == null) throw new IllegalStateException("Table cannot be null.");
+ String sql = "delete from ";
+ sql += table.render(context);
+ if (this.hasConstraint()) {
+ sql += " ";
+ sql += context.getAlias(table);
+ }
+ if (this.hasConstraint()) {
+ sql += " where ";
+ sql += this.constraint.render(context);
+ }
+ return sql;
+ }
+} \ No newline at end of file
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/InnerJoin.java b/sqlelements/src/main/java/org/israfil/sqlelements/InnerJoin.java
new file mode 100644
index 0000000..9d122fe
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/InnerJoin.java
@@ -0,0 +1,73 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: InnerJoin.java 22 2005-12-11 15:08:56Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ * A Constraint wrapper around a Join object
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 22 $
+ */
+public class InnerJoin extends AbstractJoin {
+
+
+ /**
+ * This constructs an inner join based on equality of two
+ * columns. Note: each column must contain a Table reference
+ */
+ public InnerJoin(Column left, Column right) {
+ super(left,right);
+ }
+
+ /**
+ * This constructor creates an InnerJoin based on a column of
+ * the same name that occurs in two tables - specifically where
+ * they are equal. This is a convenience constructor which
+ * creates a Column object for the column name in each table.
+ *
+ * @param columnName
+ * @param left
+ * @param right
+ */
+ public InnerJoin(String columnName,Table left,Table right) {
+ this(new SimpleColumn(left,columnName),new SimpleColumn(right,columnName));
+ }
+
+ public String render(SQLRenderContext context) {
+
+ String sql = context.getAlias(left.getTable()) + "." + left.render(context);
+ sql += " = ";
+ sql += context.getAlias(right.getTable()) + "." + right.render(context);
+ return sql;
+ }
+
+} \ No newline at end of file
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/Join.java b/sqlelements/src/main/java/org/israfil/sqlelements/Join.java
new file mode 100644
index 0000000..14d0722
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/Join.java
@@ -0,0 +1,45 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: Join.java 22 2005-12-11 15:08:56Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ * Represents a single column from a single (physical or virtual) table.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 22 $
+ */
+public interface Join /*extends ComplexConstraint*/
+{
+ public Column getLeftColumn();
+ public Column getRightColumn();
+ public String render(SQLRenderContext context);
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/LeftOuterJoin.java b/sqlelements/src/main/java/org/israfil/sqlelements/LeftOuterJoin.java
new file mode 100644
index 0000000..9765e59
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/LeftOuterJoin.java
@@ -0,0 +1,56 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: LeftOuterJoin.java 22 2005-12-11 15:08:56Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ * Represents a single column from a single (physical or virtual) table.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 22 $
+ */
+public class LeftOuterJoin extends AbstractJoin
+{
+ public LeftOuterJoin(Column left, Column right) {
+ super(left,right);
+ }
+ public LeftOuterJoin(String columnName,Table left,Table right) {
+ this(new SimpleColumn(left,columnName),new SimpleColumn(right,columnName));
+ }
+ public String render(SQLRenderContext context)
+ {
+ String sql = context.getAlias(left.getTable()) + "." + left.render(context);
+ sql += " = ";
+ sql += context.getAlias(right.getTable()) + "." + right.render(context);
+ sql += " (+)";
+ return sql;
+ }
+} \ No newline at end of file
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/LiteralColumn.java b/sqlelements/src/main/java/org/israfil/sqlelements/LiteralColumn.java
new file mode 100644
index 0000000..5deac63
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/LiteralColumn.java
@@ -0,0 +1,71 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: LiteralColumn.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import java.util.Date;
+
+import org.israfil.sqlelements.render.DatabaseType;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+
+/**
+ * A simple implementation of a Column which takes a name and a table. The table
+ * can be any Table object.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 25 $
+ */
+public class LiteralColumn extends AbstractAliasedSQLElement implements Column {
+
+ public Table getTable() { return null; }
+
+ protected Object literal;
+ public String getName() { return render(new SQLRenderContext(DatabaseType.Generic)); }
+ public Object getLiteral() { return literal; }
+
+ public LiteralColumn(Object literal) {
+ super();
+ this.literal = literal;
+ }
+
+ public LiteralColumn(Object literal, String alias)
+ {
+ super(alias);
+ this.literal = literal;
+ }
+
+
+ public String render(SQLRenderContext context) {
+ if (literal == null) return "null";
+ if (literal instanceof String || literal instanceof Enum) return context.getStringDelimiter() + literal + context.getStringDelimiter();
+ if (literal instanceof Date) return context.format((Date)literal);
+ return literal.toString();
+ }
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/ParameterizedCommand.java b/sqlelements/src/main/java/org/israfil/sqlelements/ParameterizedCommand.java
new file mode 100644
index 0000000..c173cd5
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/ParameterizedCommand.java
@@ -0,0 +1,44 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: ParameterizedCommand.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import java.util.Set;
+
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 25 $
+ */
+public interface ParameterizedCommand extends Command {
+ Set<SQLParameter> getParameters();
+ void setParameters(SQLParameter ... parameters);
+ void setParameter(SQLParameter parameter);
+ Object getParameterValue(Column c);
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/Query.java b/sqlelements/src/main/java/org/israfil/sqlelements/Query.java
new file mode 100644
index 0000000..fff3411
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/Query.java
@@ -0,0 +1,55 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: Query.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import java.util.List;
+import java.util.Set;
+
+import org.israfil.sqlelements.constraints.Constraint;
+
+/**
+ *
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 25 $
+ */
+public interface Query extends Statement {
+
+ public List<Column> getColumns();
+
+ public Set<Table> getTables();
+
+ public boolean hasJoins();
+
+ public Set<Constraint> getJoinConstraints();
+
+ public Set<Join> getJoins();
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/SQLElement.java b/sqlelements/src/main/java/org/israfil/sqlelements/SQLElement.java
new file mode 100644
index 0000000..3d320c7
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/SQLElement.java
@@ -0,0 +1,40 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: SQLElement.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public interface SQLElement extends Cloneable {
+ public String render(SQLRenderContext context);
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/SQLParameter.java b/sqlelements/src/main/java/org/israfil/sqlelements/SQLParameter.java
new file mode 100644
index 0000000..4bd6614
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/SQLParameter.java
@@ -0,0 +1,59 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: SQLParameter.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 25 $
+ */
+public class SQLParameter {
+ //public final static SQLParameter NULL = new SQLParameter();
+ public final Column column;
+ public Object value;
+
+ public SQLParameter(Column column) {
+ if (column == null) throw new IllegalArgumentException("SQLParameter column cannot be null.");
+ this.column = column;
+ this.value = null;
+ }
+
+ public SQLParameter(Column column, Object val) {
+ if (column == null) throw new IllegalArgumentException("SQLParameter column cannot be null.");
+ this.column = column;
+ this.value = val;
+ }
+
+ public String toString() {
+ return "SQLParameter[" + column + "," + value + "]";
+ }
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/Select.java b/sqlelements/src/main/java/org/israfil/sqlelements/Select.java
new file mode 100644
index 0000000..90a4946
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/Select.java
@@ -0,0 +1,177 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: Select.java 27 2006-01-14 12:50:08Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import net.israfil.foundation.collections.ArraySet;
+import net.israfil.foundation.collections.ArrayUtils;
+
+import org.israfil.sqlelements.constraints.Constraint;
+import org.israfil.sqlelements.constraints.JoinConstraint;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ *
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 27 $
+ */
+public class Select extends AbstractStatement implements Query {
+
+
+ protected Set<Join> joins;
+ public boolean hasJoins() { return (joins != null && joins.size() > 0); }
+ public Set<Join> getJoins() { return this.joins; }
+
+ /*
+ * Return the available joins as a set of constraints.
+ *
+ * @return getJoinsAsConstraints a Set<Constraint> containing current joins.
+ */
+ public Set<Constraint> getJoinConstraints() {
+
+ //Implementation notes:
+ //
+ //For some crazy reason, you can't cast the following:
+ //<pre>
+ //class C {}
+ //class D extends C {}
+ //public void example() {
+ // Set<D> d = new HashSet<D>();
+ // Set<C> c = d;
+ //}
+ //</pre>
+ //
+ //The above code will fail on a conversion error, even
+ //though semantically, it can be guarranteed that Set<D> isa Set<C>.
+ //The problem is likely that if you allowed Set<D> to be assigned to
+ //Set<C>, and then one attempted to add an object of type E, where
+ //E extends C, it would fail, violating Set<C>'s contract.
+ //
+ //So we just re-wrap the joins in a Set<Constraint>
+
+ Set<Constraint> jc = new ArraySet<Constraint>();
+ for (Join j : joins) {
+ jc.add(new JoinConstraint(j));
+ }
+ return jc;
+ }
+
+ protected Select() {
+ super();
+ }
+
+ public Select (Column column, Join ... joins) {
+ this(new Column[] { column },joins);
+ }
+
+ public Select (Column[] columns, Join ... joins) {
+ this(columns,null,joins);
+ }
+
+ public Select (Column column, Constraint constraint, Join ... joins) {
+ this(new Column[] { column },constraint,joins);
+ }
+
+ public Select (Column[] columns, Constraint constraint, Join ... joins) {
+ super(constraint);
+ this.addColumns(columns);
+ this.addJoins(joins);
+ }
+
+ protected List<Column> columns;
+ public List<Column> getColumns() { return this.columns; }
+
+ public Set<Table> getTables() {
+ Set<Table> tables = new ArraySet<Table>();
+ for (Column c : this.columns) {
+ Table table = c.getTable();
+ if (table != null) tables.add(table);
+ }
+ for (Join j : this.joins) {
+ if (j.getLeftColumn().getTable() != null) tables.add(j.getLeftColumn().getTable());
+ if (j.getRightColumn().getTable() != null) tables.add(j.getRightColumn().getTable());
+ }
+ return tables;
+ }
+
+ public void addJoins(Join ... newJoins) {
+ if (this.joins == null) this.joins = new ArraySet<Join>();
+ for (Join j : newJoins) {
+ this.joins.add(j);
+ }
+ }
+
+ public void addJoins(Set<Join> joins) {
+ if (this.joins == null) this.joins = new ArraySet<Join>();
+ for (Join j : joins) {
+ this.joins.add(j);
+ }
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ Select newSelect = new Select();
+ newSelect.addColumns(this.columns);
+ newSelect.addJoins(this.joins);
+ newSelect.constraint = this.constraint;
+ return newSelect;
+ }
+
+
+
+ public void addColumns(Column ... cols) {
+ if (this.columns == null) this.columns = new ArrayList<Column>();
+ for (Column c : cols) {
+ this.columns.add(c);
+ }
+ }
+ public void addColumns(List<Column> cols) {
+ if (this.columns == null) this.columns = new ArrayList<Column>();
+ for (Column c : cols) {
+ this.columns.add(c);
+ }
+ }
+
+ protected void clearColumns() {
+ columns = new ArrayList<Column>();
+ }
+
+ public String render(SQLRenderContext context) {
+ return context.renderQuery(this);
+ }
+
+ public static Column[] aggregate(Column[] ... columns) {
+ return ArrayUtils.aggregate(new Column[0],columns);
+ }
+}
+
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/SelectTable.java b/sqlelements/src/main/java/org/israfil/sqlelements/SelectTable.java
new file mode 100644
index 0000000..7adcaf3
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/SelectTable.java
@@ -0,0 +1,82 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: SelectTable.java 17 2005-12-10 20:06:44Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ * A Table implementation that wraps a sub-select. Used to implement sql such as
+ * "select * from at_job_wk_registry where job_id = (select max(job_id) from at_job)".
+ * the inner select would be represented via a SelectTable object.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 17 $
+ */
+
+public class SelectTable extends AbstractTable {
+ /// <summary>The inner query.</summary>
+ public final Query query;
+
+ /// <summary>Constructor</summary>
+ public SelectTable(Query query) {
+ this(query,null);
+ }
+
+ /// <summary>Constructor</summary>
+ public SelectTable(Query query, String alias) {
+ super(alias);
+ this.query=query;
+ }
+
+ /**
+ * Pretty printed string representation of the object
+ */
+ @Override
+ public String toString()
+ {
+ return "SelectTable[" + query.toString() + "]";
+ }
+
+ /** Implementation of Object.clone() */
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ SelectTable st = new SelectTable((Query)this.query.clone());
+ if (this.hasAlias()) st.setAlias(this.getAlias());
+ return st;
+ }
+
+ /** @see SQLElement.render(SQLRenderContext) */
+ public String render(SQLRenderContext context)
+ {
+ if (alias == null && "".equalsIgnoreCase(alias)) return "( " + query.render(context) + ")";
+ else return "( " + query.render(context) + ") " + alias;
+ }
+
+} \ No newline at end of file
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/SimpleColumn.java b/sqlelements/src/main/java/org/israfil/sqlelements/SimpleColumn.java
new file mode 100644
index 0000000..d5919aa
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/SimpleColumn.java
@@ -0,0 +1,101 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: SimpleColumn.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ * A simple implementation of a Column which takes a name and a table. The table
+ * can be any Table object.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 25 $
+ */
+public class SimpleColumn extends AbstractAliasedSQLElement implements Column
+{
+
+ protected Table table;
+ public Table getTable() { return table; }
+
+ protected String name;
+ public String getName() { return name; }
+
+ /**
+ * Constructs a Column implementation instance
+ *
+ * @param table A Table object of which this Column is a field.
+ * @param colName The name of this column
+ */
+ public SimpleColumn(Table table, String colName) {
+ this(table,colName,null);
+ }
+
+ /**
+ * Constructs a Column implementation instance
+ *
+ * @param table A Table object of which this Column is a field.
+ * @param colName The name of this column
+ * @param alias An alternate designation for this column - usually shorter
+ */
+ public SimpleColumn(Table table, String colName, String alias)
+ {
+ super(alias);
+ this.table = table;
+ this.name = colName;
+ }
+
+ public String render(SQLRenderContext context)
+ {
+ return this.name;
+ }
+
+ /**
+ * Convenience method to create batches of SimpleColumns from an array
+ * of names. Note: this cannot be used to create SimpleColumns with
+ * aliases.
+ *
+ * @param table A table, within whom the columns will be created.
+ * @param names An array of column names
+ * @return an array of SimpleColumns
+ */
+ public static SimpleColumn[] createColumns(Table table, String ... names)
+ {
+ SimpleColumn[] result = new SimpleColumn[names.length];
+ for (int i = 0; i < names.length; i++)
+ result[i] = new SimpleColumn(table,names[i]);
+ return result;
+ }
+
+ public String toString()
+ {
+ return "SimpleColumn[" + table + "," + name + "]";
+ }
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/SimpleTable.java b/sqlelements/src/main/java/org/israfil/sqlelements/SimpleTable.java
new file mode 100644
index 0000000..722a3d0
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/SimpleTable.java
@@ -0,0 +1,76 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: SimpleTable.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ * An object representation of a simple table from which columns can be
+ * selected.
+ *
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public class SimpleTable extends AbstractTable {
+
+ protected String name;
+
+ public SimpleTable(String name) {
+ this(name, null);
+ }
+
+ public SimpleTable(String name, String alias) {
+ super(alias);
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String toString() {
+ if (this.hasAlias())
+ return "SimpleTable[" + name + " " + alias +"]";
+ else return "SimpleTable[" + name + "]";
+ }
+
+ public Object clone() {
+ SimpleTable st = new SimpleTable(this.name);
+ if (this.hasAlias())
+ st.alias = this.alias;
+ return st;
+ }
+
+ public String render(SQLRenderContext context) {
+ return name;
+ }
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/Statement.java b/sqlelements/src/main/java/org/israfil/sqlelements/Statement.java
new file mode 100644
index 0000000..eddfcac
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/Statement.java
@@ -0,0 +1,51 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: Statement.java 17 2005-12-10 20:06:44Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import org.israfil.sqlelements.constraints.Constraint;
+
+/**
+ * A SQLElement containing the elements of a SQL query or command
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 17 $
+ */
+
+public interface Statement extends SQLElement, Cloneable {
+
+ public boolean hasConstraint();
+
+ public Constraint getConstraint();
+
+ public void setConstraint(Constraint c);
+
+ public Object clone() throws CloneNotSupportedException;
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/Table.java b/sqlelements/src/main/java/org/israfil/sqlelements/Table.java
new file mode 100644
index 0000000..a4f721c
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/Table.java
@@ -0,0 +1,41 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: Table.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public interface Table extends AliasedSQLElement, Cloneable {
+ public void setAlias(String alias);
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/Update.java b/sqlelements/src/main/java/org/israfil/sqlelements/Update.java
new file mode 100644
index 0000000..21fa01b
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/Update.java
@@ -0,0 +1,81 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: Update.java 27 2006-01-14 12:50:08Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import net.israfil.foundation.collections.ArraySet;
+
+import org.israfil.sqlelements.constraints.Constraint;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 27 $
+ */
+public class Update extends AbstractParameterizedCommand {
+ public Update() {
+ super();
+ }
+ public Update(SQLParameter ... parameters) {
+ this(null,parameters);
+ }
+ public Update (Constraint constraint, SQLParameter ... parameters) {
+ super(constraint,parameters);
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ Update update = new Update();
+ update.constraint = this.constraint;
+ update.parameters = new ArraySet<SQLParameter>(this.parameters);
+ return update;
+ }
+
+ public String render(SQLRenderContext context)
+ {
+ if (table == null) throw new IllegalStateException("Table cannot be null.");
+ String sql = "update ";
+ sql += table.render(context);
+ if (this.hasConstraint()) {
+ sql += " ";
+ sql += context.getAlias(table);
+ }
+ for (SQLParameter pm : parameters) {
+ sql += " set ";
+ sql += pm.column.render(context);
+ sql += " = ";
+ sql += new LiteralColumn(pm.value).render(context);
+ }
+ if (this.hasConstraint()) {
+ sql += " where ";
+ sql += this.constraint.render(context);
+ }
+ return sql;
+ }
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/constraints/And.java b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/And.java
new file mode 100644
index 0000000..14d82e1
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/And.java
@@ -0,0 +1,51 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: And.java 18 2005-12-10 20:08:16Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import java.util.Set;
+
+
+/**
+ * Represents an AND operator in a SQL WHERE clause.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 18 $
+ */
+public class And extends NaryConstraint {
+
+ public And(Constraint ... constraints) {
+ super("and",constraints);
+ }
+
+ public And(Set<Constraint> constraints) {
+ super("and",constraints);
+ }
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/constraints/ArbitraryStringConstraint.java b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/ArbitraryStringConstraint.java
new file mode 100644
index 0000000..cb3ddfc
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/ArbitraryStringConstraint.java
@@ -0,0 +1,57 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: ArbitraryStringConstraint.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+
+/**
+ * Represents an AND operator in a SQL WHERE clause.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+/// <summary>
+/// Constraints that contain things other than constraints (such
+/// as columns or literals) and which need no enclosing parentheses
+/// if rendered within a complex
+/// </summary>
+public class ArbitraryStringConstraint implements SimpleConstraint
+{
+ public final String text;
+ public ArbitraryStringConstraint(String constraintText)
+ {
+ this.text = constraintText;
+ }
+ public String render(SQLRenderContext context)
+ {
+ return text;
+ }
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/constraints/BetweenRange.java b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/BetweenRange.java
new file mode 100644
index 0000000..51918b5
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/BetweenRange.java
@@ -0,0 +1,86 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: BetweenRange.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import org.israfil.sqlelements.Column;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+
+/**
+ * A range comparison constraint.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 25 $
+ */
+public class BetweenRange implements ComplexConstraint {
+ private Column operand;
+ private Column begin;
+ private Column end;
+
+ public BetweenRange(Column operand, Column beginRange, Column endRange) {
+ this.operand = operand;
+ this.begin = beginRange;
+ this.end = endRange;
+ }
+
+ /**
+ * Renders the BetweenRange.
+ * TODO: Migrate this into SQLRenderContext, as some SQL variants support BETWEEN syntax
+ */
+ public String render(SQLRenderContext context)
+ {
+
+ String sql = "";
+ if (operand.getTable() != null) sql += context.getAlias(operand.getTable()) + ".";
+ sql += operand.render(context);
+ sql += " >= ";
+ if (begin.getTable() != null) sql += context.getAlias(begin.getTable()) + ".";
+ sql += begin.render(context);
+ sql += " and ";
+ if (operand.getTable() != null) sql += context.getAlias(operand.getTable()) + ".";
+ sql += operand.render(context);
+ sql += " <= ";
+ if (end.getTable() != null) sql += context.getAlias(end.getTable()) + ".";
+ sql += end.render(context);
+ return sql;
+ /*
+ String sql = "";
+ if (operand.getTable() != null) sql += context.getAlias(operand.getTable()) + ".";
+ sql += operand.render(context);
+ sql += " between ";
+ if (begin.getTable() != null) sql += context.getAlias(begin.getTable()) + ".";
+ sql += begin.render(context);
+ sql += " and ";
+ if (end.getTable() != null) sql += context.getAlias(end.getTable()) + ".";
+ sql += end.render(context);
+ return sql;
+ */
+ }
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/constraints/BinaryConstraint.java b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/BinaryConstraint.java
new file mode 100644
index 0000000..c3b990c
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/BinaryConstraint.java
@@ -0,0 +1,62 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: BinaryConstraint.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ * A friendly parent for binary column constraints.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public abstract class BinaryConstraint implements ComplexConstraint
+{
+ protected Constraint leftOperand;
+ protected Constraint rightOperand;
+ protected String operatorText;
+
+ protected BinaryConstraint(Constraint leftOperand,Constraint rightOperand, String operatorText)
+ {
+ this.leftOperand = leftOperand;
+ this.rightOperand = rightOperand;
+ this.operatorText = operatorText;
+ }
+ public String render(SQLRenderContext context)
+ {
+ String sql = ConstraintUtils.renderInParentheses(leftOperand,context);
+ sql += " ";
+ sql += operatorText;
+ sql += " ";
+ sql += ConstraintUtils.renderInParentheses(rightOperand,context);
+ return sql;
+ }
+}
+
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/constraints/ColumnConstraint.java b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/ColumnConstraint.java
new file mode 100644
index 0000000..1feae0b
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/ColumnConstraint.java
@@ -0,0 +1,65 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: ColumnConstraint.java 21 2005-12-10 21:40:45Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import org.israfil.sqlelements.Column;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+
+/**
+ * A constraint wrapper for a column. It's used internally by
+ * the library to ease implementation of column-oriented
+ * constraints such as "Equals", etc.
+ *
+ * @see BinaryConstraint
+ * @see Equals
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 21 $
+ */
+class ColumnConstraint implements SimpleConstraint
+{
+ Column column;
+ public Column getColumn() { return column; }
+
+ public ColumnConstraint(Column column)
+ {
+ this.column = column;
+ }
+
+ public String render(SQLRenderContext context)
+ {
+ if (column.getTable() != null)
+ {
+ return context.getAlias(column.getTable()) + "." + column.render(context);
+ }
+ else return column.render(context);
+ }
+} \ No newline at end of file
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/constraints/ComplexConstraint.java b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/ComplexConstraint.java
new file mode 100644
index 0000000..91960e1
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/ComplexConstraint.java
@@ -0,0 +1,43 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: ComplexConstraint.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+
+/**
+ * Represents a constraint that would need to be enclosed by parentheses.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public interface ComplexConstraint extends Constraint
+{
+
+}
+
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/constraints/Constraint.java b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/Constraint.java
new file mode 100644
index 0000000..3de2fed
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/Constraint.java
@@ -0,0 +1,42 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: Constraint.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import org.israfil.sqlelements.SQLElement;
+
+/**
+ * Represents a constraint specification for a request for data.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public interface Constraint extends SQLElement {
+}
+
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/constraints/ConstraintUtils.java b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/ConstraintUtils.java
new file mode 100644
index 0000000..9828461
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/ConstraintUtils.java
@@ -0,0 +1,48 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: ConstraintUtils.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ * Represents a constraint specification for a request for data.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public class ConstraintUtils
+{
+ public static String renderInParentheses(Constraint c,SQLRenderContext context)
+ {
+ if (c instanceof ComplexConstraint) return "(" + c.render(context) + ")";
+ else return c.render(context);
+ }
+}
+
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/constraints/Equals.java b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/Equals.java
new file mode 100644
index 0000000..3877231
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/Equals.java
@@ -0,0 +1,45 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: Equals.java 21 2005-12-10 21:40:45Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import org.israfil.sqlelements.Column;
+
+
+/**
+ * A friendly Column Equality constraint.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 21 $
+ */
+public class Equals extends BinaryConstraint {
+ public Equals(Column leftOperand,Column rightOperand) {
+ super(new ColumnConstraint(leftOperand),new ColumnConstraint(rightOperand), "=") ;
+ }
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/constraints/JoinConstraint.java b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/JoinConstraint.java
new file mode 100644
index 0000000..84d07bc
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/JoinConstraint.java
@@ -0,0 +1,56 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: JoinConstraint.java 22 2005-12-11 15:08:56Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import org.israfil.sqlelements.Join;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ * Represents a single column from a single (physical or virtual) table.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 22 $
+ */
+public class JoinConstraint implements ComplexConstraint
+{
+ private Join j;
+
+ public JoinConstraint(Join j) {
+ this.j = j;
+ }
+
+ /**
+ * Renders based on the contained Join
+ */
+ public String render(SQLRenderContext context) {
+ return j.render(context);
+ }
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/constraints/NaryConstraint.java b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/NaryConstraint.java
new file mode 100644
index 0000000..0d0058d
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/NaryConstraint.java
@@ -0,0 +1,93 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: NaryConstraint.java 27 2006-01-14 12:50:08Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import java.util.Arrays;
+import java.util.Set;
+
+import net.israfil.foundation.collections.ArraySet;
+
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ * N-ary Constraint
+ * A friendly parent for constraints that can have an infinite
+ * number of operands, such as and, or, etc.
+ * i.e.: "(a=b) and (b=c) and (c=d)" is a valid SQL construction, but
+ * can be represented (logically) by: and(condition1,condition2,condition3)
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 27 $
+ */
+public abstract class NaryConstraint implements ComplexConstraint
+{
+ protected Constraint[] operands;
+ protected String operatorText;
+
+ protected NaryConstraint(String operatorText, Constraint ... operands) {
+ this(operatorText,prepArray(operands));
+ }
+
+ protected static Set<Constraint> prepArray(Constraint[] array) {
+ Set<Constraint> s = new ArraySet<Constraint>();
+ if (array != null) s.addAll(Arrays.asList(array));
+ return s;
+ }
+ protected NaryConstraint(String operatorText, Set<Constraint> operands) {
+ if (operands == null) operands = new ArraySet<Constraint>(0);
+ this.operatorText = operatorText;
+ Set<Constraint> constraintSet = new ArraySet<Constraint>();
+ for (Constraint c : operands) {
+ if (c == null) continue;
+ if (this.getClass().equals(c.getClass())) {
+ for(Constraint sub : ((NaryConstraint)c).operands){
+ constraintSet.add(sub);
+ }
+ }
+ else constraintSet.add(c);
+ }
+ this.operands = constraintSet.toArray(new Constraint[constraintSet.size()]);
+ }
+
+ public String render(SQLRenderContext context) {
+ boolean first = true;
+ String sql = "";
+ for (Constraint c : this.operands) {
+ if (!first) {
+ sql += " ";
+ sql += operatorText;
+ sql += " ";
+ }
+ else first = false;
+ sql += ConstraintUtils.renderInParentheses(c,context);
+ }
+ return sql;
+ }
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/constraints/Not.java b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/Not.java
new file mode 100644
index 0000000..9b266c8
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/Not.java
@@ -0,0 +1,53 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: Not.java 17 2005-12-10 20:06:44Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+
+/**
+ * Represents an AND operator in a SQL WHERE clause.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 17 $
+ */
+public class Not implements ComplexConstraint
+{
+ protected Constraint operand;
+
+ public Not(Constraint operand) {
+ this.operand=operand;
+ }
+
+ public String render(SQLRenderContext context)
+ {
+ return "not (" + operand.render(context) + ")";
+ }
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/constraints/NotEquals.java b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/NotEquals.java
new file mode 100644
index 0000000..07c9836
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/NotEquals.java
@@ -0,0 +1,46 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: NotEquals.java 22 2005-12-11 15:08:56Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import org.israfil.sqlelements.Column;
+
+
+/**
+ * A friendly Column Inequality constraint.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 22 $
+ */
+public class NotEquals extends BinaryConstraint {
+ public NotEquals(Column leftOperand,Column rightOperand) {
+ super(new ColumnConstraint(leftOperand),new ColumnConstraint(rightOperand), "!=") ;
+ }
+}
+
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/constraints/Or.java b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/Or.java
new file mode 100644
index 0000000..25761b0
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/Or.java
@@ -0,0 +1,51 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: Or.java 17 2005-12-10 20:06:44Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import java.util.Set;
+
+
+/**
+ * Represents an AND operator in a SQL WHERE clause.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 17 $
+ */
+public class Or extends NaryConstraint {
+
+ public Or(Constraint ... constraints) {
+ super("or",constraints);
+ }
+
+ public Or(Set<Constraint> constraints) {
+ super("or",constraints);
+ }
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/constraints/SimpleConstraint.java b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/SimpleConstraint.java
new file mode 100644
index 0000000..89dc9ff
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/constraints/SimpleConstraint.java
@@ -0,0 +1,42 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: SimpleConstraint.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+
+/**
+ * Represents a constraint that would not need to be enclosed by parentheses.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public interface SimpleConstraint extends Constraint
+{
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/render/CommandRenderer.java b/sqlelements/src/main/java/org/israfil/sqlelements/render/CommandRenderer.java
new file mode 100644
index 0000000..b4ae7ea
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/render/CommandRenderer.java
@@ -0,0 +1,44 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: CommandRenderer.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements.render;
+
+import org.israfil.sqlelements.Command;
+
+/**
+ * A thin interface to render sql commands.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public interface CommandRenderer {
+ public String render(SQLRenderContext context, Command dt);
+}
+
+
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/render/DatabaseType.java b/sqlelements/src/main/java/org/israfil/sqlelements/render/DatabaseType.java
new file mode 100644
index 0000000..5f672d7
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/render/DatabaseType.java
@@ -0,0 +1,119 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: DatabaseType.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements.render;
+
+
+/**
+ * An enumerated type, but since eclipse doesn't quite support enums yet, we're spoofing
+ * it until a later Cheetah release.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public enum DatabaseType {
+
+ Mock (
+ -1,
+ "Mock",
+ new MockSQLRenderEngine(),
+ new MockSQLRenderEngine(),
+ new MockSQLRenderEngine(),
+ "'"
+ ),
+ Generic (
+ 0,
+ "Oracle",
+ new GenericSQLRenderEngine(),
+ new GenericSQLRenderEngine(),
+ new GenericSQLRenderEngine(),
+ "'"
+ ),
+ Oracle (
+ 1,
+ "Oracle",
+ new OracleSQLRenderEngine(),
+ new OracleSQLRenderEngine(),
+ new OracleSQLRenderEngine(),
+ "'"
+ ),
+ SQLServer (
+ 2,
+ "Oracle",
+ new GenericSQLRenderEngine(),
+ new GenericSQLRenderEngine(),
+ new GenericSQLRenderEngine(),
+ "'"
+ ),
+ Sybase (
+ 3,
+ "Oracle",
+ new GenericSQLRenderEngine(),
+ new GenericSQLRenderEngine(),
+ new GenericSQLRenderEngine(),
+ "'"
+ ),
+ MySql (
+ 4,
+ "Oracle",
+ new GenericSQLRenderEngine(),
+ new GenericSQLRenderEngine(),
+ new GenericSQLRenderEngine(),
+ "'"
+ ),
+ Delegated (
+ 5,
+ "Delegated",
+ new DelegatedSQLRenderEngine(),
+ new DelegatedSQLRenderEngine(),
+ new DelegatedSQLRenderEngine(),
+ "'"
+ );
+
+
+ private DatabaseType(int code, String name, QueryRenderer qr, CommandRenderer cr, DateRenderer dr, String sdelim) {
+ this.code = code;
+ this.name = name;
+ this.qr = qr;
+ this.cr = cr;
+ this.dr = dr;
+ this.sdelim = sdelim;
+ }
+
+ public final int code;
+ public final String name;
+ public final CommandRenderer cr;
+ public final QueryRenderer qr;
+ public final DateRenderer dr;
+
+ /** A delimiter for literal strings in sql */
+ public final String sdelim;
+
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/render/DateRenderer.java b/sqlelements/src/main/java/org/israfil/sqlelements/render/DateRenderer.java
new file mode 100644
index 0000000..571a3a4
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/render/DateRenderer.java
@@ -0,0 +1,42 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: DateRenderer.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements.render;
+
+import java.util.Date;
+
+/**
+ * A thin interface to render dates in sql.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public interface DateRenderer {
+ public String format(SQLRenderContext context, Date dt);
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/render/DelegatedSQLRenderEngine.java b/sqlelements/src/main/java/org/israfil/sqlelements/render/DelegatedSQLRenderEngine.java
new file mode 100644
index 0000000..4c222b9
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/render/DelegatedSQLRenderEngine.java
@@ -0,0 +1,73 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: DelegatedSQLRenderEngine.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements.render;
+
+import java.util.Date;
+
+import org.israfil.sqlelements.Command;
+import org.israfil.sqlelements.Query;
+
+/**
+ * A SQL rendering engine that provides for a delegate, and passes through
+ * all rendering requests to that delegate. It's for extensibility.
+ *
+ * TODO: Evaluate the elimination of the DatabaseType enum (at least as
+ * TODO: a vendor construct) and eliminate the need for this indirection.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public class DelegatedSQLRenderEngine implements QueryRenderer, CommandRenderer, DateRenderer {
+
+ protected QueryRenderer qr;
+ protected CommandRenderer cr;
+ protected DateRenderer dr;
+
+ public void setDelegates(QueryRenderer qr, CommandRenderer cr, DateRenderer dr) {
+ this.qr=qr;
+ this.cr=cr;
+ this.dr=dr;
+ }
+
+ public String render(SQLRenderContext context,Query q) {
+ if (qr == null) throw new NullPointerException("Query Renderer cannot be null.");
+ return qr.render(context,q);
+ }
+
+ public String render(SQLRenderContext context,Command cmd) {
+ if (cr == null) throw new NullPointerException("Command Renderer cannot be null.");
+ return cr.render(context,cmd);
+ }
+
+ public String format(SQLRenderContext context, Date dt) {
+ if (dr == null) throw new NullPointerException("Date Formatter cannot be null.");
+ return dr.format(context,dt);
+ }
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/render/GenericSQLRenderEngine.java b/sqlelements/src/main/java/org/israfil/sqlelements/render/GenericSQLRenderEngine.java
new file mode 100644
index 0000000..c9f9cfb
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/render/GenericSQLRenderEngine.java
@@ -0,0 +1,94 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: GenericSQLRenderEngine.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements.render;
+
+import java.util.Date;
+import java.util.Set;
+
+import org.israfil.sqlelements.Column;
+import org.israfil.sqlelements.Command;
+import org.israfil.sqlelements.Query;
+import org.israfil.sqlelements.Table;
+import org.israfil.sqlelements.constraints.And;
+import org.israfil.sqlelements.constraints.Constraint;
+
+/**
+ * A concrete SQL rendering engine.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 25 $
+ */
+public class GenericSQLRenderEngine implements QueryRenderer, CommandRenderer, DateRenderer {
+
+ public String render(SQLRenderContext context,Query q) {
+ Set<Table> tables = q.getTables();
+
+ String sql = "select ";
+
+ boolean firstColumn = true;
+ for (Column column : q.getColumns()) {
+ if (!firstColumn) sql+= ", ";
+ else firstColumn = false;
+ if (column.getTable() != null) sql += context.getAlias(column.getTable()) + ".";
+ sql += column.render(context);
+ if (column.hasAlias()) sql += " as \"" + column.getAlias() + "\"";
+ }
+
+ sql += " from ";
+
+ boolean firstTable = true;
+ for (Table table : tables)
+ {
+ if (!firstTable) sql+= ", ";
+ else firstTable = false;
+ sql += table.render(context);
+ sql += " " + context.getAlias(table);
+ }
+ Constraint c = q.getConstraint();
+ if (q.hasJoins()) {
+ if (c == null) c = new And(q.getJoinConstraints());
+ else c = new And((new And(q.getJoinConstraints())),q.getConstraint());
+ }
+ if (c != null) {
+ sql += " where ";
+ sql += c.render(context);
+ }
+ return sql;
+ }
+
+ public String render(SQLRenderContext context,Command cmd) {
+ return null;
+ }
+
+ public String format(SQLRenderContext context, Date dt) {
+ return dt.toString();
+ }
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/render/MockSQLRenderEngine.java b/sqlelements/src/main/java/org/israfil/sqlelements/render/MockSQLRenderEngine.java
new file mode 100644
index 0000000..a697c57
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/render/MockSQLRenderEngine.java
@@ -0,0 +1,60 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: MockSQLRenderEngine.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements.render;
+
+import java.util.Date;
+
+import org.israfil.sqlelements.Command;
+import org.israfil.sqlelements.Query;
+
+/**
+ * A concrete SQL rendering engine.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public class MockSQLRenderEngine implements QueryRenderer, CommandRenderer, DateRenderer {
+
+ public String render(SQLRenderContext context, Query dt) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String render(SQLRenderContext context, Command dt) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String format(SQLRenderContext context, Date dt) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/render/MySqlSQLRenderEngine.java b/sqlelements/src/main/java/org/israfil/sqlelements/render/MySqlSQLRenderEngine.java
new file mode 100644
index 0000000..0233094
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/render/MySqlSQLRenderEngine.java
@@ -0,0 +1,40 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: MySqlSQLRenderEngine.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements.render;
+
+/**
+ * A concrete SQL rendering engine.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public class MySqlSQLRenderEngine extends GenericSQLRenderEngine {
+
+}
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/render/OracleSQLRenderEngine.java b/sqlelements/src/main/java/org/israfil/sqlelements/render/OracleSQLRenderEngine.java
new file mode 100644
index 0000000..92084e6
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/render/OracleSQLRenderEngine.java
@@ -0,0 +1,97 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: OracleSQLRenderEngine.java 22 2005-12-11 15:08:56Z cgruber $
+ */
+package org.israfil.sqlelements.render;
+
+import java.util.Date;
+import java.util.Set;
+
+import org.israfil.sqlelements.Column;
+import org.israfil.sqlelements.Command;
+import org.israfil.sqlelements.Query;
+import org.israfil.sqlelements.Table;
+import org.israfil.sqlelements.constraints.And;
+import org.israfil.sqlelements.constraints.Constraint;
+
+/**
+ * A concrete SQL rendering engine.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 22 $
+ */
+public class OracleSQLRenderEngine implements QueryRenderer, CommandRenderer, DateRenderer {
+
+ public String render(SQLRenderContext context,Query q) {
+ Set<Table> tables = q.getTables();
+
+ String sql = "select ";
+
+ boolean firstColumn = true;
+ for (Column column : q.getColumns()) {
+ if (!firstColumn) sql+= ", ";
+ else firstColumn = false;
+ if (column.getTable() != null) sql += context.getAlias(column.getTable()) + ".";
+ sql += column.render(context);
+ if (column.hasAlias()) sql += " as \"" + column.getAlias() + "\"";
+ }
+
+ sql += " from ";
+
+ boolean firstTable = true;
+ for (Table table : tables)
+ {
+ if (!firstTable) sql+= ", ";
+ else firstTable = false;
+ sql += table.render(context);
+ sql += " " + context.getAlias(table);
+ }
+ if (q.hasJoins()) {
+ if (q.getJoins() != null && q.getJoins().size() > 0) {
+ if (q.hasConstraint()) {
+ q.setConstraint(new And((Constraint)(new And(q.getJoinConstraints())),q.getConstraint()));
+ } else q.setConstraint(new And(q.getJoinConstraints()));
+ }
+ }
+ if (q.hasConstraint()) {
+ sql += " where ";
+ sql += q.getConstraint().render(context);
+ }
+ return sql;
+ }
+
+ public String render(SQLRenderContext context,Command cmd) {
+ return null;
+ }
+
+ public String format(SQLRenderContext context, Date dt) {
+ return dt.toString();
+ }
+}
+
+
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/render/QueryRenderer.java b/sqlelements/src/main/java/org/israfil/sqlelements/render/QueryRenderer.java
new file mode 100644
index 0000000..3d014fe
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/render/QueryRenderer.java
@@ -0,0 +1,44 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: QueryRenderer.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements.render;
+
+import org.israfil.sqlelements.Query;
+
+
+/**
+ * A concrete SQL rendering engine.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public interface QueryRenderer {
+ public String render(SQLRenderContext context, Query dt);
+}
+
diff --git a/sqlelements/src/main/java/org/israfil/sqlelements/render/SQLRenderContext.java b/sqlelements/src/main/java/org/israfil/sqlelements/render/SQLRenderContext.java
new file mode 100644
index 0000000..6d70949
--- /dev/null
+++ b/sqlelements/src/main/java/org/israfil/sqlelements/render/SQLRenderContext.java
@@ -0,0 +1,97 @@
+/*
+ * SQLElements object-oriented SQL parsing and generation library
+ *
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
+ *
+ * $Id: SQLRenderContext.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements.render;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.israfil.sqlelements.Command;
+import org.israfil.sqlelements.Query;
+import org.israfil.sqlelements.Table;
+
+
+/**
+ * A local context for a render that includes database-specific rendering help,
+ * as well as alias re-writing for non-aliased tables, etc.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public class SQLRenderContext {
+
+ protected DatabaseType type;
+ /*
+ * protected CommandRenderer commandRenderer;
+ */
+ protected Map<Table,String> aliases = new HashMap<Table,String>();
+
+ public SQLRenderContext(DatabaseType type) {
+ this.type = type;
+ }
+
+ public void finalize() throws Throwable {
+ this.type = null;
+ }
+
+ public String getAlias(Table table) {
+ if (aliases.get(table) != null)
+ return aliases.get(table); // succeed fast.
+
+ Set<String> usedAliases = new HashSet<String>();
+ for (String alias : aliases.values())
+ usedAliases.add(alias);
+
+ if (table.hasAlias()) {
+ aliases.put(table,table.getAlias());
+ return table.getAlias();
+ } else {
+ int tnumber = 0;
+ while (usedAliases.contains("t" + tnumber)) tnumber++;
+ aliases.put(table,"t" + tnumber);
+ return aliases.get(table);
+ }
+ }
+
+ public String format(Date dt) {
+ return type.dr.format(this,dt);
+ }
+ public String renderQuery(Query q) {
+ return type.qr.render(this,q);
+ }
+ public String renderCommand(Command c) {
+ return type.cr.render(this,c);
+ }
+ public String getStringDelimiter() {
+ return type.sdelim;
+ }
+}
diff --git a/sqlelements/src/site/apt/index.apt b/sqlelements/src/site/apt/index.apt
new file mode 100644
index 0000000..049c804
--- /dev/null
+++ b/sqlelements/src/site/apt/index.apt
@@ -0,0 +1,14 @@
+ --------------------------------------------------------------------------
+ SQLElements - Object-Oriented SQL Construction from Isr&aacute;f&iacute;l
+ --------------------------------------------------------------------------
+ Israfil Consulting Services Corporation
+ ---------------------------------------
+ July 15, 2005
+
+Welcome to SQLElements
+
+ SQLElements is an object-oriented library of components that, when assembled
+ mirror the structure of the Structured Query Language (SQL). With the help
+ of a database-specific hint class, such a composition can then be rendered
+ into SQL text.
+
diff --git a/sqlelements/src/site/apt/license.apt b/sqlelements/src/site/apt/license.apt
new file mode 100644
index 0000000..efb4949
--- /dev/null
+++ b/sqlelements/src/site/apt/license.apt
@@ -0,0 +1,48 @@
+Overview
+
+ Licenses listed for the project are that of the project itself, and
+ not of dependencies. Files issued by one of these licenses will be
+ marked as such within them, or by an accompanying file in their
+ directory. Files without such designations should be considered
+ copyright their authors, and used with permission.
+
+Project Licenses
+
+*GNU Lesser General Public License
+
+ The GNU Lesser General Public License, v2.1 is a long document that is
+ very annoying to read through. It is therefore referred to, and can
+ be reached at {{{http://www.gnu.org/copyleft/lesser.html} http://www.gnu.org/copyleft/lesser.html}}.
+
+*BSD License
+
+ Copyright (c) 2003,2004,2005, Israfil Consulting Services Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of the copyright holders nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/AbstractAliasedSQLElementTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/AbstractAliasedSQLElementTest.java
new file mode 100644
index 0000000..9b0ac2c
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/AbstractAliasedSQLElementTest.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: AbstractAliasedSQLElementTest.java 20 2005-12-10 21:08:36Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.israfil.sqlelements.mock.MockAliasedElement;
+
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 20 $
+ */
+public class AbstractAliasedSQLElementTest extends TestCase {
+
+ AbstractAliasedSQLElement aae;
+ static final String aliasString0 = "AliasString0";
+ static final String aliasString1 = "AliasString1";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ aae = new MockAliasedElement();
+ }
+
+ protected void tearDown() throws Exception {
+ aae = null;
+ super.tearDown();
+ }
+
+ public void testGetAlias() {
+ aae = new MockAliasedElement(aliasString0);
+ Assert.assertEquals(aae.getAlias(),aliasString0);
+ }
+
+ public void testSetAlias() {
+ aae.setAlias(aliasString1);
+ Assert.assertEquals(aae.getAlias(),aliasString1);
+ }
+
+ public void testHasAlias() {
+ Assert.assertFalse(aae.hasAlias());
+ aae.setAlias(aliasString0);
+ Assert.assertTrue(aae.hasAlias());
+ }
+
+
+ public void testUnaliasedSLQElement()
+ {
+ aae = new MockAliasedElement();
+ Assert.assertFalse(aae.hasAlias());
+ Assert.assertEquals(null,aae.getAlias());
+ }
+
+
+}
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/AllTests.java b/sqlelements/src/test/java/org/israfil/sqlelements/AllTests.java
new file mode 100644
index 0000000..d5d7078
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/AllTests.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: AllTests.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 25 $
+ */
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for org.israfil.sqlelements");
+ //$JUnit-BEGIN$
+ suite.addTest(org.israfil.sqlelements.constraints.AllTests.suite());
+ suite.addTestSuite(AbstractAliasedSQLElementTest.class);
+ suite.addTestSuite(ColumnTest.class);
+ suite.addTestSuite(ComplexSampleQueriesTest.class);
+ suite.addTestSuite(DatabaseTypeTest.class);
+ suite.addTestSuite(DeleteTest.class);
+ suite.addTestSuite(JoinTest.class);
+ suite.addTestSuite(ParameterizedCommandTest.class);
+ suite.addTestSuite(QueryTest.class);
+ suite.addTestSuite(SimpleTableTest.class);
+ suite.addTestSuite(UpdateTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+}
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/ColumnTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/ColumnTest.java
new file mode 100644
index 0000000..2537a04
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/ColumnTest.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: ColumnTest.java 14 2005-12-08 22:29:05Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import java.util.Date;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.israfil.sqlelements.render.DatabaseType;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 14 $
+ */
+public class ColumnTest extends TestCase {
+
+ Column c;
+ Table t;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ t = new SimpleTable("MyTable");
+ }
+
+ protected void tearDown() throws Exception {
+ c = null;
+ t = null;
+ super.tearDown();
+ }
+
+ public void testSimpleColumn()
+ {
+ c = new SimpleColumn(new SimpleTable("MyTable"),"MyColumn");
+ Assert.assertEquals("MyColumn",c.render(new SQLRenderContext(DatabaseType.Generic)));
+ }
+
+ public void testLiteralColumn()
+ {
+ Assert.assertEquals("null",new LiteralColumn(null).render(new SQLRenderContext(DatabaseType.Generic)));
+ Assert.assertEquals("'MyColumn'",new LiteralColumn("MyColumn").render(new SQLRenderContext(DatabaseType.Generic)));
+ Assert.assertEquals("Fri Apr 07 00:00:00 EDT 3905",new LiteralColumn(new Date(2005,3,7)).render(new SQLRenderContext(DatabaseType.Generic)));
+ TestEnum e = TestEnum.TestOne;
+ Assert.assertEquals("'TestOne'",new LiteralColumn(e).render(new SQLRenderContext(DatabaseType.Generic)));
+ }
+
+ public enum TestEnum {
+ TestOne,TestTwo,TestThree;
+ private TestEnum() {}
+ }
+}
+
+
+
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/ComplexSampleQueriesTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/ComplexSampleQueriesTest.java
new file mode 100644
index 0000000..24ce8c1
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/ComplexSampleQueriesTest.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: ComplexSampleQueriesTest.java 27 2006-01-14 12:50:08Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.israfil.sqlelements.constraints.Equals;
+import org.israfil.sqlelements.render.DatabaseType;
+import org.israfil.sqlelements.render.SQLRenderContext;
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 27 $
+ */
+public class ComplexSampleQueriesTest extends TestCase {
+ SQLRenderContext context;
+
+
+ public void setUp() {
+ context = new SQLRenderContext(DatabaseType.Generic);
+ }
+
+ public static Table TABLE_A = new SimpleTable("table_a", "ta");
+ public static Table TABLE_B = new SimpleTable("table_b", "tb");
+ public static Table TABLE_C = new SimpleTable("table_c");
+ public static Table TABLE_D = new SimpleTable("table_d");
+
+ public static final String[] A_COLUMN_NAMES = new String[] {
+ "a_col1", "a_col2", "a_col3", "a_col4"
+ };
+
+ public static String[] B_COLUMN_NAMES = new String[] {
+ "b_col1", "b_col2", "b_col3"
+ };
+
+ public static String[] C_COLUMN_NAMES = new String[] {
+ "c_col1"
+ };
+
+ public static String[] D_COLUMN_NAMES = new String[] {
+ "d_col1"
+ };
+
+ public final static Query COMPLEX_SELECT_QUERY = new Select(
+ Select.aggregate(
+ new Column[] {
+ new LiteralColumn(1,"literal_column"),
+ new SimpleColumn(TABLE_A,"extra_column"),
+ new SimpleColumn(TABLE_B,"extra_column2", "alias2")
+ },
+ SimpleColumn.createColumns(TABLE_A, A_COLUMN_NAMES),
+ SimpleColumn.createColumns(TABLE_B, B_COLUMN_NAMES),
+ SimpleColumn.createColumns(TABLE_C, C_COLUMN_NAMES),
+ SimpleColumn.createColumns(TABLE_D, D_COLUMN_NAMES)
+ ),
+ new Equals(new SimpleColumn(TABLE_A,"comparison_column"),new LiteralColumn(0)),
+ new InnerJoin("id",TABLE_A, TABLE_B),
+ new LeftOuterJoin("id",TABLE_B,TABLE_C),
+ new LeftOuterJoin("id",TABLE_C,TABLE_D)
+ );
+
+ public void testComplexQuery() {
+ System.out.println(COMPLEX_SELECT_QUERY.render(context));
+ Assert.assertEquals("select " +
+ "1 as \"literal_column\", ta.extra_column, tb.extra_column2 as \"alias2\", " +
+ "ta.a_col1, ta.a_col2, ta.a_col3, ta.a_col4, " +
+ "tb.b_col1, tb.b_col2, tb.b_col3, " +
+ "t0.c_col1, " +
+ "t1.d_col1 " +
+ "from table_a ta, table_b tb, table_c t0, table_d t1 " +
+ "where (ta.id = tb.id) and " +
+ "(tb.id = t0.id (+)) and " +
+ "(t0.id = t1.id (+)) and " +
+ "(ta.comparison_column = 0)",
+ COMPLEX_SELECT_QUERY.render(context));
+ }
+
+ public final static Query COMPLEX_SELECT_QUERY2 = new Select(
+ Select.aggregate(
+ new Column[] {
+ new LiteralColumn(1,"literal_column"),
+ new SimpleColumn(TABLE_A,"extra_column"),
+ new SimpleColumn(TABLE_B,"extra_column2", "alias2")
+ },
+ SimpleColumn.createColumns(TABLE_A, A_COLUMN_NAMES),
+ SimpleColumn.createColumns(TABLE_B, B_COLUMN_NAMES),
+ SimpleColumn.createColumns(TABLE_C, C_COLUMN_NAMES),
+ SimpleColumn.createColumns(TABLE_D, D_COLUMN_NAMES)
+ ),
+ new Equals(new SimpleColumn(TABLE_A,"comparison_column"),new LiteralColumn(0)),
+ new InnerJoin("id",TABLE_A, TABLE_B),
+ new LeftOuterJoin("id",TABLE_B,TABLE_C),
+ new LeftOuterJoin("id",TABLE_C,TABLE_D)
+ );
+ /*
+ public void testComplexQuery2() {
+ System.out.println(COMPLEX_SELECT_QUERY.render(context));
+ Assert.assertEquals("select " +
+ "ta.a_col1, ta.a_col2, " +
+ "tb.b_col1, tb.b_col2, tb.b_col3, " +
+ "t0.c_col1, " +
+ "t1.d_col1 " +
+ "from table_a ta, table_b tb, table_c t0, table_d t1 " +
+ "where (ta.id = tb.id) and " +
+ "(tb.id = t0.id (+)) and " +
+ "(t0.id = t1.id (+)) and " +
+ "(ta.comparison_column = 0)",
+ COMPLEX_SELECT_QUERY2.render(context));
+ }
+ */
+}
+
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/DatabaseTypeTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/DatabaseTypeTest.java
new file mode 100644
index 0000000..34e10d7
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/DatabaseTypeTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: DatabaseTypeTest.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import junit.framework.TestCase;
+
+import org.israfil.sqlelements.render.DatabaseType;
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 25 $
+ */
+public class DatabaseTypeTest extends TestCase {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testInitialization() {
+ DatabaseType generic = DatabaseType.Generic;
+ DatabaseType oracle = DatabaseType.Oracle;
+ }
+
+}
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/DeleteTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/DeleteTest.java
new file mode 100644
index 0000000..b0705f5
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/DeleteTest.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: DeleteTest.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.israfil.sqlelements.constraints.Constraint;
+import org.israfil.sqlelements.constraints.Equals;
+import org.israfil.sqlelements.render.DatabaseType;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+
+
+// TODO: Migrate some tests into AbstractQuery tests and Select tests, since the functionality has been reworked
+public class DeleteTest extends TestCase {
+ SQLRenderContext context;
+ Table t0;
+ Column col0;
+ Column col1;
+ Constraint c0;
+
+ public void setUp()
+ {
+ context = new SQLRenderContext(DatabaseType.Generic);
+ t0 = new SimpleTable("Table0");
+ col0 = new SimpleColumn(t0,"column0");
+ col1 = new LiteralColumn(5);
+ c0 = new Equals(col0,col1);
+ }
+
+ public void testCreateDelete()
+ {
+ Delete delete = new Delete();
+ Assert.assertNotNull(delete);
+ }
+
+ public void testFailRenderWithNoTable()
+ {
+ Delete delete = new Delete();
+ Assert.assertNotNull(delete);
+ try {
+ delete.render(context);
+ } catch (Exception e) {
+ return;
+ }
+ Assert.fail("Failed to trap exception.");
+ }
+
+ public void testDeleteWithTable()
+ {
+ Delete delete = new Delete(t0,null);
+ Assert.assertNotNull(delete);
+ Assert.assertEquals("delete from Table0",delete.render(context));
+ }
+
+ public void testDeleteWithTableAndConstraint()
+ {
+ Delete delete = new Delete(t0,c0);
+ Assert.assertNotNull(delete);
+ Assert.assertEquals("delete from Table0 t0 where t0.column0 = 5",delete.render(context));
+ }
+}
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/JoinTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/JoinTest.java
new file mode 100644
index 0000000..18aaeb3
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/JoinTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: JoinTest.java 22 2005-12-11 15:08:56Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.israfil.sqlelements.render.DatabaseType;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+public class JoinTest extends TestCase
+{
+ SQLRenderContext context;
+
+
+ public void setUp() {
+ context = new SQLRenderContext(DatabaseType.Generic);
+ }
+
+ public void testJoinColumnAccess() {
+ SimpleColumn c1 = new SimpleColumn(new SimpleTable("table1"),"col_A");
+ SimpleColumn c2 = new SimpleColumn(new SimpleTable("table2"),"col_B");
+ Join j = new InnerJoin(c1,c2);
+ Assert.assertEquals(c1,j.getLeftColumn());
+ Assert.assertEquals(c2,j.getRightColumn());
+ }
+
+ public void InnerJoinCreation() {
+ SimpleColumn c1 = new SimpleColumn(new SimpleTable("table1"),"col_A");
+ SimpleColumn c2 = new SimpleColumn(new SimpleTable("table2"),"col_B");
+ Join j = new InnerJoin(c1,c2);
+ Assert.assertEquals("t0.col_A = t1.col_B",j.render(context));
+ }
+
+ public void LeftOuterJoinCreation() {
+ SimpleColumn c1 = new SimpleColumn(new SimpleTable("table1"),"col_A");
+ SimpleColumn c2 = new SimpleColumn(new SimpleTable("table2"),"col_B");
+ Join j = new LeftOuterJoin(c1,c2);
+ Assert.assertEquals("t0.col_A = t1.col_B (+)",j.render(context));
+ }
+
+}
+
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/ParameterizedCommandTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/ParameterizedCommandTest.java
new file mode 100644
index 0000000..e59db77
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/ParameterizedCommandTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: ParameterizedCommandTest.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.israfil.sqlelements.render.DatabaseType;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+
+// TODO: Migrate some tests into AbstractQuery tests and Select tests, since the functionality has been reworked
+public class ParameterizedCommandTest extends TestCase {
+
+ SQLRenderContext context;
+
+ public void setUp()
+ {
+ context = new SQLRenderContext(DatabaseType.Generic);
+ }
+
+ public void testGetParameterValueTest()
+ {
+ Column c = new SimpleColumn(new SimpleTable("Table0"),"columnA");
+ MockAbstractParameterizedCommand cmd = new MockAbstractParameterizedCommand();
+ Assert.assertNotNull(cmd);
+ SQLParameter parm0 = new SQLParameter(c,5);
+ cmd.setParameter(parm0);
+ for (SQLParameter p : cmd.parameters) Assert.assertEquals(parm0,p);
+ Assert.assertEquals(5,cmd.getParameterValue(c));
+ }
+
+ public class MockAbstractParameterizedCommand extends AbstractParameterizedCommand
+ {
+ public String render(SQLRenderContext context) { return null; }
+ public Object clone() throws CloneNotSupportedException { return null; }
+ }
+}
+
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/QueryTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/QueryTest.java
new file mode 100644
index 0000000..3ab5cc1
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/QueryTest.java
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: QueryTest.java 22 2005-12-11 15:08:56Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.israfil.sqlelements.constraints.Constraint;
+import org.israfil.sqlelements.constraints.Equals;
+import org.israfil.sqlelements.render.DatabaseType;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+
+
+
+// TODO: Migrate some tests into AbstractQuery tests and Select tests, since the functionality has been reworked
+
+public class QueryTest extends TestCase {
+
+ SQLRenderContext context;
+
+ public void setUp() {
+ context = new SQLRenderContext(DatabaseType.Generic);
+ }
+
+ public void testCloneQuery() throws CloneNotSupportedException {
+ Table table = new SimpleTable("Table1");
+ LiteralColumn col1 = new LiteralColumn("5");
+ Column col2 = new SimpleColumn(table,"id");
+ Column col3 = new SimpleColumn(table,"recursive_id");
+ Constraint constraint = new Equals(col1,col2);
+ Join j = new InnerJoin(col2,col3);
+ Query select1 = new Select(new Column[] {col1,col2},constraint,j);
+ Query select2 = (Query)select1.clone();
+ Assert.assertFalse("Objects should not be identical",select1==select2);
+ Assert.assertEquals(select1.render(context),select2.render(context));
+ }
+
+ public void testColumns()
+ {
+ Table t0 = new SimpleTable("FOO_TABLE");
+ Table t1 = new SimpleTable("BAR_TABLE","bar");
+ Column c0 = new SimpleColumn(t0,"colA");
+ Column c1 = new SimpleColumn(t1,"colB");
+ Query q = new Select(new Column[] {c0,c1});
+ List<Column> cols = q.getColumns();
+ Assert.assertEquals(cols.get(0),c0);
+ Assert.assertEquals(cols.get(1),c1);
+ }
+
+ public void testTables()
+ {
+ Table t0 = new SimpleTable("FOO_TABLE");
+ Table t1 = new SimpleTable("BAR_TABLE","bar");
+ Column c0 = new SimpleColumn(t0,"colA");
+ Column c1 = new SimpleColumn(t1,"colB");
+ Join j = new InnerJoin(c0,c1);
+ //Query q = new Select(c0,(Constraint)null,(Join)j);
+ Query q = new Select(new Column[]{},j);
+ Set tables = q.getTables();
+ Assert.assertTrue("Missing table " + t0,tables.contains(t0));
+ Assert.assertTrue("Missing table " + t1,tables.contains(t1));
+ }
+
+ public void testSelectTest()
+ {
+ Query q = new Select(new SimpleColumn(new SimpleTable("y"),"x"));
+ Assert.assertEquals("select t0.x from y t0",q.render(context));
+ }
+
+ public void testSelectTestWithAlias()
+ {
+ Query q = new Select(new SimpleColumn(new SimpleTable("table1","a"),"column1","b"));
+ Assert.assertEquals("select a.column1 as \"b\" from table1 a",q.render(context));
+ }
+
+ public void testMultiColumnSelectTest()
+ {
+ Table t1 = new SimpleTable("table1");
+ Column c1 = new SimpleColumn(t1,"c1");
+ Column c2 = new SimpleColumn(t1,"c2");
+ Query q = new Select(new Column[] { c1,c2} );
+ Assert.assertEquals("select t0.c1, t0.c2 from table1 t0",q.render(context));
+ }
+
+ public void testMultiColumnSelectTestWithAlias()
+ {
+ Table t1 = new SimpleTable("t1","tab1");
+ Column c1 = new SimpleColumn(t1,"c1","foo");
+ Column c2 = new SimpleColumn(t1,"c2");
+ Query q = new Select(new Column[] { c1,c2} );
+ Assert.assertEquals("select tab1.c1 as \"foo\", tab1.c2 from t1 tab1",q.render(context));
+ }
+
+ public void testSelectWithConstraint()
+ {
+ Table t1 = new SimpleTable("table1");
+ Column c1 = new SimpleColumn(t1,"c1");
+ Column c2 = new SimpleColumn(t1,"c2");
+ Constraint constraint = new Equals(c1,c2);
+ Query q = new Select(new Column[] { c1,c2 }, constraint);
+ Assert.assertEquals("select t0.c1, t0.c2 from table1 t0 where t0.c1 = t0.c2",q.render(context));
+ }
+
+ public void testSelectWithConstraintUsingInnerJoin()
+ {
+ Table t1 = new SimpleTable("table1","tab1");
+ Table t2 = new SimpleTable("table2","tab2");
+ Column c1_1 = new SimpleColumn(t1,"c1");
+ Column c2_1 = new SimpleColumn(t2,"c1");
+ Column c2_2 = new SimpleColumn(t2,"c2");
+ Join join = new InnerJoin(c1_1,c2_1);
+ Constraint constraint = new Equals(c2_2,new LiteralColumn(1));
+ Query q = new Select(new Column[] { c2_2 }, constraint, join);
+ Assert.assertEquals("select tab2.c2 from table2 tab2, table1 tab1 where (tab1.c1 = tab2.c1) and (tab2.c2 = 1)",q.render(context));
+ }
+
+ public void testSelectWithConstraintUsingInnerJoinNoTableAlias()
+ {
+ Table t1 = new SimpleTable("table1");
+ Table t2 = new SimpleTable("table2");
+ Column c1_1 = new SimpleColumn(t1,"c1");
+ Column c2_1 = new SimpleColumn(t2,"c1");
+ Column c2_2 = new SimpleColumn(t2,"c2");
+ Join join = new InnerJoin(c1_1,c2_1);
+ Constraint constraint = new Equals(c2_2,new LiteralColumn(1));
+ Query q = new Select(new Column[] { c2_2 }, constraint, join);
+ Assert.assertEquals("select t0.c2 from table2 t0, table1 t1 where (t1.c1 = t0.c1) and (t0.c2 = 1)",q.render(context));
+ }
+
+ public void testComplexInnerJoin()
+ {
+ Table t1 = new SimpleTable("table1", "tab1");
+ Table t2 = new SimpleTable("table2", "tab2");
+ Table t3 = new SimpleTable("table3");
+ Table t4 = new SimpleTable("table4");
+ Column c1_A = new SimpleColumn(t1,"A");
+ Column c1_1 = new SimpleColumn(t1,"colZ");
+ Column c2_1 = new SimpleColumn(t2,"colZ");
+ Column c2_2 = new SimpleColumn(t2,"colY");
+ Column c3_2 = new SimpleColumn(t3,"colY");
+ Column c3_3 = new SimpleColumn(t3,"colW");
+ Column c4_3 = new SimpleColumn(t4,"colW");
+ Column c4_B = new SimpleColumn(t4,"B");
+ Join join1 = new InnerJoin(c1_1,c2_1);
+ Join join2 = new InnerJoin(c2_2,c3_2);
+ Join join3 = new InnerJoin(c3_3,c4_3);
+ Constraint constraint = new Equals(c2_2,new LiteralColumn(1));
+ Query q = new Select(new Column[] { c1_A, c4_B }, constraint, join1, join2, join3);
+ Assert.assertEquals("select tab1.A, t0.B from table1 tab1, table4 t0, table2 tab2, table3 t1 where (tab1.colZ = tab2.colZ) and (tab2.colY = t1.colY) and (t1.colW = t0.colW) and (tab2.colY = 1)",q.render(context));
+ }
+
+ public void testComplexLeftOuterJoin()
+ {
+ Table t1 = new SimpleTable("table1", "tab1");
+ Table t2 = new SimpleTable("table2", "tab2");
+ Table t3 = new SimpleTable("table3");
+ Table t4 = new SimpleTable("table4");
+ Column c1_A = new SimpleColumn(t1,"A");
+ Column c1_1 = new SimpleColumn(t1,"colZ");
+ Column c2_1 = new SimpleColumn(t2,"colZ");
+ Column c2_2 = new SimpleColumn(t2,"colY");
+ Column c3_2 = new SimpleColumn(t3,"colY");
+ Column c3_3 = new SimpleColumn(t3,"colW");
+ Column c4_3 = new SimpleColumn(t4,"colW");
+ Column c4_B = new SimpleColumn(t4,"B");
+ Join join1 = new InnerJoin(c1_1,c2_1);
+ Join join2 = new LeftOuterJoin(c2_2,c3_2);
+ Join join3 = new LeftOuterJoin(c3_3,c4_3);
+ Constraint constraint = new Equals(c2_2,new LiteralColumn(1));
+ Query q = new Select(new Column[] { c1_A, c4_B }, constraint, join1, join2, join3);
+ Assert.assertEquals("select tab1.A, t0.B from table1 tab1, table4 t0, table2 tab2, table3 t1 where (tab1.colZ = tab2.colZ) and (tab2.colY = t1.colY (+)) and (t1.colW = t0.colW (+)) and (tab2.colY = 1)",q.render(context));
+ }
+}
+
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/SimpleTableTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/SimpleTableTest.java
new file mode 100644
index 0000000..a1614c0
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/SimpleTableTest.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: SimpleTableTest.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.israfil.sqlelements.render.DatabaseType;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 25 $
+ */
+public class SimpleTableTest extends TestCase {
+
+ static final String table0Name = "Table0";
+ static final String table0Alias = "TableAlias0";
+ SimpleTable table0;
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ table0 = new SimpleTable(table0Name,table0Alias);
+ }
+
+ protected void tearDown() throws Exception {
+ table0 = null;
+ super.tearDown();
+ }
+
+ public SimpleTableTest(String name) {
+ super(name);
+ }
+
+ public void testConstructSimpleTable() {
+ table0 = new SimpleTable(table0Name);
+ table0 = new SimpleTable(table0Name,table0Alias);
+ }
+
+ public void testGetName() {
+ //TODO Implement getName().
+ Assert.assertEquals(table0.getName(),table0Name);
+ }
+
+ public void testToString() {
+ Assert.assertEquals("SimpleTable["+table0Name+" "+table0Alias+"]",table0.toString());
+ table0 = new SimpleTable(table0Name);
+ Assert.assertEquals("SimpleTable["+table0Name+"]",table0.toString());
+ }
+
+ public void testClone() {
+ SimpleTable clone = (SimpleTable)table0.clone();
+ Assert.assertEquals(table0.getName(),clone.getName());
+ Assert.assertEquals(table0.getAlias(),clone.getAlias());
+ Assert.assertEquals(table0.hasAlias(),clone.hasAlias());
+ Assert.assertEquals(table0.toString(),clone.toString());
+ }
+
+ public void testRender() {
+ Assert.assertEquals(table0Name,table0.render(new SQLRenderContext(DatabaseType.Generic)));
+ }
+
+ public void testAliasesForUnaliasedTables()
+ {
+ SQLRenderContext context = new SQLRenderContext(DatabaseType.Mock);
+ Table t0 = new SimpleTable("Table0");
+ Table t1 = new SimpleTable("Table1");
+ Assert.assertEquals("t0",context.getAlias(t0));
+ Assert.assertEquals("t1",context.getAlias(t1));
+ }
+}
+
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/UpdateTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/UpdateTest.java
new file mode 100644
index 0000000..3f8d153
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/UpdateTest.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: UpdateTest.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.israfil.sqlelements.constraints.Constraint;
+import org.israfil.sqlelements.constraints.Equals;
+import org.israfil.sqlelements.render.DatabaseType;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+
+// TODO: Migrate some tests into AbstractQuery tests and Select tests, since the functionality has been reworked
+public class UpdateTest extends TestCase {
+ SQLRenderContext context;
+
+ public void setUp()
+ {
+ context = new SQLRenderContext(DatabaseType.Generic);
+ }
+
+ public void testCreateUpdate()
+ {
+ Update update = new Update();
+ Assert.assertNotNull(update);
+ }
+
+ public void testRenderWithNoTable()
+ {
+ Update update = new Update();
+ Assert.assertNotNull(update);
+ try {
+ update.render(context);
+ } catch (Exception e) {
+ return;
+ }
+ Assert.fail("Failed to trap exception.");
+ }
+
+ public void testNormalUpdate()
+ {
+ Column c = new SimpleColumn(new SimpleTable("Table0"),"columnA");
+ Update update = new Update(new SQLParameter(c,5));
+ Assert.assertNotNull(update);
+ Assert.assertEquals("update Table0 set columnA = 5",update.render(context));
+ }
+
+ public void testNormalUpdateWithConstraints()
+ {
+ Column c = new SimpleColumn(new SimpleTable("Table0"),"columnA");
+ Constraint constraint = new Equals(c,new LiteralColumn(3));
+ Update update = new Update(constraint,new SQLParameter(c,5));
+ Assert.assertNotNull(update);
+ Assert.assertEquals("update Table0 t0 set columnA = 5 where t0.columnA = 3",update.render(context));
+ }
+}
+
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/constraints/AllTests.java b/sqlelements/src/test/java/org/israfil/sqlelements/constraints/AllTests.java
new file mode 100644
index 0000000..20e22a1
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/constraints/AllTests.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: AllTests.java 22 2005-12-11 15:08:56Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 22 $
+ */
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for org.israfil.sqlelements");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(BetweenRangeConstraintTest.class);
+ suite.addTestSuite(ColumnConstraintTest.class);
+ suite.addTestSuite(EqualsConstraintTest.class);
+ suite.addTestSuite(LogicalConstraintsTest.class);
+ suite.addTestSuite(MockConstraintTest.class);
+ suite.addTestSuite(NaryConstraintTest.class);
+ suite.addTestSuite(NotEqualsConstraintTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+}
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/constraints/BetweenRangeConstraintTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/constraints/BetweenRangeConstraintTest.java
new file mode 100644
index 0000000..8f1f1bd
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/constraints/BetweenRangeConstraintTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: BetweenRangeConstraintTest.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.israfil.sqlelements.LiteralColumn;
+import org.israfil.sqlelements.SimpleColumn;
+import org.israfil.sqlelements.SimpleTable;
+import org.israfil.sqlelements.render.DatabaseType;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+public class BetweenRangeConstraintTest extends TestCase {
+ SQLRenderContext context;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ context = new SQLRenderContext(DatabaseType.Generic);
+ }
+
+ public void testBetweenRangeWithLiterals() {
+ Constraint c = new BetweenRange(new SimpleColumn(new SimpleTable("Table1"),"column1"),new LiteralColumn(0),new LiteralColumn(5));
+ Assert.assertEquals("t0.column1 >= 0 and t0.column1 <= 5",c.render(context));
+ }
+
+
+ public void testBetweenRangeWithRealColumns() {
+ Constraint c = new BetweenRange(new LiteralColumn("column1"),new SimpleColumn(new SimpleTable("Table2"),"col1"),new SimpleColumn(new SimpleTable("Table3"),"col1"));
+ Assert.assertEquals("'column1' >= t0.col1 and 'column1' <= t1.col1",c.render(context));
+ }
+}
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/constraints/ColumnConstraintTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/constraints/ColumnConstraintTest.java
new file mode 100644
index 0000000..513013f
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/constraints/ColumnConstraintTest.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: ColumnConstraintTest.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.israfil.sqlelements.Column;
+import org.israfil.sqlelements.SimpleColumn;
+import org.israfil.sqlelements.SimpleTable;
+import org.israfil.sqlelements.render.DatabaseType;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+public class ColumnConstraintTest extends TestCase {
+ SQLRenderContext context;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ context = new SQLRenderContext(DatabaseType.Generic);
+ }
+
+ public void testColumnConstraintCreationWithoutTable() {
+ Column col = new SimpleColumn(null,"col");
+ ColumnConstraint c = new ColumnConstraint(col);
+ Assert.assertEquals("col",c.render(context));
+ }
+
+ public void testColumnConstraintCreationWithoutAlias() {
+ Column col = new SimpleColumn(new SimpleTable("foo"),"col");
+ ColumnConstraint c = new ColumnConstraint(col);
+ Assert.assertEquals("t0.col",c.render(context));
+ }
+
+ public void testColumnConstraintCreationWithAlias() {
+ Column col = new SimpleColumn(new SimpleTable("foo","my_foo_table"),"col");
+ ColumnConstraint c = new ColumnConstraint(col);
+ Assert.assertEquals("my_foo_table.col",c.render(context));
+ }
+
+ public void testColumnAccessInColumnConstraint() {
+ Column col = new SimpleColumn(null,"col");
+ ColumnConstraint c = new ColumnConstraint(col);
+ Assert.assertEquals(col,c.getColumn());
+ }
+}
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/constraints/EqualsConstraintTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/constraints/EqualsConstraintTest.java
new file mode 100644
index 0000000..50cc1d5
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/constraints/EqualsConstraintTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: EqualsConstraintTest.java 22 2005-12-11 15:08:56Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.israfil.sqlelements.LiteralColumn;
+import org.israfil.sqlelements.SimpleColumn;
+import org.israfil.sqlelements.SimpleTable;
+import org.israfil.sqlelements.render.DatabaseType;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+public class EqualsConstraintTest extends TestCase {
+ SQLRenderContext context;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ context = new SQLRenderContext(DatabaseType.Generic);
+ }
+
+ public void testColumnEqualsLiteral() {
+ Constraint c = new Equals(new SimpleColumn(new SimpleTable("Table1"),"column1"),new LiteralColumn(0));
+ Assert.assertEquals("t0.column1 = 0",c.render(context));
+ }
+
+ public void testLiteralEqualsColumn() {
+ Constraint c = new Equals(new LiteralColumn(0),new SimpleColumn(new SimpleTable("Table1"),"column1"));
+ Assert.assertEquals("0 = t0.column1",c.render(context));
+ }
+}
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/constraints/LogicalConstraintsTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/constraints/LogicalConstraintsTest.java
new file mode 100644
index 0000000..347eb08
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/constraints/LogicalConstraintsTest.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: LogicalConstraintsTest.java 27 2006-01-14 12:50:08Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import java.util.Set;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import net.israfil.foundation.collections.ArraySet;
+
+import org.israfil.sqlelements.mock.MockConstraint;
+import org.israfil.sqlelements.render.DatabaseType;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ * A suite of tests for all the so-called Logical constraints, such as
+ * and, or, not, etc.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 27 $
+ */
+public class LogicalConstraintsTest extends TestCase {
+
+ Constraint constraint1 = null;
+ Constraint constraint2 = null;
+ String expectedResult = null;
+ String constraintString1 = null;
+ String constraintString2 = null;
+ SQLRenderContext context = null;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ context = new SQLRenderContext(DatabaseType.Generic);
+ constraintString1 = "'A' = 'B'";
+ constraintString2 = "'B' = 'C'";
+ constraint1 = new MockConstraint(constraintString1);
+ constraint2 = new MockConstraint(constraintString2);
+ }
+
+ public void tearDown() throws Exception {
+ constraintString1 = null;
+ constraintString2 = null;
+ constraint1 = null;
+ constraint2 = null;
+ expectedResult = null;
+ super.tearDown();
+ }
+
+ public void testAndRender() {
+ expectedResult = constraintString1 + " and " + constraintString2;
+ Constraint andc = new And(constraint1,constraint2);
+ Assert.assertEquals(expectedResult,andc.render(context));
+ }
+
+ public void testAndWithSetOfConstraints() {
+ expectedResult = constraintString1 + " and " + constraintString2;
+ Set<Constraint> set = new ArraySet<Constraint>();
+ set.add(constraint1);
+ set.add(constraint2);
+ And arc = new And(set);
+ Assert.assertEquals(expectedResult,arc.render(context));
+ }
+
+ public void testOrWithConstraints() {
+ expectedResult = constraintString1 + " or " + constraintString2;
+ Or orc = new Or(constraint1,constraint2);
+ Assert.assertEquals(expectedResult,orc.render(context));
+ }
+
+ public void testOrWithSetOfConstraints() {
+ expectedResult = constraintString1 + " or " + constraintString2;
+ Set<Constraint> set = new ArraySet<Constraint>();
+ set.add(constraint1);
+ set.add(constraint2);
+ Or orc = new Or(set);
+ Assert.assertEquals(expectedResult,orc.render(context));
+ }
+
+ public void testNotRender() {
+ expectedResult = "not (" + constraintString1 + ")";
+ Not nc = new Not(constraint1);
+ Assert.assertEquals(expectedResult,nc.render(context));
+ }
+
+}
+
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/constraints/MockConstraintTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/constraints/MockConstraintTest.java
new file mode 100644
index 0000000..8f39388
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/constraints/MockConstraintTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: MockConstraintTest.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.israfil.sqlelements.mock.MockConstraint;
+import org.israfil.sqlelements.render.DatabaseType;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+
+/**
+ * A test of the MockConstraint object
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 25 $
+ */
+public class MockConstraintTest extends TestCase
+{
+
+ public void testMockConstraint()
+ {
+ String stringValue = "Foo";
+ Constraint ic = new MockConstraint(stringValue);
+ Assert.assertEquals(stringValue,ic.render(new SQLRenderContext(DatabaseType.Generic)));
+ }
+
+}
+
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/constraints/NaryConstraintTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/constraints/NaryConstraintTest.java
new file mode 100644
index 0000000..477424c
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/constraints/NaryConstraintTest.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: NaryConstraintTest.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.israfil.sqlelements.mock.MockNaryConstraint;
+import org.israfil.sqlelements.render.DatabaseType;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+public class NaryConstraintTest extends TestCase
+{
+ SQLRenderContext context;
+ Constraint c1;
+ Constraint c2;
+ Constraint c3;
+ Constraint c4;
+
+
+ public void setUp() throws Exception {
+ super.setUp();
+ c1 = new ArbitraryStringConstraint("(a=b)");
+ c2 = new ArbitraryStringConstraint("(b=c)");
+ c3 = new ArbitraryStringConstraint("(c=d)");
+ c4 = new ArbitraryStringConstraint("(c=q)");
+ context = new SQLRenderContext(DatabaseType.Generic);
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ c1 = null;
+ c2 = null;
+ c3 = null;
+ c4 = null;
+ context = null;
+ }
+
+ public void testConstructWithOneConstraint()
+ {
+ NaryConstraint nac = new MockNaryConstraint("foo",c1);
+ Assert.assertNotNull(nac);
+ }
+
+ public void testConstructWithTwoConstraints()
+ {
+ NaryConstraint nac = new MockNaryConstraint("foo",c1,c2);
+ Assert.assertNotNull(nac);
+ }
+
+ public void testConstructWithMultipleConstraints()
+ {
+ NaryConstraint nac = new MockNaryConstraint("foo",c1,c2,c3,c4);
+ Assert.assertNotNull(nac);
+ }
+
+ public void testConstructWithNoConstraints()
+ {
+
+ NaryConstraint nac = new MockNaryConstraint("foo");
+ Assert.assertNotNull(nac);
+ }
+
+ public void testConstructWithNullSetOfConstraints() {
+ NaryConstraint nac = new MockNaryConstraint("foo",(Set<Constraint>)null);
+ Assert.assertNotNull(nac);
+ }
+
+ public void testConstructWithSelfSameConstraint() {
+ NaryConstraint nac = new MockNaryConstraint("foo",c1,c2);
+ NaryConstraint nac1 = new MockNaryConstraint("foo",nac,c3,c4);
+ Assert.assertNotNull(nac);
+ Assert.assertEquals("(a=b) foo (b=c) foo (c=d) foo (c=q)",nac1.render(context));
+ }
+
+ public void testRenderWithAConstraintSetWithNullElement() {
+ Set<Constraint> sc = new HashSet<Constraint>();
+ sc.add(null);
+ NaryConstraint nac = new MockNaryConstraint("foo",sc);
+ Assert.assertNotNull(nac);
+ Assert.assertEquals("",nac.render(context));
+ }
+
+ public void testRenderWithOneConstraint() {
+ NaryConstraint nac = new MockNaryConstraint("foo",c1);
+ Assert.assertNotNull(nac);
+ Assert.assertEquals("(a=b)",nac.render(context));
+ }
+
+ public void testRenderWithOneNullConstraint(){
+ NaryConstraint nac = new MockNaryConstraint("foo",(Constraint[])null);
+ Assert.assertNotNull(nac);
+ Assert.assertEquals("",nac.render(context));
+ }
+
+ public void testNaryConstraintWithMultipleConstraints()
+ {
+ NaryConstraint nac = new MockNaryConstraint("foo",c1,c2,c3,c4);
+ Assert.assertNotNull(nac);
+ Assert.assertEquals("(a=b) foo (b=c) foo (c=d) foo (c=q)",nac.render(context));
+ }
+
+ public void testNaryConstraintWithNullConstraints()
+ {
+ NaryConstraint nac = new MockNaryConstraint("foo",null,c1,c2,c3,null,c4);
+ Assert.assertNotNull(nac);
+ Assert.assertEquals("(a=b) foo (b=c) foo (c=d) foo (c=q)",nac.render(context));
+ }
+}
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/constraints/NotEqualsConstraintTest.java b/sqlelements/src/test/java/org/israfil/sqlelements/constraints/NotEqualsConstraintTest.java
new file mode 100644
index 0000000..6e9cdf2
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/constraints/NotEqualsConstraintTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: NotEqualsConstraintTest.java 22 2005-12-11 15:08:56Z cgruber $
+ */
+package org.israfil.sqlelements.constraints;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.israfil.sqlelements.LiteralColumn;
+import org.israfil.sqlelements.SimpleColumn;
+import org.israfil.sqlelements.SimpleTable;
+import org.israfil.sqlelements.render.DatabaseType;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+public class NotEqualsConstraintTest extends TestCase {
+ SQLRenderContext context;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ context = new SQLRenderContext(DatabaseType.Generic);
+ }
+
+ public void testColumnEqualsLiteral() {
+ Constraint c = new NotEquals(new SimpleColumn(new SimpleTable("Table1"),"column1"),new LiteralColumn(0));
+ Assert.assertEquals("t0.column1 != 0",c.render(context));
+ }
+
+ public void testLiteralEqualsColumn() {
+ Constraint c = new NotEquals(new LiteralColumn(0),new SimpleColumn(new SimpleTable("Table1"),"column1"));
+ Assert.assertEquals("0 != t0.column1",c.render(context));
+ }
+}
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/mock/MockAliasedElement.java b/sqlelements/src/test/java/org/israfil/sqlelements/mock/MockAliasedElement.java
new file mode 100644
index 0000000..3cefddf
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/mock/MockAliasedElement.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: MockAliasedElement.java 16 2005-12-09 04:03:58Z cgruber $
+ */
+package org.israfil.sqlelements.mock;
+
+import org.israfil.sqlelements.AbstractAliasedSQLElement;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 16 $
+ */
+public class MockAliasedElement extends AbstractAliasedSQLElement {
+ public MockAliasedElement () {
+ }
+
+ public MockAliasedElement (String alias) {
+ this.alias = alias;
+ }
+
+ public String render(SQLRenderContext context) {
+ return null;
+ }
+}
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/mock/MockConstraint.java b/sqlelements/src/test/java/org/israfil/sqlelements/mock/MockConstraint.java
new file mode 100644
index 0000000..1468a78
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/mock/MockConstraint.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: MockConstraint.java 15 2005-12-09 03:56:01Z cgruber $
+ */
+package org.israfil.sqlelements.mock;
+
+import org.israfil.sqlelements.constraints.Constraint;
+import org.israfil.sqlelements.render.SQLRenderContext;
+
+/**
+ * A Mock object implementing Constraint for use in testing.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 15 $
+ */
+public class MockConstraint implements Constraint
+{
+
+ private Object textValue = null;
+ public String getText() { return textValue.toString(); }
+
+ public MockConstraint(Object textValue)
+ {
+ this.textValue=textValue;
+ }
+
+
+ public String render(SQLRenderContext context)
+ {
+ return getText();
+ }
+
+}
+
diff --git a/sqlelements/src/test/java/org/israfil/sqlelements/mock/MockNaryConstraint.java b/sqlelements/src/test/java/org/israfil/sqlelements/mock/MockNaryConstraint.java
new file mode 100644
index 0000000..7acf612
--- /dev/null
+++ b/sqlelements/src/test/java/org/israfil/sqlelements/mock/MockNaryConstraint.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
+ * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: MockNaryConstraint.java 25 2005-12-15 23:36:26Z cgruber $
+ */
+package org.israfil.sqlelements.mock;
+
+import java.util.Set;
+
+import org.israfil.sqlelements.constraints.Constraint;
+import org.israfil.sqlelements.constraints.NaryConstraint;
+
+/**
+ * A Mock object implementing Constraint for use in testing.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ * @author Latest: $Author: cgruber $
+ * @version $Revision: 25 $
+ */
+public class MockNaryConstraint extends NaryConstraint
+{
+ public MockNaryConstraint(String op, Constraint ... constraints) {
+ super(op,constraints);
+ }
+ public MockNaryConstraint(String op, Set<Constraint> constraints) {
+ super(op,constraints);
+ }
+}
+