root / branches / v2_0_0_prep / extensions / org.gvsig.oracle / src / org / gvsig / fmap / dal / store / oracle / OracleResource.java @ 38186
History | View | Annotate | Download (4.47 KB)
1 | 37896 | jldominguez | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2009 Prodevelop S.L. main development
|
||
26 | */
|
||
27 | |||
28 | package org.gvsig.fmap.dal.store.oracle; |
||
29 | |||
30 | import java.sql.Connection; |
||
31 | import java.sql.SQLException; |
||
32 | import java.text.MessageFormat; |
||
33 | |||
34 | import javax.sql.DataSource; |
||
35 | |||
36 | import oracle.jdbc.pool.OracleDataSource; |
||
37 | |||
38 | import org.gvsig.fmap.dal.exception.DataException; |
||
39 | import org.gvsig.fmap.dal.exception.InitializeException; |
||
40 | import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
||
41 | import org.gvsig.fmap.dal.store.jdbc.JDBCResource; |
||
42 | import org.slf4j.Logger; |
||
43 | import org.slf4j.LoggerFactory; |
||
44 | |||
45 | public class OracleResource extends JDBCResource { |
||
46 | |||
47 | private static Logger logger = LoggerFactory.getLogger(OracleResource.class); |
||
48 | |||
49 | public final static String NAME = "OracleResource"; |
||
50 | public static final String DESCRIPTION = "Oracle Connection"; |
||
51 | |||
52 | private Connection conn = null; |
||
53 | |||
54 | /**
|
||
55 | *
|
||
56 | * @param parameters
|
||
57 | * @throws InitializeException
|
||
58 | */
|
||
59 | public OracleResource(OracleResourceParameters parameters)
|
||
60 | throws InitializeException {
|
||
61 | super(parameters);
|
||
62 | } |
||
63 | |||
64 | /**
|
||
65 | *
|
||
66 | */
|
||
67 | public String getName() throws AccessResourceException { |
||
68 | OracleResourceParameters params = (OracleResourceParameters) this
|
||
69 | .getParameters(); |
||
70 | return MessageFormat.format("OracleResource({0},{1})", new Object[] { |
||
71 | params.getUrl(), params.getUser() }); |
||
72 | } |
||
73 | |||
74 | |||
75 | |||
76 | |||
77 | /**
|
||
78 | *
|
||
79 | */
|
||
80 | protected DataSource createDataSource() { |
||
81 | |||
82 | OracleDataSource ods = null;
|
||
83 | |||
84 | try {
|
||
85 | ods = new OracleDataSource();
|
||
86 | } catch (SQLException e) { |
||
87 | logger.error("While creating OracleDataSource: " + e.getMessage());
|
||
88 | return null; |
||
89 | } |
||
90 | |||
91 | OracleResourceParameters jdbcParams = |
||
92 | (OracleResourceParameters) getParameters(); |
||
93 | |||
94 | // ods.setDriverClassName(jdbcParams.getJDBCDriverClassName());
|
||
95 | ods.setPortNumber(jdbcParams.getPort().intValue()); |
||
96 | ods.setUser(jdbcParams.getUser()); |
||
97 | ods.setPassword(jdbcParams.getPassword()); |
||
98 | ods.setURL(jdbcParams.getUrl()); |
||
99 | ods.setDatabaseName(jdbcParams.getDBName()); |
||
100 | // ods.setLoginTimeout(30000);
|
||
101 | ods.setLoginTimeout(20);
|
||
102 | |||
103 | return ods;
|
||
104 | } |
||
105 | |||
106 | 38186 | jldominguez | public static int CONN_COUNT = 0; |
107 | |||
108 | 37896 | jldominguez | protected synchronized Object getTheConnection() throws DataException { |
109 | |||
110 | if (conn == null) { |
||
111 | conn = (Connection) super.getTheConnection(); |
||
112 | 38186 | jldominguez | CONN_COUNT++; |
113 | logger.debug("ORACLE CONN_COUNT +- = " + CONN_COUNT);
|
||
114 | 37896 | jldominguez | } |
115 | return conn;
|
||
116 | |||
117 | /*
|
||
118 | try {
|
||
119 | Object conn = this.dataSource.getConnection();
|
||
120 | debugPoolStatus("getTheConnection");
|
||
121 | return conn;
|
||
122 | } catch (SQLException e) {
|
||
123 | throw new JDBCSQLException(e);
|
||
124 | }
|
||
125 | */
|
||
126 | } |
||
127 | |||
128 | protected void connectToDB() throws DataException { |
||
129 | |||
130 | if (dataSource == null) { |
||
131 | dataSource = createDataSource(); |
||
132 | } |
||
133 | |||
134 | // FIXME Set Pool parameters:
|
||
135 | /*
|
||
136 | dataSource.setMaxActive(maxActive);
|
||
137 | dataSource.setMaxIdle(maxActive);
|
||
138 | dataSource.setMaxOpenPreparedStatements(maxActive);
|
||
139 | dataSource.setMaxWait(maxActive);
|
||
140 | dataSource.setInitialSize(initialSize);
|
||
141 | dataSource.setDefaultReadOnly(defaultReadOnly);
|
||
142 | dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation);
|
||
143 | dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
|
||
144 | dataSource.setMinIdle(minIdle);
|
||
145 | dataSource.setTestOnBorrow(testOnBorrow);
|
||
146 | dataSource.setTestOnReturn(testOnReturn);
|
||
147 | dataSource.setTestWhileIdle(testOnReturn);
|
||
148 | dataSource
|
||
149 | .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
|
||
150 | |||
151 | dataSource.setAccessToUnderlyingConnectionAllowed(allow);
|
||
152 | dataSource.setLoginTimeout(seconds);
|
||
153 | dataSource.setLogWriter(out);
|
||
154 | */
|
||
155 | |||
156 | // this.dataSource = dataSource;
|
||
157 | } |
||
158 | |||
159 | } |