svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.oracle / src / org / gvsig / fmap / dal / store / oracle / OracleResource.java @ 31886
History | View | Annotate | Download (3.89 KB)
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.SQLException; |
31 |
import java.text.MessageFormat; |
32 |
|
33 |
import javax.sql.DataSource; |
34 |
|
35 |
import oracle.jdbc.pool.OracleDataSource; |
36 |
|
37 |
import org.apache.commons.dbcp.BasicDataSource; |
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.gvsig.fmap.dal.store.jdbc.JDBCResourceParameters; |
43 |
import org.slf4j.Logger; |
44 |
import org.slf4j.LoggerFactory; |
45 |
|
46 |
public class OracleResource extends JDBCResource { |
47 |
|
48 |
private static Logger logger = LoggerFactory.getLogger(OracleResource.class); |
49 |
|
50 |
public final static String NAME = "OracleResource"; |
51 |
public static final String DESCRIPTION = "Oracle Connection"; |
52 |
|
53 |
/**
|
54 |
*
|
55 |
* @param parameters
|
56 |
* @throws InitializeException
|
57 |
*/
|
58 |
public OracleResource(OracleResourceParameters parameters)
|
59 |
throws InitializeException {
|
60 |
super(parameters);
|
61 |
} |
62 |
|
63 |
/**
|
64 |
*
|
65 |
*/
|
66 |
public String getName() throws AccessResourceException { |
67 |
OracleResourceParameters params = (OracleResourceParameters) this
|
68 |
.getParameters(); |
69 |
return MessageFormat.format("OracleResource({0},{1})", new Object[] { |
70 |
params.getUrl(), params.getUser() }); |
71 |
} |
72 |
|
73 |
|
74 |
|
75 |
|
76 |
/**
|
77 |
*
|
78 |
*/
|
79 |
protected DataSource createDataSource() { |
80 |
|
81 |
OracleDataSource ods = null;
|
82 |
|
83 |
try {
|
84 |
ods = new OracleDataSource();
|
85 |
} catch (SQLException e) { |
86 |
logger.error("While creating OracleDataSource: " + e.getMessage());
|
87 |
return null; |
88 |
} |
89 |
|
90 |
OracleResourceParameters jdbcParams = |
91 |
(OracleResourceParameters) getParameters(); |
92 |
|
93 |
// ods.setDriverClassName(jdbcParams.getJDBCDriverClassName());
|
94 |
ods.setPortNumber(jdbcParams.getPort().intValue()); |
95 |
ods.setUser(jdbcParams.getUser()); |
96 |
ods.setPassword(jdbcParams.getPassword()); |
97 |
ods.setURL(jdbcParams.getUrl()); |
98 |
ods.setDatabaseName(jdbcParams.getDBName()); |
99 |
// ods.setLoginTimeout(30000);
|
100 |
ods.setLoginTimeout(20);
|
101 |
|
102 |
return ods;
|
103 |
} |
104 |
|
105 |
protected void connectToDB() throws DataException { |
106 |
|
107 |
if (dataSource == null) { |
108 |
dataSource = createDataSource(); |
109 |
} |
110 |
|
111 |
// FIXME Set Pool parameters:
|
112 |
/*
|
113 |
dataSource.setMaxActive(maxActive);
|
114 |
dataSource.setMaxIdle(maxActive);
|
115 |
dataSource.setMaxOpenPreparedStatements(maxActive);
|
116 |
dataSource.setMaxWait(maxActive);
|
117 |
dataSource.setInitialSize(initialSize);
|
118 |
dataSource.setDefaultReadOnly(defaultReadOnly);
|
119 |
dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation);
|
120 |
dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
|
121 |
dataSource.setMinIdle(minIdle);
|
122 |
dataSource.setTestOnBorrow(testOnBorrow);
|
123 |
dataSource.setTestOnReturn(testOnReturn);
|
124 |
dataSource.setTestWhileIdle(testOnReturn);
|
125 |
dataSource
|
126 |
.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
|
127 |
|
128 |
dataSource.setAccessToUnderlyingConnectionAllowed(allow);
|
129 |
dataSource.setLoginTimeout(seconds);
|
130 |
dataSource.setLogWriter(out);
|
131 |
*/
|
132 |
|
133 |
// this.dataSource = dataSource;
|
134 |
} |
135 |
|
136 |
} |