diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestNativeQueryProcedures.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestNativeQueryProcedures.java new file mode 100644 index 000000000..636f14afd --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestNativeQueryProcedures.java @@ -0,0 +1,168 @@ +/* + * 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. + */ +package org.apache.openjpa.persistence.jdbc.query; + +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.Query; + +import org.apache.openjpa.jdbc.conf.JDBCConfiguration; +import org.apache.openjpa.jdbc.sql.DerbyDictionary; +import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; +import org.apache.openjpa.persistence.jdbc.query.domain.Applicant; +import org.apache.openjpa.persistence.jdbc.query.procedure.DerbyProcedureList; +import org.apache.openjpa.persistence.jdbc.query.procedure.ProcedureList; +import org.apache.openjpa.persistence.test.SingleEMFTestCase; + +/** + * Tests that Native queries use only 1-based positional parameters and + * disallows named parameters. + * + * Originally reported in + * getCreateProcedureList () { + ArrayList retList = new ArrayList(); + + retList.add ("create procedure ADD_X_TO_CHARLIE () " + + "PARAMETER STYLE JAVA LANGUAGE JAVA MODIFIES SQL DATA " + + "EXTERNAL NAME 'org.apache.openjpa.persistence.jdbc.query.procedure.DerbyProcedureList.addXToCharlie'"); + + return retList; + } + + public List getDropProcedureList () { + ArrayList retList = new ArrayList(); + + retList.add ("drop procedure ADD_X_TO_CHARLIE"); + + return retList; + } + + public String callAddXToCharlie () { + return "{ call ADD_X_TO_CHARLIE () }"; + } + + public static void addXToCharlie () throws Exception { + Connection conn = DriverManager.getConnection("jdbc:default:connection"); + PreparedStatement ps1 = conn.prepareStatement("update APPLICANT set name = 'Charliex' where name = 'Charlie'"); + ps1.executeUpdate(); + + conn.close(); + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/procedure/ProcedureList.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/procedure/ProcedureList.java new file mode 100644 index 000000000..ac62bc03a --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/procedure/ProcedureList.java @@ -0,0 +1,40 @@ +/* + * 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. + */ +package org.apache.openjpa.persistence.jdbc.query.procedure; + +import java.util.List; + +/* + * holds the stored procedures that will be used by test cases + */ +public abstract class ProcedureList { + + abstract public List getCreateProcedureList (); + + abstract public List getDropProcedureList (); + + abstract public String callAddXToCharlie (); + + // This method should also be overriden, but it needs to be static so + // that it can be called as a stored procedure + public static void addXToCharlie () throws Exception { + Exception e = new Exception ("Method not implemented by inheriting class"); + throw e; + } +}