You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2006/03/18 17:13:03 UTC
svn commit: r386861 - in /db/derby/code/trunk: ./
java/client/org/apache/derby/client/net/ java/client/org/apache/derby/jdbc/
java/engine/org/apache/derby/impl/jdbc/ java/engine/org/apache/derby/jdbc/
java/testing/org/apache/derbyTesting/functionTests/...
Author: rhillegas
Date: Sat Mar 18 08:13:00 2006
New Revision: 386861
URL: http://svn.apache.org/viewcvs?rev=386861&view=rev
Log:
Commit Anurag's patch for DERBY-942: wiring JDBC4 Ease-of-development calls up to the default QueryObjectGenerator
Added:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestData.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQuery.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject_app.properties (with props)
Modified:
db/derby/code/trunk/build.xml
db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java
db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDataSource40.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java
db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDataSource40.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc4.runall
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/copyfiles.ant
db/derby/code/trunk/tools/jar/extraDBMSclasses.properties
Modified: db/derby/code/trunk/build.xml
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/build.xml?rev=386861&r1=386860&r2=386861&view=diff
==============================================================================
--- db/derby/code/trunk/build.xml (original)
+++ db/derby/code/trunk/build.xml Sat Mar 18 08:13:00 2006
@@ -732,6 +732,15 @@
</target>
+ <target name="jdbc4_classlist_edit" if="jdk16">
+ <!-- uncomment jdbc4 classes if jdk 1.6 is available -->
+ <echo message="uncommenting jdbc4 classes"/>
+ <replaceregexp file="${derby.jar.dir}/lists/otherDerbyClasses.properties"
+ match="^#jdbc4_optional_(.*)"
+ replace="\1"
+ byline="true"/>
+ </target>
+
<!-- - - - - - - - - - - - - - - derby.jar target - - - - - - - - - - - -->
<target name="derbyjar" depends="initjars">
@@ -741,6 +750,8 @@
<concat destfile="${derby.jar.dir}/lists/otherDerbyClasses.properties">
<fileset dir="${basedir}/tools/jar" includes="*DBMS*.properties"/>
</concat>
+
+ <antcall target="jdbc4_classlist_edit"/>
<mkdir dir="${derby.jar.dir}/lists/org/apache/derby"/>
<java classname="org.apache.derbyBuild.propertyconfig">
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java?rev=386861&r1=386860&r2=386861&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java Sat Mar 18 08:13:00 2006
@@ -20,6 +20,8 @@
package org.apache.derby.client.net;
+import java.sql.BaseQuery;
+import java.sql.QueryObjectFactory;
import org.apache.derby.client.am.SQLExceptionFactory;
import org.apache.derby.client.am.SqlException;
import org.apache.derby.jdbc.InternalDriver;
@@ -144,9 +146,16 @@
throw SQLExceptionFactory.notImplemented ("getClientInfo (Properties)");
}
- public <T> T createQueryObject(Class<T> ifc) throws SQLException {
- throw SQLExceptionFactory.notImplemented ("createQueryObject (Class<T>)");
- }
+ /**
+ * This method forwards all the calls to default query object provided by
+ * the jdk.
+ * @param ifc interface to generated concreate class
+ * @return concreat class generated by default qury object generator
+ */
+ public <T extends BaseQuery> T createQueryObject(Class<T> ifc)
+ throws SQLException {
+ return QueryObjectFactory.createDefaultQueryObject (ifc, this);
+ }
public java.util.Map<String,Class<?>> getTypeMap(){
throw new java.lang.UnsupportedOperationException("getTypeMap()");
Modified: db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDataSource40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDataSource40.java?rev=386861&r1=386860&r2=386861&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDataSource40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDataSource40.java Sat Mar 18 08:13:00 2006
@@ -20,16 +20,35 @@
package org.apache.derby.jdbc;
+import java.sql.BaseQuery;
+import java.sql.QueryObjectFactory;
+import java.sql.QueryObjectGenerator;
import java.sql.SQLException;
public class ClientDataSource40 extends ClientDataSource {
public ClientDataSource40() {
super();
- }
+ }
- public <T> T createQueryObject(Class<T> ifc) throws SQLException {
- throw new java.lang.UnsupportedOperationException();
+ /**
+ * returns null indicating that no driver specific implementation for
+ * QueryObjectGenerator available
+ * @return null
+ */
+ public QueryObjectGenerator getQueryObjectGenerator() throws SQLException {
+ return null;
}
+
+ /**
+ * This method forwards all the calls to default query object provided by
+ * the jdk.
+ * @param ifc interface to generated concreate class
+ * @return concreat class generated by default qury object generator
+ */
+ public <T extends BaseQuery> T createQueryObject(Class<T> ifc)
+ throws SQLException {
+ return QueryObjectFactory.createDefaultQueryObject (ifc, this);
+ }
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java?rev=386861&r1=386860&r2=386861&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java Sat Mar 18 08:13:00 2006
@@ -20,10 +20,12 @@
package org.apache.derby.impl.jdbc;
+import java.sql.BaseQuery;
import java.sql.Blob;
import java.sql.ClientInfoException;
import java.sql.Clob;
import java.sql.NClob;
+import java.sql.QueryObjectFactory;
import java.sql.SQLException;
import java.sql.SQLXML;
import java.util.Properties;
@@ -95,9 +97,16 @@
throw Util.notImplemented();
}
- public <T> T createQueryObject(Class<T> ifc) throws SQLException {
- throw Util.notImplemented();
- }
+ /**
+ * This method forwards all the calls to default query object provided by
+ * the jdk.
+ * @param ifc interface to generated concreate class
+ * @return concreat class generated by default qury object generator
+ */
+ public <T extends BaseQuery> T createQueryObject(Class<T> ifc)
+ throws SQLException {
+ return QueryObjectFactory.createDefaultQueryObject (ifc, this);
+ }
public java.util.Map<String,Class<?>> getTypeMap() {
throw new java.lang.UnsupportedOperationException();
Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDataSource40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDataSource40.java?rev=386861&r1=386860&r2=386861&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDataSource40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDataSource40.java Sat Mar 18 08:13:00 2006
@@ -20,6 +20,9 @@
package org.apache.derby.jdbc;
+import java.sql.BaseQuery;
+import java.sql.QueryObjectFactory;
+import java.sql.QueryObjectGenerator;
import org.apache.derby.impl.jdbc.Util;
import java.sql.SQLException;
@@ -27,10 +30,24 @@
public EmbeddedDataSource40() {
}
-
- public <T> T createQueryObject(Class<T> ifc) throws SQLException {
- throw Util.notImplemented();
+
+ /**
+ * returns null indicating that no driver specific implementation for
+ * QueryObjectGenerator available
+ * @return null
+ */
+ public QueryObjectGenerator getQueryObjectGenerator() throws SQLException {
+ return null;
}
-
+ /**
+ * This method forwards all the calls to default query object provided by
+ * the jdk.
+ * @param ifc interface to generated concreate class
+ * @return concreat class generated by default qury object generator
+ */
+ public <T extends BaseQuery> T createQueryObject(Class<T> ifc)
+ throws SQLException {
+ return QueryObjectFactory.createDefaultQueryObject (ifc, this);
+ }
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc4.runall
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc4.runall?rev=386861&r1=386860&r2=386861&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc4.runall (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc4.runall Sat Mar 18 08:13:00 2006
@@ -5,3 +5,4 @@
jdbc4/TestResultSetMethods.java
jdbc4/TestDbMetaData.java
jdbc4/TestJDBC40Exception.java
+jdbc4/TestQueryObject.java
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestData.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestData.java?rev=386861&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestData.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestData.java Sat Mar 18 08:13:00 2006
@@ -0,0 +1,47 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.functionTests.tests.jdbc4.TestData
+
+ Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed 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.
+
+ */
+
+package org.apache.derbyTesting.functionTests.tests.jdbc4;
+
+/**
+ * Data Object clas for TestQueryObject
+ * Fields of this object maps to that of querytable
+ */
+public class TestData {
+
+ private int id;
+ private String data;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestData.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQuery.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQuery.java?rev=386861&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQuery.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQuery.java Sat Mar 18 08:13:00 2006
@@ -0,0 +1,42 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.functionTests.tests.jdbc4.TestQuery
+
+ Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed 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.
+
+ */
+
+package org.apache.derbyTesting.functionTests.tests.jdbc4;
+
+import java.sql.BaseQuery;
+import java.sql.DataSet;
+import java.sql.Select;
+
+/**
+ * This interface is used by TestQueryObject test
+ * This interface will be implemented at run time
+ * by QueryObjectGenerator
+ */
+
+public interface TestQuery extends BaseQuery {
+ /**
+ * Method defnition is generated by QueryObjectGenerator
+ * It executes query specified in Select annotation and generates
+ * data set object populated with TestData objects
+ * @return DataSet populated with TestData Object
+ */
+ @Select(sql="SELECT id, data FROM querytable")
+ DataSet <TestData> getAllData();
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQuery.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject.java?rev=386861&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject.java Sat Mar 18 08:13:00 2006
@@ -0,0 +1,108 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.functionTests.tests.jdbc4.TestQueryObject
+
+ Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed 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.
+
+ */
+
+package org.apache.derbyTesting.functionTests.tests.jdbc4;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.Statement;
+import javax.sql.DataSource;
+import java.sql.*;
+import org.apache.derby.jdbc.ClientDataSource40;
+import org.apache.derby.jdbc.EmbeddedDataSource40;
+
+/**
+ * This class tests QueryObjectGenerator feature introduced in jdbc 4.0
+ */
+
+public class TestQueryObject {
+
+ private static final int RECORD_COUNT = 10;
+ /**
+ * create table and insert data
+ */
+
+ public static void initDB (Connection con) throws Exception {
+ Statement stmt = con.createStatement ();
+ stmt.execute ("create table querytable (id integer, data varchar (20))");
+ stmt.close ();
+ PreparedStatement pstmt = con.prepareStatement ("insert into querytable"
+ + "(id, data) values (?,?)");
+ for (int i = 0; i < RECORD_COUNT; i++) {
+ pstmt.setInt (1, i);
+ pstmt.setString (2, "data" + i);
+ pstmt.execute();
+ }
+ pstmt.close ();
+ }
+
+ /**
+ * Tests Connection.createQueryObject
+ * @param con
+ */
+ public static void testConnectionQuery (Connection con) throws Exception {
+ TestQuery query = con.createQueryObject (TestQuery.class);
+ if (query.getAllData().size() != RECORD_COUNT)
+ System.out.println ("expected result size 10 actual "
+ + query.getAllData().size());
+ query.close();
+ }
+
+ /**
+ * Tests DataSource.createQueryObject
+ * @param ds
+ */
+ public static void testDSQuery (DataSource ds) throws Exception {
+ TestQuery query = ds.createQueryObject (TestQuery.class);
+ if (query.getAllData().size() != RECORD_COUNT)
+ System.out.println ("expected result size 10 actual size:"
+ + query.getAllData().size());
+ query.close();
+ }
+
+ public static void doTest (DataSource ds) {
+ try {
+ //this part needs to be removed while migrating
+ //this test to junit
+ Connection con = ds.getConnection();
+ con.setAutoCommit (true);
+ initDB (con);
+ testConnectionQuery (con);
+ con.close ();
+ testDSQuery (ds);
+ }
+ catch (Exception e) {
+ e.printStackTrace ();
+ }
+ }
+
+ public static void main (String [] args) {
+ //this part needs to be removed while migrating
+ //this test to junit
+ EmbeddedDataSource40 ds = new EmbeddedDataSource40 ();
+ ds.setDatabaseName ("embedquerydb");
+ ds.setCreateDatabase ("create");
+ doTest (ds);
+ ClientDataSource40 clds = new ClientDataSource40 ();
+ clds.setDatabaseName ("netquerydb;create=true");
+ clds.setServerName ("localhost");
+ clds.setPortNumber (1527);
+ doTest (clds);
+ }
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject_app.properties?rev=386861&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject_app.properties (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject_app.properties Sat Mar 18 08:13:00 2006
@@ -0,0 +1,11 @@
+#this case tests QueryObject related methods which are present in jdk 1.6
+#default QueryObjectGenerator uses reflection to check the Data Object
+#before calling the methods to set the values. This is a privileged operation
+#and fails in the presence of security manager
+noSecurityManager=true
+runwithibm13=false
+runwithibm14=false
+runwithj9=false
+runwithjdk12=false
+runwithjdk13=false
+runwithjdk14=false
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject_app.properties
------------------------------------------------------------------------------
svn:eol-style = native
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/copyfiles.ant
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/copyfiles.ant?rev=386861&r1=386860&r2=386861&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/copyfiles.ant (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/copyfiles.ant Sat Mar 18 08:13:00 2006
@@ -11,3 +11,4 @@
TestResultSetMethods_app.properties
TestDbMetaData_app.properties
TestJDBC40Exception_app.properties
+TestQueryObject_app.properties
Modified: db/derby/code/trunk/tools/jar/extraDBMSclasses.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/tools/jar/extraDBMSclasses.properties?rev=386861&r1=386860&r2=386861&view=diff
==============================================================================
--- db/derby/code/trunk/tools/jar/extraDBMSclasses.properties (original)
+++ db/derby/code/trunk/tools/jar/extraDBMSclasses.properties Sat Mar 18 08:13:00 2006
@@ -32,6 +32,9 @@
derby.module.core.cscpds=org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource
derby.module.core.csxad=org.apache.derby.jdbc.EmbeddedXADataSource
derby.module.core.csds_simple=org.apache.derby.jdbc.EmbeddedSimpleDataSource
+#Next line will be uncommented if build with jdk 1.6 support
+#The uncommenting will be handled by {srcroot}/build.xml
+#jdbc4_optional_derby.module.core.csds.jdk16=org.apache.derby.jdbc.EmbeddedDataSource40
derby.module.database.consistency.checker=org.apache.derby.iapi.db.ConsistencyChecker
derby.module.database.optimizer.trace=org.apache.derby.iapi.db.OptimizerTrace