Revision 46076

View differences:

tags/org.gvsig.desktop-2.0.343/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4

  
5
  <modelVersion>4.0.0</modelVersion>
6
  <artifactId>org.gvsig.fmap.dal.db</artifactId>
7
  <name>${project.artifactId}</name>
8
  <packaging>pom</packaging>
9
  <description>This library has the implementation of the provider of te Data Access Library for accesing to database resources, like JDBC, PostgreSQL or H2.</description>
10
  <parent>
11
      <groupId>org.gvsig</groupId>
12
      <artifactId>org.gvsig.fmap.dal</artifactId>
13
      <version>2.0.343</version>
14
  </parent>  
15

  
16
  <modules>
17
    <module>org.gvsig.fmap.dal.db.lib</module>
18
    <module>org.gvsig.fmap.dal.db.jdbc</module>
19
    <module>org.gvsig.fmap.dal.db.mdb</module>
20
  </modules>
21
</project>
0 22

  
tags/org.gvsig.desktop-2.0.343/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/ResulSetControler.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2020 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.store.jdbc2;
25

  
26
import java.sql.ResultSet;
27
import java.sql.SQLException;
28
import java.util.List;
29
import org.gvsig.fmap.dal.exception.DataException;
30
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
31

  
32

  
33
public interface ResulSetControler extends AutoCloseable {
34

  
35
    public interface ResultSetEntry extends AutoCloseable {
36
        public ResultSet get();
37
        public int getID();
38
        public boolean isZombie();
39
        public String getSQL();
40
        public FeatureAttributeDescriptor[] getColumns();
41
        public String[] getExtraValueNames();
42
        public Object getObject(int columnIndex) throws SQLException;
43
        public byte[] getBytes(int columnIndex) throws SQLException;
44
        public boolean next() throws SQLException;
45
    }
46

  
47
    public void setTimeToZombie(long mlSeconds);
48

  
49
    public long getTimeToZombie();
50

  
51
    public ResultSetEntry create(String sql, int fetchSize, FeatureAttributeDescriptor[] columns, String[] extraValueNames ) throws DataException;
52

  
53
    public ResultSetEntry create(String sql, List<Object> values, int fetchSize, FeatureAttributeDescriptor[] columns, String[] extraValueNames) throws DataException;
54

  
55
    public int getOpenCount();
56
    
57
    public void closeAll();
58

  
59
    public void pack();    
60
}
tags/org.gvsig.desktop-2.0.343/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/impl/JDBCSetProvider.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.dal.store.jdbc2.impl;
24

  
25
import java.util.ArrayList;
26
import java.util.List;
27
import java.util.NoSuchElementException;
28
import org.apache.commons.collections.CollectionUtils;
29
import org.apache.commons.lang3.BooleanUtils;
30
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.fmap.dal.feature.FeatureQuery;
32
import org.gvsig.fmap.dal.feature.FeatureType;
33

  
34
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureSetProvider;
35
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider;
36
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
37
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
38
import org.gvsig.fmap.dal.store.jdbc2.JDBCStoreProvider;
39
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
40
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
41
import org.gvsig.fmap.dal.store.jdbc2.ResulSetControler;
42
import org.gvsig.fmap.dal.store.jdbc2.ResulSetControler.ResultSetEntry;
43
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.TableIsEmptyOperation;
44
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation;
45
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CountOperation;
46
import org.gvsig.tools.evaluator.Evaluator;
47
import org.gvsig.tools.exception.BaseException;
48
import org.slf4j.Logger;
49
import org.slf4j.LoggerFactory;
50

  
51
public class JDBCSetProvider extends AbstractFeatureSetProvider {
52

  
53
    final static protected Logger LOGGER = LoggerFactory.getLogger(JDBCSetProvider.class);
54

  
55
    private class EmptyJDBCIterator extends JDBCIterator {
56

  
57
        protected EmptyJDBCIterator(JDBCStoreProvider store) throws DataException {
58
            super(store, null, null, null);
59
        }
60

  
61
        @Override
62
        protected boolean internalHasNext() {
63
            return false;
64
        }
65

  
66
        @Override
67
        protected Object internalNext() {
68
            throw new NoSuchElementException();
69
        }
70

  
71
        @Override
72
        protected void doDispose() throws BaseException {
73
            // nothing to do
74
        }
75

  
76
    }
77

  
78
    
79
    protected Long size = null;
80
    protected Boolean isEmpty = null;
81
    protected List<ResultSetEntry> resultSets;
82
    private int defaultFetchSize = 1000;
83

  
84
    public JDBCSetProvider(
85
            AbstractFeatureStoreProvider store,
86
            JDBCHelper helper,
87
            FeatureQuery query,
88
            FeatureType featureType
89
    ) throws DataException {
90
        super(store, query, featureType);
91
        this.resultSets = new ArrayList<>();
92
    }
93

  
94
    /**
95
     * @return the defaultFetchSize
96
     */
97
    public int getDefaultFetchSize() {
98
        return defaultFetchSize;
99
    }
100

  
101
    /**
102
     * @param defaultFetchSize the defaultFetchSize to set
103
     */
104
    public void setDefaultFetchSize(int defaultFetchSize) {
105
        this.defaultFetchSize = defaultFetchSize;
106
    }
107

  
108
//    @Override
109
//    protected JDBCStoreProvider getStore() {
110
//        return (JDBCStoreProvider) super.getStore();
111
//    }
112

  
113
    protected JDBCStoreProvider getJDBCStore() {
114
//        Corregido el problema en AbstractFeatureSetProvider, de que getStore
115
//        debe ser un FeatureStoreProvider y no un AbstractFeatureStoreProvider
116
//        este metodo debe desaparecer y quedar el getStore de arriba que esta
117
//          comentarizado
118
        return (JDBCStoreProvider) super.getStore();
119
    }    
120
    
121
    protected JDBCHelper getHelper() {
122
        return this.getJDBCStore().getHelper();
123
    }
124
    
125
    protected OperationsFactory getOperations() {
126
        return this.getHelper().getOperations();
127
    }
128

  
129
    @Override
130
    public boolean canIterateFromIndex() {
131
        return this.getHelper().supportOffsetInSelect();
132
    }
133
    
134
    @Override
135
    public boolean canFilter() {
136
        return this.getHelper().supportFilter(this.getFeatureType(), getQuery().getFilter());
137
    }
138

  
139
    @Override
140
    public boolean canOrder() {
141
        return this.getHelper().supportOrder(this.getFeatureType(), getQuery().getOrder());
142
    }
143
    
144
    public ResulSetControler getResulSetControler() {
145
        return this.getHelper().getResulSetControler();
146
    }
147

  
148
    @Override
149
    protected void doDispose() throws BaseException {
150
        if( ! CollectionUtils.isEmpty(this.resultSets) ) {
151
            for( ResultSetEntry resulset : this.resultSets ) {
152
               JDBCUtils.closeQuietly(resulset);
153
            }
154
        }
155
        size = null;
156
        isEmpty = null;
157
    }
158

  
159
    protected int getFetchSize() {
160
        long pageSize = -1;
161
        if (getQuery() != null) {
162
            pageSize = getQuery().getPageSize();
163
            pageSize = pageSize > Integer.MAX_VALUE ? Integer.MAX_VALUE : pageSize;
164
        }
165
        return (pageSize > 0 ? (int) pageSize : defaultFetchSize);
166
    }
167

  
168
    @Override
169
    public long getSize() throws DataException {
170
        if (size == null) {
171
            JDBCStoreParameters params = this.getJDBCStore().getParameters();
172
            CountOperation selectCount = this.getOperations().createCount(
173
                    this.getFeatureType(),
174
                    this.getOperations().createTableReference(params),
175
                    params.getBaseFilter(), 
176
                    this.getQuery()
177
            );
178
            size = (Long) selectCount.perform();              
179
        }
180
        return size;
181
    }
182

  
183
    @Override
184
    public boolean isEmpty() throws DataException {
185
        if (this.isEmpty == null) {
186
            if (this.size == null) {
187
                JDBCStoreParameters params = this.getJDBCStore().getParameters();
188
//                String filtersql = null;
189
//                Evaluator filter = this.getQuery().getFilter();
190
//                if( filter != null ) {
191
//                    filtersql = filter.getSQL();
192
//                }
193
                TableIsEmptyOperation isEmpty_ = this.getOperations().createTableIsEmpty(
194
                        this.getFeatureType(),
195
                        this.getOperations().createTableReference(params),
196
                        params.getBaseFilter(), 
197
                        this.getQuery()
198
                );
199
                this.isEmpty = (Boolean) isEmpty_.perform();   
200
            } else {
201
                this.isEmpty = (this.size < 1);
202
            }
203
        }
204
        return isEmpty;
205
    }
206

  
207

  
208
    @Override
209
    protected JDBCIterator createFastIterator(long index) throws DataException {
210
        return createFastIterator(index, 0);
211
    }
212
    
213
    @Override
214
    protected JDBCIterator createFastIterator(long index, long elements) throws DataException {
215
        if( BooleanUtils.isTrue(isEmpty) ) {
216
            return new EmptyJDBCIterator(this.getJDBCStore());
217
        }
218
        
219
        JDBCStoreParameters params = this.getJDBCStore().getParameters();
220
        FeatureType storeType = this.getStore()
221
                .getStoreServices()
222
		.getProviderFeatureType(this.getFeatureType().getId());
223
        ResultSetForSetProviderOperation createResultSet 
224
            = getOperations().createResultSetForSetProvider(
225
                    this.getOperations().createTableReference(params),
226
                    params.getBaseFilter(), 
227
                    params.getBaseOrder(), 
228
                    this.getQuery(), 
229
                    storeType, 
230
                    this.getFeatureType(), 
231
                    elements, 
232
                    index, 
233
                    this.getFetchSize()
234
            );
235

  
236
        ResultSetEntry resultSetEntry = (ResultSetEntry) createResultSet.perform();
237

  
238
        this.resultSets.add(resultSetEntry);
239
        return new JDBCFastIterator(
240
                this.getJDBCStore(), 
241
                this, 
242
                this.getFeatureType(),
243
                resultSetEntry
244
        );
245
    }
246

  
247
    @Override
248
    protected JDBCIterator createIterator(long index) throws DataException {
249
        return createIterator(index, -1);
250
    }
251
    
252
    @Override
253
    protected JDBCIterator createIterator(long index, long elements) throws DataException {
254
        if( BooleanUtils.isTrue(isEmpty) ) {
255
            return new EmptyJDBCIterator(this.getJDBCStore());
256
        }
257
        JDBCStoreParameters params = this.getJDBCStore().getParameters();
258
        FeatureType storeType = this.getStore()
259
                .getStoreServices()
260
		.getProviderFeatureType(this.getFeatureType().getId());
261
        ResultSetForSetProviderOperation createResultSet 
262
            = getOperations().createResultSetForSetProvider(
263
                    this.getOperations().createTableReference(params),
264
                    params.getBaseFilter(), 
265
                    params.getBaseOrder(), 
266
                    this.getQuery(), 
267
                    storeType, 
268
                    this.getFeatureType(), 
269
                    elements, 
270
                    index, 
271
                    this.getDefaultFetchSize()
272
            );
273

  
274
        ResultSetEntry resultSetEntry = (ResultSetEntry) createResultSet.perform();
275
        this.resultSets.add(resultSetEntry);
276
        return new JDBCIterator(
277
                this.getJDBCStore(), 
278
                this, 
279
                this.getFeatureType(),
280
                resultSetEntry
281
        );
282
    }
283

  
284
}
tags/org.gvsig.desktop-2.0.343/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/impl/ResulSetControlerBase.java
1
package org.gvsig.fmap.dal.store.jdbc2.impl;
2

  
3
import java.sql.Connection;
4
import java.sql.PreparedStatement;
5
import java.sql.ResultSet;
6
import java.sql.SQLException;
7
import java.sql.Statement;
8
import java.util.ArrayList;
9
import java.util.HashMap;
10
import java.util.List;
11
import java.util.Map;
12
import org.gvsig.fmap.dal.exception.DataException;
13
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
14
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCExecutePreparedSQLException;
15
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
16
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
17
import org.gvsig.fmap.dal.store.jdbc2.ResulSetControler;
18
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCHelperBase;
19
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
20
import org.gvsig.tools.dispose.Disposable;
21
import org.gvsig.tools.dispose.DisposeUtils;
22
import org.slf4j.Logger;
23
import org.slf4j.LoggerFactory;
24

  
25
public class ResulSetControlerBase implements ResulSetControler {
26

  
27
    final static private Logger LOGGER = LoggerFactory.getLogger(ResulSetControlerBase.class);
28

  
29
    public class ResultSetEntryBase implements ResultSetEntry {
30

  
31
        private ResultSet resultSet = null;
32
        private final int id;
33
        private long lastUse = 0;
34
        private final String sql;
35
        private final FeatureAttributeDescriptor[] columns;
36
        private final String[] extraValueNames;
37
        private Throwable closeCause ;
38
        
39
        private final String connId;
40
        private final String hexId;
41

  
42
        public ResultSetEntryBase(ResultSet resulSet, String sql, FeatureAttributeDescriptor[] columns, String[] extraValueNames) {
43
            this.closeCause = null;
44
            this.resultSet = resulSet;
45
            this.connId = JDBCUtils.getConnId(this.resultSet);
46
            this.hexId = JDBCUtils.getHexId(this);
47
            this.id = nextid++;
48
            this.sql = sql;
49
            this.columns = columns;
50
            this.extraValueNames = extraValueNames;
51
            used();
52
            synchronized(resulSets){
53
                resulSets.put(this.getID(), this);
54
            }
55
            if( LOGGER.isDebugEnabled() ) {
56
                LOGGER.debug("["+JDBCUtils.getConnId(resulSet)+"] ResultSetEntryBase "+this.hexId+" "+sql);
57
            }
58
            LOGGER.debug(((JDBCHelperBase)helper).getConnectionProviderStatus());
59
        }
60

  
61
        private void used() {
62
            lastUse = System.currentTimeMillis();
63
        }
64

  
65
        @Override
66
        public ResultSet get() {
67
            used();
68
            return resultSet;
69
        }
70

  
71
        @Override
72
        public int getID() {
73
            return this.id;
74
        }
75

  
76
        @Override
77
        public boolean isZombie() {
78
            if( this.resultSet == null ) {
79
                return true;
80
            }
81
            return System.currentTimeMillis() - lastUse > mlsecondsToZombie;
82
        }
83

  
84
        @Override
85
        public String getSQL() {
86
            return this.sql;
87
        }
88

  
89
        @Override
90
        public String[] getExtraValueNames() {
91
            return this.extraValueNames;
92
        }
93
        
94
        @Override
95
        public FeatureAttributeDescriptor[] getColumns() {
96
            return this.columns;
97
        }
98
        
99
        @Override
100
        public Object getObject(int columnIndex) throws SQLException {
101
            used();
102
            return this.resultSet.getObject(columnIndex);
103
        }
104

  
105
        @Override
106
        public byte[] getBytes(int columnIndex) throws SQLException {
107
            used();
108
            return this.resultSet.getBytes(columnIndex);
109
        }
110

  
111
        @Override
112
        public boolean next() throws SQLException {
113
            if( this.closeCause!=null ) {
114
                LOGGER.debug("["+this.connId+"] ResultSetEntryBase already closed "+this.hexId);
115
                throw new IllegalStateException("ResultSetEntryBase already closed, connId="+this.connId+", id="+this.hexId+" (sql="+sql+")", closeCause);
116
            }
117
            return this.resultSet.next();
118
        }
119

  
120
        @Override
121
        public void close() throws Exception {
122
            if( LOGGER.isDebugEnabled() ) {
123
                LOGGER.debug("["+this.connId+"] ResultSetEntryBase close "+this.hexId);
124
            }
125
            if( this.resultSet == null ) {
126
                // Already close
127
                return;
128
            }
129
            this.closeCause = new Throwable();
130
            
131
            Statement st = null;
132
            Connection con = null;
133
            try {
134
                synchronized(resulSets){
135
                    resulSets.remove(this.getID());
136
                }
137
                st = this.resultSet.getStatement();
138
                if( st != null ) {
139
                    con = st.getConnection();
140
                }
141
            } catch(Exception ex) {
142
                LOGGER.warn("Problems closing ResulSetEntryBase.",ex);
143
            }
144
            JDBCUtils.closeQuietly(this.resultSet);
145
            JDBCUtils.closeQuietly(st);
146
            helper.closeConnection(con);
147
            this.resultSet = null;
148
            LOGGER.debug(
149
                    "Close ResulSetEntryBase id {} (total {})",
150
                    this.getID(),
151
                    getOpenCount()
152
            );
153
            LOGGER.debug(((JDBCHelperBase)helper).getConnectionProviderStatus());
154
            pack();
155
        }
156

  
157
    }
158

  
159
    private int nextid = 1;
160

  
161
    private final Map<Integer, ResultSetEntryBase> resulSets;
162

  
163
    private long mlsecondsToZombie = 1000 * 60 * 10; // 10 Min
164

  
165
    private JDBCHelper helper = null;
166

  
167
    public ResulSetControlerBase(JDBCHelper helper) {
168
        this.helper = helper;
169
        this.resulSets = new HashMap<>();
170
        this.nextid = 1;
171
    }
172

  
173
    @Override
174
    public long getTimeToZombie() {
175
        return mlsecondsToZombie;
176
    }
177

  
178
    @Override
179
    public void setTimeToZombie(long mlSeconds) {
180
        mlsecondsToZombie = mlSeconds;
181
    }
182

  
183
    @Override
184
    public void close() throws Exception {
185
        this.closeAll();
186
        this.helper = null;
187
        this.resulSets.clear();
188
        this.nextid = -10;
189
    }
190

  
191
    @Override
192
    public ResultSetEntryBase create(
193
            String sql, 
194
            int fetchSize, 
195
            FeatureAttributeDescriptor[] columns,
196
            String[] extraValueNames) throws DataException {
197
        return create(sql, null, fetchSize, columns, extraValueNames);
198
    }
199

  
200
    @Override
201
    public synchronized ResultSetEntryBase create(
202
            String sql, 
203
            List<Object> values, 
204
            int fetchSize, 
205
            FeatureAttributeDescriptor[] columns, 
206
            String[] extraValueNames) throws DataException {
207
        this.pack();
208
        ResultSet rs = null;
209
        Connection conn = null;
210
        PreparedStatement st = null;
211
        Disposable paramsDisposer = null;
212
        try {
213
            conn = helper.getConnection();
214
            conn.setAutoCommit(false);
215
            st = conn.prepareStatement(sql);
216

  
217
            JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
218
            paramsDisposer = sqlbuilder.setStatementParameters(st, values, helper.getGeometrySupportType());
219

  
220
            if (fetchSize > 0) {
221
                // See parameter "SelectMethod" of SQL Server Connection Properties
222
                // https://docs.oracle.com/cd/E13157_01/wlevs/docs30/jdbc_drivers/mssqlserver.html
223
                st.setFetchSize(fetchSize);
224
            }
225
            rs = JDBCUtils.executeQuery(st, sql);
226
            if (fetchSize > 0) {
227
                rs.setFetchSize(fetchSize);
228
            }
229
            ResultSetEntryBase rsentry = new ResultSetEntryBase(rs, sql, columns,  extraValueNames);
230
            return rsentry;
231

  
232
        } catch (SQLException e) {
233
            JDBCUtils.closeQuietly(rs);
234
            JDBCUtils.closeQuietly(st);
235
            this.helper.closeConnectionQuietly(conn);
236
            throw new JDBCExecutePreparedSQLException(sql, values, e);
237
        } finally {
238
            DisposeUtils.disposeQuietly(paramsDisposer);
239
        }
240
    }
241
    
242
    private List<ResultSetEntryBase> getResultSetValues() {
243
        synchronized(this.resulSets){
244
            List<ResultSetEntryBase> values = new ArrayList<>();
245
            values.addAll(this.resulSets.values());
246
            return values;
247
        }
248
    }
249

  
250
    @Override
251
    public synchronized void closeAll() {
252

  
253
        List<ResultSetEntryBase> values = getResultSetValues();
254

  
255
        for (ResultSetEntryBase entry : values) {
256
            JDBCUtils.closeQuietly(entry);
257
        }
258
    }
259

  
260
    @Override
261
    public synchronized void pack() {
262

  
263
        List<ResultSetEntryBase> values = getResultSetValues();
264

  
265
        int maxID = 0;
266
        for (ResultSetEntryBase entry : values) {
267
            if (entry.isZombie()) {
268
                JDBCUtils.closeQuietly(entry);
269
            } else {
270
                if (entry.getID() > maxID) {
271
                    maxID = entry.getID();
272
                }
273
            }
274
        }
275
        this.nextid = maxID + 1;
276
    }
277

  
278
    @Override
279
    public int getOpenCount() {
280
        synchronized(resulSets){
281
            return this.resulSets.size();
282
        }
283
    }
284
}
tags/org.gvsig.desktop-2.0.343/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/impl/JDBCFastIterator.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.store.jdbc2.impl;
25

  
26
import org.gvsig.fmap.dal.exception.DataException;
27
import org.gvsig.fmap.dal.feature.FeatureType;
28
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
29
import org.gvsig.fmap.dal.store.jdbc2.JDBCStoreProvider;
30
import org.gvsig.fmap.dal.store.jdbc2.ResulSetControler.ResultSetEntry;
31
import org.gvsig.tools.exception.BaseException;
32

  
33

  
34
public class JDBCFastIterator extends JDBCIterator {
35

  
36
	protected FeatureProvider featureProvider;
37

  
38
	protected JDBCFastIterator(
39
                JDBCStoreProvider store, 
40
                JDBCSetProvider set,
41
		FeatureType featureType, 
42
                ResultSetEntry resultSetEntry 
43
            ) throws DataException {
44
            super(store, set, featureType, resultSetEntry);
45
            this.featureProvider = super.createFeatureProvider();
46
	}
47

  
48
        @Override
49
	protected FeatureProvider createFeatureProvider() throws DataException {
50
		return this.featureProvider;
51
	}
52

  
53
	@Override
54
	protected void doDispose() throws BaseException {
55
		super.doDispose();
56
		featureProvider = null;
57
	}
58

  
59
}
tags/org.gvsig.desktop-2.0.343/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/impl/JDBCIterator.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.dal.store.jdbc2.impl;
24

  
25
import java.sql.SQLException;
26
import java.util.NoSuchElementException;
27

  
28
import org.gvsig.fmap.dal.exception.DataException;
29
import org.gvsig.fmap.dal.feature.FeatureType;
30
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureProviderIterator;
31
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
32
import org.gvsig.fmap.dal.store.jdbc2.JDBCStoreProvider;
33
import org.gvsig.fmap.dal.store.jdbc2.ResulSetControler.ResultSetEntry;
34
import org.gvsig.tools.exception.BaseException;
35

  
36
public class JDBCIterator extends AbstractFeatureProviderIterator {
37

  
38
    protected ResultSetEntry resulsetEntry;
39
    protected Boolean hasNext = null;
40
    protected FeatureType featureType;
41
    protected JDBCSetProvider set;
42

  
43
    protected JDBCIterator(
44
            JDBCStoreProvider store, 
45
            JDBCSetProvider set,
46
            FeatureType featureType,
47
            ResultSetEntry resulsetEntry
48
        ) throws DataException {
49
        super(store);
50
        this.resulsetEntry = resulsetEntry;
51
        this.featureType = featureType;
52
        this.set = set;
53
        this.hasNext = null;
54
    }
55

  
56
    @Override
57
    protected JDBCStoreProvider getFeatureStoreProvider() {
58
        return (JDBCStoreProvider) super.getFeatureStoreProvider();
59
    }
60

  
61
    @Override
62
    public final Object next() {
63
        return internalNext();
64
    }
65

  
66
    @Override
67
    public final boolean hasNext() {
68
        return internalHasNext();
69
    }
70

  
71
    @Override
72
    protected boolean internalHasNext() {
73
        if (hasNext == null) {
74
            try {
75
                if ( resulsetEntry.next() ) {
76
                    hasNext = Boolean.TRUE;
77
                } else {
78
                    hasNext = Boolean.FALSE;
79
                    this.close();
80
                }
81
            } catch (SQLException e) {
82
                throw new RuntimeException(e);
83
            }
84
        }
85
        return hasNext;
86
    }
87

  
88
    @Override
89
    protected Object internalNext() {
90
        if (!hasNext()) {
91
            throw new NoSuchElementException();
92
        }
93
        FeatureProvider data;
94
        try {
95
            data = getFeatureProvider();
96
        } catch (DataException e) {
97
            throw new RuntimeException(e);
98
        }
99
        hasNext = null;
100
        return data;
101
    }
102

  
103
    @Override
104
    public void remove() {
105
        throw new UnsupportedOperationException();
106
    }
107

  
108
    protected FeatureProvider createFeatureProvider() throws DataException {
109
        return getFeatureStoreProvider().createFeatureProvider(featureType);
110
    }
111

  
112
    protected FeatureProvider getFeatureProvider() throws DataException {
113
        FeatureProvider data = createFeatureProvider();
114
        this.getFeatureStoreProvider().getHelper().fetchFeature(data, this.resulsetEntry);
115
        return data;
116
    }
117

  
118
    @Override
119
    protected void doDispose() throws BaseException {
120
        if (this.resulsetEntry!=null) {
121
            this.close();
122
        }
123
        this.featureType = null;
124
    }
125

  
126
    protected void close() {
127
        try {
128
            this.resulsetEntry.close();
129
            this.resulsetEntry = null;
130
        } catch (Exception e) {
131
            throw new RuntimeException(e);
132
        }
133
    }
134

  
135
}
tags/org.gvsig.desktop-2.0.343/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/impl/JDBCServerExplorerFactory.java
1

  
2
package org.gvsig.fmap.dal.store.jdbc2.impl;
3

  
4
import org.apache.commons.lang3.StringUtils;
5
import org.gvsig.fmap.dal.store.jdbc2.JDBCLibrary;
6
import org.gvsig.fmap.dal.DataServerExplorerParameters;
7
import org.gvsig.fmap.dal.exception.InitializeException;
8
import org.gvsig.fmap.dal.spi.AbstractDataServerExplorerFactory;
9
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
10
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters;
11
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
12
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
13
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
14
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCHelperBase;
15

  
16

  
17
public class JDBCServerExplorerFactory extends AbstractDataServerExplorerFactory {
18

  
19
    private static final String NAME = JDBCLibrary.NAME;
20

  
21
    public JDBCServerExplorerFactory() {
22
        this(
23
                NAME,
24
                "JDBC generic server (2)"
25
        );
26
    }
27
    
28
    protected JDBCServerExplorerFactory(String name, String description) {
29
        super(name,description);
30
    }
31
    
32
    protected JDBCServerExplorerFactory(String name, String description, boolean hidden) {
33
        super(name,description, hidden);
34
    }
35

  
36
    @Override
37
    public JDBCServerExplorer create(
38
            DataServerExplorerParameters parameters, 
39
            DataServerExplorerProviderServices providerServices
40
        ) throws InitializeException {
41
        JDBCHelper helper = new JDBCHelperBase((JDBCConnectionParameters) parameters);
42
        JDBCServerExplorer server = helper.createServerExplorer(
43
                (JDBCServerExplorerParameters) parameters, 
44
                providerServices
45
        );
46
        return server;
47
    }
48
        
49
    @Override
50
    public JDBCServerExplorerParameters createParameters() {
51
        JDBCServerExplorerParameters params = new JDBCServerExplorerParameters(
52
                NAME + "ServerExplorerParameters",
53
                NAME 
54
        );
55
        return params;    
56
    }
57

  
58
    @Override
59
    public boolean isStoreSupported(String name) {
60
        return StringUtils.equalsIgnoreCase(name, this.getName());
61
    }
62

  
63

  
64
}
tags/org.gvsig.desktop-2.0.343/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/impl/JDBCStoreProviderFactory.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.dal.store.jdbc2.impl;
24

  
25
import org.gvsig.fmap.dal.store.jdbc2.JDBCLibrary;
26

  
27
import org.gvsig.fmap.dal.DataParameters;
28
import org.gvsig.fmap.dal.exception.InitializeException;
29
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProviderFactory;
30
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
31
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters;
32
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
33
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
34
import org.gvsig.fmap.dal.store.jdbc2.JDBCStoreProvider;
35
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCHelperBase;
36

  
37
public class JDBCStoreProviderFactory 
38
    extends AbstractFeatureStoreProviderFactory 
39
    {
40

  
41
    private static final String NAME = JDBCLibrary.NAME;
42
    
43
    public static final int CASE_IDENTIFIERS_INDIFERENT = 0;
44
    public static final int CASE_IDENTIFIERS_UPPERCASE = 1;
45
    public static final int CASE_IDENTIFIERS_LOWERCASE = 2;
46
    
47
    public JDBCStoreProviderFactory() {
48
        this(
49
                NAME, 
50
                "JDBC generic store (2)"
51
        );
52
    }
53
    
54
    @Override
55
    public int hasTabularSupport() {
56
        return YES;
57
    }    
58

  
59
    @Override
60
    public int hasSQLSupport() {
61
        return YES;
62
    }
63
    
64
    protected JDBCStoreProviderFactory(String name, String description) {
65
        super(name, description);
66
    }
67
    
68
    protected JDBCStoreProviderFactory(String name, String description, boolean hidden) {
69
        super(name, description, hidden);
70
    }
71

  
72
    @Override
73
    public JDBCStoreProvider createProvider(
74
            DataParameters parameters,
75
            DataStoreProviderServices providerServices
76
    ) throws InitializeException {
77
        JDBCHelper helper = new JDBCHelperBase((JDBCConnectionParameters) parameters);
78
        JDBCStoreProvider provider = helper.createProvider(
79
                (JDBCStoreParameters) parameters, 
80
                providerServices
81
        );
82
        return provider;
83
    }
84
    
85
    @Override
86
    public JDBCStoreParameters createParameters() {
87
        JDBCStoreParameters params = new JDBCStoreParameters(
88
                NAME + "StoreParameters",
89
                NAME 
90
        );
91
        return params;
92
    }
93

  
94
    @Override
95
    public int isOptimalRecoverFeaturesByReference() {
96
        return NO;
97
    }
98

  
99
    public int useLocalIndexesCanImprovePerformance() {
100
        return NO;
101
    }
102
    
103
    @Override
104
    public boolean allowSpatialIndexSupport() {
105
        if (this.hasVectorialSupport() == YES) {
106
            return true;
107
        }
108
        return false;
109
    }
110
    
111
    public int caseIndentifierPreferedMode() {
112
        return CASE_IDENTIFIERS_UPPERCASE;
113
    }
114
}
tags/org.gvsig.desktop-2.0.343/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/impl/expressionevaluator/JDBCSymbolTable.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2020 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.store.jdbc2.impl.expressionevaluator;
25

  
26
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable;
27
import static org.gvsig.fmap.dal.store.jdbc2.impl.expressionevaluator.JDBCSymbolTableFactory.SYMBOLTABLE_NAME;
28

  
29
/**
30
 *
31
 * @author jjdelcerro
32
 */
33
public class JDBCSymbolTable 
34
        extends AbstractSymbolTable
35
    {   
36

  
37
    public JDBCSymbolTable() {
38
        super(SYMBOLTABLE_NAME);
39
        this.initFunctions();
40
    }
41
    
42
    private void initFunctions() {
43
        this.addFunction(new ExecuteSQLFunction());
44
        
45
    }    
46
}
tags/org.gvsig.desktop-2.0.343/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/impl/expressionevaluator/ExecuteSQLFunction.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2020 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.store.jdbc2.impl.expressionevaluator;
25

  
26
import org.apache.commons.lang3.Range;
27
import org.gvsig.expressionevaluator.Interpreter;
28
import org.gvsig.expressionevaluator.spi.AbstractFunction;
29
import org.gvsig.fmap.dal.DALLocator;
30
import org.gvsig.fmap.dal.DataManager;
31
import org.gvsig.fmap.dal.DataServerExplorerParameters;
32
import org.gvsig.fmap.dal.DataServerExplorerPoolEntry;
33
import org.gvsig.fmap.dal.feature.FeatureStore;
34
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
35
import static org.gvsig.fmap.dal.store.jdbc2.impl.expressionevaluator.JDBCSymbolTableFactory.GROUP_JDBC;
36

  
37
/**
38
 *
39
 * @author jjdelcerro
40
 */
41
public class ExecuteSQLFunction extends AbstractFunction {
42

  
43
  public static final String FUNCTION_EXECUTESQL = "EXECUTESQL";
44

  
45
  public ExecuteSQLFunction() {
46
    super(  GROUP_JDBC,
47
            FUNCTION_EXECUTESQL,
48
            Range.between(1,2),
49
            "Receive a connection and SQL string as argument.",
50
            FUNCTION_EXECUTESQL + "({{connection}}, sql)",
51
            new String[]{
52
              "connection - conextion string (optional)",
53
              "sql - sql string"
54
            },
55
            "Object",
56
            false
57
    );
58
  }
59

  
60
  @Override
61
  public boolean allowConstantFolding() {
62
    return false;
63
  }
64

  
65
  @Override
66
  public boolean useArgumentsInsteadObjects() {
67
    return false;
68
  }
69

  
70
  @Override
71
  public Object call(Interpreter interpreter, Object[] args) throws Exception {
72
      String connectionName;
73
      String sql;
74
      JDBCServerExplorer explorer;
75
      if (args.length==1) {
76
          sql = this.getStr(args, 0);
77
          FeatureStore store = (FeatureStore) interpreter.getSymbolTable().function(DataManager.FUNCTION_CURRENT_STORE).call(interpreter,(Object[]) null);
78
          explorer = (JDBCServerExplorer) store.getExplorer();
79
      } else {
80
        connectionName = this.getStr(args, 0);
81
        sql = this.getStr(args, 1);
82
        if (this.getObject(args, 0) instanceof JDBCServerExplorer) {
83
            explorer = (JDBCServerExplorer) this.getObject(args, 0);
84
        } else if (this.getObject(args, 0) instanceof FeatureStore) {
85
            explorer = (JDBCServerExplorer) ((FeatureStore) this.getObject(args, 0)).getExplorer();
86
        } else {
87
            DataManager dalManager = DALLocator.getManager();
88
            DataServerExplorerPoolEntry poolEntry = dalManager.getDataServerExplorerPool().get(connectionName);
89
            DataServerExplorerParameters explorerParameters = poolEntry.getExplorerParameters();
90
            explorer = (JDBCServerExplorer) dalManager.openServerExplorer(explorerParameters.getProviderName(), explorerParameters);
91
        }
92
      }
93
      Object result = explorer.execute(sql);
94
      return result;
95
      
96
  }
97

  
98
}
tags/org.gvsig.desktop-2.0.343/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/impl/expressionevaluator/JDBCSymbolTableFactory.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2020 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.store.jdbc2.impl.expressionevaluator;
25

  
26
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
27
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
28
import org.gvsig.expressionevaluator.SymbolTable;
29
import org.gvsig.expressionevaluator.spi.AbstractSymbolTableFactory;
30

  
31
/**
32
 *
33
 * @author jjdelcerro
34
 */
35
public class JDBCSymbolTableFactory extends AbstractSymbolTableFactory {
36

  
37
    private SymbolTable symbolTable;
38
    public static final String SYMBOLTABLE_NAME = "JDBC";
39
    public static final String GROUP_JDBC = "Data access";
40
    
41
    public JDBCSymbolTableFactory() {
42
        super(SYMBOLTABLE_NAME, true);
43
    }
44
    
45
    @Override
46
    public SymbolTable create(Object... args) {
47
        if( this.symbolTable==null ) {
48
            this.symbolTable = new JDBCSymbolTable();
49
        }
50
        return this.symbolTable;
51
    }
52
    
53
    public static final void selfRegister() {
54
        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
55
        
56
        manager.registerSymbolTable(new JDBCSymbolTableFactory());
57
    }
58
}
tags/org.gvsig.desktop-2.0.343/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/JDBCHelper.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2020 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.store.jdbc2;
25

  
26
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
27
import java.sql.Connection;
28
import java.sql.ResultSet;
29
import java.util.List;
30
import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType;
31
import org.gvsig.fmap.dal.SQLBuilder;
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.fmap.dal.exception.InitializeException;
34
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
35
import org.gvsig.fmap.dal.feature.FeatureQueryOrder;
36
import org.gvsig.fmap.dal.feature.FeatureType;
37
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
38
import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
39
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
40
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
41
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
42
import org.gvsig.fmap.dal.spi.DataTransactionServices;
43
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters;
44
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters;
45
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
46
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
47
import org.gvsig.fmap.dal.store.jdbc2.ResulSetControler.ResultSetEntry;
48
import org.gvsig.fmap.geom.Geometry;
49
import org.gvsig.fmap.geom.GeometryManager;
50
import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolver;
51
import org.gvsig.tools.evaluator.Evaluator;
52

  
53
public interface JDBCHelper extends AutoCloseable {
54

  
55
    /**
56
     * Return the name of the driver.
57
     * 
58
     * By default rerturn "JDBC".
59
     * 
60
     * @return 
61
     */
62
    public String getProviderName();
63
    
64
    /**
65
     * Indica como deben ser guardadas las geometrias en la BBDD. Pueden
66
     * guardarse en WKT, WKB o EWKB.
67
     *
68
     * @return
69
     */
70
    public GeometrySupportType getGeometrySupportType();
71

  
72
    /**
73
     * Devuelve un SQLBuilder adaptado al proveedor. Por ejemplo, uno especifico
74
     * para PostgreSQL, MySQL, Oracle, MSSQLServer...
75
     *
76
     * @return
77
     */
78
    public JDBCSQLBuilderBase createSQLBuilder();
79

  
80
    /**
81
     * Devuelve las comillas que han de usaese para los identificadores.
82
     *
83
     * @return
84
     */
85
    public String getQuoteForIdentifiers();
86

  
87
    /**
88
     * Devuelve las comillas que han de usaese en las constantes de cadena.
89
     *
90
     * @return
91
     */
92
    public String getQuoteForStrings();
93
    
94
    public FeatureType getProviderFeatureType();
95
    
96
    /**
97
     * @param providerFeatureType the providerFeatureType to set
98
     */
99
    public void setProviderFeatureType(FeatureType providerFeatureType);
100

  
101
    /**
102
     * Indica si la BBDD soporta valores automaticos, tipo serial.
103
     *
104
     * @return
105
     */
106
    public boolean allowAutomaticValues();
107

  
108
    /**
109
     * Indica si la BBDD soporta el uso de OFFSET en la sentencia select.
110
     *
111
     * @return
112
     */
113
    public boolean supportOffsetInSelect();
114

  
115
    /**
116
     * Indica si se especifico un subquery al abrir el proveedor.
117
     *
118
     * @return
119
     */
120
    public boolean useSubquery();
121

  
122
    /**
123
     * Indica si la BBDD tiene soporte espacial.
124
     *
125
     * @return
126
     */
127
    public boolean hasSpatialFunctions();
128

  
129
    public boolean supportFilter(FeatureType type, Evaluator evaluator);
130
    
131
    public boolean supportExpression(final FeatureType type, String sql);
132
    
133
    public boolean supportOrder(FeatureType type, FeatureQueryOrder order);
134
    
135
    public boolean allowNestedOperations();
136
    /**
137
     * Indica si podemos escribir el tipo de geometria indicado.
138
     *
139
     * @param geometryType
140
     * @param geometrySubtype
141
     * @return
142
     */
143
    public boolean canWriteGeometry(
144
            int geometryType, 
145
            int geometrySubtype
146
    );
147

  
148
    public Connection getConnection() throws AccessResourceException;
149

  
150
    public Connection getConnectionWritable() throws AccessResourceException;
151

  
152
    public String getConnectionURL();
153
    
154
    public JDBCConnectionParameters getConnectionParameters();
155

  
156
    public void closeConnection(Connection connection);
157

  
158
    public void closeConnectionQuietly(Connection connection);
159

  
160
    public GeometryManager getGeometryManager();
161

  
162
    public ResulSetControler getResulSetControler();
163

  
164
    public String getSourceId();
165

  
166
    public ResourceProvider getResource();
167

  
168
    public void dispose();
169

  
170
    public void fetchFeature(
171
            FeatureProvider feature, 
172
            ResultSet rs,
173
            FeatureAttributeDescriptor[] columns,
174
            String[] extraValueNames
175
    ) throws DataException;
176
    
177
    public void fetchFeature(
178
            FeatureProvider feature, 
179
            ResultSetEntry rs
180
    ) throws DataException;
181

  
182
    public Geometry getGeometryFromColumn(
183
            ResultSet rs, 
184
            int index
185
    ) throws DataException;
186

  
187
    public Geometry getGeometryFromColumn(
188
            ResultSetEntry rs, 
189
            int index
190
    ) throws DataException;
191

  
192
    public OperationsFactory getOperations();
193

  
194
    public FeatureProvider createFeature(
195
            FeatureType featureType
196
    ) throws DataException;
197

  
198
    public JDBCStoreProvider createProvider(
199
            JDBCStoreParameters parameters,
200
            DataStoreProviderServices providerServices
201
    ) throws InitializeException;
202

  
203
    public JDBCServerExplorer createServerExplorer(
204
            JDBCServerExplorerParameters parameters, 
205
            DataServerExplorerProviderServices providerServices
206
    ) throws InitializeException;
207

  
208
    public SRSSolver getSRSSolver();
209
    
210
    public JDBCNewStoreParameters createNewStoreParameters();
211

  
212
    public JDBCStoreParameters createOpenStoreParameters();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff