Revision 28661 branches/v2_0_0_prep/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/store/postgresql/PostgreSQLStoreProviderWriter.java
PostgreSQLStoreProviderWriter.java | ||
---|---|---|
46 | 46 |
import org.gvsig.fmap.dal.feature.FeatureType; |
47 | 47 |
import org.gvsig.fmap.dal.feature.exception.PerformEditingException; |
48 | 48 |
import org.gvsig.fmap.dal.feature.spi.FeatureData; |
49 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
|
49 | 50 |
import org.gvsig.fmap.dal.resource.exception.ResourceBeginException; |
50 | 51 |
import org.gvsig.fmap.dal.store.jdbc.JDBCExecutePreparedSQLException; |
51 | 52 |
import org.gvsig.fmap.dal.store.jdbc.JDBCExecuteSQLException; |
52 | 53 |
import org.gvsig.fmap.dal.store.jdbc.JDBCPreparingSQLException; |
53 | 54 |
import org.gvsig.fmap.dal.store.jdbc.JDBCSQLException; |
55 |
import org.gvsig.fmap.dal.store.jdbc.JDBCUpdateWithoutChangesException; |
|
54 | 56 |
import org.gvsig.fmap.dal.store.postgresql.PostgreSQLHelper.TransactionalAction; |
55 | 57 |
import org.gvsig.fmap.geom.Geometry; |
56 | 58 |
import org.slf4j.Logger; |
... | ... | |
145 | 147 |
final Iterator originalFeatureTypesUpdated) |
146 | 148 |
throws PerformEditingException { |
147 | 149 |
|
150 |
boolean countChanged = deleteds.hasNext() || inserteds.hasNext(); |
|
151 |
|
|
148 | 152 |
try { |
149 | 153 |
this.open(); |
150 | 154 |
} catch (OpenException e2) { |
... | ... | |
196 | 200 |
try { |
197 | 201 |
this.helper.doConnectionAction(action); |
198 | 202 |
|
203 |
if (countChanged) { |
|
204 |
resetCount(); |
|
205 |
} |
|
206 |
|
|
199 | 207 |
} catch (Exception e) { |
200 | 208 |
throw new PerformEditingException(this.getName(), e); |
201 | 209 |
} finally { |
... | ... | |
295 | 303 |
String sql = sqlb.toString(); |
296 | 304 |
// ************ Prepare SQL (end) **************** |
297 | 305 |
|
298 |
executePreparedStatement(conn, sql, pkAttributes, deleteds); |
|
306 |
executeRemovePreparedStatement(conn, sql, pkAttributes, deleteds);
|
|
299 | 307 |
} |
300 | 308 |
|
301 | 309 |
private void performUpdates(Connection conn, Iterator updateds, |
... | ... | |
372 | 380 |
updateAttrs.addAll(pkAttributes); |
373 | 381 |
|
374 | 382 |
try { |
375 |
executePreparedStatement(conn, sql, updateAttrs, updateds); |
|
383 |
executeUpdatePreparedStatement(conn, sql, updateAttrs, updateds);
|
|
376 | 384 |
} catch (Exception e) { |
377 | 385 |
// TODO Auto-generated catch block |
378 | 386 |
e.printStackTrace(); |
379 | 387 |
} |
380 | 388 |
} |
381 | 389 |
|
382 |
private void executePreparedStatement(Connection conn, String sql, |
|
390 |
private void executeRemovePreparedStatement(Connection conn, String sql, |
|
391 |
List attributes, Iterator featureReferences) throws DataException { |
|
392 |
PreparedStatement st; |
|
393 |
try { |
|
394 |
st = conn.prepareStatement(sql); |
|
395 |
} catch (SQLException e) { |
|
396 |
throw new JDBCPreparingSQLException(sql, e); |
|
397 |
} |
|
398 |
try { |
|
399 |
List values = new ArrayList(); |
|
400 |
FeatureReferenceProviderServices featureRef; |
|
401 |
FeatureType featureType; |
|
402 |
while (featureReferences.hasNext()) { |
|
403 |
st.clearParameters(); |
|
404 |
featureRef = (FeatureReferenceProviderServices) featureReferences |
|
405 |
.next(); |
|
406 |
values.clear(); |
|
407 |
featureType = this.store.getFeatureType(featureRef |
|
408 |
.getFeatureTypeId()); |
|
409 |
|
|
410 |
Iterator iter = attributes.iterator(); |
|
411 |
FeatureAttributeDescriptor attr; |
|
412 |
while (iter.hasNext()) { |
|
413 |
attr = (FeatureAttributeDescriptor) iter.next(); |
|
414 |
values.add(helper.dalValueToJDBC(attr, featureRef |
|
415 |
.getKeyValue(attr.getName()))); |
|
416 |
} |
|
417 |
|
|
418 |
for (int i = 0; i < values.size(); i++) { |
|
419 |
st.setObject(i + 1, values.get(i)); |
|
420 |
} |
|
421 |
try { |
|
422 |
int nAffected =st.executeUpdate(); |
|
423 |
if (nAffected == 0) { |
|
424 |
throw new JDBCUpdateWithoutChangesException(sql, values); |
|
425 |
} |
|
426 |
if (nAffected > 1){ |
|
427 |
logger.warn("Remove statement affectst to {} rows: {}", |
|
428 |
nAffected, sql); |
|
429 |
} |
|
430 |
|
|
431 |
} catch (SQLException e) { |
|
432 |
throw new JDBCExecutePreparedSQLException(sql, values, e); |
|
433 |
} |
|
434 |
|
|
435 |
} |
|
436 |
} catch (SQLException e) { |
|
437 |
throw new JDBCSQLException(e); |
|
438 |
} finally { |
|
439 |
try {st.close();} catch (SQLException e) { }; |
|
440 |
} |
|
441 |
|
|
442 |
} |
|
443 |
|
|
444 |
private void executeUpdatePreparedStatement(Connection conn, String sql, |
|
383 | 445 |
List attributes, Iterator featureDatas) throws DataException { |
384 | 446 |
PreparedStatement st; |
385 | 447 |
try { |
... | ... | |
399 | 461 |
st.setObject(i + 1, values.get(i)); |
400 | 462 |
} |
401 | 463 |
try { |
402 |
st.execute(); |
|
464 |
if (st.executeUpdate() == 0) { |
|
465 |
throw new JDBCUpdateWithoutChangesException(sql, values); |
|
466 |
} |
|
403 | 467 |
} catch (SQLException e) { |
404 | 468 |
throw new JDBCExecutePreparedSQLException(sql, values, e); |
405 | 469 |
} |
Also available in: Unified diff