|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
TransactionHandle.java | 0% | 0% | 0% | 0% |
|
1 |
package nmp.dbms.JDBC;
|
|
2 |
|
|
3 |
import java.sql.*;
|
|
4 |
import nmp.dbms.*;
|
|
5 |
|
|
6 |
/**
|
|
7 |
* Handle used to process transaction with multiple statements
|
|
8 |
*/
|
|
9 |
public class TransactionHandle |
|
10 |
{ |
|
11 |
protected DBConnection con;
|
|
12 |
protected Jdbc_Sql database;
|
|
13 |
protected boolean inuse; |
|
14 |
|
|
15 | 0 |
public TransactionHandle( Jdbc_Sql database, DBConnection con) throws SQLException { |
16 | 0 |
this.database = database;
|
17 | 0 |
this.con = con;
|
18 | 0 |
con.setAutoCommit( false);
|
19 | 0 |
inuse = true;
|
20 |
} |
|
21 |
|
|
22 |
/**
|
|
23 |
* Executes a SQL query, returning all found rows
|
|
24 |
*/
|
|
25 | 0 |
public SQLVectorResult executeQuery( String sqlstring)
|
26 |
throws SQLException {
|
|
27 | 0 |
if( inuse)
|
28 | 0 |
return database.executeQuery( con, sqlstring, -1);
|
29 | 0 |
throw new SQLException( "Connection already released"); |
30 |
} |
|
31 |
|
|
32 |
/**
|
|
33 |
* Executes a SQL query, returning the ResultSet
|
|
34 |
*/
|
|
35 | 0 |
public ResultSet executeRawQuery( String sqlstring)
|
36 |
throws SQLException {
|
|
37 | 0 |
if( inuse)
|
38 | 0 |
return database.executeRawQuery( con, sqlstring);
|
39 | 0 |
throw new SQLException( "Connection already released"); |
40 |
} |
|
41 |
|
|
42 |
/**
|
|
43 |
* Executes a SQL query, returning only some of the found rows
|
|
44 |
* To fetch more rows you should do the following:<br>
|
|
45 |
* <p> SQLVectorResult result = executeQuery( "select * from X;", 10);<br>
|
|
46 |
* if( executeQuery( result,10) )<br>//some rows available<br>else<br>////no more rows
|
|
47 |
*/
|
|
48 | 0 |
public SQLVectorResult executeQuery( String sqlstring, int count) |
49 |
throws SQLException {
|
|
50 | 0 |
if( inuse)
|
51 | 0 |
return database.executeQuery( con, sqlstring, count);
|
52 | 0 |
throw new SQLException( "Connection already released"); |
53 |
} |
|
54 |
|
|
55 |
/**
|
|
56 |
* Gets more rows that conform to the executed query
|
|
57 |
*/
|
|
58 | 0 |
public boolean executeQuery( SQLVectorResult result, int count) |
59 |
throws SQLException {
|
|
60 | 0 |
if( inuse)
|
61 | 0 |
return database.executeQuery( result, count);
|
62 | 0 |
throw new SQLException( "Connection already released"); |
63 |
} |
|
64 |
|
|
65 |
/**
|
|
66 |
* Executes a SQL update, returning the number of modified rows
|
|
67 |
*/
|
|
68 | 0 |
public int executeUpdate(String sqlstring) |
69 |
throws SQLException {
|
|
70 | 0 |
if( inuse)
|
71 | 0 |
return database.executeUpdate( con, sqlstring);
|
72 | 0 |
throw new SQLException( "Connection already released"); |
73 |
} |
|
74 |
|
|
75 |
/**
|
|
76 |
* Releases the resources associated with this connection
|
|
77 |
*/
|
|
78 | 0 |
public void release() throws SQLException { |
79 | 0 |
if( inuse) {
|
80 | 0 |
inuse = false;
|
81 | 0 |
con.setAutoCommit( true);
|
82 | 0 |
database.putConnection( con); |
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
/**
|
|
87 |
* Commits transaction and restarts a new transaction
|
|
88 |
*/
|
|
89 | 0 |
public void commit() throws SQLException { |
90 | 0 |
if( inuse)
|
91 | 0 |
con.commit(); |
92 |
} |
|
93 |
|
|
94 |
/**
|
|
95 |
* Rollbacks transaction and restarts a new transaction
|
|
96 |
*/
|
|
97 | 0 |
public void rollback() throws SQLException { |
98 | 0 |
if( inuse)
|
99 | 0 |
con.rollback(); |
100 |
} |
|
101 |
|
|
102 |
|
|
103 |
} |
|
104 |
|
|