Change how we find the frame to use for the UOW's purpose.

This commit is contained in:
Greg Burd 2017-11-01 16:17:00 -04:00
parent 5905663c58
commit 13eaa7e7ea

View file

@ -306,17 +306,22 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab
UnitOfWork uow = ctor.newInstance(this, parent); UnitOfWork uow = ctor.newInstance(this, parent);
if (LOG.isInfoEnabled() && uow.getPurpose() == null) { if (LOG.isInfoEnabled() && uow.getPurpose() == null) {
StringBuilder purpose = null; StringBuilder purpose = null;
int frame = 0;
StackTraceElement[] trace = Thread.currentThread().getStackTrace(); StackTraceElement[] trace = Thread.currentThread().getStackTrace();
int frame = 2; String targetClassName = HelenusSession.class.getName();
if (trace[2].getMethodName().equals("begin")) { do { frame++; } while (!trace[frame].getClassName().equals(targetClassName) && frame < trace.length);
frame = 3; do { frame++; } while (trace[frame].getClassName().equals(targetClassName) && frame < trace.length);
} else if (trace[2].getClassName().equals(unitOfWorkClass.getName())) { if (frame < trace.length) {
frame = 3; purpose = new StringBuilder().append(trace[frame].getClassName())
} .append(".")
purpose = new StringBuilder().append(trace[frame].getClassName()).append(".") .append(trace[frame].getMethodName())
.append(trace[frame].getMethodName()).append("(").append(trace[frame].getFileName()).append(":") .append("(")
.append(trace[frame].getLineNumber()).append(")"); .append(trace[frame].getFileName())
.append(":")
.append(trace[frame].getLineNumber())
.append(")");
uow.setPurpose(purpose.toString()); uow.setPurpose(purpose.toString());
}
} }
if (parent != null) { if (parent != null) {
parent.addNestedUnitOfWork(uow); parent.addNestedUnitOfWork(uow);