org.babyfish.jimmer.sql.runtime.ExecutorContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jimmer-sql Show documentation
Show all versions of jimmer-sql Show documentation
A revolutionary ORM framework for both java and kotlin
The newest version!
package org.babyfish.jimmer.sql.runtime;
import org.babyfish.jimmer.sql.JSqlClient;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class ExecutorContext {
private final StackTraceElement primaryElement;
private final List matchedElements;
private final List elements;
private ExecutorContext(
StackTraceElement primaryElement,
List matchedElements,
List elements
) {
this.primaryElement = primaryElement;
this.matchedElements = matchedElements;
this.elements = elements;
}
@NotNull
public StackTraceElement getPrimaryElement() {
return primaryElement;
}
@NotNull
public List getElements() {
return elements;
}
@NotNull
public List getMatchedElements() {
return matchedElements;
}
@Nullable
public static ExecutorContext create(JSqlClient sqlClient) {
List prefixes = ((JSqlClientImplementor)sqlClient).getExecutorContextPrefixes();
if (prefixes == null) {
return null;
}
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
List matchedElements = new ArrayList<>();
for (StackTraceElement element : elements) {
if (element.getLineNumber() >= 0) {
for (String prefix : prefixes) {
if (element.getClassName().startsWith(prefix)) {
matchedElements.add(element);
break;
}
}
}
}
if (matchedElements.isEmpty()) {
return null;
}
return new ExecutorContext(
matchedElements.get(0),
Collections.unmodifiableList(matchedElements),
Collections.unmodifiableList(
Arrays.asList(elements)
)
);
}
}