comparison flys-aft/src/main/java/de/intevation/db/ConnectedStatements.java @ 4074:100c4e0a45e1

Improved infrastructure for prepared statements. flys-aft/trunk@3407 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 13 Dec 2011 14:32:55 +0000
parents
children ee0c60757a94
comparison
equal deleted inserted replaced
4073:2c70fae83d0c 4074:100c4e0a45e1
1 package de.intevation.db;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import java.sql.Connection;
7 import java.sql.SQLException;
8
9 public class ConnectedStatements
10 {
11 protected Connection connection;
12
13 protected Map<String, SymbolicStatement> statements;
14
15 protected Map<String, SymbolicStatement.Instance> boundStatements;
16
17 public ConnectedStatements(
18 Connection connection,
19 Map<String, SymbolicStatement> statements
20 ) {
21 this.connection = connection;
22 this.statements = statements;
23
24 boundStatements = new HashMap<String, SymbolicStatement.Instance>();
25 }
26
27 public SymbolicStatement.Instance getStatement(String key)
28 throws SQLException
29 {
30 SymbolicStatement.Instance stmnt = boundStatements.get(key);
31 if (stmnt != null) {
32 return stmnt;
33 }
34
35 SymbolicStatement ss = statements.get(key);
36 if (ss == null) {
37 return null;
38 }
39
40 stmnt = ss.new Instance(connection);
41 boundStatements.put(key, stmnt);
42 return stmnt;
43 }
44
45 public void close() {
46 for (SymbolicStatement.Instance s: boundStatements.values()) {
47 s.close();
48 }
49
50 try {
51 connection.close();
52 }
53 catch (SQLException sqle) {
54 }
55 }
56 }
57 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org