Revision 37896 branches/v2_0_0_prep/extensions/org.gvsig.oracle/src/org/gvsig/fmap/dal/store/oracle/OracleResource.java
OracleResource.java | ||
---|---|---|
1 |
/* 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 |
protected synchronized Object getTheConnection() throws DataException { |
|
107 |
|
|
108 |
if (conn == null) { |
|
109 |
conn = (Connection) super.getTheConnection(); |
|
110 |
} |
|
111 |
return conn; |
|
112 |
|
|
113 |
/* |
|
114 |
try { |
|
115 |
Object conn = this.dataSource.getConnection(); |
|
116 |
debugPoolStatus("getTheConnection"); |
|
117 |
return conn; |
|
118 |
} catch (SQLException e) { |
|
119 |
throw new JDBCSQLException(e); |
|
120 |
} |
|
121 |
*/ |
|
122 |
} |
|
123 |
|
|
124 |
protected void connectToDB() throws DataException { |
|
125 |
|
|
126 |
if (dataSource == null) { |
|
127 |
dataSource = createDataSource(); |
|
128 |
} |
|
129 |
|
|
130 |
// FIXME Set Pool parameters: |
|
131 |
/* |
|
132 |
dataSource.setMaxActive(maxActive); |
|
133 |
dataSource.setMaxIdle(maxActive); |
|
134 |
dataSource.setMaxOpenPreparedStatements(maxActive); |
|
135 |
dataSource.setMaxWait(maxActive); |
|
136 |
dataSource.setInitialSize(initialSize); |
|
137 |
dataSource.setDefaultReadOnly(defaultReadOnly); |
|
138 |
dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation); |
|
139 |
dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); |
|
140 |
dataSource.setMinIdle(minIdle); |
|
141 |
dataSource.setTestOnBorrow(testOnBorrow); |
|
142 |
dataSource.setTestOnReturn(testOnReturn); |
|
143 |
dataSource.setTestWhileIdle(testOnReturn); |
|
144 |
dataSource |
|
145 |
.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); |
|
146 |
|
|
147 |
dataSource.setAccessToUnderlyingConnectionAllowed(allow); |
|
148 |
dataSource.setLoginTimeout(seconds); |
|
149 |
dataSource.setLogWriter(out); |
|
150 |
*/ |
|
151 |
|
|
152 |
// this.dataSource = dataSource; |
|
153 |
} |
|
154 |
|
|
155 |
} |
|
1 |
/* 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 |
protected synchronized Object getTheConnection() throws DataException { |
|
107 |
|
|
108 |
if (conn == null) { |
|
109 |
conn = (Connection) super.getTheConnection(); |
|
110 |
} |
|
111 |
return conn; |
|
112 |
|
|
113 |
/* |
|
114 |
try { |
|
115 |
Object conn = this.dataSource.getConnection(); |
|
116 |
debugPoolStatus("getTheConnection"); |
|
117 |
return conn; |
|
118 |
} catch (SQLException e) { |
|
119 |
throw new JDBCSQLException(e); |
|
120 |
} |
|
121 |
*/ |
|
122 |
} |
|
123 |
|
|
124 |
protected void connectToDB() throws DataException { |
|
125 |
|
|
126 |
if (dataSource == null) { |
|
127 |
dataSource = createDataSource(); |
|
128 |
} |
|
129 |
|
|
130 |
// FIXME Set Pool parameters: |
|
131 |
/* |
|
132 |
dataSource.setMaxActive(maxActive); |
|
133 |
dataSource.setMaxIdle(maxActive); |
|
134 |
dataSource.setMaxOpenPreparedStatements(maxActive); |
|
135 |
dataSource.setMaxWait(maxActive); |
|
136 |
dataSource.setInitialSize(initialSize); |
|
137 |
dataSource.setDefaultReadOnly(defaultReadOnly); |
|
138 |
dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation); |
|
139 |
dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); |
|
140 |
dataSource.setMinIdle(minIdle); |
|
141 |
dataSource.setTestOnBorrow(testOnBorrow); |
|
142 |
dataSource.setTestOnReturn(testOnReturn); |
|
143 |
dataSource.setTestWhileIdle(testOnReturn); |
|
144 |
dataSource |
|
145 |
.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); |
|
146 |
|
|
147 |
dataSource.setAccessToUnderlyingConnectionAllowed(allow); |
|
148 |
dataSource.setLoginTimeout(seconds); |
|
149 |
dataSource.setLogWriter(out); |
|
150 |
*/ |
|
151 |
|
|
152 |
// this.dataSource = dataSource; |
|
153 |
} |
|
154 |
|
|
155 |
} |
Also available in: Unified diff