Author: tfischer
Date: Sun Nov 19 06:14:09 2006
New Revision: 476822
URL: http://svn.apache.org/viewvc?view=rev&rev=476822
Log:
Skip subselect tests in the test project if mysql < 4.1 is used.
Fixes TORQUE-65.
Modified:
db/torque/test/trunk/test-project/src/java/org/apache/torque/BaseRuntimeTestCase.java
db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java
db/torque/test/trunk/test-project/src/java/org/apache/torque/DocsTest.java
Modified:
db/torque/test/trunk/test-project/src/java/org/apache/torque/BaseRuntimeTestCase.java
URL:
http://svn.apache.org/viewvc/db/torque/test/trunk/test-project/src/java/org/apache/torque/BaseRuntimeTestCase.java?view=diff&rev=476822&r1=476821&r2=476822
==============================================================================
---
db/torque/test/trunk/test-project/src/java/org/apache/torque/BaseRuntimeTestCase.java
(original)
+++
db/torque/test/trunk/test-project/src/java/org/apache/torque/BaseRuntimeTestCase.java
Sun Nov 19 06:14:09 2006
@@ -19,8 +19,18 @@
* under the License.
*/
+import java.util.List;
+
import junit.framework.TestCase;
+import org.apache.torque.adapter.DB;
+import org.apache.torque.adapter.DBMM;
+import org.apache.torque.util.BasePeer;
+
+import com.workingdogs.village.DataSetException;
+import com.workingdogs.village.Record;
+import com.workingdogs.village.Value;
+
/**
* Base functionality to be extended by all Torque test cases. Test
* case implementations are used to automate unit testing via JUnit.
@@ -63,4 +73,62 @@
}
}
+ /**
+ * Queries mysql for its version.
+ * @return the version String mysql returns
+ * @throws TorqueException if the database is not mysql or the query fails.
+ * @throws DataSetException if the version string can not be extracted from
+ * the select result.
+ */
+ protected String getMysqlVersion() throws TorqueException, DataSetException
+ {
+ DB adapter = Torque.getDatabase(Torque.getDefaultDB()).getAdapter();
+ if (!(adapter instanceof DBMM))
+ {
+ throw new TorqueException(
+ "getMysqlVersion called but database adapter is "
+ + adapter.getClass().getName());
+ }
+ List records = BasePeer.executeQuery("show variables like
\"version\"");
+ Record record = (Record) records.get(0);
+ Value versionValue = record.getValue("Value");
+ String version = versionValue.asString();
+ return version;
+ }
+
+ /**
+ * 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 DataSetException if the version string can not be extracted from
+ * the select result.
+ * @throws NumberFormatException if the mysql major version cannot be
+ * converted to an int
+ */
+ protected int getMysqlMajorVersion()
+ throws TorqueException, DataSetException
+ {
+ String completeVersion = getMysqlVersion();
+ String majorVersion
+ = completeVersion.substring(0, completeVersion.indexOf('.'));
+ return Integer.parseInt(majorVersion);
+ }
+
+ /**
+ * Queries mysql for its minor version. (format is major.minor.release)
+ * @return the minor version of mysql
+ * @throws TorqueException if the database is not mysql or the query fails.
+ * @throws DataSetException if the version string can not be extracted from
+ * the select result.
+ */
+ protected int getMysqlMinorVersion()
+ throws TorqueException, DataSetException
+ {
+ String completeVersion = getMysqlVersion();
+ String minorVersion
+ = completeVersion.substring(
+ completeVersion.indexOf('.') + 1,
+ completeVersion.lastIndexOf('.'));
+ return Integer.parseInt(minorVersion);
+ }
}
Modified:
db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java
URL:
http://svn.apache.org/viewvc/db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java?view=diff&rev=476822&r1=476821&r2=476822
==============================================================================
--- db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java
(original)
+++ db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java
Sun Nov 19 06:14:09 2006
@@ -98,7 +98,7 @@
*/
public class DataTest extends BaseRuntimeTestCase
{
- private static Log log = LogFactory.getLog(DataTest.class);;
+ private static Log log = LogFactory.getLog(DataTest.class);
/**
* Creates a new instance.
@@ -1552,11 +1552,23 @@
}
/**
- * Tests whether we can execute subqueries
+ * Tests whether we can execute subqueries.
* @throws Exception if the test fails
*/
public void testSubqueries() throws Exception
{
+ DB adapter = Torque.getDatabase(Torque.getDefaultDB()).getAdapter();
+ if (adapter instanceof DBMM)
+ {
+ int majorVersion = getMysqlMajorVersion();
+ int minorVersion = getMysqlMinorVersion();
+ if (majorVersion < 4 || (majorVersion == 4 && minorVersion == 0))
+ {
+ log.error("testSubqueries(): "
+ + "Subselects are not supported by Mysql < 4.1");
+ return;
+ }
+ }
cleanBookstore();
Author author1 = new Author();
author1.setName("author1");
Modified:
db/torque/test/trunk/test-project/src/java/org/apache/torque/DocsTest.java
URL:
http://svn.apache.org/viewvc/db/torque/test/trunk/test-project/src/java/org/apache/torque/DocsTest.java?view=diff&rev=476822&r1=476821&r2=476822
==============================================================================
--- db/torque/test/trunk/test-project/src/java/org/apache/torque/DocsTest.java
(original)
+++ db/torque/test/trunk/test-project/src/java/org/apache/torque/DocsTest.java
Sun Nov 19 06:14:09 2006
@@ -21,6 +21,10 @@
import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.torque.adapter.DB;
+import org.apache.torque.adapter.DBMM;
import org.apache.torque.test.Author;
import org.apache.torque.test.AuthorPeer;
import org.apache.torque.test.Book;
@@ -28,6 +32,8 @@
import org.apache.torque.util.BasePeer;
import org.apache.torque.util.Criteria;
+import com.workingdogs.village.DataSetException;
+
/**
* Runtime tests to make sure that the code which is supplied
* in the documentation actually works ;-)
@@ -55,6 +61,8 @@
public static final String BOOK_3_ISBN = "0-201-63354-X";
+ private static Log log = LogFactory.getLog(DocsTest.class);
+
/**
* Creates a new instance.
*/
@@ -364,8 +372,20 @@
/**
* Criteria Howto, section "subselects"
*/
- public void testSubselects() throws TorqueException
+ public void testSubselects() throws TorqueException, DataSetException
{
+ DB adapter = Torque.getDatabase(Torque.getDefaultDB()).getAdapter();
+ if (adapter instanceof DBMM)
+ {
+ int majorVersion = getMysqlMajorVersion();
+ int minorVersion = getMysqlMinorVersion();
+ if (majorVersion < 4 || (majorVersion == 4 && minorVersion == 0))
+ {
+ log.error("testSubqueries(): "
+ + "Subselects are not supported by Mysql < 4.1");
+ return;
+ }
+ }
Criteria subquery = new Criteria();
subquery.addSelectColumn("MAX(" + AuthorPeer.AUTHOR_ID + ")");
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]