1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
package org.apache.tapestry.contrib.jdbc; |
16 | |
|
17 | |
import java.sql.Connection; |
18 | |
import java.sql.ResultSet; |
19 | |
import java.sql.SQLException; |
20 | |
import java.sql.Statement; |
21 | |
|
22 | |
import org.apache.commons.logging.Log; |
23 | |
import org.apache.commons.logging.LogFactory; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public class SimpleStatement implements IStatement |
33 | |
{ |
34 | 0 | private static final Log LOG = LogFactory.getLog(SimpleStatement.class); |
35 | |
|
36 | |
private String _sql; |
37 | |
private Statement _statement; |
38 | |
|
39 | |
public SimpleStatement(String SQL, Connection connection) throws SQLException |
40 | 0 | { |
41 | 0 | _sql = SQL; |
42 | 0 | _statement = connection.createStatement(); |
43 | 0 | } |
44 | |
|
45 | |
public SimpleStatement(String SQL, Connection connection, int resultSetType, int resultSetConcurrency) |
46 | |
throws SQLException |
47 | 0 | { |
48 | 0 | _sql = SQL; |
49 | 0 | _statement = connection.createStatement(resultSetType, resultSetConcurrency); |
50 | 0 | } |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
public String getSQL() |
58 | |
{ |
59 | 0 | return _sql; |
60 | |
} |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public Statement getStatement() |
68 | |
{ |
69 | 0 | return _statement; |
70 | |
} |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
public void close() throws SQLException |
78 | |
{ |
79 | 0 | _statement.close(); |
80 | |
|
81 | 0 | _statement = null; |
82 | 0 | _sql = null; |
83 | 0 | } |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public ResultSet executeQuery() throws SQLException |
91 | |
{ |
92 | 0 | if (LOG.isDebugEnabled()) |
93 | 0 | LOG.debug("Executing query: " + this); |
94 | |
|
95 | 0 | return _statement.executeQuery(_sql); |
96 | |
} |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
public int executeUpdate() throws SQLException |
105 | |
{ |
106 | 0 | if (LOG.isDebugEnabled()) |
107 | 0 | LOG.debug("Executing update: " + this); |
108 | |
|
109 | 0 | return _statement.executeUpdate(_sql); |
110 | |
} |
111 | |
|
112 | |
public String toString() |
113 | |
{ |
114 | |
StringBuffer buffer; |
115 | |
|
116 | 0 | buffer = new StringBuffer("SimpleStatement@"); |
117 | 0 | buffer.append(Integer.toHexString(hashCode())); |
118 | |
|
119 | 0 | buffer.append("[SQL=<\n"); |
120 | 0 | buffer.append(_sql); |
121 | 0 | buffer.append("\n>]"); |
122 | |
|
123 | 0 | return buffer.toString(); |
124 | |
} |
125 | |
|
126 | |
} |