Mercurial > dive4elements > gnv-client
comparison geo-backend/src/main/java/de/intevation/gnv/geobackend/base/query/DefaultQueryExceutor.java @ 132:5a583cff97ea
Implementation of the Datainfrastructure for fetching Data from different DataStores.
geo-backend/trunk@12 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 04 Sep 2009 08:11:30 +0000 |
parents | |
children | 9f2eaefe9dd4 |
comparison
equal
deleted
inserted
replaced
131:d8ff739b9f3b | 132:5a583cff97ea |
---|---|
1 /** | |
2 * | |
3 */ | |
4 package de.intevation.gnv.geobackend.base.query; | |
5 | |
6 import java.sql.Connection; | |
7 import java.sql.ResultSet; | |
8 import java.sql.SQLException; | |
9 import java.sql.Statement; | |
10 import java.util.Collection; | |
11 | |
12 import org.apache.log4j.Logger; | |
13 | |
14 import de.intevation.gnv.geobackend.base.Result; | |
15 import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool; | |
16 import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPoolFactory; | |
17 import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException; | |
18 import de.intevation.gnv.geobackend.base.query.container.QueryContainerFactory; | |
19 import de.intevation.gnv.geobackend.base.query.container.exception.QueryContainerException; | |
20 import de.intevation.gnv.geobackend.base.query.exception.QueryException; | |
21 | |
22 /** | |
23 * This is an Standard Implementation of the Interface QueryExecutor. | |
24 * It fetchs the Query from the Querycontainer an put the Filtervalues into the Query. | |
25 * @author Tim Englich <tim.englich@intevation.de> | |
26 * | |
27 */ | |
28 public class DefaultQueryExceutor extends QueryExecutorBase{ | |
29 | |
30 | |
31 /** | |
32 * the logger, used to log exceptions and additonaly information | |
33 */ | |
34 private static Logger log = Logger.getLogger(DefaultQueryExceutor.class); | |
35 | |
36 /** | |
37 * The ConnectionID identifing the Connection to use executing the Query. | |
38 */ | |
39 private String connectionID = "N/N"; | |
40 | |
41 /** | |
42 * Constructor | |
43 */ | |
44 public DefaultQueryExceutor() { | |
45 super(); | |
46 } | |
47 | |
48 /** | |
49 * @see de.intevation.gnv.geobackend.base.query.QueryExecutor#executeQuery(java.lang.String, java.lang.String[]) | |
50 */ | |
51 public Collection<Result> executeQuery(String queryID, String[] filter) throws QueryException { | |
52 Collection<Result> returnValue = null; | |
53 try { | |
54 String queryString = QueryContainerFactory.getInstance().getQueryContainer().getQuery(queryID); | |
55 if (queryString != null){ | |
56 if (filter != null && filter.length > 0){ | |
57 //Insert the Filtervalues into the QueryString | |
58 queryString = super.setFilterValues(queryString, filter); | |
59 } | |
60 | |
61 Connection connection = null; | |
62 ConnectionPool connectionPool = ConnectionPoolFactory.getInstance().getConnectionPool(); | |
63 try { | |
64 // Submit the Query | |
65 connection = connectionPool.getConnection(this.connectionID); | |
66 if (connection != null){ | |
67 Statement stmt = connection.createStatement(); | |
68 ResultSet rs = stmt.executeQuery(queryString); | |
69 returnValue = super.createResultCollection(rs); | |
70 | |
71 }else{ | |
72 log.error("Could not establish Databaseconnection."); | |
73 throw new QueryException("Could not establish Databaseconnection."); | |
74 } | |
75 | |
76 } catch (ConnectionException e) { | |
77 log.error(e,e); | |
78 throw new QueryException("Could not establish Databaseconnection.",e); | |
79 } catch (SQLException e) { | |
80 log.error(e,e); | |
81 throw new QueryException(e); | |
82 }finally{ | |
83 if (connection != null){ | |
84 try { | |
85 connectionPool.closeConnection(connection); | |
86 } catch (ConnectionException e) { | |
87 log.error("Connection could not be returned to ConnectionPool."); | |
88 log.error(e,e); | |
89 } | |
90 } | |
91 } | |
92 }else{ | |
93 log.error("No QueryString defined for "+queryID); | |
94 throw new QueryException("Cannot get the Querystring"); | |
95 } | |
96 | |
97 } catch (QueryContainerException e) { | |
98 log.error(e,e); | |
99 throw new QueryException("Cannot get the Querystring",e); | |
100 } | |
101 return returnValue; | |
102 } | |
103 } |