18 package testsuite.clusterj;
20 import java.sql.PreparedStatement;
21 import java.sql.ResultSet;
22 import java.sql.SQLException;
24 import org.junit.Ignore;
33 private String newId =
"1+1:9000000000000099";
34 private String sqlQuery =
"select id from t_basic where id = 0";
35 private String getTransactionIdVariableName =
"@@ndb_transaction_id";
36 private String setTransactionIdVariableName =
"@@ndb_join_transaction_id";
40 createSessionFactory();
43 setAutoCommit(connection,
false);
56 errorIfNotEqual(
"Coordinated transaction id must default to null.", null,
id);
67 errorIfNotEqual(
"failed to set coordinated transaction id.", newId,
id);
83 errorIfEqual(
"Coordinated transaction must not be null after transaction start", null,
id);
86 errorIfNotEqual(
"Coordinated transaction id must be null after commit.", null,
id);
99 errorIfEqual(
"Coordinated transaction must not be null after transaction start", null,
id);
102 errorIfNotEqual(
"Coordinated transaction id must be null after rollback.", null,
id);
111 statement = connection.prepareStatement(sqlQuery);
112 rs = statement.executeQuery();
113 boolean hasNext = rs.next();
114 if (
getDebug()) System.out.println(where +
" executeJDBCQuery rs.next() returned " + hasNext);
115 }
catch (SQLException e) {
116 error(where +
" query threw exception ", e);
121 }
catch (SQLException e) {
122 error(where +
" rs.close threw exception " + e.getMessage());
125 if (statement != null) {
128 }
catch (SQLException e) {
129 error(where +
" statement.close threw exception ", e);
140 fail(where +
" test case error: coordinated transaction id must not be null.");
143 String setSql =
"set " + setTransactionIdVariableName +
" = '" + newId +
"'";
144 PreparedStatement setCoordinatedTransactionIdStatement = connection.prepareStatement(setSql);
145 boolean result = setCoordinatedTransactionIdStatement.execute();
146 errorIfNotEqual(where +
" set coordinated transaction id returned true.",
false, result);
147 }
catch (SQLException e) {
148 error(where +
" caught exception on set coordinated transaction id:", e);
156 String getId =
"select " + getTransactionIdVariableName;
159 PreparedStatement getCoordinatedTransactionIdStatement = connection.prepareStatement(getId);
160 ResultSet rs = getCoordinatedTransactionIdStatement.executeQuery();
161 boolean hasResult = rs.next();
162 errorIfNotEqual(where +
" select coordinated transaction id returned false.",
true, hasResult);
163 result = rs.getString(1);
164 if (
getDebug()) System.out.println(where +
" getJDBCCoordinatedTransactionId returns " + result);
165 }
catch (SQLException e) {
166 error(where +
" caught exception on get coordinated transaction id.", e);
176 }
catch (SQLException e) {
177 error(
"connection.commit threw exception: ", e);
185 connection.rollback();
186 }
catch (SQLException e) {
187 error(
"connection.rollback threw exception: ", e);