Revision 31128 branches/v2_0_0_prep/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/store/jdbc/JDBCStoreProvider.java
JDBCStoreProvider.java | ||
---|---|---|
165 | 165 |
*/ |
166 | 166 |
public void loadFeatureProvider(final FeatureProvider data, final int resultsetID) |
167 | 167 |
throws DataException { |
168 |
// this.resourcesBegin(); |
|
169 |
// try { |
|
170 | 168 |
getResource().execute(new ResourceAction() { |
171 | 169 |
public Object run() throws Exception { |
172 | 170 |
ResultSet rs = getResultSet(resultsetID); |
... | ... | |
179 | 177 |
return null; |
180 | 178 |
} |
181 | 179 |
}); |
182 |
// } finally { |
|
183 |
// this.resourcesEnd(); |
|
184 |
// } |
|
185 |
|
|
186 |
|
|
187 |
|
|
188 | 180 |
} |
189 | 181 |
|
190 | 182 |
|
... | ... | |
246 | 238 |
} |
247 | 239 |
} |
248 | 240 |
|
249 |
public final int createResultSet(String sql) |
|
241 |
public final int createResultSet(String sql, int fetchSize)
|
|
250 | 242 |
throws DataException { |
251 |
return createResultSet(sql, null); |
|
243 |
return createResultSet(sql, null, -1);
|
|
252 | 244 |
} |
253 | 245 |
|
254 |
public final int createResultSet(final String sql, final Object[] values) |
|
246 |
public final int createResultSet(final String sql, final Object[] values, |
|
247 |
final int fetchSize) |
|
255 | 248 |
throws DataException { |
256 | 249 |
synchronized (this) { |
257 | 250 |
checksResulsets(); |
258 |
// resourcesBegin(); |
|
259 |
// try { |
|
260 | 251 |
return ((Integer) getResource().execute(new ResourceAction() { |
261 | 252 |
public Object run() throws Exception { |
262 | 253 |
ResultSetInfo newRs = |
263 |
new ResultSetInfo(createNewResultSet(sql, values)); |
|
254 |
new ResultSetInfo(createNewResultSet(sql, values, |
|
255 |
fetchSize)); |
|
264 | 256 |
int newId = getNewId(); |
265 | 257 |
if (newId < 0) { |
266 | 258 |
newId = resulsetList.size(); |
... | ... | |
276 | 268 |
return Integer.valueOf(newId); |
277 | 269 |
} |
278 | 270 |
})).intValue(); |
279 |
// } finally { |
|
280 |
// resourcesEnd(); |
|
281 |
// } |
|
282 |
|
|
283 | 271 |
} |
284 | 272 |
} |
285 | 273 |
|
... | ... | |
363 | 351 |
return Boolean.valueOf(getResultSet(resultsetID).next()); |
364 | 352 |
} |
365 | 353 |
})).booleanValue(); |
366 |
|
|
367 |
// ResultSet rs = getResultSet(resultsetID); |
|
368 |
// |
|
369 |
// resourcesBegin(); |
|
370 |
// try { |
|
371 |
// return rs.next(); |
|
372 |
// } catch (SQLException e) { |
|
373 |
// throw new JDBCSQLException(e); |
|
374 |
// } finally { |
|
375 |
// resourcesEnd(); |
|
376 |
// } |
|
377 | 354 |
} |
378 | 355 |
|
379 | 356 |
public final void closeResulset(final int resultsetID) |
380 | 357 |
throws JDBCException, |
381 | 358 |
InvalidResultSetIdException, ResourceExecuteException { |
382 | 359 |
synchronized (this) { |
383 |
// resourcesBegin(); |
|
384 |
// try { |
|
385 | 360 |
getResource().execute(new ResourceAction() { |
386 | 361 |
public Object run() throws Exception { |
387 | 362 |
ResultSet rs = dropResultSet(resultsetID); |
... | ... | |
393 | 368 |
logger.debug(" id: " + resultsetID + " (total " |
394 | 369 |
+ getResultsetOpenCount() + ")"); |
395 | 370 |
} |
396 |
|
|
397 |
// } finally { |
|
398 |
// resourcesEnd(); |
|
399 |
// } |
|
400 | 371 |
checksResulsets(); |
401 | 372 |
} |
402 | 373 |
} |
... | ... | |
404 | 375 |
public final void checksResulsets() throws JDBCException, |
405 | 376 |
InvalidResultSetIdException, ResourceExecuteException { |
406 | 377 |
synchronized (this) { |
407 |
// resourcesBegin(); |
|
408 |
// try { |
|
409 | 378 |
getResource().execute(new ResourceAction() { |
410 | 379 |
public Object run() throws Exception { |
411 | 380 |
ResultSetInfo rsInfo; |
... | ... | |
421 | 390 |
return null; |
422 | 391 |
} |
423 | 392 |
}); |
424 |
|
|
425 |
// } finally { |
|
426 |
// resourcesEnd(); |
|
427 |
// } |
|
428 |
|
|
429 | 393 |
} |
430 | 394 |
} |
431 | 395 |
|
432 |
|
|
433 | 396 |
private int getResultsetOpenCount() { |
434 | 397 |
int count = 0; |
435 | 398 |
Iterator iter = resulsetList.iterator(); |
... | ... | |
443 | 406 |
|
444 | 407 |
protected void closeResulset(final ResultSet rs) throws JDBCException, |
445 | 408 |
ResourceExecuteException { |
446 |
// resourcesBegin(); |
|
447 |
// try { |
|
448 | 409 |
getResource().execute(new ResourceAction() { |
449 | 410 |
public Object run() throws Exception { |
450 | 411 |
Statement st = rs.getStatement(); |
... | ... | |
459 | 420 |
return null; |
460 | 421 |
} |
461 | 422 |
}); |
462 |
// } catch (SQLException e) { |
|
463 |
// throw new JDBCSQLException(e); |
|
464 |
// } finally { |
|
465 |
// resourcesEnd(); |
|
466 |
// } |
|
467 |
|
|
468 | 423 |
} |
469 | 424 |
|
470 | 425 |
protected final int openResulsetCount() { |
... | ... | |
523 | 478 |
* @return |
524 | 479 |
* @throws DataException |
525 | 480 |
*/ |
526 |
protected long getCount(String filter) throws DataException { |
|
481 |
protected long getCount(String filter) |
|
482 |
throws DataException { |
|
527 | 483 |
this.open(); |
528 | 484 |
if (filter == null && totalCount != null) { |
529 | 485 |
return totalCount.longValue(); |
530 | 486 |
} |
531 | 487 |
final String sql = compoundCountSelect(filter); |
532 |
// resourcesBegin(); |
|
533 |
// try { |
|
488 |
|
|
534 | 489 |
long count = ((Long) getResource().execute(new ResourceAction() { |
535 | 490 |
public Object run() throws Exception { |
536 | 491 |
long count = 0; |
537 |
ResultSet rs = createNewResultSet(sql, null); |
|
492 |
ResultSet rs = createNewResultSet(sql, null, 1);
|
|
538 | 493 |
try { |
539 | 494 |
if (rs.next()) { |
540 | 495 |
count = rs.getLong(1); |
... | ... | |
547 | 502 |
return Long.valueOf(count); |
548 | 503 |
} |
549 | 504 |
})).longValue(); |
550 |
// } finally { |
|
551 |
// resourcesEnd(); |
|
552 |
// } |
|
505 |
|
|
553 | 506 |
if (filter == null) { |
554 | 507 |
totalCount = new Long(count); |
555 | 508 |
} |
... | ... | |
564 | 517 |
helper.open(); |
565 | 518 |
} |
566 | 519 |
|
567 |
|
|
568 | 520 |
@Override |
569 | 521 |
protected FeatureProvider internalGetFeatureProviderByReference( |
570 | 522 |
FeatureReferenceProviderServices reference) throws DataException { |
... | ... | |
575 | 527 |
|
576 | 528 |
@Override |
577 | 529 |
protected FeatureProvider internalGetFeatureProviderByReference( |
578 |
FeatureReferenceProviderServices reference, FeatureType featureType) |
|
530 |
FeatureReferenceProviderServices reference, |
|
531 |
FeatureType featureType) |
|
579 | 532 |
throws DataException { |
580 | 533 |
StringBuilder filter = new StringBuilder(); |
581 | 534 |
FeatureAttributeDescriptor[] pk = |
... | ... | |
599 | 552 |
String sql = compoundSelect(featureType, filter.toString(), null, 1, 0); |
600 | 553 |
|
601 | 554 |
FeatureProvider data; |
602 |
int rsId = createResultSet(sql, values.toArray()); |
|
555 |
int rsId = createResultSet(sql, values.toArray(), 1);
|
|
603 | 556 |
try { |
604 | 557 |
if (!resulsetNext(rsId)) { |
605 | 558 |
// FIXME Exception |
... | ... | |
641 | 594 |
} |
642 | 595 |
|
643 | 596 |
protected ResultSet createNewResultSet(final String sql, |
644 |
final Object[] values) throws DataException { |
|
597 |
final Object[] values, final int fetchSize) |
|
598 |
throws DataException { |
|
645 | 599 |
this.open(); |
646 | 600 |
return (ResultSet) getResource().execute(new ResourceAction() { |
647 | 601 |
public Object run() throws Exception { |
... | ... | |
651 | 605 |
try { |
652 | 606 |
|
653 | 607 |
conn = helper.getConnection(); |
608 |
conn.setAutoCommit(false); |
|
654 | 609 |
st = conn.prepareStatement(sql); |
655 | 610 |
|
656 | 611 |
if (values != null) { |
... | ... | |
673 | 628 |
} |
674 | 629 |
} |
675 | 630 |
|
631 |
if (fetchSize > 0) { |
|
632 |
st.setFetchSize(fetchSize); |
|
633 |
} |
|
676 | 634 |
rs = st.executeQuery(); |
677 |
rs.setFetchSize(5000); // TODO add to params? |
|
635 |
if (fetchSize > 0) { |
|
636 |
rs.setFetchSize(fetchSize); |
|
637 |
} |
|
678 | 638 |
return rs; |
679 | 639 |
} catch (SQLException e) { |
680 | 640 |
// TODO throw exception ??? |
... | ... | |
915 | 875 |
} |
916 | 876 |
} |
917 | 877 |
// limit offset |
918 |
if (limit >= 1 || offset >= 1) {
|
|
878 |
if (limit > 0 || offset > 0) {
|
|
919 | 879 |
sql.append(helper.compoundLimitAndOffset(limit,offset)); |
920 | 880 |
} |
921 | 881 |
return sql.toString(); |
... | ... | |
946 | 906 |
public ResourceProvider getResource() { |
947 | 907 |
return getHelper().getResource(); |
948 | 908 |
} |
949 |
|
|
950 |
// public void resourcesBegin() throws ResourceExecuteException { |
|
951 |
// this.helper.begin(); |
|
952 |
// } |
|
953 |
// |
|
954 |
// public void resourcesEnd() { |
|
955 |
// this.helper.end(); |
|
956 |
// } |
|
957 | 909 |
} |
Also available in: Unified diff