001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data.oracle;
017:
018: import java.sql.DriverManager;
019: import java.sql.SQLException;
020: import java.util.Properties;
021:
022: import javax.sql.DataSource;
023:
024: import org.geotools.data.jdbc.datasource.ManageableDataSource;
025:
026: import oracle.jdbc.OracleConnection;
027:
028: /**
029: * Capture in one spot the location of *your* oracle instance.
030: * <p>
031: * This class is used by all test cases to provide a connection
032: * to the database.
033: * </p>
034: * @author jgarnett
035: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/oracle-spatial/src/test/java/org/geotools/data/oracle/OracleTestFixture.java $
036: */
037: public class OracleTestFixture {
038: public OracleConnection connection;
039:
040: private Properties properties;
041:
042: /** schema name incase you need access to types - like SDO */
043: private String schemaName;
044:
045: /** Connection pool - incase you want to test a EPSG authority */
046: private ManageableDataSource cPool;
047:
048: /**
049: * OracleTestFixture used in JUnit
050: * <p>
051: * Connects to database and grabs the contents of the first row.
052: * </p>
053: * Example:
054: * <code><pre>
055: * protected void setUp() throws Exception {
056: * super.setUp();
057: * fixture = new OracleTestFixture();
058: * geom = fixture.geom;
059: * }
060: * </pre></code>
061: */
062: public OracleTestFixture() throws Exception {
063: // make connection to DB
064: // DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver() );
065:
066: properties = new Properties();
067: properties.load(this .getClass().getResourceAsStream(
068: "remote.properties"));
069:
070: schemaName = properties.getProperty("schema");
071:
072: try {
073: cPool = OracleDataStoreFactory.getDefaultDataSource(
074: properties.getProperty("host"), properties
075: .getProperty("user"), properties
076: .getProperty("passwd"), Integer
077: .parseInt(properties.getProperty("port")),
078: properties.getProperty("instance"), 10, 4, false);
079: System.out.println("Connect to" + properties);
080:
081: connection = (OracleConnection) cPool.getConnection();
082:
083: // connection = (OracleConnection) DriverManager.getConnection ("jdbc:oracle:thin:@hydra:1521:rrdev","dblasby","dave2000");
084: // connection = (OracleConnection) DriverManager.getConnection ("jdbc:oracle:thin:@hydra:1521:dev","egouge","emily2004");
085: } catch (Throwable t) {
086: System.out.println("Warning: could not connect, configure "
087: + getClass().getResource("test.properties"));
088: return;
089: }
090: System.out.println(connection.getTypeMap());
091: }
092:
093: public void close() throws SQLException {
094: if (connection != null)
095: connection.close();
096: connection = null;
097: if (cPool != null)
098: cPool.close();
099: }
100: }
|