-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add benchmark for https://jira.spring.io/browse/DATAJPA-1370
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...-runners/src/main/java/com/luxoft/logeek/benchmark/sequence/QueryValidationBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.luxoft.logeek.benchmark.sequence; | ||
|
||
import com.luxoft.logeek.benchmark.ContextAwareBenchmark; | ||
import org.openjdk.jmh.annotations.*; | ||
|
||
import javax.persistence.EntityManager; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@State(Scope.Thread) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
public class QueryValidationBenchmark extends ContextAwareBenchmark { | ||
|
||
private EntityManager entityManager; | ||
|
||
@Setup | ||
public void init() { | ||
super.init(); | ||
entityManager = context.getBean(EntityManager.class); | ||
} | ||
|
||
@Benchmark | ||
public Object measureQuery() { | ||
return validateQueryDefault(); | ||
} | ||
|
||
private Object validateQueryDefault() { | ||
EntityManager validatingEm = null; | ||
|
||
try { | ||
validatingEm = entityManager.getEntityManagerFactory().createEntityManager(); | ||
return validatingEm.createQuery("select r from CpyEntity r "); | ||
|
||
} catch (RuntimeException e) { | ||
throw new IllegalArgumentException("", e); | ||
} finally { | ||
if (validatingEm != null) { | ||
validatingEm.close(); | ||
} | ||
} | ||
} | ||
|
||
} |