Revision 43358
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/spi/JDBCHelperBase.java | ||
---|---|---|
202 | 202 |
return null; |
203 | 203 |
} |
204 | 204 |
|
205 |
@Override |
|
205 | 206 |
public JDBCConnectionParameters getConnectionParameters() { |
206 | 207 |
return connectionParameters; |
207 | 208 |
} |
... | ... | |
253 | 254 |
|
254 | 255 |
@Override |
255 | 256 |
public void fetchFeature(FeatureProvider feature, ResultSetEntry rs) throws DataException { |
256 |
fetchFeature(feature, rs.get()); |
|
257 |
fetchFeature(feature, rs.get(), rs.getColumns());
|
|
257 | 258 |
} |
258 | 259 |
|
259 | 260 |
@Override |
260 |
public void fetchFeature(FeatureProvider feature, ResultSet rs) throws DataException { |
|
261 |
public void fetchFeature(FeatureProvider feature, ResultSet rs, FeatureAttributeDescriptor[] columns) throws DataException {
|
|
261 | 262 |
try { |
262 |
int index; |
|
263 | 263 |
Object value; |
264 |
for (FeatureAttributeDescriptor attr : feature.getType()) {
|
|
265 |
index = attr.getIndex();
|
|
266 |
switch (attr.getType()) {
|
|
264 |
for (int index = 0; index < columns.length; index++) {
|
|
265 |
FeatureAttributeDescriptor column = columns[index];
|
|
266 |
switch (column.getType()) {
|
|
267 | 267 |
case DataTypes.GEOMETRY: |
268 | 268 |
value = this.getGeometryFromColumn(rs, index + 1); |
269 | 269 |
break; |
270 | 270 |
default: |
271 | 271 |
value = rs.getObject(index + 1); |
272 | 272 |
} |
273 |
feature.set(index, value);
|
|
273 |
feature.set(column.getIndex(), value);
|
|
274 | 274 |
} |
275 | 275 |
} catch (Exception ex) { |
276 | 276 |
throw new JDBCCantFetchValueException(ex); |
... | ... | |
287 | 287 |
try { |
288 | 288 |
Object value; |
289 | 289 |
switch (this.getGeometrySupportType()) { |
290 |
case NATIVE: |
|
290 | 291 |
case WKB: |
291 | 292 |
value = rs.getBytes(index); |
292 | 293 |
if (value == null) { |
... | ... | |
395 | 396 |
return new JDBCStoreParameters(); |
396 | 397 |
} |
397 | 398 |
|
399 |
@Override |
|
398 | 400 |
public JDBCServerExplorerParameters createServerExplorerParameters() { |
399 | 401 |
return new JDBCServerExplorerParameters(); |
400 | 402 |
} |
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/spi/operations/ResultSetForSetProviderOperation.java | ||
---|---|---|
3 | 3 |
import java.sql.Connection; |
4 | 4 |
import java.util.ArrayList; |
5 | 5 |
import java.util.List; |
6 |
import org.apache.commons.lang3.ArrayUtils; |
|
6 | 7 |
import org.apache.commons.lang3.StringUtils; |
7 | 8 |
import org.gvsig.fmap.dal.ExpressionBuilder.Config; |
8 | 9 |
import org.gvsig.fmap.dal.exception.DataException; |
... | ... | |
84 | 85 |
long offset, |
85 | 86 |
int fetchSize |
86 | 87 |
) throws DataException { |
88 |
List<FeatureAttributeDescriptor> columns = new ArrayList<>(); |
|
87 | 89 |
|
88 | 90 |
double tolerance = -1 ; //query.getScale(); |
89 | 91 |
JDBCSQLBuilderBase sqlbuilder = createSQLBuilder(); |
... | ... | |
96 | 98 |
// Ordenamos siempre por las claves primarias para garantizar |
97 | 99 |
// un orden predecible. Ademas se precisa indicar un orden para |
98 | 100 |
// usar OFFSET. |
99 |
sqlbuilder.select().order_by().column(sqlbuilder.identifier(attrName)); |
|
101 |
sqlbuilder.select().order_by().column(sqlbuilder.identifier(attrName)).ascending();
|
|
100 | 102 |
} |
103 |
String[] constantsAttributeNames = null; |
|
104 |
if(query !=null && query.hasConstantsAttributeNames() ) { |
|
105 |
constantsAttributeNames = query.getConstantsAttributeNames(); |
|
106 |
} |
|
101 | 107 |
for(FeatureAttributeDescriptor attr : setType ) { |
108 |
if( ArrayUtils.contains(constantsAttributeNames, attr.getName()) ) { |
|
109 |
continue; |
|
110 |
} |
|
102 | 111 |
if( attr.isPrimaryKey() ) { |
103 | 112 |
primaryKeys.remove(attr.getName()); |
104 | 113 |
} |
... | ... | |
113 | 122 |
) |
114 | 123 |
).as_geometry(); |
115 | 124 |
} |
125 |
columns.add(attr); |
|
116 | 126 |
} else { |
117 | 127 |
sqlbuilder.select().column().name(attr.getName()); |
128 |
columns.add(attr); |
|
118 | 129 |
} |
119 | 130 |
} |
120 | 131 |
for(String attrName : primaryKeys ) { |
121 | 132 |
sqlbuilder.select().column().name(attrName); |
133 |
columns.add(setType.getAttributeDescriptor(attrName)); |
|
122 | 134 |
} |
123 | 135 |
|
124 | 136 |
if( StringUtils.isEmpty(subquery) ) { |
... | ... | |
170 | 182 |
|
171 | 183 |
String sql = sqlbuilder.toString(); |
172 | 184 |
ResultSetEntry resultSetEntry = this.helper.getResulSetControler().create( |
173 |
sql, fetchSize |
|
185 |
sql, fetchSize, columns.toArray(new FeatureAttributeDescriptor[columns.size()])
|
|
174 | 186 |
); |
175 | 187 |
return resultSetEntry; |
176 | 188 |
} |
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/spi/operations/FetchFeatureProviderByReferenceOperation.java | ||
---|---|---|
5 | 5 |
import java.sql.PreparedStatement; |
6 | 6 |
import java.sql.ResultSet; |
7 | 7 |
import java.sql.SQLException; |
8 |
import java.util.ArrayList; |
|
9 |
import java.util.List; |
|
8 | 10 |
import org.gvsig.fmap.dal.exception.DataException; |
9 | 11 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
10 | 12 |
import org.gvsig.fmap.dal.feature.FeatureType; |
... | ... | |
62 | 64 |
String schema, |
63 | 65 |
String table |
64 | 66 |
) throws DataException { |
67 |
List<FeatureAttributeDescriptor> columns = new ArrayList<>(); |
|
65 | 68 |
|
66 | 69 |
// FeatureAttributeDescriptor[] primaryKey = storeType.getPrimaryKey(); |
67 | 70 |
String[] primaryKeys = reference.getKeyNames(); |
... | ... | |
71 | 74 |
for (FeatureAttributeDescriptor attr : featureType) { |
72 | 75 |
if( attr.getType()==DataTypes.GEOMETRY ) { |
73 | 76 |
sqlbuilder.select().column().name(attr.getName()).as_geometry(); |
77 |
columns.add(attr); |
|
74 | 78 |
} else { |
75 | 79 |
sqlbuilder.select().column().name(attr.getName()); |
80 |
columns.add(attr); |
|
76 | 81 |
} |
77 | 82 |
} |
78 | 83 |
sqlbuilder.select().from().table().database(database).schema(schema).name(table); |
79 | 84 |
for (String name : primaryKeys ) { |
80 | 85 |
if( !sqlbuilder.select().has_column(name) ) { |
81 | 86 |
sqlbuilder.select().column().name(name); |
87 |
columns.add(featureType.getAttributeDescriptor(name)); |
|
82 | 88 |
} |
83 | 89 |
Object value = reference.getKeyValue(name); |
84 | 90 |
if( value == null ) { |
... | ... | |
108 | 114 |
return null; |
109 | 115 |
} |
110 | 116 |
FeatureProvider data = this.helper.createFeature(featureType); |
111 |
this.helper.fetchFeature(data, rs);
|
|
117 |
this.helper.fetchFeature(data, rs, columns.toArray(new FeatureAttributeDescriptor[columns.size()]));
|
|
112 | 118 |
return data; |
113 | 119 |
|
114 | 120 |
} catch (SQLException ex) { |
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/ResulSetControler.java | ||
---|---|---|
5 | 5 |
import java.sql.SQLException; |
6 | 6 |
import java.util.List; |
7 | 7 |
import org.gvsig.fmap.dal.exception.DataException; |
8 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
8 | 9 |
|
9 | 10 |
|
10 | 11 |
public interface ResulSetControler extends AutoCloseable { |
... | ... | |
14 | 15 |
public int getID(); |
15 | 16 |
public boolean isZombie(); |
16 | 17 |
public String getSQL(); |
18 |
public FeatureAttributeDescriptor[] getColumns(); |
|
17 | 19 |
public Object getObject(int columnIndex) throws SQLException; |
18 | 20 |
public byte[] getBytes(int columnIndex) throws SQLException; |
19 | 21 |
public boolean next() throws SQLException; |
... | ... | |
23 | 25 |
|
24 | 26 |
public long getTimeToZombie(); |
25 | 27 |
|
26 |
public ResultSetEntry create(String sql, int fetchSize) throws DataException; |
|
28 |
public ResultSetEntry create(String sql, int fetchSize, FeatureAttributeDescriptor[] columns ) throws DataException;
|
|
27 | 29 |
|
28 |
public ResultSetEntry create(String sql, List<Object> values, int fetchSize) throws DataException; |
|
30 |
public ResultSetEntry create(String sql, List<Object> values, int fetchSize, FeatureAttributeDescriptor[] columns ) throws DataException;
|
|
29 | 31 |
|
30 | 32 |
public int getOpenCount(); |
31 | 33 |
|
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/JDBCSetProvider.java | ||
---|---|---|
286 | 286 |
return isEmpty; |
287 | 287 |
} |
288 | 288 |
|
289 |
|
|
290 |
protected JDBCIterator createFastIterator(long index) throws DataException { |
|
291 |
return createFastIterator(index, 0); |
|
292 |
} |
|
293 |
|
|
289 | 294 |
@Override |
290 |
protected JDBCIterator createFastIterator(long index) throws DataException { |
|
295 |
protected JDBCIterator createFastIterator(long index, long elements) throws DataException {
|
|
291 | 296 |
if( BooleanUtils.isTrue(isEmpty) ) { |
292 | 297 |
return new EmptyJDBCIterator(this.getJDBCStore()); |
293 | 298 |
} |
... | ... | |
307 | 312 |
this.getQuery(), |
308 | 313 |
storeType, |
309 | 314 |
this.getFeatureType(), |
310 |
-1,
|
|
315 |
elements,
|
|
311 | 316 |
index, |
312 | 317 |
this.getDefaultFetchSize() |
313 | 318 |
); |
... | ... | |
325 | 330 |
|
326 | 331 |
@Override |
327 | 332 |
protected JDBCIterator createIterator(long index) throws DataException { |
333 |
return createIterator(index, -1); |
|
334 |
} |
|
335 |
|
|
336 |
@Override |
|
337 |
protected JDBCIterator createIterator(long index, long elements) throws DataException { |
|
328 | 338 |
if( BooleanUtils.isTrue(isEmpty) ) { |
329 | 339 |
return new EmptyJDBCIterator(this.getJDBCStore()); |
330 | 340 |
} |
... | ... | |
343 | 353 |
this.getQuery(), |
344 | 354 |
storeType, |
345 | 355 |
this.getFeatureType(), |
346 |
-1,
|
|
356 |
elements,
|
|
347 | 357 |
index, |
348 | 358 |
this.getDefaultFetchSize() |
349 | 359 |
); |
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/ResulSetControlerBase.java | ||
---|---|---|
10 | 10 |
import java.util.List; |
11 | 11 |
import java.util.Map; |
12 | 12 |
import org.gvsig.fmap.dal.exception.DataException; |
13 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
13 | 14 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCExecutePreparedSQLException; |
14 | 15 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
15 | 16 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
... | ... | |
27 | 28 |
private final int id; |
28 | 29 |
private long lastUse = 0; |
29 | 30 |
private String sql; |
31 |
private final FeatureAttributeDescriptor[] columns; |
|
30 | 32 |
|
31 |
public ResultSetEntryBase(ResultSet resulSet) { |
|
32 |
this(resulSet,null); |
|
33 |
public ResultSetEntryBase(ResultSet resulSet, FeatureAttributeDescriptor[] columns) {
|
|
34 |
this(resulSet,null, columns);
|
|
33 | 35 |
} |
34 | 36 |
|
35 |
public ResultSetEntryBase(ResultSet resulSet, String sql) { |
|
37 |
public ResultSetEntryBase(ResultSet resulSet, String sql, FeatureAttributeDescriptor[] columns) {
|
|
36 | 38 |
this.resultSet = resulSet; |
37 | 39 |
this.id = nextid++; |
38 | 40 |
this.sql = sql; |
41 |
this.columns = columns; |
|
39 | 42 |
used(); |
40 | 43 |
resulSets.put(this.getID(), this); |
41 | 44 |
} |
... | ... | |
68 | 71 |
return this.sql; |
69 | 72 |
} |
70 | 73 |
|
74 |
public FeatureAttributeDescriptor[] getColumns() { |
|
75 |
return this.columns; |
|
76 |
} |
|
77 |
|
|
71 | 78 |
@Override |
72 | 79 |
public Object getObject(int columnIndex) throws SQLException { |
73 | 80 |
used(); |
... | ... | |
149 | 156 |
} |
150 | 157 |
|
151 | 158 |
@Override |
152 |
public ResultSetEntryBase create(String sql, int fetchSize) throws DataException { |
|
153 |
return create(sql, null, fetchSize); |
|
159 |
public ResultSetEntryBase create( |
|
160 |
String sql, |
|
161 |
int fetchSize, |
|
162 |
FeatureAttributeDescriptor[] columns) throws DataException { |
|
163 |
return create(sql, null, fetchSize, columns); |
|
154 | 164 |
} |
155 | 165 |
|
156 | 166 |
@Override |
157 | 167 |
public synchronized ResultSetEntryBase create( |
158 | 168 |
final String sql, |
159 | 169 |
final List values, |
160 |
final int fetchSize) throws DataException { |
|
170 |
final int fetchSize, |
|
171 |
FeatureAttributeDescriptor[] columns) throws DataException { |
|
161 | 172 |
|
162 | 173 |
this.pack(); |
163 | 174 |
ResultSet rs = null; |
... | ... | |
171 | 182 |
JDBCUtils.setObjects(st, values, helper.getGeometrySupportType()); |
172 | 183 |
|
173 | 184 |
if (fetchSize > 0) { |
185 |
// See parameter "SelectMethod" of SQL Server Connection Properties |
|
186 |
// https://docs.oracle.com/cd/E13157_01/wlevs/docs30/jdbc_drivers/mssqlserver.html |
|
174 | 187 |
st.setFetchSize(fetchSize); |
175 | 188 |
} |
176 | 189 |
rs = JDBCUtils.executeQuery(st, sql); |
... | ... | |
184 | 197 |
JDBCUtils.closeQuietly(conn); |
185 | 198 |
throw new JDBCExecutePreparedSQLException(sql, values, e); |
186 | 199 |
} |
187 |
ResultSetEntryBase rsentry = new ResultSetEntryBase(rs, sql); |
|
200 |
ResultSetEntryBase rsentry = new ResultSetEntryBase(rs, sql, columns);
|
|
188 | 201 |
return rsentry; |
189 | 202 |
} |
190 | 203 |
|
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/JDBCHelper.java | ||
---|---|---|
7 | 7 |
import org.gvsig.fmap.dal.exception.DataException; |
8 | 8 |
import org.gvsig.fmap.dal.exception.InitializeException; |
9 | 9 |
import org.gvsig.fmap.dal.ExpressionBuilder.GeometrySupportType; |
10 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
10 | 11 |
import org.gvsig.fmap.dal.feature.FeatureType; |
11 | 12 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
12 | 13 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
... | ... | |
124 | 125 |
|
125 | 126 |
public void fetchFeature( |
126 | 127 |
FeatureProvider feature, |
127 |
ResultSet rs |
|
128 |
ResultSet rs, |
|
129 |
FeatureAttributeDescriptor[] columns |
|
128 | 130 |
) throws DataException; |
129 |
|
|
131 |
|
|
130 | 132 |
public void fetchFeature( |
131 | 133 |
FeatureProvider feature, |
132 | 134 |
ResultSetEntry rs |
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/JDBCUtils.java | ||
---|---|---|
111 | 111 |
value = ((Geometry) value).convertToWKT(); |
112 | 112 |
st.setObject(columnIndex, value); |
113 | 113 |
break; |
114 |
case NATIVE: |
|
114 | 115 |
case WKB: |
115 | 116 |
bytes = ((Geometry) value).convertToWKB(); |
116 | 117 |
st.setBytes(columnIndex, bytes); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/featuretable/FeatureSelectionModel.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
import java.awt.event.ActionEvent; |
31 | 31 |
import java.awt.event.ActionListener; |
32 |
import java.util.logging.Level; |
|
32 | 33 |
import javax.swing.ListSelectionModel; |
33 | 34 |
import javax.swing.event.EventListenerList; |
34 | 35 |
import javax.swing.event.ListSelectionEvent; |
... | ... | |
436 | 437 |
try { |
437 | 438 |
FeatureSelection selection = getFeatureSelection(); |
438 | 439 |
if (!selection.isEmpty()) { |
440 |
FeatureStore store = getFeatureStore(); |
|
439 | 441 |
FeatureQuery query = this.featureTableModel.getFeatureQuery(); |
440 |
if(query!= null){
|
|
441 |
fs = getFeatureStore().getFeatureSet(query);
|
|
442 |
if(query== null){
|
|
443 |
query = store.createFeatureQuery();
|
|
442 | 444 |
}else{ |
443 |
fs = getFeatureStore().getFeatureSet(); |
|
445 |
try { |
|
446 |
query = (FeatureQuery) query.clone(); |
|
447 |
} catch (CloneNotSupportedException ex) { |
|
448 |
} |
|
444 | 449 |
} |
450 |
query.addEssentialAttributeNames(store); |
|
451 |
fs = store.getFeatureSet(query); |
|
445 | 452 |
diter = fs.fastIterator(); |
446 |
Feature feat = null;
|
|
453 |
Feature feat; |
|
447 | 454 |
while (diter.hasNext()) { |
448 | 455 |
ind++; |
449 | 456 |
feat = (Feature) diter.next(); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/ExpressionBuilder.java | ||
---|---|---|
10 | 10 |
public enum GeometrySupportType { |
11 | 11 |
WKT, |
12 | 12 |
WKB, |
13 |
EWKB |
|
13 |
EWKB, |
|
14 |
NATIVE |
|
14 | 15 |
} |
15 | 16 |
|
16 | 17 |
public enum ParameterType { |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureQuery.java | ||
---|---|---|
87 | 87 |
*/ |
88 | 88 |
void addAttributeName(String attributeName); |
89 | 89 |
|
90 |
/** |
|
91 |
* Return true if has set attribute names |
|
92 |
* |
|
93 |
* @return true if has attribute names, otherwise false |
|
94 |
*/ |
|
95 |
boolean hasAttributeNames(); |
|
90 |
public void addPrimaryKeyAttributeNames(FeatureStore store); |
|
96 | 91 |
|
97 |
/** |
|
98 |
* Remove all the attribute names specifieds. |
|
99 |
*/ |
|
100 |
void clearAttributeNames(); |
|
92 |
public void addEssentialAttributeNames(FeatureStore store); |
|
101 | 93 |
|
102 |
/** |
|
94 |
/** |
|
95 |
* Return true if has set attribute names |
|
96 |
* |
|
97 |
* @return true if has attribute names, otherwise false |
|
98 |
*/ |
|
99 |
boolean hasAttributeNames(); |
|
100 |
|
|
101 |
/** |
|
102 |
* Remove all the attribute names specifieds. |
|
103 |
*/ |
|
104 |
void clearAttributeNames(); |
|
105 |
|
|
106 |
/** |
|
103 | 107 |
* Returns the names of the attributes that are constants in each {@link Feature}. |
104 | 108 |
* These attributes will not be charged. |
105 | 109 |
* |
... | ... | |
224 | 228 |
boolean hasOrder(); |
225 | 229 |
|
226 | 230 |
/** |
231 |
* @return |
|
227 | 232 |
* @deprecated to be removed in gvSIG 2.0 |
228 | 233 |
* @see #clone() |
229 | 234 |
*/ |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureType.java | ||
---|---|---|
267 | 267 |
|
268 | 268 |
/** |
269 | 269 |
* Returns an Array of the FeatureAttributeDescriptor that compounds the |
270 |
* primary key |
|
270 |
* primary key. If not have primary keys return a empty array.
|
|
271 | 271 |
* |
272 | 272 |
* @return |
273 | 273 |
*/ |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureSet.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.dal.feature; |
25 | 25 |
|
26 |
import java.util.Iterator; |
|
27 | 26 |
import java.util.List; |
28 | 27 |
|
29 | 28 |
import org.gvsig.fmap.dal.DataSet; |
... | ... | |
128 | 127 |
*/ |
129 | 128 |
DisposableIterator iterator(long index) throws DataException; |
130 | 129 |
|
130 |
DisposableIterator iterator(long index, long elements) throws DataException; |
|
131 |
|
|
131 | 132 |
/** |
132 | 133 |
* Returns an iterator over the elements in this collection, in the order |
133 | 134 |
* (if any) defined when the collection was obtained. |
... | ... | |
141 | 142 |
* sequence). |
142 | 143 |
* |
143 | 144 |
* @deprecated use fastiterator. In next versions the signature of this |
144 |
* method will be changed to "Iterator<Feature> iterator()".
|
|
145 |
* method will be changed to "Iterator<Feature> iterator()".
|
|
145 | 146 |
*/ |
146 | 147 |
DisposableIterator iterator(); |
147 | 148 |
|
... | ... | |
215 | 216 |
*/ |
216 | 217 |
public DisposableIterator fastIterator(long index) throws DataException; |
217 | 218 |
|
219 |
public DisposableIterator fastIterator(long index, long elemets) throws DataException; |
|
220 |
|
|
218 | 221 |
/** |
219 | 222 |
* Indicates whether this FeatureSet contains zero features. |
220 | 223 |
* |
... | ... | |
320 | 323 |
* @exception BaseException |
321 | 324 |
* if there is an error while performing the visit |
322 | 325 |
*/ |
326 |
@Override |
|
323 | 327 |
void accept(Visitor visitor, long firstValueIndex) throws BaseException; |
328 |
|
|
329 |
void accept(Visitor visitor, long firstValueIndex, long elements) throws BaseException; |
|
324 | 330 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureStoreProviderFactory.java | ||
---|---|---|
96 | 96 |
* @return |
97 | 97 |
*/ |
98 | 98 |
public int getMaxAttributeNameSize(); |
99 |
|
|
100 |
public boolean supportNumericOID(); |
|
99 | 101 |
|
100 | 102 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureStore.java | ||
---|---|---|
727 | 727 |
/** |
728 | 728 |
* Returns the current {@link FeatureSelection}. |
729 | 729 |
* Create a empty selection if not exits. |
730 |
* |
|
731 |
* Manage of the selection can be slow on some data sources. |
|
732 |
* Use with care. |
|
733 |
* In data sources that do not support position access to records, |
|
734 |
* it may be slow to retrieve items from the selection. In some data |
|
735 |
* sources it may be necessary to access to this to retrieve each |
|
736 |
* item in the selection. |
|
730 | 737 |
* |
731 | 738 |
* @return |
732 | 739 |
* current {@link FeatureSelection}. |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/AbstractFeatureStoreProviderFactory.java | ||
---|---|---|
90 | 90 |
public int getMaxAttributeNameSize() { |
91 | 91 |
return -1; |
92 | 92 |
} |
93 |
|
|
94 |
@Override |
|
95 |
public boolean supportNumericOID() { |
|
96 |
return false; |
|
97 |
} |
|
98 |
|
|
99 |
|
|
93 | 100 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/ExpressionBuilderBase.java | ||
---|---|---|
363 | 363 |
switch (config.getGeometryTypeSupport()) { |
364 | 364 |
case EWKB: |
365 | 365 |
return bytearray(((Geometry) this.value).convertToEWKB()); |
366 |
case NATIVE: |
|
366 | 367 |
case WKB: |
367 | 368 |
return bytearray(((Geometry) this.value).convertToWKB()); |
368 | 369 |
case WKT: |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/AbstractFeatureSetProvider.java | ||
---|---|---|
89 | 89 |
return featureType; |
90 | 90 |
} |
91 | 91 |
|
92 |
@Override |
|
92 | 93 |
public final DisposableIterator fastIterator() throws DataException { |
93 | 94 |
return fastIterator(0); |
94 | 95 |
} |
... | ... | |
98 | 99 |
return createFastIterator(index); |
99 | 100 |
} |
100 | 101 |
|
102 |
@Override |
|
103 |
public final DisposableIterator fastIterator(long index, long elements) throws DataException { |
|
104 |
return createFastIterator(index, elements); |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
101 | 108 |
public final DisposableIterator iterator() throws DataException { |
102 | 109 |
return iterator(0); |
103 | 110 |
} |
... | ... | |
106 | 113 |
return createIterator(index); |
107 | 114 |
} |
108 | 115 |
|
116 |
@Override |
|
117 |
public final DisposableIterator iterator(long index, long elements) throws DataException { |
|
118 |
return createIterator(index, elements); |
|
119 |
} |
|
120 |
|
|
109 | 121 |
/** |
110 | 122 |
* Creates a new {@link Iterator}, begginning at the specified data index. |
111 | 123 |
* |
... | ... | |
119 | 131 |
protected abstract AbstractFeatureProviderIterator createIterator(long index) |
120 | 132 |
throws DataException; |
121 | 133 |
|
122 |
/** |
|
134 |
protected AbstractFeatureProviderIterator createIterator(long index, long elements) |
|
135 |
throws DataException { |
|
136 |
return createIterator(index); |
|
137 |
} |
|
138 |
|
|
139 |
/** |
|
123 | 140 |
* Creates a new fast {@link Iterator}, begginning at the specified data |
124 | 141 |
* index. By fast this means the object instances of data ( |
125 | 142 |
* {@link FeatureProvider}) may be reused between the |
... | ... | |
134 | 151 |
*/ |
135 | 152 |
protected abstract AbstractFeatureProviderIterator createFastIterator( |
136 | 153 |
long index) throws DataException; |
154 |
|
|
155 |
protected AbstractFeatureProviderIterator createFastIterator( |
|
156 |
long index, long elements) throws DataException { |
|
157 |
return createFastIterator(index); |
|
158 |
} |
|
137 | 159 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/FeatureSetProvider.java | ||
---|---|---|
90 | 90 |
* @param index |
91 | 91 |
* index of first element to be returned from the iterator (by a |
92 | 92 |
* call to the <tt>next</tt> method). |
93 |
* @param elements |
|
93 | 94 |
* @return an iterator of the elements in this collection (in proper |
94 | 95 |
* sequence). |
95 | 96 |
* |
... | ... | |
98 | 99 |
* |
99 | 100 |
* @deprecated use {@link #fastIterator()} instead |
100 | 101 |
*/ |
101 |
DisposableIterator iterator(long index) throws DataException; |
|
102 |
DisposableIterator iterator(long index, long elements) throws DataException;
|
|
102 | 103 |
|
103 | 104 |
/** |
104 | 105 |
* Returns an iterator over the elements in this set, in the order |
... | ... | |
119 | 120 |
* Returns an iterator over the elements in this set, in the order |
120 | 121 |
* (if any) defined when the collection was obtained. |
121 | 122 |
* |
123 |
* @param elements |
|
122 | 124 |
* @see #fastIterator() |
123 | 125 |
* @see #fastIterator(long) |
124 | 126 |
* |
... | ... | |
131 | 133 |
* @throws DataException |
132 | 134 |
* if there is an error getting the iterator |
133 | 135 |
*/ |
134 |
DisposableIterator fastIterator(long index) throws DataException; |
|
136 |
DisposableIterator fastIterator(long index, long elements) throws DataException;
|
|
135 | 137 |
|
136 | 138 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/featureset/AbstractFeatureSet.java | ||
---|---|---|
36 | 36 |
import org.gvsig.tools.visitor.VisitCanceledException; |
37 | 37 |
import org.gvsig.tools.visitor.Visitor; |
38 | 38 |
import org.gvsig.tools.visitor.impl.AbstractIndexedVisitable; |
39 |
import org.slf4j.Logger; |
|
40 |
import org.slf4j.LoggerFactory; |
|
39 | 41 |
|
40 | 42 |
|
41 | 43 |
public abstract class AbstractFeatureSet |
42 | 44 |
extends AbstractIndexedVisitable |
43 | 45 |
implements FeatureSet { |
44 | 46 |
|
47 |
protected static final Logger LOG = LoggerFactory.getLogger(AbstractFeatureSet.class); |
|
48 |
|
|
45 | 49 |
public abstract FeatureStore getFeatureStore(); |
46 | 50 |
|
47 |
|
|
48 | 51 |
@Override |
52 |
public final void accept(Visitor visitor, long firstValueIndex, long elements) throws BaseException { |
|
53 |
try { |
|
54 |
doAccept(visitor, firstValueIndex, elements); |
|
55 |
} catch (VisitCanceledException ex) { |
|
56 |
// The visit has been cancelled by the visitor, so we finish here. |
|
57 |
LOG.debug( |
|
58 |
"The visit, beggining on position {}, has been cancelled " |
|
59 |
+ "by the visitor: {}", new Long(firstValueIndex), |
|
60 |
visitor); |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
49 | 65 |
protected void doAccept(Visitor visitor, long firstValueIndex) |
50 | 66 |
throws VisitCanceledException, BaseException { |
51 |
DisposableIterator iterator = fastIterator(firstValueIndex); |
|
52 |
if( iterator != null ) { |
|
53 |
try { |
|
54 |
while (iterator.hasNext()) { |
|
55 |
Feature feature = (Feature) iterator.next(); |
|
56 |
visitor.visit(feature); |
|
57 |
} |
|
58 |
} finally { |
|
59 |
DisposeUtils.disposeQuietly(iterator); |
|
67 |
doAccept(visitor, firstValueIndex, 0); |
|
68 |
} |
|
69 |
|
|
70 |
protected void doAccept(Visitor visitor, long firstValueIndex, long elements) |
|
71 |
throws VisitCanceledException, BaseException { |
|
72 |
DisposableIterator iterator = fastIterator(firstValueIndex, elements); |
|
73 |
|
|
74 |
try { |
|
75 |
while (iterator.hasNext()) { |
|
76 |
Feature feature = (Feature) iterator.next(); |
|
77 |
visitor.visit(feature); |
|
60 | 78 |
} |
79 |
} finally { |
|
80 |
iterator.dispose(); |
|
61 | 81 |
} |
62 | 82 |
} |
63 |
|
|
83 |
|
|
64 | 84 |
@Override |
65 | 85 |
public Feature first() { |
66 | 86 |
DisposableIterator it = null; |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/featureset/DefaultFeatureSet.java | ||
---|---|---|
317 | 317 |
return; |
318 | 318 |
} |
319 | 319 |
} |
320 |
|
|
320 |
|
|
321 | 321 |
protected void checkSourceStoreModified() { |
322 | 322 |
if (sourceStoreModified) { |
323 | 323 |
throw new ConcurrentDataModificationException(store == null ? "" |
... | ... | |
325 | 325 |
} |
326 | 326 |
} |
327 | 327 |
|
328 |
@Override |
|
328 | 329 |
public DisposableIterator fastIterator(long index) throws DataException { |
330 |
return fastIterator(index, 0); |
|
331 |
} |
|
332 |
|
|
333 |
@Override |
|
334 |
public DisposableIterator fastIterator(long index, long elements) throws DataException { |
|
329 | 335 |
if (index < 0) { |
330 | 336 |
throw new IndexOutOfBoundsException("The index (" + index |
331 | 337 |
+ ") is less than 0"); |
... | ... | |
334 | 340 |
|
335 | 341 |
switch (mode) { |
336 | 342 |
case DEFAULT: |
337 |
return new FastDefaultIterator(this, index); |
|
343 |
return new FastDefaultIterator(this, index, elements);
|
|
338 | 344 |
|
339 | 345 |
case FILTERED: |
340 | 346 |
return new FastFilteredIterator(this, index); |
... | ... | |
343 | 349 |
if (this.orderedData != null) { |
344 | 350 |
return new FastOrderedIterator(this, index); |
345 | 351 |
} else { |
346 |
return new FastOrderedIterator(this, new FastDefaultIterator( |
|
347 |
this, 0), index); |
|
352 |
return new FastOrderedIterator(this, new FastDefaultIterator(this, 0, elements), index); |
|
348 | 353 |
} |
349 | 354 |
|
350 | 355 |
case ORDERED_FILTERED: |
... | ... | |
382 | 387 |
} |
383 | 388 |
|
384 | 389 |
|
390 |
@Override |
|
385 | 391 |
public DisposableIterator iterator(long index) throws DataException { |
392 |
return iterator(index,0); |
|
393 |
} |
|
394 |
|
|
395 |
@Override |
|
396 |
public DisposableIterator iterator(long index, long elements) throws DataException { |
|
386 | 397 |
if (index < 0) { |
387 | 398 |
throw new IndexOutOfBoundsException("The index (" + index |
388 | 399 |
+ ") is less than 0"); |
... | ... | |
391 | 402 |
|
392 | 403 |
switch (mode) { |
393 | 404 |
case DEFAULT: |
394 |
return new DefaultIterator(this, index); |
|
405 |
return new DefaultIterator(this, index, elements);
|
|
395 | 406 |
|
396 | 407 |
case FILTERED: |
397 | 408 |
return new FilteredIterator(this, index); |
... | ... | |
401 | 412 |
return new OrderedIterator(this, index); |
402 | 413 |
|
403 | 414 |
} else { |
404 |
return new OrderedIterator(this, new DefaultIterator(this, 0), |
|
405 |
index); |
|
415 |
return new OrderedIterator(this, new DefaultIterator(this, 0, elements),index); |
|
406 | 416 |
} |
407 | 417 |
|
408 | 418 |
case ORDERED_FILTERED: |
... | ... | |
515 | 525 |
public FeatureStore getFeatureStore() { |
516 | 526 |
return store; |
517 | 527 |
} |
528 |
|
|
518 | 529 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/featureset/FastDefaultIterator.java | ||
---|---|---|
32 | 32 |
|
33 | 33 |
DefaultFeature myFeature; |
34 | 34 |
|
35 |
public FastDefaultIterator(DefaultFeatureSet featureSet, long index) |
|
35 |
public FastDefaultIterator(DefaultFeatureSet featureSet, long index, long elements)
|
|
36 | 36 |
throws DataException { |
37 | 37 |
super(featureSet); |
38 | 38 |
this.initializeFeature(); |
39 |
if (index > 0) { |
|
39 |
if (index > 0 || elements>0 ) {
|
|
40 | 40 |
if (featureSet.provider.canIterateFromIndex()) { |
41 | 41 |
try { |
42 |
this.iterator = featureSet.provider.fastIterator(index); |
|
42 |
this.iterator = featureSet.provider.fastIterator(index,elements);
|
|
43 | 43 |
} catch (UnsupportedOperationException e) { |
44 | 44 |
this.iterator = featureSet.provider.fastIterator(); |
45 | 45 |
skypto(index); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/featureset/DefaultIterator.java | ||
---|---|---|
45 | 45 |
this.fset = featureSet; |
46 | 46 |
} |
47 | 47 |
|
48 |
public DefaultIterator(DefaultFeatureSet featureSet, long index) |
|
48 |
public DefaultIterator(DefaultFeatureSet featureSet, long index, long elements)
|
|
49 | 49 |
throws DataException { |
50 | 50 |
this.fset = featureSet; |
51 | 51 |
if (index > 0) { |
52 | 52 |
if (featureSet.provider.canIterateFromIndex()) { |
53 | 53 |
try { |
54 |
this.iterator = featureSet.provider.iterator(index); |
|
54 |
this.iterator = featureSet.provider.iterator(index, elements);
|
|
55 | 55 |
} catch (UnsupportedOperationException e) { |
56 | 56 |
this.iterator = featureSet.provider.iterator(); |
57 | 57 |
skypto(index); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureStore.java | ||
---|---|---|
74 | 74 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
75 | 75 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
76 | 76 |
import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
77 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
|
77 | 78 |
import org.gvsig.fmap.dal.feature.FeatureStoreTransforms; |
78 | 79 |
import org.gvsig.fmap.dal.feature.FeatureType; |
79 | 80 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
... | ... | |
123 | 124 |
import org.gvsig.fmap.dal.spi.DataStoreInitializer2; |
124 | 125 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
125 | 126 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
127 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
128 |
import org.gvsig.fmap.geom.GeometryManager; |
|
129 |
import org.gvsig.fmap.geom.SpatialIndex; |
|
126 | 130 |
import org.gvsig.fmap.geom.primitive.Envelope; |
127 | 131 |
import org.gvsig.metadata.MetadataLocator; |
128 | 132 |
import org.gvsig.metadata.MetadataManager; |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureReference.java | ||
---|---|---|
24 | 24 |
package org.gvsig.fmap.dal.feature.impl; |
25 | 25 |
|
26 | 26 |
import java.lang.ref.WeakReference; |
27 |
import java.text.MessageFormat; |
|
28 |
import java.util.ArrayList; |
|
29 | 27 |
import java.util.Arrays; |
30 |
import java.util.Iterator; |
|
31 | 28 |
import java.util.List; |
29 |
import org.apache.commons.lang3.ArrayUtils; |
|
32 | 30 |
|
33 | 31 |
import org.gvsig.fmap.dal.exception.DataException; |
34 | 32 |
import org.gvsig.fmap.dal.feature.Feature; |
... | ... | |
115 | 113 |
} |
116 | 114 |
|
117 | 115 |
private void calculatePK(FeatureProvider fdata) { |
118 |
ArrayList keys = new ArrayList(); |
|
119 |
ArrayList keyNames = new ArrayList(); |
|
120 |
FeatureType type = fdata.getType(); |
|
121 |
Iterator it = type.iterator(); |
|
122 |
while (it.hasNext()) { |
|
123 |
FeatureAttributeDescriptor attr = (FeatureAttributeDescriptor) it |
|
124 |
.next(); |
|
125 |
if (attr.isPrimaryKey()) { |
|
126 |
keys.add(fdata.get(attr.getIndex())); |
|
127 |
keyNames.add(attr.getName()); |
|
128 |
} |
|
129 |
} |
|
130 |
if (keys.size() < 1) { |
|
131 |
pk = null; |
|
132 |
pkNames = null; |
|
133 |
} else { |
|
134 |
pk = keys.toArray(); |
|
135 |
pkNames = (String[]) keyNames.toArray(new String[keyNames.size()]); |
|
136 |
} |
|
137 |
} |
|
116 |
FeatureAttributeDescriptor[] pkattrs = fdata.getType().getPrimaryKey(); |
|
117 |
if( ArrayUtils.isEmpty(pkattrs) ) { |
|
118 |
this.pk = null; |
|
119 |
this.pkNames = null; |
|
120 |
return ; |
|
121 |
} |
|
122 |
this.pk = new Object[pkattrs.length]; |
|
123 |
this.pkNames = new String[pkattrs.length]; |
|
124 |
int n = 0; |
|
125 |
for (FeatureAttributeDescriptor pkattr : pkattrs) { |
|
126 |
this.pk[n] = fdata.get(pkattr.getIndex()); |
|
127 |
this.pkNames[n] = pkattr.getName(); |
|
128 |
n++; |
|
129 |
} |
|
130 |
} |
|
138 | 131 |
|
132 |
@Override |
|
139 | 133 |
public Feature getFeature() throws DataException { |
140 | 134 |
return this.getStore().getFeatureByReference(this); |
141 | 135 |
} |
142 | 136 |
|
137 |
@Override |
|
143 | 138 |
public Feature getFeature(FeatureType featureType) throws DataException { |
144 | 139 |
return this.getStore().getFeatureByReference(this, featureType); |
145 | 140 |
} |
146 | 141 |
|
142 |
@Override |
|
147 | 143 |
public Object getOID() { |
148 | 144 |
return this.oid; |
149 | 145 |
} |
150 | 146 |
|
147 |
@Override |
|
151 | 148 |
public boolean isNewFeature() { |
152 | 149 |
return this.isNewFeature; |
153 | 150 |
} |
154 | 151 |
|
155 | 152 |
|
153 |
@Override |
|
156 | 154 |
public boolean equals(Object obj) { |
157 | 155 |
if (!(obj instanceof DefaultFeatureReference)) { |
158 | 156 |
return false; |
... | ... | |
186 | 184 |
return true; |
187 | 185 |
} |
188 | 186 |
|
187 |
@Override |
|
189 | 188 |
public int hashCode() { |
190 | 189 |
if (this.oid != null) { |
191 | 190 |
return this.oid.hashCode(); |
192 | 191 |
} |
193 | 192 |
if (myHashCode == null) { |
194 |
StringBuffer buff = new StringBuffer();
|
|
193 |
StringBuilder buff = new StringBuilder();
|
|
195 | 194 |
|
196 | 195 |
for (int i = 0; i < this.pk.length; i++) { |
197 | 196 |
buff.append(this.pk[i].hashCode()); |
198 | 197 |
buff.append("##"); |
199 | 198 |
} |
200 |
myHashCode = new Integer(buff.toString().hashCode());
|
|
199 |
myHashCode = buff.toString().hashCode();
|
|
201 | 200 |
} |
202 |
return myHashCode.intValue();
|
|
201 |
return myHashCode; |
|
203 | 202 |
} |
204 | 203 |
|
204 |
@Override |
|
205 | 205 |
public String[] getKeyNames() { |
206 | 206 |
return pkNames; |
207 | 207 |
} |
208 | 208 |
|
209 |
@Override |
|
209 | 210 |
public Object getKeyValue(String name) { |
210 | 211 |
for (int i = 0; i < pkNames.length; i++) { |
211 | 212 |
if (pkNames[i].equalsIgnoreCase(name)) { |
... | ... | |
216 | 217 |
return null; |
217 | 218 |
} |
218 | 219 |
|
220 |
@Override |
|
219 | 221 |
public String getFeatureTypeId() { |
220 | 222 |
return featureTypeId; |
221 | 223 |
} |
222 | 224 |
|
223 | 225 |
// *** Persistence *** |
224 | 226 |
|
227 |
@Override |
|
225 | 228 |
public void loadFromState(PersistentState state) |
226 | 229 |
throws PersistenceException { |
227 | 230 |
this.oid = state.get("oid"); |
... | ... | |
244 | 247 |
} |
245 | 248 |
} |
246 | 249 |
|
250 |
@Override |
|
247 | 251 |
public void saveToState(PersistentState state) throws PersistenceException { |
248 | 252 |
state.set("oid", oid); |
249 | 253 |
state.set("myHashCode", myHashCode); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureQuery.java | ||
---|---|---|
29 | 29 |
import java.util.Map; |
30 | 30 |
import java.util.logging.Level; |
31 | 31 |
import java.util.logging.Logger; |
32 |
import org.apache.commons.lang3.ArrayUtils; |
|
32 | 33 |
import org.gvsig.fmap.dal.DALLocator; |
34 |
import org.gvsig.fmap.dal.DataTypes; |
|
35 |
import org.gvsig.fmap.dal.exception.DataException; |
|
33 | 36 |
import org.gvsig.fmap.dal.exception.InitializeException; |
37 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
34 | 38 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
35 | 39 |
import org.gvsig.fmap.dal.feature.FeatureQueryOrder; |
40 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
36 | 41 |
import org.gvsig.fmap.dal.feature.FeatureType; |
37 | 42 |
import org.gvsig.tools.ToolsLocator; |
38 | 43 |
import org.gvsig.tools.dynobject.DynStruct; |
... | ... | |
102 | 107 |
/** |
103 | 108 |
* Creates a FeatureQuery which will load all available Features of a type. |
104 | 109 |
* |
105 |
* @param featureType |
|
106 |
* the type of Features of the query |
|
107 | 110 |
*/ |
108 | 111 |
public DefaultFeatureQuery() { |
109 | 112 |
super(); |
... | ... | |
128 | 131 |
* the type of Features of the query |
129 | 132 |
* @param filter |
130 | 133 |
* based on the properties of the Features |
131 |
* @param order |
|
132 |
* for the result |
|
133 | 134 |
*/ |
134 | 135 |
public DefaultFeatureQuery(FeatureType featureType, Evaluator filter) { |
135 | 136 |
super(); |
... | ... | |
145 | 146 |
* the type of Features of the query |
146 | 147 |
* @param filter |
147 | 148 |
* based on the properties of the Features |
148 |
* @param order |
|
149 |
* for the result |
|
150 | 149 |
* @param scale |
151 | 150 |
* to view the Features. |
152 | 151 |
*/ |
... | ... | |
177 | 176 |
* the list of attribute names to load |
178 | 177 |
* @param filter |
179 | 178 |
* based on the properties of the Features |
180 |
* @param order |
|
181 |
* for the result |
|
182 | 179 |
*/ |
183 | 180 |
public DefaultFeatureQuery(String[] attributeNames, Evaluator filter) { |
184 | 181 |
super(); |
... | ... | |
194 | 191 |
* the list of attribute names to load |
195 | 192 |
* @param filter |
196 | 193 |
* based on the properties of the Features |
197 |
* @param order |
|
198 |
* for the result |
|
199 | 194 |
* @param scale |
200 | 195 |
* to view the Features. |
201 | 196 |
*/ |
... | ... | |
206 | 201 |
this.setScale(scale); |
207 | 202 |
} |
208 | 203 |
|
204 |
@Override |
|
209 | 205 |
public double getScale() { |
210 | 206 |
Double scale = (Double) this.getQueryParameter(SCALE_PARAM_NAME); |
211 | 207 |
if (scale == null) { |
212 | 208 |
return 0; |
213 | 209 |
} |
214 |
return scale.doubleValue();
|
|
210 |
return scale; |
|
215 | 211 |
} |
216 | 212 |
|
213 |
@Override |
|
217 | 214 |
public void setScale(double scale) { |
218 |
this.setQueryParameter(SCALE_PARAM_NAME, new Double(scale));
|
|
215 |
this.setQueryParameter(SCALE_PARAM_NAME, scale);
|
|
219 | 216 |
} |
220 | 217 |
|
218 |
@Override |
|
221 | 219 |
public Object getQueryParameter(String name) { |
222 | 220 |
return queryParameters.get(name); |
223 | 221 |
} |
224 | 222 |
|
223 |
@Override |
|
225 | 224 |
public void setQueryParameter(String name, Object value) { |
226 | 225 |
queryParameters.put(name, value); |
227 | 226 |
} |
228 | 227 |
|
228 |
@Override |
|
229 | 229 |
public void setFeatureType(FeatureType featureType) { |
230 | 230 |
this.featureTypeId = featureType.getId(); |
231 | 231 |
} |
232 | 232 |
|
233 |
@Override |
|
233 | 234 |
public String[] getAttributeNames() { |
234 | 235 |
return (String[])attributeNames.toArray(new String[attributeNames.size()]); |
235 | 236 |
} |
236 | 237 |
|
238 |
@Override |
|
237 | 239 |
public void setAttributeNames(String[] attributeNames) { |
238 | 240 |
this.attributeNames.clear(); |
239 | 241 |
if (attributeNames != null){ |
... | ... | |
243 | 245 |
} |
244 | 246 |
} |
245 | 247 |
|
248 |
@Override |
|
246 | 249 |
public void addAttributeName(String attributeName){ |
247 | 250 |
//If the attribute exists finish the method |
248 | 251 |
for (int i=0 ; i<attributeNames.size() ; i++){ |
... | ... | |
253 | 256 |
this.attributeNames.add(attributeName); |
254 | 257 |
} |
255 | 258 |
|
259 |
@Override |
|
260 |
public void addEssentialAttributeNames(FeatureStore store) { |
|
261 |
FeatureType storeType; |
|
262 |
try { |
|
263 |
storeType = store.getDefaultFeatureType(); |
|
264 |
} catch (DataException ex) { |
|
265 |
throw new RuntimeException("Can't access to the default feature type of tghe store", ex); |
|
266 |
} |
|
267 |
FeatureAttributeDescriptor[] pks = storeType.getPrimaryKey(); |
|
268 |
if( storeType.hasOID() || ArrayUtils.isEmpty(pks) ) { |
|
269 |
FeatureAttributeDescriptor attrInt = null; |
|
270 |
FeatureAttributeDescriptor attrStr = null; |
|
271 |
FeatureAttributeDescriptor attrNotGeom = null; |
|
272 |
for (FeatureAttributeDescriptor attr : storeType) { |
|
273 |
if( attrInt == null && (attr.getType()==DataTypes.INT || attr.getType()==DataTypes.LONG) ) { |
|
274 |
attrInt = attr; |
|
275 |
} else if( attrStr == null && attr.getType()==DataTypes.STRING ) { |
|
276 |
attrStr = attr; |
|
277 |
} else if( attrNotGeom == null && attr.getType()!=DataTypes.GEOMETRY ) { |
|
278 |
attrNotGeom = attr; |
|
279 |
} |
|
280 |
} |
|
281 |
if( attrInt != null ) { |
|
282 |
this.addAttributeName(attrInt.getName()); |
|
283 |
} else if( attrStr != null ) { |
|
284 |
this.addAttributeName(attrStr.getName()); |
|
285 |
} else if( attrNotGeom != null ) { |
|
286 |
this.addAttributeName(attrNotGeom.getName()); |
|
287 |
} else { |
|
288 |
this.addAttributeName(storeType.getAttributeDescriptor(0).getName()); |
|
289 |
} |
|
290 |
} else { |
|
291 |
for(FeatureAttributeDescriptor attr : pks ) { |
|
292 |
this.addAttributeName(attr.getName()); |
|
293 |
} |
|
294 |
} |
|
295 |
} |
|
296 |
|
|
297 |
@Override |
|
298 |
public void addPrimaryKeyAttributeNames(FeatureStore store) { |
|
299 |
FeatureType storeType; |
|
300 |
try { |
|
301 |
storeType = store.getDefaultFeatureType(); |
|
302 |
} catch (DataException ex) { |
|
303 |
throw new RuntimeException("Can't access to the default feature type of tghe store", ex); |
|
304 |
} |
|
305 |
for(FeatureAttributeDescriptor attr : storeType.getPrimaryKey() ) { |
|
306 |
this.addAttributeName(attr.getName()); |
|
307 |
} |
|
308 |
} |
|
309 |
|
|
310 |
@Override |
|
256 | 311 |
public boolean hasAttributeNames() { |
257 | 312 |
return !this.attributeNames.isEmpty(); |
258 | 313 |
} |
259 | 314 |
|
315 |
@Override |
|
260 | 316 |
public void clearAttributeNames() { |
261 | 317 |
this.attributeNames = new ArrayList(); |
262 | 318 |
} |
263 | 319 |
|
320 |
@Override |
|
264 | 321 |
public Evaluator getFilter() { |
265 | 322 |
return filter; |
266 | 323 |
} |
... | ... | |
274 | 331 |
} |
275 | 332 |
} |
276 | 333 |
|
334 |
@Override |
|
277 | 335 |
public void setFilter(Evaluator filter) { |
278 | 336 |
this.filter = filter; |
279 | 337 |
addFilterAttributes(filter); |
... | ... | |
314 | 372 |
// isAddFilter = true; |
315 | 373 |
} |
316 | 374 |
|
375 |
@Override |
|
317 | 376 |
public void clearFilter() { |
318 | 377 |
this.filter = null; |
319 | 378 |
} |
... | ... | |
337 | 396 |
} |
338 | 397 |
} |
339 | 398 |
|
399 |
@Override |
|
340 | 400 |
public FeatureQueryOrder getOrder() { |
341 | 401 |
return order; |
342 | 402 |
} |
343 | 403 |
|
404 |
@Override |
|
344 | 405 |
public void setOrder(FeatureQueryOrder order) { |
345 | 406 |
this.order = order; |
346 | 407 |
} |
347 | 408 |
|
409 |
@Override |
|
348 | 410 |
public boolean hasFilter() { |
349 | 411 |
return this.filter != null; |
350 | 412 |
} |
351 | 413 |
|
414 |
@Override |
|
352 | 415 |
public boolean hasOrder() { |
353 | 416 |
return this.order != null && this.order.size() > 0; |
354 | 417 |
} |
355 | 418 |
|
419 |
@Override |
|
356 | 420 |
public Object clone() throws CloneNotSupportedException { |
357 | 421 |
DefaultFeatureQuery clone = (DefaultFeatureQuery) super.clone(); |
358 | 422 |
|
... | ... | |
372 | 436 |
return clone; |
373 | 437 |
} |
374 | 438 |
|
439 |
@Override |
|
375 | 440 |
public FeatureQuery getCopy() { |
376 | 441 |
try { |
377 | 442 |
return (FeatureQuery) clone(); |
... | ... | |
398 | 463 |
// return aCopy; |
399 | 464 |
} |
400 | 465 |
|
466 |
@Override |
|
401 | 467 |
public String getFeatureTypeId() { |
402 | 468 |
return featureTypeId; |
403 | 469 |
} |
404 | 470 |
|
471 |
@Override |
|
405 | 472 |
public void setFeatureTypeId(String featureTypeId) { |
406 | 473 |
this.featureTypeId = featureTypeId; |
407 | 474 |
} |
408 | 475 |
|
476 |
@Override |
|
409 | 477 |
public void saveToState(PersistentState state) throws PersistenceException { |
410 | 478 |
// FIXME: falta por terminar de implementar |
411 | 479 |
state.set("queryParameters", this.queryParameters); |
... | ... | |
417 | 485 |
|
418 | 486 |
} |
419 | 487 |
|
488 |
@Override |
|
420 | 489 |
public void loadFromState(PersistentState state) throws PersistenceException { |
421 | 490 |
// FIXME: falta por terminar de implementar |
422 | 491 |
this.queryParameters = (Map) state.get("queryParameters"); |
... | ... | |
465 | 534 |
|
466 | 535 |
} |
467 | 536 |
|
537 |
@Override |
|
468 | 538 |
public long getLimit() { |
469 | 539 |
return limit; |
470 | 540 |
} |
471 | 541 |
|
542 |
@Override |
|
472 | 543 |
public long getPageSize() { |
473 | 544 |
return pageSize; |
474 | 545 |
} |
475 | 546 |
|
547 |
@Override |
|
476 | 548 |
public void setLimit(long limit) { |
477 | 549 |
this.limit = limit; |
478 | 550 |
} |
479 | 551 |
|
552 |
@Override |
|
480 | 553 |
public void setPageSize(long pageSize) { |
481 | 554 |
this.pageSize = pageSize; |
482 | 555 |
} |
483 | 556 |
|
557 |
@Override |
|
484 | 558 |
public String[] getConstantsAttributeNames() { |
485 | 559 |
return (String[])constantsAttributeNames.toArray(new String[constantsAttributeNames.size()]); |
486 | 560 |
} |
487 | 561 |
|
562 |
@Override |
|
488 | 563 |
public void setConstantsAttributeNames(String[] constantsAttributeNames) { |
489 | 564 |
this.constantsAttributeNames.clear(); |
490 | 565 |
if (constantsAttributeNames != null){ |
... | ... | |
494 | 569 |
} |
495 | 570 |
} |
496 | 571 |
|
572 |
@Override |
|
497 | 573 |
public void addConstantAttributeName(String attributeName) { |
498 | 574 |
//If the attribute exists finish the method |
499 | 575 |
for (int i=0 ; i<constantsAttributeNames.size() ; i++){ |
... | ... | |
504 | 580 |
this.constantsAttributeNames.add(attributeName); |
505 | 581 |
} |
506 | 582 |
|
583 |
@Override |
|
507 | 584 |
public boolean hasConstantsAttributeNames() { |
508 | 585 |
return !this.constantsAttributeNames.isEmpty(); |
509 | 586 |
} |
510 | 587 |
|
588 |
@Override |
|
511 | 589 |
public void clearConstantsAttributeNames() { |
512 | 590 |
this.constantsAttributeNames = new ArrayList(); |
513 | 591 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/IndexFeatureSet.java | ||
---|---|---|
30 | 30 |
import java.util.Iterator; |
31 | 31 |
import java.util.List; |
32 | 32 |
|
33 |
import org.gvsig.fmap.dal.DataStore; |
|
34 | 33 |
import org.gvsig.fmap.dal.exception.DataException; |
35 | 34 |
import org.gvsig.fmap.dal.exception.ReadRuntimeException; |
36 | 35 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
... | ... | |
39 | 38 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
40 | 39 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
41 | 40 |
import org.gvsig.fmap.dal.feature.FeatureType; |
42 |
import org.gvsig.fmap.dal.feature.impl.dynobjectutils.DynObjectSetFeatureSetFacade; |
|
43 | 41 |
import org.gvsig.fmap.dal.feature.impl.featureset.AbstractFeatureSet; |
44 | 42 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
45 | 43 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
... | ... | |
49 | 47 |
import org.gvsig.fmap.dal.feature.spi.LongList; |
50 | 48 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices; |
51 | 49 |
import org.gvsig.tools.dispose.DisposableIterator; |
52 |
import org.gvsig.tools.dynobject.DynObjectSet; |
|
53 |
import org.gvsig.tools.exception.BaseException; |
|
54 |
import org.gvsig.tools.visitor.Visitor; |
|
55 | 50 |
|
56 | 51 |
public class IndexFeatureSet |
57 | 52 |
extends AbstractFeatureSet |
... | ... | |
155 | 150 |
return false; |
156 | 151 |
} |
157 | 152 |
|
158 |
public DisposableIterator fastIterator(long index) throws DataException { |
|
159 |
if (store.getFeatureStore().isEditing()) { |
|
160 |
return this.iterator(index); |
|
161 |
} |
|
162 |
return new FastIndexIterator(this.featureReferences.iterator(index)); |
|
163 |
} |
|
153 |
public DisposableIterator fastIterator(long index) throws DataException { |
|
154 |
return fastIterator(index, 0); |
|
155 |
} |
|
164 | 156 |
|
157 |
public DisposableIterator fastIterator(long index, long elements) throws DataException { |
|
158 |
if (store.getFeatureStore().isEditing()) { |
|
159 |
return this.iterator(index, elements); |
|
160 |
} |
|
161 |
return new FastIndexIterator(this.featureReferences.iterator(index)); |
|
162 |
} |
|
163 |
|
|
164 |
|
|
165 | 165 |
public long getSize() throws DataException { |
166 | 166 |
return featureReferences.getSize(); |
167 | 167 |
} |
... | ... | |
174 | 174 |
return new IndexIterator(this.featureReferences.iterator(index)); |
175 | 175 |
} |
176 | 176 |
|
177 |
public DisposableIterator iterator(long index, long elements) throws DataException { |
|
178 |
return new IndexIterator(this.featureReferences.iterator(index)); |
|
179 |
} |
|
180 |
|
|
177 | 181 |
public void delete(Feature feature) throws DataException { |
178 | 182 |
index.delete(feature); |
179 | 183 |
store.getFeatureStore().delete(feature); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureType.java | ||
---|---|---|
31 | 31 |
import java.util.Iterator; |
32 | 32 |
import java.util.List; |
33 | 33 |
import java.util.Set; |
34 |
import org.apache.commons.lang3.ArrayUtils; |
|
34 | 35 |
|
35 | 36 |
import org.cresques.cts.IProjection; |
36 | 37 |
|
... | ... | |
259 | 260 |
} |
260 | 261 |
|
261 | 262 |
public FeatureType getSubtype(String[] names, String[] constantsNames) throws DataException { |
262 |
if( (names==null || names.length <1) && (constantsNames==null || constantsNames.length <1) ) {
|
|
263 |
return (FeatureType) this.clone();
|
|
264 |
}
|
|
263 |
if( ArrayUtils.isEmpty(names) && ArrayUtils.isEmpty(constantsNames) ) {
|
|
264 |
return (FeatureType) this.clone(); |
|
265 |
} |
|
265 | 266 |
return new SubtypeFeatureType(this, names,constantsNames); |
266 | 267 |
} |
267 | 268 |
|
... | ... | |
283 | 284 |
super(parent, false); |
284 | 285 |
DefaultFeatureAttributeDescriptor attrcopy; |
285 | 286 |
DefaultFeatureAttributeDescriptor attr; |
286 |
Set attrnames = null;
|
|
287 |
List attrnames = null;
|
|
287 | 288 |
|
288 | 289 |
// Copy attributes |
289 | 290 |
if ( names != null && names.length > 0 ) { |
290 |
attrnames = new HashSet();
|
|
291 |
attrnames = new ArrayList();
|
|
291 | 292 |
attrnames.addAll(Arrays.asList(names)); |
292 | 293 |
if ( parent.hasEmulators ) { |
293 | 294 |
for ( int i = 0; i < parent.size(); i++ ) { |
... | ... | |
326 | 327 |
} |
327 | 328 |
|
328 | 329 |
// Set the consttants attributes. |
329 |
if ( constantsNames != null && constantsNames.length > 0 ) {
|
|
330 |
if ( !ArrayUtils.isEmpty(constantsNames) ) {
|
|
330 | 331 |
for ( int i = 0; i < constantsNames.length; i++ ) { |
331 | 332 |
if ( attrnames != null && attrnames.contains(constantsNames[i]) ) { |
332 | 333 |
continue; |
... | ... | |
451 | 452 |
|
452 | 453 |
public FeatureAttributeDescriptor[] getPrimaryKey() { |
453 | 454 |
if (pk == null) { |
454 |
List pkList = new ArrayList();
|
|
455 |
List pks = new ArrayList();
|
|
455 | 456 |
Iterator iter = super.iterator(); |
456 | 457 |
FeatureAttributeDescriptor attr; |
457 | 458 |
while (iter.hasNext()){ |
458 | 459 |
attr = (FeatureAttributeDescriptor) iter.next(); |
459 | 460 |
if (attr.isPrimaryKey()){ |
460 |
pkList.add(attr);
|
|
461 |
pks.add(attr);
|
|
461 | 462 |
} |
462 | 463 |
} |
463 |
pk = (FeatureAttributeDescriptor[]) pkList |
|
464 |
.toArray(new FeatureAttributeDescriptor[pkList.size()]); |
|
464 |
if( pks.isEmpty() ) { |
|
465 |
pk = new FeatureAttributeDescriptor[0]; |
|
466 |
} else { |
|
467 |
pk = (FeatureAttributeDescriptor[])pks.toArray(new FeatureAttributeDescriptor[pks.size()]); |
|
468 |
} |
|
465 | 469 |
} |
466 | 470 |
return pk; |
467 | 471 |
} |
Also available in: Unified diff