Index: java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java =================================================================== --- java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java (revision 380197) +++ java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java (working copy) @@ -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(); Index: java/engine/org/apache/derby/jdbc/EmbeddedDataSource40.java =================================================================== --- java/engine/org/apache/derby/jdbc/EmbeddedDataSource40.java (revision 380197) +++ java/engine/org/apache/derby/jdbc/EmbeddedDataSource40.java (working copy) @@ -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); + } } Index: java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQuery.java =================================================================== --- java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQuery.java (revision 0) +++ java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQuery.java (revision 0) @@ -0,0 +1,32 @@ +/* + + 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; + + +public interface TestQuery extends BaseQuery { + @Select(sql="SELECT id, data FROM querytable") + DataSet <TestData> getAllData(); + +} Index: java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject_app.properties =================================================================== --- java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject_app.properties (revision 0) +++ java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject_app.properties (revision 0) @@ -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 Index: java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestData.java =================================================================== --- java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestData.java (revision 0) +++ java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestData.java (revision 0) @@ -0,0 +1,44 @@ +/* + + 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; + +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; + } + +} Index: java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject.java =================================================================== --- java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject.java (revision 0) +++ java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestQueryObject.java (revision 0) @@ -0,0 +1,94 @@ +/* + + 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; + +public class TestQueryObject { + + + + 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 < 10; i++) { + pstmt.setInt (1, i); + pstmt.setString (2, "data" + i); + pstmt.execute(); + } + pstmt.close (); + } + + public static void testConnectionQuery (Connection con) throws Exception { + TestQuery query = con.createQueryObject (TestQuery.class); + if (query.getAllData().size() != 10) + System.out.println ("expected result size 10 actual " + + query.getAllData().size()); + query.close(); + } + + public static void testDSQuery (DataSource ds) throws Exception { + TestQuery query = ds.createQueryObject (TestQuery.class); + if (query.getAllData().size() != 10) + 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); + } +} Index: java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/copyfiles.ant =================================================================== --- java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/copyfiles.ant (revision 380197) +++ java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/copyfiles.ant (working copy) @@ -7,3 +7,4 @@ aclob.txt littleclob.txt short.txt +TestQueryObject_app.properties Index: java/testing/org/apache/derbyTesting/functionTests/suites/jdbc4.runall =================================================================== --- java/testing/org/apache/derbyTesting/functionTests/suites/jdbc4.runall (revision 380197) +++ java/testing/org/apache/derbyTesting/functionTests/suites/jdbc4.runall (working copy) @@ -4,3 +4,4 @@ jdbc4/TestPreparedStatementMethods.java jdbc4/TestResultSetMethods.java jdbc4/TestDbMetaData.java +jdbc4/TestQueryObject.java Index: java/client/org/apache/derby/jdbc/ClientDataSource40.java =================================================================== --- java/client/org/apache/derby/jdbc/ClientDataSource40.java (revision 380197) +++ java/client/org/apache/derby/jdbc/ClientDataSource40.java (working copy) @@ -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); + } + } Index: java/client/org/apache/derby/client/net/NetConnection40.java =================================================================== --- java/client/org/apache/derby/client/net/NetConnection40.java (revision 380197) +++ java/client/org/apache/derby/client/net/NetConnection40.java (working copy) @@ -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()"); Index: build.xml =================================================================== --- build.xml (revision 380197) +++ build.xml (working copy) @@ -719,6 +719,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"> @@ -729,6 +738,8 @@ <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"> <arg value="${out.dir}/org/apache/derby/modules.properties"/> Index: tools/jar/extraDBMSclasses.properties =================================================================== --- tools/jar/extraDBMSclasses.properties (revision 380197) +++ tools/jar/extraDBMSclasses.properties (working copy) @@ -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