svn-gvsig-desktop / trunk / org.gvsig.desktop / 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 @ 43020
History | View | Annotate | Download (4.04 KB)
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 |
} |