HHH-17347 Support for JDK which do not support JFR events
This commit is contained in:
parent
1b2be49045
commit
8492d1c4b8
|
@ -16,6 +16,13 @@ dependencies {
|
|||
testImplementation testLibs.jfrUnit
|
||||
}
|
||||
|
||||
compileTestJava {
|
||||
//Testing JFR events require JDK > 16
|
||||
javaCompiler = javaToolchains.compilerFor {
|
||||
languageVersion = JavaLanguageVersion.of( 17 )
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
//Testing JFR events require JDK > 16
|
||||
javaLauncher = javaToolchains.launcherFor {
|
||||
|
|
|
@ -31,7 +31,7 @@ public class FlushEvent extends Event implements HibernateEvent {
|
|||
@Label("Number Of Processed Entities")
|
||||
public int numberOfEntitiesProcessed;
|
||||
|
||||
@Label("Number Of Processed Collectionc")
|
||||
@Label("Number Of Processed Collections")
|
||||
public int numberOfCollectionsProcessed;
|
||||
|
||||
@Label("Flush time")
|
||||
|
|
|
@ -10,10 +10,10 @@ import org.hibernate.cache.spi.Region;
|
|||
import org.hibernate.cache.spi.access.CachedDomainDataAccess;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.event.spi.EventManager;
|
||||
import org.hibernate.event.spi.HibernateEvent;
|
||||
import org.hibernate.event.spi.AutoFlushEvent;
|
||||
import org.hibernate.event.spi.EventManager;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.event.spi.HibernateEvent;
|
||||
import org.hibernate.internal.build.AllowNonPortable;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
@ -27,11 +27,26 @@ import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
|||
@AllowNonPortable
|
||||
public class JfrEventManager implements EventManager {
|
||||
|
||||
private static final EventType eventType = EventType.getEventType( SessionOpenEvent.class );
|
||||
private static final EventType sessionOpenEventType = EventType.getEventType( SessionOpenEvent.class );
|
||||
private static final EventType sessionClosedEventType = EventType.getEventType( SessionClosedEvent.class );
|
||||
private static final EventType jdbcConnectionAcquisitionEventType = EventType
|
||||
.getEventType( JdbcConnectionAcquisitionEvent.class );
|
||||
private static final EventType jdbcConnectionReleaseEventType = EventType
|
||||
.getEventType( JdbcConnectionReleaseEvent.class );
|
||||
private static final EventType jdbcPreparedStatementCreationEventType = EventType
|
||||
.getEventType( JdbcPreparedStatementCreationEvent.class );
|
||||
private static final EventType jdbcPreparedStatementExecutionEventType = EventType.getEventType(
|
||||
JdbcPreparedStatementExecutionEvent.class );
|
||||
private static final EventType jdbcBatchExecutionEventType = EventType.getEventType( JdbcBatchExecutionEvent.class );
|
||||
private static final EventType cachePutEventType = EventType.getEventType( CachePutEvent.class );
|
||||
private static final EventType cacheGetEventType = EventType.getEventType( CacheGetEvent.class );
|
||||
private static final EventType flushEventType = EventType.getEventType( FlushEvent.class );
|
||||
private static final EventType partialFlushEventType = EventType.getEventType( PartialFlushEvent.class );
|
||||
private static final EventType dirtyCalculationEventType = EventType.getEventType( DirtyCalculationEvent.class );
|
||||
|
||||
@Override
|
||||
public SessionOpenEvent beginSessionOpenEvent() {
|
||||
if ( eventType.isEnabled() ) {
|
||||
if ( sessionOpenEventType.isEnabled() ) {
|
||||
final SessionOpenEvent sessionOpenEvent = new SessionOpenEvent();
|
||||
sessionOpenEvent.begin();
|
||||
return sessionOpenEvent;
|
||||
|
@ -57,19 +72,22 @@ public class JfrEventManager implements EventManager {
|
|||
|
||||
@Override
|
||||
public SessionClosedEvent beginSessionClosedEvent() {
|
||||
if ( sessionClosedEventType.isEnabled() ) {
|
||||
final SessionClosedEvent sessionClosedEvent = new SessionClosedEvent();
|
||||
if ( sessionClosedEvent.isEnabled() ) {
|
||||
sessionClosedEvent.begin();
|
||||
}
|
||||
return sessionClosedEvent;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeSessionClosedEvent(
|
||||
HibernateEvent event,
|
||||
SharedSessionContractImplementor session) {
|
||||
if ( event != null ) {
|
||||
final SessionClosedEvent sessionClosedEvent = (SessionClosedEvent) event;
|
||||
if ( sessionClosedEvent.isEnabled() ) {
|
||||
sessionClosedEvent.end();
|
||||
if ( sessionClosedEvent.shouldCommit() ) {
|
||||
sessionClosedEvent.sessionIdentifier = getSessionIdentifier( session );
|
||||
|
@ -80,21 +98,24 @@ public class JfrEventManager implements EventManager {
|
|||
|
||||
@Override
|
||||
public JdbcConnectionAcquisitionEvent beginJdbcConnectionAcquisitionEvent() {
|
||||
if ( jdbcConnectionAcquisitionEventType.isEnabled() ) {
|
||||
final JdbcConnectionAcquisitionEvent jdbcConnectionAcquisitionEvent = new JdbcConnectionAcquisitionEvent();
|
||||
if ( jdbcConnectionAcquisitionEvent.isEnabled() ) {
|
||||
jdbcConnectionAcquisitionEvent.begin();
|
||||
jdbcConnectionAcquisitionEvent.startedAt = System.nanoTime();
|
||||
}
|
||||
return jdbcConnectionAcquisitionEvent;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeJdbcConnectionAcquisitionEvent(
|
||||
HibernateEvent event,
|
||||
SharedSessionContractImplementor session,
|
||||
Object tenantId) {
|
||||
if ( event != null ) {
|
||||
final JdbcConnectionAcquisitionEvent jdbcConnectionAcquisitionEvent = (JdbcConnectionAcquisitionEvent) event;
|
||||
if ( jdbcConnectionAcquisitionEvent.isEnabled() ) {
|
||||
jdbcConnectionAcquisitionEvent.end();
|
||||
if ( jdbcConnectionAcquisitionEvent.shouldCommit() ) {
|
||||
jdbcConnectionAcquisitionEvent.executionTime = getExecutionTime( jdbcConnectionAcquisitionEvent.startedAt );
|
||||
|
@ -109,21 +130,24 @@ public class JfrEventManager implements EventManager {
|
|||
|
||||
@Override
|
||||
public JdbcConnectionReleaseEvent beginJdbcConnectionReleaseEvent() {
|
||||
if ( jdbcConnectionReleaseEventType.isEnabled() ) {
|
||||
final JdbcConnectionReleaseEvent jdbcConnectionReleaseEvent = new JdbcConnectionReleaseEvent();
|
||||
if ( jdbcConnectionReleaseEvent.isEnabled() ) {
|
||||
jdbcConnectionReleaseEvent.begin();
|
||||
jdbcConnectionReleaseEvent.startedAt = System.nanoTime();
|
||||
}
|
||||
return jdbcConnectionReleaseEvent;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeJdbcConnectionReleaseEvent(
|
||||
HibernateEvent event,
|
||||
SharedSessionContractImplementor session,
|
||||
Object tenantId) {
|
||||
if ( event != null ) {
|
||||
final JdbcConnectionReleaseEvent jdbcConnectionReleaseEvent = (JdbcConnectionReleaseEvent) event;
|
||||
if ( jdbcConnectionReleaseEvent.isEnabled() ) {
|
||||
jdbcConnectionReleaseEvent.end();
|
||||
if ( jdbcConnectionReleaseEvent.shouldCommit() ) {
|
||||
jdbcConnectionReleaseEvent.executionTime = getExecutionTime( jdbcConnectionReleaseEvent.startedAt );
|
||||
|
@ -138,20 +162,23 @@ public class JfrEventManager implements EventManager {
|
|||
|
||||
@Override
|
||||
public JdbcPreparedStatementCreationEvent beginJdbcPreparedStatementCreationEvent() {
|
||||
if ( jdbcPreparedStatementCreationEventType.isEnabled() ) {
|
||||
final JdbcPreparedStatementCreationEvent jdbcPreparedStatementCreation = new JdbcPreparedStatementCreationEvent();
|
||||
if ( jdbcPreparedStatementCreation.isEnabled() ) {
|
||||
jdbcPreparedStatementCreation.begin();
|
||||
jdbcPreparedStatementCreation.startedAt = System.nanoTime();
|
||||
}
|
||||
return jdbcPreparedStatementCreation;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeJdbcPreparedStatementCreationEvent(
|
||||
HibernateEvent event,
|
||||
String preparedStatementSql) {
|
||||
if ( event != null ) {
|
||||
final JdbcPreparedStatementCreationEvent jdbcPreparedStatementCreation = (JdbcPreparedStatementCreationEvent) event;
|
||||
if ( jdbcPreparedStatementCreation.isEnabled() ) {
|
||||
jdbcPreparedStatementCreation.end();
|
||||
if ( jdbcPreparedStatementCreation.shouldCommit() ) {
|
||||
jdbcPreparedStatementCreation.executionTime = getExecutionTime( jdbcPreparedStatementCreation.startedAt );
|
||||
|
@ -163,20 +190,23 @@ public class JfrEventManager implements EventManager {
|
|||
|
||||
@Override
|
||||
public JdbcPreparedStatementExecutionEvent beginJdbcPreparedStatementExecutionEvent() {
|
||||
if ( jdbcPreparedStatementExecutionEventType.isEnabled() ) {
|
||||
final JdbcPreparedStatementExecutionEvent jdbcPreparedStatementExecutionEvent = new JdbcPreparedStatementExecutionEvent();
|
||||
if ( jdbcPreparedStatementExecutionEvent.isEnabled() ) {
|
||||
jdbcPreparedStatementExecutionEvent.begin();
|
||||
jdbcPreparedStatementExecutionEvent.startedAt = System.nanoTime();
|
||||
}
|
||||
return jdbcPreparedStatementExecutionEvent;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeJdbcPreparedStatementExecutionEvent(
|
||||
HibernateEvent event,
|
||||
String preparedStatementSql) {
|
||||
if ( event != null ) {
|
||||
final JdbcPreparedStatementExecutionEvent jdbcPreparedStatementExecutionEvent = (JdbcPreparedStatementExecutionEvent) event;
|
||||
if ( jdbcPreparedStatementExecutionEvent.isEnabled() ) {
|
||||
jdbcPreparedStatementExecutionEvent.end();
|
||||
if ( jdbcPreparedStatementExecutionEvent.shouldCommit() ) {
|
||||
jdbcPreparedStatementExecutionEvent.executionTime = getExecutionTime(
|
||||
|
@ -189,20 +219,23 @@ public class JfrEventManager implements EventManager {
|
|||
|
||||
@Override
|
||||
public JdbcBatchExecutionEvent beginJdbcBatchExecutionEvent() {
|
||||
if ( jdbcBatchExecutionEventType.isEnabled() ) {
|
||||
final JdbcBatchExecutionEvent jdbcBatchExecutionEvent = new JdbcBatchExecutionEvent();
|
||||
if ( jdbcBatchExecutionEvent.isEnabled() ) {
|
||||
jdbcBatchExecutionEvent.begin();
|
||||
jdbcBatchExecutionEvent.startedAt = System.nanoTime();
|
||||
}
|
||||
return jdbcBatchExecutionEvent;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeJdbcBatchExecutionEvent(
|
||||
HibernateEvent event,
|
||||
String statementSql) {
|
||||
if ( event != null ) {
|
||||
final JdbcBatchExecutionEvent jdbcBatchExecutionEvent = (JdbcBatchExecutionEvent) event;
|
||||
if ( jdbcBatchExecutionEvent.isEnabled() ) {
|
||||
jdbcBatchExecutionEvent.end();
|
||||
if ( jdbcBatchExecutionEvent.shouldCommit() ) {
|
||||
jdbcBatchExecutionEvent.executionTime = getExecutionTime( jdbcBatchExecutionEvent.startedAt );
|
||||
|
@ -214,13 +247,16 @@ public class JfrEventManager implements EventManager {
|
|||
|
||||
@Override
|
||||
public HibernateEvent beginCachePutEvent() {
|
||||
if ( cachePutEventType.isEnabled() ) {
|
||||
final CachePutEvent cachePutEvent = new CachePutEvent();
|
||||
if ( cachePutEvent.isEnabled() ) {
|
||||
cachePutEvent.begin();
|
||||
cachePutEvent.startedAt = System.nanoTime();
|
||||
}
|
||||
return cachePutEvent;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeCachePutEvent(
|
||||
|
@ -229,8 +265,8 @@ public class JfrEventManager implements EventManager {
|
|||
Region region,
|
||||
boolean cacheContentChanged,
|
||||
CacheActionDescription description) {
|
||||
if ( event != null ) {
|
||||
final CachePutEvent cachePutEvent = (CachePutEvent) event;
|
||||
if ( cachePutEvent.isEnabled() ) {
|
||||
cachePutEvent.end();
|
||||
if ( cachePutEvent.shouldCommit() ) {
|
||||
cachePutEvent.executionTime = getExecutionTime( cachePutEvent.startedAt );
|
||||
|
@ -271,8 +307,8 @@ public class JfrEventManager implements EventManager {
|
|||
boolean cacheContentChanged,
|
||||
boolean isNatualId,
|
||||
CacheActionDescription description) {
|
||||
if ( event != null ) {
|
||||
final CachePutEvent cachePutEvent = (CachePutEvent) event;
|
||||
if ( cachePutEvent.isEnabled() ) {
|
||||
cachePutEvent.end();
|
||||
if ( cachePutEvent.shouldCommit() ) {
|
||||
cachePutEvent.executionTime = getExecutionTime( cachePutEvent.startedAt );
|
||||
|
@ -295,8 +331,8 @@ public class JfrEventManager implements EventManager {
|
|||
CollectionPersister persister,
|
||||
boolean cacheContentChanged,
|
||||
CacheActionDescription description) {
|
||||
if ( event != null ) {
|
||||
final CachePutEvent cachePutEvent = (CachePutEvent) event;
|
||||
if ( cachePutEvent.isEnabled() ) {
|
||||
cachePutEvent.end();
|
||||
if ( cachePutEvent.shouldCommit() ) {
|
||||
cachePutEvent.executionTime = getExecutionTime( cachePutEvent.startedAt );
|
||||
|
@ -312,13 +348,16 @@ public class JfrEventManager implements EventManager {
|
|||
|
||||
@Override
|
||||
public HibernateEvent beginCacheGetEvent() {
|
||||
if ( cacheGetEventType.isEnabled() ) {
|
||||
final CacheGetEvent cacheGetEvent = new CacheGetEvent();
|
||||
if ( cacheGetEvent.isEnabled() ) {
|
||||
cacheGetEvent.begin();
|
||||
cacheGetEvent.startedAt = System.nanoTime();
|
||||
}
|
||||
return cacheGetEvent;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeCacheGetEvent(
|
||||
|
@ -326,8 +365,8 @@ public class JfrEventManager implements EventManager {
|
|||
SharedSessionContractImplementor session,
|
||||
Region region,
|
||||
boolean hit) {
|
||||
if ( event != null ) {
|
||||
final CacheGetEvent cacheGetEvent = (CacheGetEvent) event;
|
||||
if ( cacheGetEvent.isEnabled() ) {
|
||||
cacheGetEvent.end();
|
||||
if ( cacheGetEvent.shouldCommit() ) {
|
||||
cacheGetEvent.executionTime = getExecutionTime( cacheGetEvent.startedAt );
|
||||
|
@ -347,8 +386,8 @@ public class JfrEventManager implements EventManager {
|
|||
EntityPersister persister,
|
||||
boolean isNaturalKey,
|
||||
boolean hit) {
|
||||
if ( event != null ) {
|
||||
final CacheGetEvent cacheGetEvent = (CacheGetEvent) event;
|
||||
if ( cacheGetEvent.isEnabled() ) {
|
||||
cacheGetEvent.end();
|
||||
if ( cacheGetEvent.shouldCommit() ) {
|
||||
cacheGetEvent.executionTime = getExecutionTime( cacheGetEvent.startedAt );
|
||||
|
@ -369,8 +408,8 @@ public class JfrEventManager implements EventManager {
|
|||
Region region,
|
||||
CollectionPersister persister,
|
||||
boolean hit) {
|
||||
if ( event != null ) {
|
||||
final CacheGetEvent cacheGetEvent = (CacheGetEvent) event;
|
||||
if ( cacheGetEvent.isEnabled() ) {
|
||||
cacheGetEvent.end();
|
||||
if ( cacheGetEvent.shouldCommit() ) {
|
||||
cacheGetEvent.executionTime = getExecutionTime( cacheGetEvent.startedAt );
|
||||
|
@ -385,13 +424,16 @@ public class JfrEventManager implements EventManager {
|
|||
|
||||
@Override
|
||||
public FlushEvent beginFlushEvent() {
|
||||
if ( flushEventType.isEnabled() ) {
|
||||
final FlushEvent flushEvent = new FlushEvent();
|
||||
if ( flushEvent.isEnabled() ) {
|
||||
flushEvent.begin();
|
||||
flushEvent.startedAt = System.nanoTime();
|
||||
}
|
||||
return flushEvent;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeFlushEvent(
|
||||
|
@ -405,8 +447,8 @@ public class JfrEventManager implements EventManager {
|
|||
HibernateEvent hibernateEvent,
|
||||
org.hibernate.event.spi.FlushEvent event,
|
||||
boolean autoFlush) {
|
||||
if ( hibernateEvent != null ) {
|
||||
final FlushEvent flushEvent = (FlushEvent) hibernateEvent;
|
||||
if ( flushEvent.isEnabled() ) {
|
||||
flushEvent.end();
|
||||
if ( flushEvent.shouldCommit() ) {
|
||||
flushEvent.executionTime = getExecutionTime( flushEvent.startedAt );
|
||||
|
@ -422,20 +464,23 @@ public class JfrEventManager implements EventManager {
|
|||
|
||||
@Override
|
||||
public PartialFlushEvent beginPartialFlushEvent() {
|
||||
if ( partialFlushEventType.isEnabled() ) {
|
||||
final PartialFlushEvent partialFlushEvent = new PartialFlushEvent();
|
||||
if ( partialFlushEvent.isEnabled() ) {
|
||||
partialFlushEvent.startedAt = System.nanoTime();
|
||||
partialFlushEvent.begin();
|
||||
}
|
||||
return partialFlushEvent;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completePartialFlushEvent(
|
||||
HibernateEvent hibernateEvent,
|
||||
AutoFlushEvent event) {
|
||||
if ( event != null ) {
|
||||
final PartialFlushEvent flushEvent = (PartialFlushEvent) hibernateEvent;
|
||||
if ( flushEvent.isEnabled() ) {
|
||||
flushEvent.end();
|
||||
if ( flushEvent.shouldCommit() ) {
|
||||
flushEvent.executionTime = getExecutionTime( flushEvent.startedAt );
|
||||
|
@ -451,13 +496,16 @@ public class JfrEventManager implements EventManager {
|
|||
|
||||
@Override
|
||||
public DirtyCalculationEvent beginDirtyCalculationEvent() {
|
||||
if ( dirtyCalculationEventType.isEnabled() ) {
|
||||
final DirtyCalculationEvent dirtyCalculationEvent = new DirtyCalculationEvent();
|
||||
if ( dirtyCalculationEvent.isEnabled() ) {
|
||||
dirtyCalculationEvent.startedAt = System.nanoTime();
|
||||
dirtyCalculationEvent.begin();
|
||||
}
|
||||
return dirtyCalculationEvent;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeDirtyCalculationEvent(
|
||||
|
@ -466,8 +514,8 @@ public class JfrEventManager implements EventManager {
|
|||
EntityPersister persister,
|
||||
EntityEntry entry,
|
||||
int[] dirtyProperties) {
|
||||
if ( event != null ) {
|
||||
final DirtyCalculationEvent dirtyCalculationEvent = (DirtyCalculationEvent) event;
|
||||
if ( dirtyCalculationEvent.isEnabled() ) {
|
||||
dirtyCalculationEvent.end();
|
||||
if ( dirtyCalculationEvent.shouldCommit() ) {
|
||||
dirtyCalculationEvent.executionTime = getExecutionTime( dirtyCalculationEvent.startedAt );
|
||||
|
|
|
@ -31,7 +31,7 @@ public class PartialFlushEvent extends Event implements HibernateEvent {
|
|||
@Label( "Number Of Processed Entities" )
|
||||
public int numberOfEntitiesProcessed;
|
||||
|
||||
@Label( "Number Of Processed Collectionc" )
|
||||
@Label( "Number Of Processed Collections" )
|
||||
public int numberOfCollectionsProcessed;
|
||||
|
||||
@Label( "PartialFlushEvent time" )
|
||||
|
|
|
@ -40,7 +40,7 @@ public class DirtyCalculationEventTests {
|
|||
|
||||
@Test
|
||||
@EnableEvent(DirtyCalculationEvent.NAME)
|
||||
public void testFlushEvent(SessionFactoryScope scope) {
|
||||
public void testDirtyCalculationEvent(SessionFactoryScope scope) {
|
||||
jfrEvents.reset();
|
||||
String sessionId = scope.fromTransaction(
|
||||
session -> {
|
||||
|
|
Loading…
Reference in New Issue