001: /* Copyright (c) 2001-2005, The HSQL Development Group
002: * All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * Redistributions of source code must retain the above copyright notice, this
008: * list of conditions and the following disclaimer.
009: *
010: * Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * Neither the name of the HSQL Development Group nor the names of its
015: * contributors may be used to endorse or promote products derived from this
016: * software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
022: * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
026: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package org.hsqldb.test;
032:
033: import java.sql.Connection;
034: import java.sql.DriverManager;
035: import java.sql.ResultSet;
036: import java.sql.Statement;
037:
038: public class TestMultipleConnections {
039:
040: public TestMultipleConnections() {
041: }
042:
043: public static void main(String[] args) throws Exception {
044:
045: // test for bug itme 500105 commit does not work with multiple con. FIXED
046: TestMultipleConnections hs = new TestMultipleConnections();
047: Connection con1 = hs.createObject();
048: Connection con2 = hs.createObject();
049: Connection con3 = hs.createObject();
050:
051: con1.setAutoCommit(false);
052:
053: //connection1.commit();
054: con2.setAutoCommit(false);
055:
056: //connection1.commit();
057: con3.setAutoCommit(false);
058:
059: //connection1.commit();
060: Statement st = con3.createStatement();
061:
062: st.execute("DROP TABLE T IF EXISTS");
063: st.execute("CREATE TABLE T (I INT)");
064: st.execute("INSERT INTO T VALUES (2)");
065:
066: ResultSet rs = st.executeQuery("SELECT * FROM T");
067:
068: rs.next();
069:
070: int value = rs.getInt(1);
071:
072: con2.commit();
073: con3.commit();
074: con1.commit();
075:
076: rs = st.executeQuery("SELECT * FROM T");
077:
078: rs.next();
079:
080: if (value != rs.getInt(1)) {
081: throw new Exception("value doesn't exist");
082: }
083: }
084:
085: /**
086: * create a connection and wait
087: */
088: protected Connection createObject() {
089:
090: try {
091: Class.forName("org.hsqldb.jdbcDriver");
092:
093: return DriverManager.getConnection(
094: "jdbc:hsqldb:/hsql/test/test", "sa", "");
095: } catch (Exception ex) {
096: ex.printStackTrace();
097: }
098:
099: return null;
100: }
101: }
|