001: /*
002:
003: Derby - Class org.apache.derbyTesting.functionTests.tests.lang.repeat
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derbyTesting.functionTests.tests.lang;
023:
024: import java.sql.Connection;
025: import java.sql.DriverManager;
026: import java.sql.Statement;
027: import java.sql.PreparedStatement;
028: import java.sql.ResultSet;
029: import java.sql.ResultSetMetaData;
030: import java.sql.SQLException;
031: import java.sql.SQLWarning;
032:
033: import org.apache.derby.tools.ij;
034:
035: /**
036: Test the statement cache -- reusing statements with the
037: matching SQL text. The only way to verify this output
038: is to look at the log file for StatementCache debug flag
039: messages about accesses.
040: <p>
041: The one concrete test here is that the statements
042: are actually dumped when the connection is closed,
043: and attempts to execute them will fail.
044:
045: @author ames
046: */
047:
048: public class repeat {
049:
050: public static void main(String[] args) {
051: System.out.println("Test repeat starting");
052: boolean passed = false;
053: try {
054: Connection conn;
055:
056: // use the ij utility to read the property file and
057: // make the initial connection.
058: ij.getPropertyArg(args);
059: conn = ij.startJBMS();
060:
061: Statement s = conn.createStatement();
062: s.execute("create table t (i int)");
063:
064: s.execute("insert into t values(180)");
065:
066: // should find statement in cache:
067: s.execute("insert into t values(180)");
068:
069: // should find statement in cache:
070: PreparedStatement ps1 = conn
071: .prepareStatement("insert into t values(180)");
072:
073: for (int i = 1; i <= 2; i++) {
074: int rows = ps1.executeUpdate();
075:
076: if (rows != 1)
077: System.out
078: .println("FAIL -- insert wrong number of rows");
079: }
080:
081: conn.close();
082:
083: try {
084: int rows = ps1.executeUpdate();
085: } catch (Throwable e) {
086: passed = true;
087: }
088: if (!passed)
089: System.out
090: .println("FAIL -- able to insert after disconnect");
091:
092: } catch (Throwable e) {
093: e.printStackTrace();
094: }
095:
096: if (passed)
097: System.out.println("PASS");
098: System.out.println("Test repeat finished");
099: }
100: }
|