comparison flys-aft/src/main/java/de/intevation/db/ConnectedStatements.java @ 4087:aad1886ea226

Store new gauges in FLYS db. flys-aft/trunk@3568 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 02 Jan 2012 17:45:25 +0000
parents ee0c60757a94
children b195fede1c3b
comparison
equal deleted inserted replaced
4086:ee0c60757a94 4087:aad1886ea226
6 import java.util.ArrayDeque; 6 import java.util.ArrayDeque;
7 7
8 import java.sql.Connection; 8 import java.sql.Connection;
9 import java.sql.SQLException; 9 import java.sql.SQLException;
10 import java.sql.Savepoint; 10 import java.sql.Savepoint;
11 import java.sql.DatabaseMetaData;
12
13 import org.apache.log4j.Logger;
11 14
12 public class ConnectedStatements 15 public class ConnectedStatements
13 { 16 {
17 private static Logger log = Logger.getLogger(ConnectedStatements.class);
18
14 protected Connection connection; 19 protected Connection connection;
15 20
16 protected Map<String, SymbolicStatement> statements; 21 protected Map<String, SymbolicStatement> statements;
17 22
18 protected Map<String, SymbolicStatement.Instance> boundStatements; 23 protected Map<String, SymbolicStatement.Instance> boundStatements;
31 36
32 boundStatements = new HashMap<String, SymbolicStatement.Instance>(); 37 boundStatements = new HashMap<String, SymbolicStatement.Instance>();
33 } 38 }
34 39
35 protected void checkSavePoints() throws SQLException { 40 protected void checkSavePoints() throws SQLException {
36 if (connection.getMetaData().supportsSavepoints()) { 41 DatabaseMetaData metaData = connection.getMetaData();
42 if (metaData.supportsSavepoints()) {
43 log.info("Driver '" + metaData.getDriverName() +
44 "' does support savepoints.");
37 savepoints = new ArrayDeque<Savepoint>(); 45 savepoints = new ArrayDeque<Savepoint>();
46 }
47 else {
48 log.info("Driver '" + metaData.getDriverName() +
49 "' does not support savepoints.");
38 } 50 }
39 } 51 }
40 52
41 public SymbolicStatement.Instance getStatement(String key) 53 public SymbolicStatement.Instance getStatement(String key)
42 throws SQLException 54 throws SQLException
54 stmnt = ss.new Instance(connection); 66 stmnt = ss.new Instance(connection);
55 boundStatements.put(key, stmnt); 67 boundStatements.put(key, stmnt);
56 return stmnt; 68 return stmnt;
57 } 69 }
58 70
59 void beginTransaction() throws SQLException { 71 public void beginTransaction() throws SQLException {
60 if (savepoints != null) { 72 if (savepoints != null) {
61 savepoints.push(connection.setSavepoint()); 73 savepoints.push(connection.setSavepoint());
62 } 74 }
63 } 75 }
64 76
65 void commitTransaction() throws SQLException { 77 public void commitTransaction() throws SQLException {
66 if (savepoints != null) { 78 if (savepoints != null) {
67 savepoints.pop(); 79 savepoints.pop();
68 } 80 }
69 connection.commit(); 81 connection.commit();
70 } 82 }
71 83
72 void rollbackTransaction() throws SQLException { 84 public void rollbackTransaction() throws SQLException {
73 if (savepoints != null) { 85 if (savepoints != null) {
74 Savepoint savepoint = savepoints.pop(); 86 Savepoint savepoint = savepoints.pop();
75 connection.rollback(savepoint); 87 connection.rollback(savepoint);
76 } 88 }
77 else { 89 else {

http://dive4elements.wald.intevation.org