comparison geo-backend/src/test/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnectionPoolTestCase.java @ 130:e4eacd613356

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

http://dive4elements.wald.intevation.org