You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2011/11/26 11:59:52 UTC
svn commit: r1206426 [6/7] - in /db/torque/torque4/trunk:
torque-runtime/src/main/java/org/apache/torque/
torque-runtime/src/main/java/org/apache/torque/avalon/
torque-runtime/src/main/java/org/apache/torque/dsfactory/
torque-runtime/src/main/java/org/...
Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/tableConstantInit.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/tableConstantInit.vm?rev=1206426&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/tableConstantInit.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/tableConstantInit.vm Sat Nov 26 10:59:15 2011
@@ -0,0 +1,73 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied. See the License for the
+## specific language governing permissions and limitations
+## under the License.
+##
+######
+##
+## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26 Aug 2005) tfischer $
+##
+## Initializes the constant for the table map in the map builder class.
+##
+## This template expects the current source element to be a "table" element
+## from the torque schema.
+## The options and the attributes of the current source element must be set
+## as velocity variables.
+##
+ TABLE = dbMap.getTable("$name");
+ TABLE.setJavaName("$javaName");
+ TABLE.setOMClass(${dbObjectPackage}.${dbObjectClassName}.class);
+ TABLE.setPeerClass(${peerPackage}.${peerClassName}.class);
+#if ( $description )
+ TABLE.setDescription("$description");
+#end
+#if ($idMethod == "native")
+ TABLE.setPrimaryKeyMethod(TableMap.NATIVE);
+#elseif ($idMethod == "idbroker")
+ TABLE.setPrimaryKeyMethod(TableMap.ID_BROKER);
+#else
+ TABLE.setPrimaryKeyMethod("$idMethod");
+#end
+#set ( $idMethodParameterElements = $torqueGen.getChildren("id-method-parameter"))
+#if (!$idMethodParameterElements.isEmpty())
+## assume one parameter.
+ #set ( $idMethodParameterElement = $idMethodParameterElements.get(0) )
+ #set ( $value = $idMethodParameterElement.getAttribute("value") )
+ TABLE.setPrimaryKeyMethodInfo("$value");
+#else
+ TABLE.setPrimaryKeyMethodInfo(ID_BROKER, TABLE.getName());
+ TABLE.setPrimaryKeyMethodInfo(SEQUENCE, "$sequenceName");
+ TABLE.setPrimaryKeyMethodInfo(AUTO_INCREMENT, "$name");
+#end
+#set ( $primaryKeyColumnElements = $torqueGen.getChild("primary-keys").getChildren("column") )
+#if ($useManagers == "true" && $primaryKeyColumnElements.size() > 0)
+ TABLE.setUseManager(true);
+ TABLE.setManagerClass(${managerPackage}.${managerClassName}.class);
+#end
+#set ( $tableOptionElements = $torqueGen.getChildren("option") )
+#foreach ( $optionElement in $tableOptionElements )
+ #set ( $key = $optionElement.getAttribute("key") )
+ #set ( $value = $optionElement.getAttribute("value") )
+ TABLE.setOption("$key", "$value");
+#end
+#set ( $columnElements = $torqueGen.getChildren("column") )
+#set ( $tableUseInheritance = "false" )
+#foreach ($columnElement in $columnElements)
+ #if ($inheritance != "false")
+ #set ( $tableUseInheritance = "true" )
+ #end
+#end
+ TABLE.setUseInheritance($tableUseInheritance);
+
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapInit/baseMapInit.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapInit/baseMapInit.vm?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapInit/baseMapInit.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapInit/baseMapInit.vm Sat Nov 26 10:59:15 2011
@@ -26,9 +26,6 @@
##
package ${mapBuilderPackage};
-import org.apache.torque.Torque;
-import org.apache.torque.TorqueException;
-
/**
* This is a Torque Generated class that is used to load all database map
* information at once. This is useful because Torque's default behaviour
@@ -37,17 +34,15 @@ import org.apache.torque.TorqueException
*
* @see org.apache.torque.map.DatabaseMap#initialize() DatabaseMap.initialize()
*/
-public class ${baseMapInitClassName}
+public class ${baseDatabaseMapInitClassName}
{
public static final void init()
- throws TorqueException
{
-#set ( $allTableElement = $torqueGen.getChild("all-tables") )
-#set ( $tableElements = $allTableElement.getChildren("table") )
+#set ( $databaseSetElement = $torqueGen.getSourceElement() )
+#set ( $tableElements = $databaseSetElement.getChildren("table") )
#foreach ( $tableElement in $tableElements )
#set ( $mapBuilderClassName = $tableElement.getAttribute("mapBuilderClassName") )
- #set ( $mapBuilderPackage = $tableElement.getAttribute("mapBuilderPackage") )
- Torque.getMapBuilder(${mapBuilderPackage}.${mapBuilderClassName}.CLASS_NAME);
+ ${mapBuilderClassName}.getTableMap();
#end
}
}
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapInit/mapInit.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapInit/mapInit.vm?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapInit/mapInit.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapInit/mapInit.vm Sat Nov 26 10:59:15 2011
@@ -25,7 +25,7 @@
## This template expects the current source element to be a "database" element
## from the torque schema.
##
-package ${mapInitPackage};
+package ${databaseMapInitPackage};
/**
* This Torque generated class is used to link the runtime code
@@ -36,7 +36,7 @@ package ${mapInitPackage};
*
* @see org.apache.torque.map.DatabaseMap#initialize() DatabaseMap.initialize()
*/
-public class ${mapInitClassName}
- extends ${mapBuilderPackage}.${baseMapInitClassName}
+public class ${databaseMapInitClassName}
+ extends ${mapBuilderPackage}.${baseDatabaseMapInitClassName}
{
}
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/columnConstant.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/columnConstant.vm?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/columnConstant.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/columnConstant.vm Sat Nov 26 10:59:15 2011
@@ -27,6 +27,8 @@
## The options and the attributes of the current source element must be set
## as velocity variables.
##
-
- /** the column name for the ${name} field */
- public static final String ${peerColumnName};
+#set ( $tableElement = $torqueGen.getParent() )
+#set ( $mapBuilderClassName = $tableElement.getAttribute("mapBuilderClassName") )
+ /** The column for the ${name} field */
+ public static final Column ${peerColumnName}
+ = ${mapBuilderClassName}.${peerColumnName};
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/imports.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/imports.vm?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/imports.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/imports.vm Sat Nov 26 10:59:15 2011
@@ -42,10 +42,10 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.torque.NoRowsException;
import org.apache.torque.TooManyRowsException;
+import org.apache.torque.Column;
import org.apache.torque.Torque;
import org.apache.torque.TorqueException;
import org.apache.torque.TorqueRuntimeException;
-import org.apache.torque.map.MapBuilder;
import org.apache.torque.map.TableMap;
import org.apache.torque.om.mapper.RecordMapper;
import org.apache.torque.om.mapper.CompositeMapper;
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/staticInit.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/staticInit.vm?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/staticInit.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/staticInit.vm Sat Nov 26 10:59:15 2011
@@ -30,6 +30,4 @@
static
{
$torqueGen.mergepoint("tableDatabaseNameConstantsInit")
-$torqueGen.mergepoint("columnConstantsInit")
-$torqueGen.mergepoint("mapBuilderInit")##
}
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/imports.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/imports.vm?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/imports.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/imports.vm Sat Nov 26 10:59:15 2011
@@ -59,7 +59,6 @@ import org.apache.torque.TooManyRowsExce
import org.apache.torque.Torque;
import org.apache.torque.TorqueException;
import org.apache.torque.TorqueRuntimeException;
-import org.apache.torque.map.MapBuilder;
import org.apache.torque.map.TableMap;
import org.apache.torque.om.mapper.RecordMapper;
import org.apache.torque.om.mapper.CompositeMapper;
Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTableTransformer.properties
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTableTransformer.properties?rev=1206426&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTableTransformer.properties (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTableTransformer.properties Sat Nov 26 10:59:15 2011
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+${attribute(noOverride):mapBuilderClassName}=${option:torque.om.className.mapBuilderClassNamePrefix}${attribute:javaName}${option:torque.om.className.mapBuilderClassNameSuffix}
+${attribute(noOverride):mapBuilderPackage}=${option:torque.om.package.package}${option:torque.om.package.mapPackageSuffix}
Modified: db/torque/torque4/trunk/torque-test/src/main/schema/bookstore-schema.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/main/schema/bookstore-schema.xml?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/main/schema/bookstore-schema.xml (original)
+++ db/torque/torque4/trunk/torque-test/src/main/schema/bookstore-schema.xml Sat Nov 26 10:59:15 2011
@@ -39,7 +39,7 @@
/>
<column
name="isbn"
- required="true"
+ required="false"
type="VARCHAR"
size="15"
description="ISBN"
Added: db/torque/torque4/trunk/torque-test/src/main/schema/databaseMapInit-schema.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/main/schema/databaseMapInit-schema.xml?rev=1206426&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/main/schema/databaseMapInit-schema.xml (added)
+++ db/torque/torque4/trunk/torque-test/src/main/schema/databaseMapInit-schema.xml Sat Nov 26 10:59:15 2011
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<!-- this schema is used to test problems users reported -->
+
+<database name="databaseMapInit"
+ defaultIdMethod="@DATABASE_ID_METHOD@"
+ package="org.apache.torque.test"
+ xmlns="http://db.apache.org/torque/4.0/templates/database"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://db.apache.org/torque/4.0/templates/database
+ http://db.apache.org/torque/4.0/templates/database.xsd">
+
+ <option key="databaseOptionKey1" value="databaseOptionValue1"/>
+ <option key="databaseOptionKey2" value="databaseOptionValue2"/>
+
+ <!-- Table for use by Database Map tests -->
+ <table name="NOT_USED_BEFORE_MAP_INIT"
+ description="Table used for database map initialisation checks">
+ <column name="id" required="true" primaryKey="true" type="INTEGER"
+ description="id column" autoIncrement="true" />
+ <column name="one" required="true" type="VARCHAR" size="50" default="unknown" protected="true"/>
+ <column name="two" required="true" type="VARCHAR" size="50" />
+ <column name="three" required="true" type="INTEGER"/>
+ <column name="CLASS_NAME" inheritance="single" type="CHAR" size="1">
+ <inheritance key="B" class="MapInheritanceChildB"/>
+ <inheritance key="C" class="MapInheritanceChildC" extends="org.apache.torque.test.NotUsedBeforeMapInit"/>
+ <inheritance key="D" class="MapInheritanceChildD" extends="org.apache.torque.test.MapInheritanceChildC"/>
+ </column>
+ <foreign-key foreignTable="SECOND_MAP_INIT_TABLE">
+ <reference
+ local="three"
+ foreign="id"/>
+ </foreign-key>
+ </table>
+ <table name="SECOND_MAP_INIT_TABLE" javaName="SecondMapInit">
+ <column name="id" required="true" primaryKey="true" type="INTEGER"
+ description="id column" autoIncrement="true"/>
+ </table>
+
+ <table name="OPTION" description="table with options">
+ <option key="tableOptionKey1" value="tableOptionValue1"/>
+ <option key="tableOptionKey2" value="tableOptionValue2"/>
+ <column name="ID" primaryKey="true" type="INTEGER" description="id for table with options">
+ <option key="columnOptionKey1" value="columnOptionValue1"/>
+ <option key="columnOptionKey2" value="columnOptionValue2"/>
+ </column>
+ </table>
+
+</database>
Modified: db/torque/torque4/trunk/torque-test/src/main/schema/foreign-key-schema.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/main/schema/foreign-key-schema.xml?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/main/schema/foreign-key-schema.xml (original)
+++ db/torque/torque4/trunk/torque-test/src/main/schema/foreign-key-schema.xml Sat Nov 26 10:59:15 2011
@@ -133,7 +133,9 @@
</foreign-key>
</table>
- <table name="COMPOSITE_INTEGER_VARCHAR_PK" idMethod="none">
+ <table name="COMP_INTEGER_VARCHAR_PK" idMethod="none"
+ description="table with a composite primary key consisting of an integer
+ and a varchar column">
<column name="ID1" primaryKey="true" type="INTEGER" javaType="object"/>
<column name="ID2" primaryKey="true" type="VARCHAR" size="50"/>
<column name="INTEGER_COLUMN" type="INTEGER" javaType="object"/>
@@ -141,23 +143,28 @@
<column name="NAME" type="VARCHAR" size="100"/>
</table>
- <table name="COMPOSITE_INTEGER_VARCHAR_FK">
+ <table name="COMP_INTEGER_VARCHAR_FK"
+ description="table with a composite foreign key consisting of an integer
+ and a varchar column">
<column name="ID" primaryKey="true" type="INTEGER" javaType="object"/>
<column name="FK1" type="INTEGER" javaType="object"/>
<column name="FK2" type="VARCHAR" size="50"/>
<column name="NAME" type="VARCHAR" size="100"/>
- <foreign-key foreignTable="COMPOSITE_INTEGER_VARCHAR_PK">
+ <foreign-key foreignTable="COMP_INTEGER_VARCHAR_PK">
<reference local="FK1" foreign="ID1"/>
<reference local="FK2" foreign="ID2"/>
</foreign-key>
</table>
- <table name="COMPOSITE_NONPK_FK">
+ <table name="COMP_NONPK_FK"
+ description="table with a composite foreign key consisting of an integer
+ and a varchar column, not pointing to the primary key
+ of the referenced table">
<column name="ID" primaryKey="true" type="INTEGER" javaType="object"/>
<column name="FK1" type="INTEGER" javaType="object"/>
<column name="FK2" type="VARCHAR" size="50"/>
<column name="NAME" type="VARCHAR" size="100"/>
- <foreign-key foreignTable="COMPOSITE_INTEGER_VARCHAR_PK">
+ <foreign-key foreignTable="COMP_INTEGER_VARCHAR_PK">
<reference local="FK1" foreign="INTEGER_COLUMN"/>
<reference local="FK2" foreign="VARCHAR_COLUMN"/>
</foreign-key>
Modified: db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml (original)
+++ db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml Sat Nov 26 10:59:15 2011
@@ -27,9 +27,6 @@
xsi:schemaLocation="http://db.apache.org/torque/4.0/templates/database
http://db.apache.org/torque/4.0/templates/database.xsd">
- <option key="databaseOptionKey1" value="databaseOptionValue1"/>
- <option key="databaseOptionKey2" value="databaseOptionValue2"/>
-
<external-schema filename="ext-schema.xml" />
<!-- TRQS77 -->
@@ -383,30 +380,6 @@
</foreign-key>
</table>
-<!-- Table for use by Database Map tests -->
- <table name="Not_Used_Before_Map_Init" javaName="UninitializedTable"
- description="A table description">
- <column name="id" required="true" primaryKey="true" type="INTEGER"
- description="id column" autoIncrement="true" />
- <column name="one" required="true" type="VARCHAR" size="50" default="unknown" protected="true"/>
- <column name="two" required="true" type="VARCHAR" size="50" />
- <column name="three" required="true" type="INTEGER"/>
- <column name="CLASS_NAME" inheritance="single" type="CHAR" size="1">
- <inheritance key="B" class="MapInheritanceChildB" extends="org.apache.torque.test.UninitializedTable"/>
- <inheritance key="C" class="MapInheritanceChildC" extends="org.apache.torque.test.UninitializedTable"/>
- <inheritance key="D" class="MapInheritanceChildD" extends="org.apache.torque.test.MapInheritanceChildC"/>
- </column>
- <foreign-key foreignTable="CIRCULAR_REFERENCE_A">
- <reference
- local="three"
- foreign="CIRCULAR_REFERENCE_A_ID"/>
- </foreign-key>
- </table>
- <table name="After_NotUsedBeforeMapInit" javaName="AfterNotUsedBeforeMapInit">
- <column name="id" required="true" primaryKey="true" type="INTEGER"
- description="id column" autoIncrement="true"/>
- </table>
-
<!-- Used by TestOMSetByName but can be used to test all types as needed.
Modified from Generator domaintest-schema.xml -->
@@ -499,13 +472,4 @@ Column.getJavaObject() not implimented f
<table name="ABSTRACT" abstract="true" description="table with abstract OM class">
<column name="ID" primaryKey="true" type="INTEGER" description="id for table with abstract OM class"/>
</table>
-
- <table name="OPTION" description="table with options">
- <option key="tableOptionKey1" value="tableOptionValue1"/>
- <option key="tableOptionKey2" value="tableOptionValue2"/>
- <column name="ID" primaryKey="true" type="INTEGER" description="id for table with options">
- <option key="columnOptionKey1" value="columnOptionValue1"/>
- <option key="columnOptionKey2" value="columnOptionValue2"/>
- </column>
- </table>
</database>
Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/BaseRuntimeTestCase.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/BaseRuntimeTestCase.java?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/BaseRuntimeTestCase.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/BaseRuntimeTestCase.java Sat Nov 26 10:59:15 2011
@@ -42,7 +42,7 @@ import org.apache.torque.util.Criteria;
public abstract class BaseRuntimeTestCase extends TestCase
{
/** The system property containing the path to the configuration file. */
- protected static final String CONFIG_FILE_SYSTEM_PROPERTY
+ public static final String CONFIG_FILE_SYSTEM_PROPERTY
= "torque.configuration.file";
/**
@@ -96,8 +96,8 @@ public abstract class BaseRuntimeTestCas
* Queries mysql for its major version. (format is major.minor.release)
* @return the major version of mysql
* @throws TorqueException if the database is not mysql or the query fails.
- * @throws NumberFormatException if the mysql major version cannot be
- * converted to an int
+ * @throws NumberFormatException if the mysql major version cannot be
+ * converted to an int
*/
protected int getMysqlMajorVersion()
throws TorqueException
@@ -123,7 +123,7 @@ public abstract class BaseRuntimeTestCas
completeVersion.lastIndexOf('.'));
return Integer.parseInt(minorVersion);
}
-
+
/**
* Deletes all authors and books in the bookstore tables.
*
Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java Sat Nov 26 10:59:15 2011
@@ -196,7 +196,7 @@ public class DataTest extends BaseRuntim
bc.setBintValue(false);
bc.setBcharValue(false);
bc.save();
-
+
// check a primitive id can be set manually
Author author = new Author();
author.setAuthorId(2000);
@@ -207,7 +207,7 @@ public class DataTest extends BaseRuntim
criteria.add(AuthorPeer.AUTHOR_ID, 2000);
List<Author> authorList = AuthorPeer.doSelect(criteria);
assertEquals(1, authorList.size());
-
+
// check an object id can be set manually
criteria = new Criteria();
IntegerObjectPkPeer.doDelete(criteria);
@@ -217,7 +217,7 @@ public class DataTest extends BaseRuntim
assertEquals(new Integer(3001), integerObjectPk.getId());
criteria = new Criteria();
criteria.add(IntegerObjectPkPeer.ID, 3001);
- List<IntegerObjectPk> integerObjectPkList
+ List<IntegerObjectPk> integerObjectPkList
= IntegerObjectPkPeer.doSelect(criteria);
assertEquals(1, integerObjectPkList.size());
}
@@ -242,7 +242,7 @@ public class DataTest extends BaseRuntim
private static final String[] validTitles = {
"Book 6 - Author 4", "Book 6 - Author 5", "Book 6 - Author 6",
- "Book 6 - Author 7", "Book 6 - Author 8",
+ "Book 6 - Author 7", "Book 6 - Author 8",
"Book 7 - Author 4", "Book 7 - Author 5", "Book 7 - Author 6",
"Book 7 - Author 7", "Book 7 - Author 8"
};
@@ -262,9 +262,9 @@ public class DataTest extends BaseRuntim
Criteria crit = new Criteria();
Criteria.Criterion c = crit.getNewCriterion(BookPeer.TITLE,
- (Object) "Book 6 - Author 1", Criteria.GREATER_EQUAL);
+ "Book 6 - Author 1", Criteria.GREATER_EQUAL);
c.and(crit.getNewCriterion(BookPeer.TITLE,
- (Object) "Book 8 - Author 3", Criteria.LESS_EQUAL));
+ "Book 8 - Author 3", Criteria.LESS_EQUAL));
crit.add(c);
crit.addDescendingOrderByColumn(BookPeer.BOOK_ID);
crit.setLimit(10);
@@ -292,7 +292,7 @@ public class DataTest extends BaseRuntim
{
if (Torque.getDB(Torque.getDefaultDB()).supportsNativeLimit())
{
- throw e;
+ throw e;
}
log.error("testLimitOffset(): "
+ "A limit of 0 is not supported for Databases "
@@ -308,7 +308,7 @@ public class DataTest extends BaseRuntim
// Check that limiting also works if a table with an equal column name
// is joined. This is problematic for oracle, see TORQUE-10.
-
+
crit = new Criteria();
crit.setLimit(10);
crit.setOffset(5);
@@ -346,8 +346,8 @@ public class DataTest extends BaseRuntim
}
/**
- * Tests whether selects work correctly if the value <code>null</code>
- * is used.
+ * Tests whether selects work correctly if the value <code>null</code>
+ * is used.
* @throws Exception if the test fails
*/
public void testNullSelects() throws Exception
@@ -356,7 +356,7 @@ public class DataTest extends BaseRuntim
Criteria criteria = new Criteria();
criteria.add(
NullValueTablePeer.NULL_VALUE_TABLE_ID,
- -1,
+ -1,
Criteria.NOT_EQUAL);
NullValueTablePeer.doDelete(criteria);
@@ -368,19 +368,19 @@ public class DataTest extends BaseRuntim
nvt = new NullValueTable();
nvt.setText2("text");
nvt.save();
-
- // do check for comparison NOT_EQUAL and value null
+
+ // do check for comparison NOT_EQUAL and value null
criteria.clear();
criteria.add(
- NullValueTablePeer.TEXT1,
- (Integer)null,
+ NullValueTablePeer.TEXT1,
+ (Integer)null,
Criteria.NOT_EQUAL);
criteria.add(NullValueTablePeer.NUMBER_OBJ1,
(Integer)null,
Criteria.NOT_EQUAL);
List<NullValueTable> result = NullValueTablePeer.doSelect(criteria);
- assertEquals("testNullSelects()"
- + "Result size should be 1 but is "
+ assertEquals("testNullSelects()"
+ + "Result size should be 1 but is "
+ result.size(),
1,
result.size());
@@ -390,19 +390,19 @@ public class DataTest extends BaseRuntim
+ nvt.getText1(),
nvt.getText1(),
"text");
-
- // do check for comparison EQUAL and value null
+
+ // do check for comparison EQUAL and value null
criteria.clear();
criteria.add(
- NullValueTablePeer.TEXT1,
- (Integer)null,
+ NullValueTablePeer.TEXT1,
+ (Integer)null,
Criteria.EQUAL);
criteria.add(NullValueTablePeer.NUMBER_OBJ1,
(Integer)null,
Criteria.EQUAL);
result = NullValueTablePeer.doSelect(criteria);
- assertEquals("testNullSelects()"
- + "Result size should be 1 but is "
+ assertEquals("testNullSelects()"
+ + "Result size should be 1 but is "
+ result.size(),
1,
result.size());
@@ -413,7 +413,7 @@ public class DataTest extends BaseRuntim
nvt.getText2(),
"text");
}
-
+
/**
* tests whether null values can be processed successfully by datadump
* For this, a row containing null values is inserted here,
@@ -475,7 +475,7 @@ public class DataTest extends BaseRuntim
bitCompositePk.setPk2(Boolean.FALSE);
bitCompositePk.setPayload("false payload");
bitCompositePk.save();
-
+
bitCompositePk = new BitCompositePk();
bitCompositePk.setPk1("true value");
bitCompositePk.setPk2(Boolean.TRUE);
@@ -492,7 +492,7 @@ public class DataTest extends BaseRuntim
criteria = new Criteria();
criteria.and(BitCompositePkPeer.PK1, "false value");
criteria.and(BitCompositePkPeer.PK2, Boolean.FALSE);
- List<BitCompositePk> result
+ List<BitCompositePk> result
= BitCompositePkPeer.doSelect(criteria);
assertEquals(1, result.size());
assertEquals("false payload", result.get(0).getPayload());
@@ -503,11 +503,11 @@ public class DataTest extends BaseRuntim
result = BitCompositePkPeer.doSelect(criteria);
assertEquals(1, result.size());
assertEquals("true payload", result.get(0).getPayload());
-
+
// check updating works
result.get(0).setPayload("true updated payload");
result.get(0).save();
-
+
criteria = new Criteria();
criteria.and(BitCompositePkPeer.PK1, "true value");
criteria.and(BitCompositePkPeer.PK2, Boolean.TRUE);
@@ -618,7 +618,7 @@ public class DataTest extends BaseRuntim
assertTrue("Primary key of data set should be f1 but is "
+ booleanCheck.getTestKey().trim(),
"f1".equals(booleanCheck.getTestKey().trim()));
-
+
if (Torque.getDB(Torque.getDefaultDB()) instanceof DBInterbase
|| Torque.getDB(Torque.getDefaultDB()) instanceof DBFirebird)
{
@@ -633,96 +633,102 @@ public class DataTest extends BaseRuntim
// replaced in joined tables
criteria.clear();
criteria.addAlias("bc", BooleanCheckPeer.TABLE_NAME);
- criteria.addJoin(BooleanCheckPeer.TEST_KEY, "bc.test_key");
+ criteria.addJoin(
+ BooleanCheckPeer.TEST_KEY,
+ new ColumnImpl("bc.test_key"));
criteria.add("bc.bint_value", new Boolean(false));
criteria.add("bc.bchar_value", new Boolean(false));
booleanCheckList = BooleanCheckPeer.doSelect(criteria);
assertTrue("Should have read 1 dataset with both values false "
+ "but read " + booleanCheckList.size(),
booleanCheckList.size() == 1);
- booleanCheck = (BooleanCheck) booleanCheckList.get(0);
+ booleanCheck = booleanCheckList.get(0);
assertTrue("Primary key of data set should be f1 but is "
+ booleanCheck.getTestKey().trim(),
"f1".equals(booleanCheck.getTestKey().trim()));
}
-
+
// check whether complex criteria are overwritten by
// replaceBooleans
criteria.clear();
Criteria.Criterion criterion1 = criteria.getNewCriterion(
- BooleanCheckPeer.BCHAR_VALUE,
+ BooleanCheckPeer.BCHAR_VALUE,
Boolean.FALSE,
Criteria.EQUAL);
Criteria.Criterion criterion2 = criteria.getNewCriterion(
- BooleanCheckPeer.BCHAR_VALUE,
- null,
+ BooleanCheckPeer.BCHAR_VALUE,
+ null,
Criteria.ISNULL);
criteria.add(criterion1.and(criterion2));
booleanCheckList = BooleanCheckPeer.doSelect(criteria);
// List should be empty, because and creates unfulfillable condition
// If BasePeer.correctBooleans() replaces Criterion wrongly,
// then we get entries in the list.
- assertTrue("List should be empty but contains "
+ assertTrue("List should be empty but contains "
+ booleanCheckList.size() + " datasets",
booleanCheckList.isEmpty());
-
+
// check whether complex criteria are overwritten by
// replaceBooleans
criteria.clear();
criterion1 = criteria.getNewCriterion(
- BooleanCheckPeer.BCHAR_VALUE,
+ BooleanCheckPeer.BCHAR_VALUE,
null,
Criteria.ISNULL);
criterion2 = criteria.getNewCriterion(
- BooleanCheckPeer.BCHAR_VALUE,
- Boolean.FALSE,
+ BooleanCheckPeer.BCHAR_VALUE,
+ Boolean.FALSE,
Criteria.EQUAL);
criteria.add(criterion1.or(criterion2));
booleanCheckList = BooleanCheckPeer.doSelect(criteria);
assertTrue("Should have read 1 dataset complex Criteria "
+ "but read " + booleanCheckList.size(),
booleanCheckList.size() == 1);
- booleanCheck = (BooleanCheck) booleanCheckList.get(0);
+ booleanCheck = booleanCheckList.get(0);
// use trim() for testkey because some databases will return the
// testkey filled up with blanks, as it is defined as char(10)
assertTrue("Primary key of data set should be f1 but is "
+ booleanCheck.getTestKey().trim(),
"f1".equals(booleanCheck.getTestKey().trim()));
-
+
// check whether booleans are replaced with unqualified columns
criteria.clear();
- criteria.add("bint_value", true);
- criteria.add("bchar_value", true);
-
+ criteria.add("BooleanCheck.bint_value", true);
+ criteria.add("BooleanCheck.bchar_value", true);
+
BooleanCheckPeer.correctBooleans(criteria);
- Criteria.Criterion criterionInt = criteria.getCriterion("bint_value");
+ Criteria.Criterion criterionInt
+ = criteria.getCriterion("BooleanCheck.bint_value");
Object intValue = criterionInt.getValue();
assertTrue("The boolean value should be an instance of Integer",
intValue instanceof Integer);
-
- Criteria.Criterion criterionChar = criteria.getCriterion("bchar_value");
+
+ Criteria.Criterion criterionChar = criteria.getCriterion(
+ "BooleanCheck.bchar_value");
Object charValue = criterionChar.getValue();
assertTrue("The boolean value should be an instance of String",
charValue instanceof String);
-
- // check whether booleans are left alone with unqualified columns and
+
+ // check whether booleans are left alone with unqualified columns and
// no table map
criteria.clear();
- criteria.add("bint_value", true);
- criteria.add("bchar_value", true);
-
+ criteria.add("BooleanCheck.bint_value", true);
+ criteria.add("BooleanCheck.bchar_value", true);
+
BasePeer.correctBooleans(criteria, null);
- Criteria.Criterion criterionBool1 = criteria.getCriterion("bint_value");
+ Criteria.Criterion criterionBool1 = criteria.getCriterion(
+ "BooleanCheck.bint_value");
Object boolValue1 = criterionBool1.getValue();
assertTrue("The boolean value should be an instance of Boolean",
boolValue1 instanceof Boolean);
-
- Criteria.Criterion criterionBool2 = criteria.getCriterion("bchar_value");
+
+ Criteria.Criterion criterionBool2 = criteria.getCriterion(
+ "BooleanCheck.bchar_value");
Object boolValue2 = criterionBool2.getValue();
assertTrue("The boolean value should be an instance of Boolean",
@@ -730,7 +736,7 @@ public class DataTest extends BaseRuntim
}
/**
- * Test whether an update works and whether it only affects the
+ * Test whether an update works and whether it only affects the
* specified record.
* @throws Exception if anything in the test goes wrong.
*/
@@ -745,10 +751,10 @@ public class DataTest extends BaseRuntim
Author author = new Author();
author.setName("Name");
author.save();
-
+
Criteria criteria = new Criteria();
criteria.addAscendingOrderByColumn(AuthorPeer.NAME);
-
+
List<Author> authors = AuthorPeer.doSelect(criteria);
assertEquals("List should contain 2 authors", 2, authors.size());
assertEquals("First Author's name should be \"Name\"",
@@ -757,13 +763,13 @@ public class DataTest extends BaseRuntim
assertEquals("Second Author's name should be \"OtherName\"",
"OtherName",
authors.get(1).getName());
-
+
author.setName("NewName");
author.save();
-
+
criteria.clear();
criteria.addAscendingOrderByColumn(AuthorPeer.NAME);
-
+
authors = AuthorPeer.doSelect(criteria);
assertEquals("List should contain 2 authors", 2, authors.size());
assertEquals("First Author's name should be \"NewName\"",
@@ -772,51 +778,51 @@ public class DataTest extends BaseRuntim
assertEquals("Second Author's name should be \"OtherName\"",
"OtherName",
authors.get(1).getName());
-
+
// Test doUpdate methods in Peer explicitly
Connection connection = Transaction.begin(AuthorPeer.DATABASE_NAME);
author.setName("NewName2");
AuthorPeer.doUpdate(author);
Transaction.commit(connection);
-
+
criteria.clear();
criteria.addAscendingOrderByColumn(AuthorPeer.NAME);
-
+
authors = AuthorPeer.doSelect(criteria);
assertEquals("List should contain 2 authors", 2, authors.size());
assertEquals("First Author's name should be \"NewName2\"",
"NewName2",
- ((Author) authors.get(0)).getName());
+ authors.get(0).getName());
assertEquals("Second Author's name should be \"OtherName\"",
"OtherName",
- ((Author) authors.get(1)).getName());
+ authors.get(1).getName());
author.setName("NewName3");
AuthorPeer.doUpdate(author);
-
+
criteria.clear();
criteria.addAscendingOrderByColumn(AuthorPeer.NAME);
-
+
authors = AuthorPeer.doSelect(criteria);
assertEquals("List should contain 2 authors", 2, authors.size());
assertEquals("First Author's name should be \"NewName3\"",
"NewName3",
- ((Author) authors.get(0)).getName());
+ authors.get(0).getName());
assertEquals("Second Author's name should be \"OtherName\"",
"OtherName",
- ((Author) authors.get(1)).getName());
+ authors.get(1).getName());
// Test updates for objects without primary keys. As we do not store
- // information which values were modified, we throw an Exception at
+ // information which values were modified, we throw an Exception at
// the attempt.
-
+
Nopk nopk = new Nopk();
nopk.setName("name");
nopk.save();
-
+
// check that save does not throw an error if nothing is modified
nopk.save();
-
+
nopk.setName("otherName");
try
{
@@ -826,7 +832,7 @@ public class DataTest extends BaseRuntim
catch (TorqueException e)
{
}
-
+
// check the doPupdate Peer methods themselves
try
{
@@ -847,9 +853,9 @@ public class DataTest extends BaseRuntim
{
}
Transaction.safeRollback(connection);
-
+
}
-
+
/**
* test special cases in the select clause
* @throws Exception if the test fails
@@ -874,7 +880,7 @@ public class DataTest extends BaseRuntim
public void testSelectFromDefault() throws Exception
{
Criteria criteria = new Criteria("default");
-
+
criteria.addSelectColumn(BookPeer.BOOK_ID);
BasePeer.doSelect(criteria, new IntegerMapper(), null);
@@ -920,11 +926,12 @@ public class DataTest extends BaseRuntim
Author author = new Author();
author.setName("name");
author.save((Connection) null);
- fail("NullPointerException expected");
+ fail("TorqueException expected");
}
- catch (NullPointerException e)
+ catch (TorqueException e)
{
//expected
+ assertEquals("connection is null", e.getMessage());
}
}
@@ -1027,7 +1034,7 @@ public class DataTest extends BaseRuntim
Criteria.RIGHT_JOIN);
criteria.addJoin(
AuthorPeer.AUTHOR_ID,
- "b." + getRawColumnName(BookPeer.AUTHOR_ID),
+ new ColumnImpl("b." + BookPeer.AUTHOR_ID.getColumnName()),
Criteria.LEFT_JOIN);
authorList = AuthorPeer.doSelect(criteria);
// Here we get 11 authors:
@@ -1047,7 +1054,7 @@ public class DataTest extends BaseRuntim
criteria.addJoin(BookPeer.AUTHOR_ID, AuthorPeer.AUTHOR_ID,
Criteria.RIGHT_JOIN);
criteria.addJoin(
- "b." + getRawColumnName(BookPeer.AUTHOR_ID),
+ new ColumnImpl("b." + BookPeer.AUTHOR_ID.getColumnName()),
AuthorPeer.AUTHOR_ID,
Criteria.RIGHT_JOIN);
authorList = AuthorPeer.doSelect(criteria);
@@ -1076,8 +1083,8 @@ public class DataTest extends BaseRuntim
List<Book> books = MyBookPeer.doSelectJoinAuthor(criteria);
assertTrue("books should contain 4 books but contains "
+ books.size(), books.size() == 4);
- Book bookTwo = (Book) books.get(1);
- Book bookThree = (Book) books.get(2);
+ Book bookTwo = books.get(1);
+ Book bookThree = books.get(2);
assertTrue ("the authors of BookTwo and BookThree"
+ " should point to the same instance",
bookTwo.getAuthor() == bookThree.getAuthor());
@@ -1090,39 +1097,39 @@ public class DataTest extends BaseRuntim
public void testDoSelectJoinAllExceptY() throws Exception
{
cleanABC();
-
+
// setup test data
A a = new A();
a.setName("test a");
a.save();
-
+
B b = new B();
b.setName("test b");
b.save();
-
+
RAb rab = new RAb();
rab.setName("test rab");
rab.setA(a);
rab.setB(b);
rab.save();
-
+
C c = new C();
c.setName("test c");
c.setA(a);
c.setB(b);
c.setRAb(rab);
c.save();
-
+
Criteria criteria = new Criteria();
criteria.add(APeer.A_ID, a.getAId());
List<C> list = MyCPeer.doSelectJoinAllExceptA(criteria);
assertTrue("list should contain 1 entry but contains "
+ list.size(), list.size() == 1);
-
+
C c1 = list.get(0);
B b1 = c1.getB();
RAb rab1 = c1.getRAb();
-
+
assertTrue("The name of c1 should be 'test c' but is " + c1.getName(),
c1.getName().equals("test c"));
assertTrue("The name of b1 should be 'test b' but is " + b1.getName(),
@@ -1179,7 +1186,7 @@ public class DataTest extends BaseRuntim
{
fail("Ascending Order By: "
+ "Title of first Book is "
- + ((Book) bookList.get(0)).getTitle()
+ + bookList.get(0).getTitle()
+ ", should be \"Book 1\"");
}
if (! "Book 4".equals(bookList.get(3).getTitle()))
@@ -1232,9 +1239,9 @@ public class DataTest extends BaseRuntim
criteria.addJoin(BookPeer.AUTHOR_ID, AuthorPeer.AUTHOR_ID);
criteria.addJoin(
AuthorPeer.AUTHOR_ID,
- "b." + getRawColumnName(BookPeer.AUTHOR_ID));
+ new ColumnImpl("b." + BookPeer.AUTHOR_ID.getColumnName()));
criteria.addAscendingOrderByColumn(
- "b." + getRawColumnName(BookPeer.TITLE));
+ new ColumnImpl("b." + BookPeer.TITLE.getColumnName()));
criteria.addDescendingOrderByColumn(BookPeer.TITLE);
// the retrieved columns are
// author book b
@@ -1252,18 +1259,18 @@ public class DataTest extends BaseRuntim
+ bookList.size()
+ ", should be 10");
}
- if (!"Book 4".equals(((Book)bookList.get(1)).getTitle()))
+ if (!"Book 4".equals(bookList.get(1).getTitle()))
{
fail("ordering by Aliases: "
+ "Title of second Book is "
- + ((Book) bookList.get(1)).getTitle()
+ + bookList.get(1).getTitle()
+ ", should be \"Book 4\"");
}
- if (!"Book 3".equals(((Book)bookList.get(2)).getTitle()))
+ if (!"Book 3".equals(bookList.get(2).getTitle()))
{
fail("ordering by Aliases: "
+ "Title of third Book is "
- + ((Book) bookList.get(2)).getTitle()
+ + bookList.get(2).getTitle()
+ ", should be \"Book 3\"");
}
@@ -1272,10 +1279,10 @@ public class DataTest extends BaseRuntim
criteria.addJoin(BookPeer.AUTHOR_ID, AuthorPeer.AUTHOR_ID);
criteria.addJoin(
AuthorPeer.AUTHOR_ID,
- "b." + getRawColumnName(BookPeer.AUTHOR_ID));
+ new ColumnImpl("b." + BookPeer.AUTHOR_ID.getColumnName()));
criteria.addAscendingOrderByColumn(BookPeer.TITLE);
criteria.addDescendingOrderByColumn(
- "b." + getRawColumnName(BookPeer.TITLE));
+ new ColumnImpl("b." + BookPeer.TITLE.getColumnName()));
// the retrieved columns are
// author book b
// author1 book1 book1
@@ -1292,18 +1299,18 @@ public class DataTest extends BaseRuntim
+ bookList.size()
+ ", should be 10");
}
- if (!"Book 2".equals(((Book)bookList.get(1)).getTitle()))
+ if (!"Book 2".equals(bookList.get(1).getTitle()))
{
fail("ordering by Aliases (2, PS): "
+ "Title of second Book is "
- + ((Book) bookList.get(1)).getTitle()
+ + bookList.get(1).getTitle()
+ ", should be \"Book 2\"");
}
- if (!"Book 2".equals(((Book)bookList.get(2)).getTitle()))
+ if (!"Book 2".equals(bookList.get(2).getTitle()))
{
fail("ordering by Aliases (2, PS): "
+ "Title of third Book is "
- + ((Book) bookList.get(2)).getTitle()
+ + bookList.get(2).getTitle()
+ ", should be \"Book 2\"");
}
@@ -1332,20 +1339,20 @@ public class DataTest extends BaseRuntim
criteria.add(AuthorPeer.NAME, author.getName().toLowerCase());
criteria.setIgnoreCase(true);
List<Author> result = AuthorPeer.doSelect(criteria);
- assertTrue("Size of result is not 1, but " + result.size(),
+ assertTrue("Size of result is not 1, but " + result.size(),
result.size() == 1);
// LIKE treatment might be different (e.g. postgres), so check extra
criteria = new Criteria();
criteria.add(
- AuthorPeer.NAME,
- (Object) author.getName().toLowerCase().replace('r', '%'),
+ AuthorPeer.NAME,
+ author.getName().toLowerCase().replace('r', '%'),
Criteria.LIKE);
criteria.setIgnoreCase(true);
result = AuthorPeer.doSelect(criteria);
- assertTrue("Size of result is not 1, but " + result.size(),
+ assertTrue("Size of result is not 1, but " + result.size(),
result.size() == 1);
-
+
// Test ignore case in criterion
criteria = new Criteria();
Criteria.Criterion criterion1 = criteria.getNewCriterion(
@@ -1363,10 +1370,10 @@ public class DataTest extends BaseRuntim
// nor in other criterions
assertFalse(criteria.isIgnoreCase());
assertFalse(criterion2.isIgnoreCase());
- assertTrue("Size of result is not 1, but " + result.size(),
+ assertTrue("Size of result is not 1, but " + result.size(),
result.size() == 1);
-
+
// Test ignore case in attached criterion
criteria = new Criteria();
criterion1 = criteria.getNewCriterion(
@@ -1385,7 +1392,7 @@ public class DataTest extends BaseRuntim
assertFalse(criteria.isIgnoreCase());
assertFalse(criterion1.isIgnoreCase());
- assertTrue("Size of result is not 1, but " + result.size(),
+ assertTrue("Size of result is not 1, but " + result.size(),
result.size() == 1);
// ignore case in "in" query
@@ -1395,10 +1402,10 @@ public class DataTest extends BaseRuntim
names.add(author.getName().toLowerCase());
criteria.add(AuthorPeer.NAME, names, Criteria.IN);
criteria.setIgnoreCase(true);
-
+
result = AuthorPeer.doSelect(criteria);
assertEquals("Expected result of size 1 but got " + result.size(),
- result.size(),
+ result.size(),
1);
}
@@ -1407,10 +1414,10 @@ public class DataTest extends BaseRuntim
author = new Author();
author.setName("author");
author.save();
-
- DB db = Torque.getDB(Torque.getDefaultDB());
- if (db instanceof DBMM
- || db instanceof DBAxion
+
+ DB db = Torque.getDB(Torque.getDefaultDB());
+ if (db instanceof DBMM
+ || db instanceof DBAxion
|| db instanceof DBCloudscape
|| db instanceof DBInformix
|| db instanceof DBInstantDB
@@ -1429,23 +1436,23 @@ public class DataTest extends BaseRuntim
criteria = new Criteria();
criteria.add(AuthorPeer.NAME, author.getName());
result = AuthorPeer.doSelect(criteria);
- assertTrue("Size of result is not 1, but " + result.size(),
+ assertTrue("Size of result is not 1, but " + result.size(),
result.size() == 1);
-
+
// again check LIKE treatment
criteria = new Criteria();
criteria.add(
- AuthorPeer.NAME,
- (Object) author.getName().replace('r', '%'),
+ AuthorPeer.NAME,
+ author.getName().replace('r', '%'),
Criteria.LIKE);
result = AuthorPeer.doSelect(criteria);
- assertTrue("Size of result is not 1, but " + result.size(),
+ assertTrue("Size of result is not 1, but " + result.size(),
result.size() == 1);
// Test different ignore cases in criterions
criteria = new Criteria();
criterion1 = criteria.getNewCriterion(
- AuthorPeer.NAME,
+ AuthorPeer.NAME,
author.getName().toLowerCase(),
Criteria.NOT_EQUAL);
criterion2 = criteria.getNewCriterion(
@@ -1457,7 +1464,7 @@ public class DataTest extends BaseRuntim
criteria.add(criterion1);
result = AuthorPeer.doSelect(criteria);
- assertTrue("Size of result is not 1, but " + result.size(),
+ assertTrue("Size of result is not 1, but " + result.size(),
result.size() == 1);
// ignore case in "in" query
@@ -1466,10 +1473,10 @@ public class DataTest extends BaseRuntim
Set<String> names = new HashSet<String>();
names.add(author.getName());
criteria.add(AuthorPeer.NAME, names, Criteria.IN);
-
+
result = AuthorPeer.doSelect(criteria);
assertEquals("Expected result of size 1 but got " + result.size(),
- result.size(),
+ result.size(),
1);
}
}
@@ -1495,11 +1502,11 @@ public class DataTest extends BaseRuntim
criteria.setIgnoreCase(true);
criteria.addAscendingOrderByColumn(AuthorPeer.NAME);
result = AuthorPeer.doSelect(criteria);
- assertTrue("Size of result is not 2, but " + result.size(),
+ assertTrue("Size of result is not 2, but " + result.size(),
result.size() == 2);
- author = (Author) result.get(0);
+ author = result.get(0);
assertEquals("First", author.getName(), "a");
-
+
cleanBookstore();
author = new Author();
author.setName("A");
@@ -1511,9 +1518,9 @@ public class DataTest extends BaseRuntim
criteria.setIgnoreCase(true);
criteria.addAscendingOrderByColumn(AuthorPeer.NAME);
result = AuthorPeer.doSelect(criteria);
- assertTrue("Size of result is not 2, but " + result.size(),
+ assertTrue("Size of result is not 2, but " + result.size(),
result.size() == 2);
- author = (Author) result.get(0);
+ author = result.get(0);
assertEquals("First", author.getName(), "A");
}
}
@@ -1565,7 +1572,7 @@ public class DataTest extends BaseRuntim
mapper.addMapper(
new AuthorRecordMapper(),
BookPeer.numColumns);
-
+
List<List<Object>> queryResult
= BookPeer.doSelect(criteria, mapper, null);
List<Object> mappedRow = queryResult.get(0);
@@ -1655,10 +1662,10 @@ public class DataTest extends BaseRuntim
DB adapter = Torque.getDatabase(Torque.getDefaultDB()).getAdapter();
if (adapter instanceof DBMSSQL)
{
- log.warn("testCurrentDate(): "
+ log.warn("testCurrentDate(): "
+ Criteria.CURRENT_DATE
+ " and "
- + Criteria.CURRENT_TIME
+ + Criteria.CURRENT_TIME
+ "are not supported by MSSQL");
return;
}
@@ -1666,8 +1673,8 @@ public class DataTest extends BaseRuntim
c.add(DateTestPeer.DATE_VALUE, Criteria.CURRENT_DATE);
if (adapter instanceof DBOracle)
{
- log.warn("testCurrentDate(): "
- + Criteria.CURRENT_TIME
+ log.warn("testCurrentDate(): "
+ + Criteria.CURRENT_TIME
+ "is not supported by Oracle");
}
else
@@ -1934,7 +1941,7 @@ public class DataTest extends BaseRuntim
assertTrue("read and written clobs should be equal",
clobTest.getClobValue().equals(readClobTest.getClobValue()));
-
+
// Test updating
clobTest = readClobTest;
{
@@ -1969,24 +1976,24 @@ public class DataTest extends BaseRuntim
{
Author author = new Author();
author.setAuthorId(1000);
-
+
Book book = new Book();
book.setBookId(1000);
-
+
Book bookNotEqual = new Book();
bookNotEqual.setBookId(2000);
-
+
Book bookEqual = new Book();
bookEqual.setBookId(1000);
-
- assertFalse("Author and Book should not be equal",
+
+ assertFalse("Author and Book should not be equal",
author.equals(book));
- assertTrue("Book compared with itself should be equal",
+ assertTrue("Book compared with itself should be equal",
book.equals(book));
- assertTrue("Book compared with book with same id should be equal",
+ assertTrue("Book compared with book with same id should be equal",
book.equals(bookEqual));
assertFalse("Book compared with book with different id "
- + "should not be equal",
+ + "should not be equal",
book.equals(bookNotEqual));
}
@@ -2021,7 +2028,7 @@ public class DataTest extends BaseRuntim
Author author3 = new Author();
author3.setName("author3");
author3.save();
-
+
// subquery with "in" clause
{
Criteria subquery = new Criteria();
@@ -2033,34 +2040,34 @@ public class DataTest extends BaseRuntim
Criteria criteria = new Criteria();
criteria.add(AuthorPeer.AUTHOR_ID, subquery, Criteria.IN);
criteria.addDescendingOrderByColumn(AuthorPeer.AUTHOR_ID);
-
+
List<?> result = AuthorPeer.doSelect(criteria);
assertEquals("Expected result of size 2 but got " + result.size(),
- result.size(),
+ result.size(),
3);
Author author = (Author) result.get(0);
- assertEquals("Expected author with Id "
- + author2b.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author2b.getAuthorId()
+ " at first position but got "
+ author.getAuthorId(),
author2b.getAuthorId(),
author.getAuthorId());
author = (Author) result.get(1);
- assertEquals("Expected author with Id "
- + author2.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author2.getAuthorId()
+ " at second position but got "
+ author.getAuthorId(),
author2.getAuthorId(),
author.getAuthorId());
author = (Author) result.get(2);
- assertEquals("Expected author with Id "
- + author1.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author1.getAuthorId()
+ " at second position but got "
+ author.getAuthorId(),
author1.getAuthorId(),
author.getAuthorId());
}
-
+
// subquery with =
{
Criteria subquery = new Criteria();
@@ -2068,20 +2075,20 @@ public class DataTest extends BaseRuntim
subquery.add(AuthorPeer.NAME, author1.getName());
Criteria criteria = new Criteria();
criteria.add(AuthorPeer.AUTHOR_ID, subquery);
-
+
List<Author> result = AuthorPeer.doSelect(criteria);
assertEquals("Expected result of size 1 but got " + result.size(),
- result.size(),
+ result.size(),
1);
Author author = result.get(0);
- assertEquals("Expected author with Id "
- + author1.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author1.getAuthorId()
+ " but got "
+ author.getAuthorId(),
author1.getAuthorId(),
author.getAuthorId());
}
-
+
// subquery containin an in()
{
Criteria subquery = new Criteria();
@@ -2093,35 +2100,35 @@ public class DataTest extends BaseRuntim
Criteria criteria = new Criteria();
criteria.add(AuthorPeer.AUTHOR_ID, subquery, Criteria.IN);
criteria.addAscendingOrderByColumn(AuthorPeer.AUTHOR_ID);
-
+
List<Author> result = AuthorPeer.doSelect(criteria);
assertEquals("Expected result of size 2 but got " + result.size(),
- result.size(),
+ result.size(),
3);
Author author = result.get(0);
- assertEquals("Expected author with Id "
- + author1.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author1.getAuthorId()
+ " but got "
+ author.getAuthorId(),
author1.getAuthorId(),
author.getAuthorId());
author = result.get(1);
- assertEquals("Expected author with Id "
- + author2.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author2.getAuthorId()
+ " but got "
+ author.getAuthorId(),
author2.getAuthorId(),
author.getAuthorId());
author = result.get(2);
- assertEquals("Expected author with Id "
- + author2b.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author2b.getAuthorId()
+ " but got "
+ author.getAuthorId(),
author2b.getAuthorId(),
author.getAuthorId());
}
}
-
+
/**
* Tests whether we can in statements.
* @throws Exception if the test fails
@@ -2138,7 +2145,22 @@ public class DataTest extends BaseRuntim
Author author3 = new Author();
author3.setName("author3");
author3.save();
-
+ Book book1 = new Book();
+ book1.setTitle("book1");
+ book1.setIsbn("isbn1");
+ book1.setAuthor(author1);
+ book1.save();
+ Book book2 = new Book();
+ book2.setTitle("book2");
+ book2.setIsbn("isbn2");
+ book2.setAuthor(author1);
+ book2.save();
+ Book book3 = new Book();
+ book3.setTitle("title3");
+ book3.setIsbn(null);
+ book3.setAuthor(author1);
+ book3.save();
+
// "in" query with String list and ignoreCase = false
{
Criteria criteria = new Criteria();
@@ -2147,21 +2169,21 @@ public class DataTest extends BaseRuntim
nameList.add("author2");
criteria.add(AuthorPeer.NAME, nameList, Criteria.IN);
criteria.addDescendingOrderByColumn(AuthorPeer.AUTHOR_ID);
-
+
List<Author> result = AuthorPeer.doSelect(criteria);
assertEquals("Expected result of size 2 but got " + result.size(),
2,
result.size());
Author author = result.get(0);
- assertEquals("Expected author with Id "
- + author2.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author2.getAuthorId()
+ " at first position but got "
+ author.getAuthorId(),
author2.getAuthorId(),
author.getAuthorId());
author = result.get(1);
- assertEquals("Expected author with Id "
- + author1.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author1.getAuthorId()
+ " at second position but got "
+ author.getAuthorId(),
author1.getAuthorId(),
@@ -2176,48 +2198,79 @@ public class DataTest extends BaseRuntim
idList.add(author2.getAuthorId());
criteria.add(AuthorPeer.AUTHOR_ID, idList, Criteria.IN);
criteria.addDescendingOrderByColumn(AuthorPeer.AUTHOR_ID);
-
+
List<Author> result = AuthorPeer.doSelect(criteria);
assertEquals("Expected result of size 2 but got " + result.size(),
2,
result.size());
Author author = result.get(0);
- assertEquals("Expected author with Id "
- + author2.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author2.getAuthorId()
+ " at first position but got "
+ author.getAuthorId(),
author2.getAuthorId(),
author.getAuthorId());
author = result.get(1);
- assertEquals("Expected author with Id "
- + author1.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author1.getAuthorId()
+ " at second position but got "
+ author.getAuthorId(),
author1.getAuthorId(),
author.getAuthorId());
}
+ // "in" query with String list and null value
+ // TODO fails
+// {
+// Criteria criteria = new Criteria();
+// List<String> isbnList = new ArrayList<String>();
+//
+// isbnList.add("isbn1");
+// isbnList.add(null);
+// criteria.add(BookPeer.ISBN, isbnList, Criteria.IN);
+// criteria.addAscendingOrderByColumn(BookPeer.BOOK_ID);
+//
+// List<Book> result = BookPeer.doSelect(criteria);
+// assertEquals("Expected result of size 2 but got " + result.size(),
+// 2,
+// result.size());
+// Book book = result.get(0);
+// assertEquals("Expected book with Id "
+// + book1.getBookId()
+// + " at first position but got "
+// + book.getBookId(),
+// book1.getBookId(),
+// book.getBookId());
+// book = result.get(1);
+// assertEquals("Expected book with Id "
+// + book3.getBookId()
+// + " at second position but got "
+// + book.getBookId(),
+// book3.getBookId(),
+// book.getBookId());
+// }
+
// "in" query with array and ignoreCase = false
{
Criteria criteria = new Criteria();
String[] nameArray = new String[] {"author1", "author3"};
criteria.add(AuthorPeer.NAME, nameArray, Criteria.IN);
criteria.addDescendingOrderByColumn(AuthorPeer.AUTHOR_ID);
-
+
List<Author> result = AuthorPeer.doSelect(criteria);
assertEquals("Expected result of size 2 but got " + result.size(),
- result.size(),
+ result.size(),
2);
Author author = result.get(0);
- assertEquals("Expected author with Id "
- + author3.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author3.getAuthorId()
+ " at first position but got "
+ author.getAuthorId(),
author3.getAuthorId(),
author.getAuthorId());
author = result.get(1);
- assertEquals("Expected author with Id "
- + author1.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author1.getAuthorId()
+ " at second position but got "
+ author.getAuthorId(),
author1.getAuthorId(),
@@ -2233,27 +2286,27 @@ public class DataTest extends BaseRuntim
criteria.add(AuthorPeer.NAME, nameList, Criteria.IN);
criteria.setIgnoreCase(true);
criteria.addDescendingOrderByColumn(AuthorPeer.AUTHOR_ID);
-
+
List<Author> result = AuthorPeer.doSelect(criteria);
assertEquals("Expected result of size 2 but got " + result.size(),
2,
result.size());
Author author = result.get(0);
- assertEquals("Expected author with Id "
- + author2.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author2.getAuthorId()
+ " at first position but got "
+ author.getAuthorId(),
author2.getAuthorId(),
author.getAuthorId());
author = result.get(1);
- assertEquals("Expected author with Id "
- + author1.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author1.getAuthorId()
+ " at second position but got "
+ author.getAuthorId(),
author1.getAuthorId(),
author.getAuthorId());
}
-
+
// "in" query with Integer list and ignoreCase = true
{
Criteria criteria = new Criteria();
@@ -2263,21 +2316,21 @@ public class DataTest extends BaseRuntim
criteria.add(AuthorPeer.AUTHOR_ID, idList, Criteria.IN);
criteria.setIgnoreCase(true);
criteria.addDescendingOrderByColumn(AuthorPeer.AUTHOR_ID);
-
+
List<Author> result = AuthorPeer.doSelect(criteria);
assertEquals("Expected result of size 2 but got " + result.size(),
2,
result.size());
Author author = result.get(0);
- assertEquals("Expected author with Id "
- + author2.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author2.getAuthorId()
+ " at first position but got "
+ author.getAuthorId(),
author2.getAuthorId(),
author.getAuthorId());
author = result.get(1);
- assertEquals("Expected author with Id "
- + author1.getAuthorId()
+ assertEquals("Expected author with Id "
+ + author1.getAuthorId()
+ " at second position but got "
+ author.getAuthorId(),
author1.getAuthorId(),
@@ -2287,7 +2340,7 @@ public class DataTest extends BaseRuntim
/**
* Tests whether a table implementing an interface actually
- * returns an instance of this interface
+ * returns an instance of this interface
* @throws Exception if the test fails
*/
public void testInterface() throws Exception
@@ -2295,35 +2348,35 @@ public class DataTest extends BaseRuntim
Criteria criteria = new Criteria();
criteria.add(IfcTablePeer.ID, -1, Criteria.NOT_EQUAL);
IfcTablePeer.doDelete(criteria);
-
+
IfcTable ifc = new IfcTable();
-
+
assertTrue("IfcTable should be an instance of TestInterface", ifc instanceof TestInterface);
-
+
ifc.setID(1);
ifc.setName("John Doe");
ifc.save();
List<IfcTable> results = IfcTablePeer.doSelect(new Criteria());
-
+
for (IfcTable ifcTable : results)
{
assertTrue("IfcTablePeer.doSelect should return"
- + " instances of TestInterface",
+ + " instances of TestInterface",
ifcTable instanceof TestInterface);
}
-
+
IfcTable2 ifc2 = new IfcTable2();
assertTrue("IfcTable2 should be an instance of LocalTestInterface",
ifc2 instanceof LocalTestInterface);
List<IfcTable2> results2 = IfcTable2Peer.doSelect(new Criteria());
-
+
for (IfcTable2 ifcTable2 : results2)
{
assertTrue("IfcTable2Peer.doSelect should return"
- + " instances of LocalTestInterface",
+ + " instances of LocalTestInterface",
ifcTable2 instanceof LocalTestInterface);
}
}
@@ -2333,14 +2386,14 @@ public class DataTest extends BaseRuntim
// make sure that the InheritanceTest table is empty before the test
Criteria criteria = new Criteria();
criteria.add(
- InheritanceTestPeer.INHERITANCE_TEST,
- (Object) null,
+ InheritanceTestPeer.INHERITANCE_TEST,
+ (Object) null,
Criteria.ISNOTNULL);
InheritanceTestPeer.doDelete(criteria);
criteria = new Criteria();
criteria.add(
- InheritanceTestPeer.INHERITANCE_TEST,
- (Object) null,
+ InheritanceTestPeer.INHERITANCE_TEST,
+ (Object) null,
Criteria.ISNOTNULL);
assertEquals(0,
new CountHelper().count(criteria));
@@ -2358,12 +2411,12 @@ public class DataTest extends BaseRuntim
InheritanceChildD inheritanceChildD = new InheritanceChildD();
inheritanceChildD.setPayloadParent("payload Parent 4");
inheritanceChildD.save();
-
+
// Check that all objects are saved into the InheritanceTest table
criteria = new Criteria();
criteria.add(
- InheritanceTestPeer.INHERITANCE_TEST,
- (Object) null,
+ InheritanceTestPeer.INHERITANCE_TEST,
+ (Object) null,
Criteria.ISNOTNULL);
assertEquals("InheritanceTestTable should contain 4 rows",
4,
@@ -2371,21 +2424,21 @@ public class DataTest extends BaseRuntim
criteria = new Criteria();
criteria.addAscendingOrderByColumn(
InheritanceTestPeer.INHERITANCE_TEST);
-
+
// Check that the class of the object is retained when loading
- List<InheritanceTest> inheritanceObjects
+ List<InheritanceTest> inheritanceObjects
= InheritanceTestPeer.doSelect(criteria);
assertEquals(
- InheritanceTest.class,
+ InheritanceTest.class,
inheritanceObjects.get(0).getClass());
assertEquals(
- InheritanceChildB.class,
+ InheritanceChildB.class,
inheritanceObjects.get(1).getClass());
assertEquals(
- InheritanceChildC.class,
+ InheritanceChildC.class,
inheritanceObjects.get(2).getClass());
assertEquals(
- InheritanceChildD.class,
+ InheritanceChildD.class,
inheritanceObjects.get(3).getClass());
}
@@ -2396,31 +2449,31 @@ public class DataTest extends BaseRuntim
InheritanceClassnameTestPeer.doDelete(criteria);
criteria = new Criteria();
criteria.add(
- InheritanceClassnameTestPeer.INHERITANCE_TEST,
- (Object) null,
+ InheritanceClassnameTestPeer.INHERITANCE_TEST,
+ (Object) null,
Criteria.ISNOTNULL);
assertEquals(0,
new CountHelper().count(criteria));
// create & save test data
- InheritanceClassnameTest inheritanceClassnameTest
+ InheritanceClassnameTest inheritanceClassnameTest
= new InheritanceClassnameTest();
inheritanceClassnameTest.setPayload("0 parent");
inheritanceClassnameTest.save();
- InheritanceClassnameTestChild1 inheritanceClassnameChild1
+ InheritanceClassnameTestChild1 inheritanceClassnameChild1
= new InheritanceClassnameTestChild1();
inheritanceClassnameChild1.setPayload("1 child");
inheritanceClassnameChild1.save();
- InheritanceClassnameTestChild2 inheritanceClassnameChild2
+ InheritanceClassnameTestChild2 inheritanceClassnameChild2
= new InheritanceClassnameTestChild2();
inheritanceClassnameChild2.setPayload("2 child");
inheritanceClassnameChild2.save();
-
+
// Check that all objects are saved into the InheritanceTest table
criteria = new Criteria();
criteria.add(
- InheritanceClassnameTestPeer.INHERITANCE_TEST,
- (Object) null,
+ InheritanceClassnameTestPeer.INHERITANCE_TEST,
+ (Object) null,
Criteria.ISNOTNULL);
assertEquals("InheritanceClassnameTest table should contain 3 rows",
3,
@@ -2428,20 +2481,20 @@ public class DataTest extends BaseRuntim
criteria = new Criteria();
criteria.addAscendingOrderByColumn(
InheritanceClassnameTestPeer.PAYLOAD);
-
+
// Check that the class of the object is retained when loading
- List<InheritanceClassnameTest> inheritanceObjects
+ List<InheritanceClassnameTest> inheritanceObjects
= InheritanceClassnameTestPeer.doSelect(criteria);
assertEquals(
- InheritanceClassnameTest.class,
+ InheritanceClassnameTest.class,
inheritanceObjects.get(0).getClass());
assertEquals("0 parent", inheritanceObjects.get(0).getPayload());
assertEquals(
- InheritanceClassnameTestChild1.class,
+ InheritanceClassnameTestChild1.class,
inheritanceObjects.get(1).getClass());
assertEquals("1 child", inheritanceObjects.get(1).getPayload());
assertEquals(
- InheritanceClassnameTestChild2.class,
+ InheritanceClassnameTestChild2.class,
inheritanceObjects.get(2).getClass());
assertEquals("2 child", inheritanceObjects.get(2).getPayload());
}
@@ -2457,17 +2510,17 @@ public class DataTest extends BaseRuntim
Author author = new Author();
author.setName("Joshua Bloch");
author.save();
-
+
Criteria criteria = new Criteria();
criteria.add(AuthorPeer.AUTHOR_ID, (Object) null, Criteria.NOT_EQUAL);
criteria.add("name", (Object) "Joshua Bloch", Criteria.EQUAL);
List<Author> authors = AuthorPeer.doSelect(criteria);
assertEquals(1, authors.size());
}
-
+
public void testLikeClauseEscaping() throws Exception
{
- String[] authorNames
+ String[] authorNames
= {"abc", "bbc", "a_c", "a%c", "a\\c", "a\"c", "a'c"};
Map<String, String> likeResults = new HashMap<String, String>();
@@ -2475,7 +2528,7 @@ public class DataTest extends BaseRuntim
likeResults.put("a\\_c", "a_c");
likeResults.put("a\\_%", "a_c");
likeResults.put("%\\_c", "a_c");
-
+
likeResults.put("a\\%c", "a%c");
likeResults.put("a\\%%", "a%c");
likeResults.put("%\\%c", "a%c");
@@ -2487,7 +2540,7 @@ public class DataTest extends BaseRuntim
likeResults.put("a\"c", "a\"c");
likeResults.put("a\"%", "a\"c");
likeResults.put("%\"c", "a\"c");
-
+
likeResults.put("a'c", "a'c");
likeResults.put("a'%", "a'c");
likeResults.put("%'c", "a'c");
@@ -2500,7 +2553,7 @@ public class DataTest extends BaseRuntim
author.setName(authorNames[i]);
author.save();
}
-
+
// Check authors are in the database
for (int i = 0; i < authorNames.length; ++i)
{
@@ -2509,8 +2562,8 @@ public class DataTest extends BaseRuntim
List<Author> authorList = AuthorPeer.doSelect(criteria);
assertEquals(
"AuthorList should contain one author"
- + " when querying for " + authorNames[i],
- 1,
+ + " when querying for " + authorNames[i],
+ 1,
authorList.size());
Author author = authorList.get(0);
assertEquals("Name of author should be " + authorNames[i],
@@ -2522,54 +2575,54 @@ public class DataTest extends BaseRuntim
{
Criteria criteria = new Criteria();
criteria.add(
- AuthorPeer.NAME,
- (Object) likeResult.getKey(),
+ AuthorPeer.NAME,
+ likeResult.getKey(),
Criteria.LIKE);
List<Author> authorList = AuthorPeer.doSelect(criteria);
assertEquals(
"AuthorList should contain one author"
- + " when querying for " + likeResult.getKey(),
- 1,
+ + " when querying for " + likeResult.getKey(),
+ 1,
authorList.size());
- Author author = (Author) authorList.get(0);
- assertEquals("Name of author should be "
+ Author author = authorList.get(0);
+ assertEquals("Name of author should be "
+ likeResult.getValue()
+ " when querying for "
+ likeResult.getKey(),
likeResult.getValue(),
author.getName());
}
-
+
// check that case insensitivity is maintained if
// a like is replaced with an equals (no wildcard present)
// This might be a problem for databases which use ILIKE
Criteria criteria = new Criteria();
- criteria.add(AuthorPeer.NAME, (Object) "AbC", Criteria.LIKE);
+ criteria.add(AuthorPeer.NAME, "AbC", Criteria.LIKE);
criteria.setIgnoreCase(true);
List<Author> authorList = AuthorPeer.doSelect(criteria);
assertEquals(
- "AuthorList should contain one author",
- 1,
+ "AuthorList should contain one author",
+ 1,
authorList.size());
Author author = authorList.get(0);
assertEquals("Name of author should be abc",
"abc",
author.getName());
-
+
// check that the escape clause (where needed) also works
// with limit, offset and order by
criteria = new Criteria();
Criteria.Criterion criterion1 = criteria.getNewCriterion(
- AuthorPeer.NAME,
- (Object) "b%",
+ AuthorPeer.NAME,
+ "b%",
Criteria.LIKE);
Criteria.Criterion criterion2 = criteria.getNewCriterion(
- AuthorPeer.NAME,
- (Object) "a\\%%",
+ AuthorPeer.NAME,
+ "a\\%%",
Criteria.LIKE);
Criteria.Criterion criterion3 = criteria.getNewCriterion(
- AuthorPeer.NAME,
- (Object) "cbc",
+ AuthorPeer.NAME,
+ "cbc",
Criteria.LIKE);
criteria.add(criterion1.or(criterion2).or(criterion3));
criteria.addAscendingOrderByColumn(AuthorPeer.NAME);
@@ -2577,10 +2630,10 @@ public class DataTest extends BaseRuntim
criteria.setLimit(1);
authorList = AuthorPeer.doSelect(criteria);
assertEquals(
- "AuthorList should contain one author",
- 1,
+ "AuthorList should contain one author",
+ 1,
authorList.size());
- author = (Author) authorList.get(0);
+ author = authorList.get(0);
assertEquals("Name of author should be bbc",
"bbc",
author.getName());
@@ -2659,7 +2712,7 @@ public class DataTest extends BaseRuntim
return CPeer.doSelectJoinAllExceptA(criteria);
}
}
-
+
static class DoNothingMapper implements RecordMapper<Object>
{
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org