Revision c44864dc
Added by Andreas Müller over 3 years ago
eu.etaxonomy.taxeditor.cdmlib/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java | ||
---|---|---|
352 | 352 |
LOG.info("--> readIndexExistence, of " + getRole() + " with key " + getKey()); |
353 | 353 |
read(); |
354 | 354 |
} else { |
355 |
Boolean extraLazyExistenceCheck = withTemporarySessionIfNeeded( |
|
356 |
new LazyInitializationWork<Boolean>() { |
|
357 |
@Override |
|
358 |
public Boolean doWork() { |
|
359 |
CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); |
|
360 |
CollectionPersister persister = entry.getLoadedPersister(); |
|
361 |
if ( persister.isExtraLazy() ) { |
|
362 |
if ( hasQueuedOperations() ) { |
|
363 |
session.flush(); |
|
364 |
} |
|
365 |
return persister.indexExists( entry.getLoadedKey(), index, session ); |
|
366 |
} |
|
367 |
else { |
|
368 |
read(); |
|
355 |
final Boolean extraLazyExistenceCheck = withTemporarySessionIfNeeded( |
|
356 |
new LazyInitializationWork<Boolean>() { |
|
357 |
@Override |
|
358 |
public Boolean doWork() { |
|
359 |
final CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); |
|
360 |
final CollectionPersister persister = entry.getLoadedPersister(); |
|
361 |
if ( persister.isExtraLazy() ) { |
|
362 |
if ( hasQueuedOperations() ) { |
|
363 |
session.flush(); |
|
369 | 364 |
} |
370 |
return null;
|
|
365 |
return persister.indexExists( entry.getLoadedKey(), index, session );
|
|
371 | 366 |
} |
367 |
else { |
|
368 |
read(); |
|
369 |
} |
|
370 |
return null; |
|
372 | 371 |
} |
373 |
); |
|
374 |
if ( extraLazyExistenceCheck != null ) { |
|
375 |
return extraLazyExistenceCheck; |
|
376 |
} |
|
372 |
} |
|
373 |
); |
|
374 |
if ( extraLazyExistenceCheck != null ) { |
|
375 |
return extraLazyExistenceCheck; |
|
376 |
} |
|
377 | 377 |
} |
378 | 378 |
} |
379 | 379 |
return null; |
... | ... | |
388 | 388 |
read(); |
389 | 389 |
|
390 | 390 |
} else { |
391 |
Boolean extraLazyExistenceCheck = withTemporarySessionIfNeeded( |
|
392 |
new LazyInitializationWork<Boolean>() { |
|
393 |
@Override |
|
394 |
public Boolean doWork() { |
|
395 |
CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); |
|
396 |
CollectionPersister persister = entry.getLoadedPersister(); |
|
397 |
if ( persister.isExtraLazy() ) { |
|
398 |
if ( hasQueuedOperations() ) { |
|
399 |
session.flush(); |
|
400 |
} |
|
401 |
return persister.elementExists( entry.getLoadedKey(), element, session ); |
|
402 |
} |
|
403 |
else { |
|
404 |
read(); |
|
391 |
final Boolean extraLazyExistenceCheck = withTemporarySessionIfNeeded( |
|
392 |
new LazyInitializationWork<Boolean>() { |
|
393 |
@Override |
|
394 |
public Boolean doWork() { |
|
395 |
final CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); |
|
396 |
final CollectionPersister persister = entry.getLoadedPersister(); |
|
397 |
if ( persister.isExtraLazy() ) { |
|
398 |
if ( hasQueuedOperations() ) { |
|
399 |
session.flush(); |
|
405 | 400 |
} |
406 |
return null;
|
|
401 |
return persister.elementExists( entry.getLoadedKey(), element, session );
|
|
407 | 402 |
} |
403 |
else { |
|
404 |
read(); |
|
405 |
} |
|
406 |
return null; |
|
408 | 407 |
} |
409 |
); |
|
410 |
if ( extraLazyExistenceCheck != null ) { |
|
411 |
return extraLazyExistenceCheck; |
|
412 |
} |
|
408 |
} |
|
409 |
); |
|
410 |
if ( extraLazyExistenceCheck != null ) { |
|
411 |
return extraLazyExistenceCheck; |
|
412 |
} |
|
413 | 413 |
} |
414 | 414 |
} |
415 | 415 |
return null; |
... | ... | |
426 | 426 |
read(); |
427 | 427 |
|
428 | 428 |
} else { |
429 |
class ExtraLazyElementByIndexReader implements LazyInitializationWork {
|
|
430 |
private boolean isExtraLazy;
|
|
431 |
private Object element;
|
|
429 |
class ExtraLazyElementByIndexReader implements LazyInitializationWork { |
|
430 |
private boolean isExtraLazy; |
|
431 |
private Object element; |
|
432 | 432 |
|
433 |
@Override |
|
434 |
public Object doWork() { |
|
435 |
CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); |
|
436 |
CollectionPersister persister = entry.getLoadedPersister(); |
|
437 |
isExtraLazy = persister.isExtraLazy(); |
|
438 |
if ( isExtraLazy ) { |
|
439 |
if ( hasQueuedOperations() ) { |
|
440 |
session.flush(); |
|
441 |
} |
|
442 |
element = persister.getElementByIndex( entry.getLoadedKey(), index, session, owner ); |
|
443 |
} |
|
444 |
else { |
|
445 |
read(); |
|
433 |
@Override |
|
434 |
public Object doWork() { |
|
435 |
final CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); |
|
436 |
final CollectionPersister persister = entry.getLoadedPersister(); |
|
437 |
isExtraLazy = persister.isExtraLazy(); |
|
438 |
if ( isExtraLazy ) { |
|
439 |
if ( hasQueuedOperations() ) { |
|
440 |
session.flush(); |
|
446 | 441 |
} |
447 |
return null; |
|
442 |
element = persister.getElementByIndex( entry.getLoadedKey(), index, session, owner ); |
|
443 |
} |
|
444 |
else { |
|
445 |
read(); |
|
448 | 446 |
} |
447 |
return null; |
|
449 | 448 |
} |
449 |
} |
|
450 | 450 |
|
451 |
ExtraLazyElementByIndexReader reader = new ExtraLazyElementByIndexReader();
|
|
452 |
//noinspection unchecked
|
|
453 |
withTemporarySessionIfNeeded( reader );
|
|
454 |
if ( reader.isExtraLazy ) {
|
|
455 |
return reader.element;
|
|
456 |
}
|
|
451 |
final ExtraLazyElementByIndexReader reader = new ExtraLazyElementByIndexReader();
|
|
452 |
//noinspection unchecked |
|
453 |
withTemporarySessionIfNeeded( reader ); |
|
454 |
if ( reader.isExtraLazy ) { |
|
455 |
return reader.element; |
|
456 |
} |
|
457 | 457 |
} |
458 | 458 |
} |
459 | 459 |
return UNKNOWN; |
... | ... | |
643 | 643 |
* @throws LazyInitializationException if we cannot initialize |
644 | 644 |
*/ |
645 | 645 |
protected final void initialize(final boolean writing) { |
646 |
if ( initialized ) { |
|
647 |
return; |
|
648 |
} |
|
649 |
|
|
646 |
if ( initialized ) { |
|
647 |
return; |
|
648 |
} |
|
650 | 649 |
// In remoting we are sure that session is null |
651 | 650 |
// both when using property paths and switching off conversations |
652 | 651 |
if(session == null && remoting) { |
653 | 652 |
remoteInitialize(); |
654 |
} else { |
|
655 |
withTemporarySessionIfNeeded(
|
|
656 |
new LazyInitializationWork<Object>() {
|
|
657 |
@Override
|
|
658 |
public Object doWork() {
|
|
659 |
session.initializeCollection( AbstractPersistentCollection.this, writing );
|
|
660 |
return null;
|
|
661 |
}
|
|
662 |
}
|
|
663 |
);
|
|
653 |
} else { //keep formatting to ease update to newer hibernate version
|
|
654 |
withTemporarySessionIfNeeded(
|
|
655 |
new LazyInitializationWork<Object>() {
|
|
656 |
@Override
|
|
657 |
public Object doWork() {
|
|
658 |
session.initializeCollection( AbstractPersistentCollection.this, writing );
|
|
659 |
return null;
|
|
660 |
}
|
|
661 |
}
|
|
662 |
);
|
|
664 | 663 |
} |
665 | 664 |
} |
666 | 665 |
|
... | ... | |
696 | 695 |
} |
697 | 696 |
|
698 | 697 |
@Override |
699 |
public final boolean unsetSession(SessionImplementor currentSession) {
|
|
700 |
prepareForPossibleSpecialSpecjInitialization();
|
|
698 |
public final boolean unsetSession(SessionImplementor currentSession) {
|
|
699 |
prepareForPossibleLoadingOutsideTransaction();
|
|
701 | 700 |
if ( currentSession == this.session ) { |
702 | 701 |
this.session = null; |
703 | 702 |
return true; |
... | ... | |
707 | 706 |
} |
708 | 707 |
} |
709 | 708 |
|
710 |
protected void prepareForPossibleSpecialSpecjInitialization() {
|
|
709 |
protected void prepareForPossibleLoadingOutsideTransaction() {
|
|
711 | 710 |
if ( session != null ) { |
712 | 711 |
specjLazyLoad = session.getFactory().getSettings().isInitializeLazyStateOutsideTransactionsEnabled(); |
713 | 712 |
|
Also available in: Unified diff
ref #9204 further uncritical updates to AbstractPersistentCollection