HHH-8613 - ClassCastException in AbstractLoadPlanBuildingAssociationVisitationStrategy
This commit is contained in:
parent
67fccf231b
commit
ba3c2f656f
|
@ -86,6 +86,8 @@ public abstract class AbstractLoadPlanBuildingAssociationVisitationStrategy
|
||||||
private final SessionFactoryImplementor sessionFactory;
|
private final SessionFactoryImplementor sessionFactory;
|
||||||
private final QuerySpacesImpl querySpaces;
|
private final QuerySpacesImpl querySpaces;
|
||||||
|
|
||||||
|
private final PropertyPathStack propertyPathStack = new PropertyPathStack();
|
||||||
|
|
||||||
private final ArrayDeque<ExpandingFetchSource> fetchSourceStack = new ArrayDeque<ExpandingFetchSource>();
|
private final ArrayDeque<ExpandingFetchSource> fetchSourceStack = new ArrayDeque<ExpandingFetchSource>();
|
||||||
|
|
||||||
protected AbstractLoadPlanBuildingAssociationVisitationStrategy(SessionFactoryImplementor sessionFactory) {
|
protected AbstractLoadPlanBuildingAssociationVisitationStrategy(SessionFactoryImplementor sessionFactory) {
|
||||||
|
@ -111,18 +113,14 @@ public abstract class AbstractLoadPlanBuildingAssociationVisitationStrategy
|
||||||
|
|
||||||
private void pushToStack(ExpandingFetchSource fetchSource) {
|
private void pushToStack(ExpandingFetchSource fetchSource) {
|
||||||
log.trace( "Pushing fetch source to stack : " + fetchSource );
|
log.trace( "Pushing fetch source to stack : " + fetchSource );
|
||||||
mdcStack().push( fetchSource.getPropertyPath() );
|
propertyPathStack.push( fetchSource.getPropertyPath() );
|
||||||
fetchSourceStack.addFirst( fetchSource );
|
fetchSourceStack.addFirst( fetchSource );
|
||||||
}
|
}
|
||||||
|
|
||||||
private MDCStack mdcStack() {
|
|
||||||
return (MDCStack) MDC.get( MDC_KEY );
|
|
||||||
}
|
|
||||||
|
|
||||||
private ExpandingFetchSource popFromStack() {
|
private ExpandingFetchSource popFromStack() {
|
||||||
final ExpandingFetchSource last = fetchSourceStack.removeFirst();
|
final ExpandingFetchSource last = fetchSourceStack.removeFirst();
|
||||||
log.trace( "Popped fetch owner from stack : " + last );
|
log.trace( "Popped fetch owner from stack : " + last );
|
||||||
mdcStack().pop();
|
propertyPathStack.pop();
|
||||||
if ( FetchStackAware.class.isInstance( last ) ) {
|
if ( FetchStackAware.class.isInstance( last ) ) {
|
||||||
( (FetchStackAware) last ).poppedFromStack();
|
( (FetchStackAware) last ).poppedFromStack();
|
||||||
}
|
}
|
||||||
|
@ -144,11 +142,12 @@ public abstract class AbstractLoadPlanBuildingAssociationVisitationStrategy
|
||||||
"be sure to not use LoadPlanBuilderStrategy instances concurrently"
|
"be sure to not use LoadPlanBuilderStrategy instances concurrently"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
MDC.put( MDC_KEY, new MDCStack() );
|
propertyPathStack.push( new PropertyPath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void finish() {
|
public void finish() {
|
||||||
|
propertyPathStack.pop();
|
||||||
MDC.remove( MDC_KEY );
|
MDC.remove( MDC_KEY );
|
||||||
fetchSourceStack.clear();
|
fetchSourceStack.clear();
|
||||||
}
|
}
|
||||||
|
@ -302,14 +301,14 @@ public abstract class AbstractLoadPlanBuildingAssociationVisitationStrategy
|
||||||
|
|
||||||
private void pushToCollectionStack(CollectionReference collectionReference) {
|
private void pushToCollectionStack(CollectionReference collectionReference) {
|
||||||
log.trace( "Pushing collection reference to stack : " + collectionReference );
|
log.trace( "Pushing collection reference to stack : " + collectionReference );
|
||||||
mdcStack().push( collectionReference.getPropertyPath() );
|
propertyPathStack.push( collectionReference.getPropertyPath() );
|
||||||
collectionReferenceStack.addFirst( collectionReference );
|
collectionReferenceStack.addFirst( collectionReference );
|
||||||
}
|
}
|
||||||
|
|
||||||
private CollectionReference popFromCollectionStack() {
|
private CollectionReference popFromCollectionStack() {
|
||||||
final CollectionReference last = collectionReferenceStack.removeFirst();
|
final CollectionReference last = collectionReferenceStack.removeFirst();
|
||||||
log.trace( "Popped collection reference from stack : " + last );
|
log.trace( "Popped collection reference from stack : " + last );
|
||||||
mdcStack().pop();
|
propertyPathStack.pop();
|
||||||
if ( FetchStackAware.class.isInstance( last ) ) {
|
if ( FetchStackAware.class.isInstance( last ) ) {
|
||||||
( (FetchStackAware) last ).poppedFromStack();
|
( (FetchStackAware) last ).poppedFromStack();
|
||||||
}
|
}
|
||||||
|
@ -821,24 +820,26 @@ public abstract class AbstractLoadPlanBuildingAssociationVisitationStrategy
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used as the MDC object for logging purposes. Because of the recursive calls it is often useful (while debugging)
|
* Maintains stack information for the property paths we are processing for logging purposes. Because of the
|
||||||
* to be able to see the "property path" as part of the logging output. This class helps fulfill that role
|
* recursive calls it is often useful (while debugging) to be able to see the "property path" as part of the
|
||||||
* here by acting as the object that gets put into the logging libraries underlying MDC.
|
* logging output.
|
||||||
*/
|
*/
|
||||||
public static class MDCStack {
|
public static class PropertyPathStack {
|
||||||
private ArrayDeque<PropertyPath> pathStack = new ArrayDeque<PropertyPath>();
|
private ArrayDeque<PropertyPath> pathStack = new ArrayDeque<PropertyPath>();
|
||||||
|
|
||||||
public void push(PropertyPath path) {
|
public void push(PropertyPath path) {
|
||||||
pathStack.addFirst( path );
|
pathStack.addFirst( path );
|
||||||
|
MDC.put( MDC_KEY, extractFullPath( path ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private String extractFullPath(PropertyPath path) {
|
||||||
|
return path == null ? "<no-path>" : path.getFullPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pop() {
|
public void pop() {
|
||||||
pathStack.removeFirst();
|
pathStack.removeFirst();
|
||||||
}
|
PropertyPath newHead = pathStack.peekFirst();
|
||||||
|
MDC.put( MDC_KEY, extractFullPath( newHead ) );
|
||||||
public String toString() {
|
|
||||||
final PropertyPath path = pathStack.peekFirst();
|
|
||||||
return path == null ? "<no-path>" : path.getFullPath();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue