Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.oracle / src / org / gvsig / fmap / dal / store / oracle / OracleResource.java @ 38188

History | View | Annotate | Download (4.51 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.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
        public static int CONN__COUNT = 0;
107
        
108
        protected synchronized Object getTheConnection() throws DataException {
109
                
110
                if (conn == null) {
111
                        conn = (Connection) super.getTheConnection();
112
                        CONN__COUNT++;
113
                        if (CONN__COUNT > 5) {
114
                                logger.info("ORACLE CONN_COUNT +- = " + CONN__COUNT);
115
                        }
116
                        
117
                }
118
                return conn;
119

    
120
                /*
121
                try {
122
                        Object conn = this.dataSource.getConnection();
123
                        debugPoolStatus("getTheConnection");
124
                        return conn;
125
                } catch (SQLException e) {
126
                        throw new JDBCSQLException(e);
127
                }
128
                */
129
        }
130
        
131
        protected void connectToDB() throws DataException {
132

    
133
                if (dataSource == null) {
134
                        dataSource = createDataSource();
135
                }
136
                
137
                // FIXME Set Pool parameters:
138
                /*
139
                dataSource.setMaxActive(maxActive);
140
                dataSource.setMaxIdle(maxActive);
141
                dataSource.setMaxOpenPreparedStatements(maxActive);
142
                dataSource.setMaxWait(maxActive);
143
                dataSource.setInitialSize(initialSize);
144
                dataSource.setDefaultReadOnly(defaultReadOnly);
145
                dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation);
146
                dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
147
                dataSource.setMinIdle(minIdle);
148
                dataSource.setTestOnBorrow(testOnBorrow);
149
                dataSource.setTestOnReturn(testOnReturn);
150
                dataSource.setTestWhileIdle(testOnReturn);
151
                dataSource
152
                                .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
153

154
                dataSource.setAccessToUnderlyingConnectionAllowed(allow);
155
                dataSource.setLoginTimeout(seconds);
156
                dataSource.setLogWriter(out);
157
                */
158

    
159
                // this.dataSource = dataSource;
160
        }
161

    
162
}