annotate geo-backend/src/test/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnectionPoolTestCase.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 e4eacd613356
children 1c3efbd2fc5a
rev   line source
130
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.geobackend.sde.datasources;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
2
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
3 import java.io.FileInputStream;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
4 import java.io.FileNotFoundException;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
5 import java.io.IOException;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
6 import java.io.InputStream;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
7 import java.sql.Connection;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
8 import java.sql.SQLException;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
9 import java.sql.Statement;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
10 import java.util.Properties;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
11 import java.sql.ResultSet;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
12
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
13 import junit.framework.TestCase;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
14
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
15 import org.apache.log4j.BasicConfigurator;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
16 import org.apache.log4j.Logger;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
17
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
18 import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
19 import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPoolFactory;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
20 import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
21 import de.intevation.gnv.geobackend.sde.connectionpool.ArcSDEPoolableObjectFactory;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
22
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
23 /**
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
24 * TestCase for the usage of the ArcSDEConnectionPool.
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
25 * @author Tim Englich <tim.englich@intevation.de>
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
26 *
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
27 */
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
28 public class ArcSDEConnectionPoolTestCase extends TestCase {
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
29
132
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
30 /**
130
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
31 * the logger, used to log exceptions and additonaly information
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
32 */
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
33 private static Logger log = null;
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
34
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
35 static {
132
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
36 BasicConfigurator.configure();
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
37 log = Logger.getLogger(ArcSDEPoolableObjectFactory.class);
130
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
38 }
132
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
39 /**
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
40 *
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
41 */
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
42 public ArcSDEConnectionPoolTestCase() {
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
43 super();
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
44 }
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
45
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
46 /**
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
47 *
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
48 * @param name
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
49 */
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
50 public ArcSDEConnectionPoolTestCase(String name) {
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
51 super(name);
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
52 }
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
53
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
54 /**
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
55 * Test if the ArcSDEConnectionPool can be established
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
56 * and if a Request could be done.
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
57 */
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
58 public void testArcSDEConnectionPool(){
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
59 log.debug("ArcSDEConnectionPoolTestCase.testArcSDEConnectionPool");
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
60 try {
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
61 InputStream inputStream = new FileInputStream("src/test/ressources/ArcSDEConnectionPoolTestCase.properties");
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
62 Properties properties = new Properties();
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
63 properties.load(inputStream);
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
64
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
65 ConnectionPoolFactory cpf = ConnectionPoolFactory.getInstance();
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
66 cpf.initializeConnectionPool(properties);
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
67
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
68 assertTrue(cpf.isInitialized());
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
69 log.debug("ConnectionPoolFactory ist initialisiert.");
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
70
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
71 ConnectionPool cp = cpf.getConnectionPool();
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
72 assertNotNull(cp);
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
73 log.debug("ConnectionPool ist initialisiert.");
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
74
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
75 Connection connection = null;
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
76 try{
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
77 try {
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
78 connection = cp.getConnection("N/N");
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
79 assertNotNull(connection);
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
80 log.debug("Connection ist initialisiert.");
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
81 } catch (ConnectionException e) {
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
82 log.error("Es traten Probleme bei der Verbinung zur Datenbank auf.");
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
83 fail();
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
84 }
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
85
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
86
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
87 try {
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
88 Statement stmt = connection.createStatement();
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
89 ResultSet rs = stmt.executeQuery("Select MESHID, NAME from MEDIAN.MESH");
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
90
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
91 while (rs.next()){
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
92 log.debug(rs.getInt(1));
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
93 log.debug(rs.getString(2));
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
94
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
95 log.debug(rs.getInt("MESHID"));
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
96 log.debug(rs.getString("NAME"));
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
97 }
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
98
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
99 } catch (SQLException e) {
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
100 log.error(e,e);
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
101 }
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
102 }finally{
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
103 if (connection != null){
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
104 try {
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
105 connection.close();
130
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
106 } catch (SQLException e) {
132
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
107 log.error(e,e);
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
108 fail();
130
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
109 }
132
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
110 }
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
111 }
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
112 } catch (FileNotFoundException e) {
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
113 log.error(e,e);
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
114 fail();
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
115 } catch (IOException e) {
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
116 log.error(e,e);
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
117 fail();
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
118 }
5a583cff97ea Implementation of the Datainfrastructure for fetching Data from different DataStores.
Tim Englich <tim.englich@intevation.de>
parents: 130
diff changeset
119 }
130
e4eacd613356 Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
120 }

http://dive4elements.wald.intevation.org