Skip to content

Commit 5b30d36

Browse files
committed
1 parent 6f76536 commit 5b30d36

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.luxoft.logeek.benchmark.sequence;
2+
3+
import com.luxoft.logeek.benchmark.ContextAwareBenchmark;
4+
import org.openjdk.jmh.annotations.*;
5+
6+
import javax.persistence.EntityManager;
7+
import java.util.concurrent.TimeUnit;
8+
9+
@State(Scope.Thread)
10+
@BenchmarkMode(Mode.AverageTime)
11+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
12+
public class QueryValidationBenchmark extends ContextAwareBenchmark {
13+
14+
private EntityManager entityManager;
15+
16+
@Setup
17+
public void init() {
18+
super.init();
19+
entityManager = context.getBean(EntityManager.class);
20+
}
21+
22+
@Benchmark
23+
public Object measureQuery() {
24+
return validateQueryDefault();
25+
}
26+
27+
private Object validateQueryDefault() {
28+
EntityManager validatingEm = null;
29+
30+
try {
31+
validatingEm = entityManager.getEntityManagerFactory().createEntityManager();
32+
return validatingEm.createQuery("select r from CpyEntity r ");
33+
34+
} catch (RuntimeException e) {
35+
throw new IllegalArgumentException("", e);
36+
} finally {
37+
if (validatingEm != null) {
38+
validatingEm.close();
39+
}
40+
}
41+
}
42+
43+
}

0 commit comments

Comments
 (0)