01: /*
02:
03: Derby - Class org.apache.derbyTesting.functionTests.util.StaticInitializers.InsertInStaticInitializer
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to You under the Apache License, Version 2.0
09: (the "License"); you may not use this file except in compliance with
10: the License. You may obtain a copy of the License at
11:
12: http://www.apache.org/licenses/LICENSE-2.0
13:
14: Unless required by applicable law or agreed to in writing, software
15: distributed under the License is distributed on an "AS IS" BASIS,
16: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: See the License for the specific language governing permissions and
18: limitations under the License.
19:
20: */
21:
22: package org.apache.derbyTesting.functionTests.util.StaticInitializers;
23:
24: import java.sql.DriverManager;
25: import java.sql.Statement;
26: import java.sql.ResultSet;
27: import java.sql.SQLException;
28:
29: /** Test Insert statement called from within static initializer holds
30: * onto locks it should hold onto and doesn't hold onto locks it shouldn't
31: * hold onto.
32: */
33: public class InsertInStaticInitializer {
34:
35: /* This is the method that is invoked from the outer query */
36: public static int getANumber() {
37: return 1;
38: }
39:
40: static {
41: /* Execute a DML statement from within the static initializer */
42: doADMLStatement();
43: }
44:
45: private static void doADMLStatement() {
46: ResultSet rs = null;
47:
48: try {
49: int value;
50:
51: /* Connect to the database */
52: Statement s = DriverManager.getConnection(
53: "jdbc:default:connection").createStatement();
54:
55: /* Execute a DML statement. This depends on t1 existing. */
56: boolean b = s.execute("INSERT into t1 values (1)");
57:
58: //if (rs.next())
59: //{
60: // System.out.println("Value of t1.s is " + rs.getShort(1));
61: //}
62: } catch (SQLException se) {
63: System.out.println("Caught exception " + se);
64: se.printStackTrace(System.out);
65: } finally {
66: try {
67: if (rs != null)
68: rs.close();
69: } catch (SQLException se) {
70: System.out.println("Caught exception " + se);
71: se.printStackTrace(System.out);
72: }
73: }
74: }
75: }
|