From f6fae83427a4ddb9763b0aba040227f3dfc2e9bc Mon Sep 17 00:00:00 2001 From: Chihiro Ito Date: Fri, 5 Apr 2024 18:26:48 +0900 Subject: [PATCH] Refactoring a lot --- artifact-test/pom.xml | 51 +- ...iveImageTest.java => DemoApplication.java} | 20 +- .../dev/jfr4jdbc/sample/DemoApplication.java | 95 ---- artifact-test/src/main/java/module-info.java | 2 +- .../{sample => artifact}/ModuleTest.java | 2 +- .../ReleaseJarTest.java} | 54 +- .../ServiceLoaderTest.java | 9 +- artifact-test/src/test/java/module-info.java | 2 +- bin/test.sh | 4 +- jdbc42/pom.xml | 51 -- .../main/java/dev/jfr4jdbc/JfrConnection.java | 30 - .../main/java/dev/jfr4jdbc/JfrDataSource.java | 24 - .../main/java/dev/jfr4jdbc/JfrStatement.java | 21 - .../interceptor/ResourceMonitorContext.java | 25 - .../impl/ResourceMonitorInterceptor.java | 22 - .../instant/InstantCancelInterceptor.java | 43 -- .../impl/instant/InstantCloseInterceptor.java | 43 -- .../instant/InstantCommitInterceptor.java | 43 -- .../instant/InstantDataSourceInterceptor.java | 45 -- .../instant/InstantDriverInterceptor.java | 43 -- .../instant/InstantResultSetInterceptor.java | 45 -- .../instant/InstantRollbackInterceptor.java | 43 -- .../instant/InstantStatementInterceptor.java | 56 -- .../impl/period/PeriodCancelInterceptor.java | 33 -- .../impl/period/PeriodCloseInterceptor.java | 33 -- .../impl/period/PeriodCommitInterceptor.java | 33 -- .../period/PeriodDataSourceInterceptor.java | 35 -- .../impl/period/PeriodDriverInterceptor.java | 34 -- .../impl/period/PeriodInterceptorFactory.java | 51 -- .../period/PeriodResultSetInterceptor.java | 35 -- .../period/PeriodRollbackInterceptor.java | 33 -- .../period/PeriodStatementInterceptor.java | 40 -- jdbc43/pom.xml | 42 -- .../main/java/dev/jfr4jdbc/JfrConnection.java | 31 - .../java/dev/jfr4jdbc/JfrConnection43.java | 68 --- .../main/java/dev/jfr4jdbc/JfrDataSource.java | 24 - .../java/dev/jfr4jdbc/JfrDataSource43.java | 37 -- .../main/java/dev/jfr4jdbc/JfrStatement.java | 22 - .../java/dev/jfr4jdbc/JfrStatement43.java | 43 -- .../java/dev/jfr4jdbc/JfrConnectionTest.java | 85 --- .../java/dev/jfr4jdbc/JfrDataSourceTest.java | 40 -- .../java/dev/jfr4jdbc/JfrStatementTest.java | 66 --- jfr4jdbc-driver/pom.xml | 140 ++--- .../main/java/dev/jfr4jdbc/ConnectionId.java | 0 .../java/dev/jfr4jdbc/DataSourceLabel.java | 0 .../main/java/dev/jfr4jdbc/EventFactory.java | 2 + .../java/dev/jfr4jdbc/Jfr4JdbcException.java | 0 .../java/dev/jfr4jdbc/Jfr4JdbcMetrics.java | 14 + .../jfr4jdbc/Jfr4JdbcRuntimeException.java | 0 .../dev/jfr4jdbc/JfrCallableStatement.java | 4 +- .../main/java/dev/jfr4jdbc/JfrConnection.java | 104 ++-- .../main/java/dev/jfr4jdbc/JfrDataSource.java | 70 +-- .../src/main/java/dev/jfr4jdbc/JfrDriver.java | 24 +- .../dev/jfr4jdbc/JfrPreparedStatement.java | 4 +- .../main/java/dev/jfr4jdbc/JfrResultSet.java | 18 +- .../dev/jfr4jdbc/JfrServiceLoadedDriver.java | 51 +- .../main/java/dev/jfr4jdbc/JfrStatement.java | 75 ++- .../java/dev/jfr4jdbc/ResourceMetrics.java | 0 .../dev/jfr4jdbc/WrappedConnectionId.java | 0 .../java/dev/jfr4jdbc/event/CancelEvent.java | 0 .../java/dev/jfr4jdbc/event/CloseEvent.java | 0 .../java/dev/jfr4jdbc/event/CommitEvent.java | 0 .../java/dev/jfr4jdbc/event/ConnectEvent.java | 0 .../java/dev/jfr4jdbc/event/JdbcEvent.java | 0 .../dev/jfr4jdbc/event/ResultSetEvent.java | 0 .../dev/jfr4jdbc/event/RollbackEvent.java | 0 .../dev/jfr4jdbc/event/StatementEvent.java | 0 .../jfr4jdbc/event/jfr/JfrCancelEvent.java | 0 .../dev/jfr4jdbc/event/jfr/JfrCloseEvent.java | 0 .../jfr4jdbc/event/jfr/JfrCommitEvent.java | 0 .../event/jfr/JfrConnectionEvent.java | 0 .../dev/jfr4jdbc/event/jfr/JfrJdbcEvent.java | 0 .../jfr4jdbc/event/jfr/JfrResultSetEvent.java | 0 .../jfr4jdbc/event/jfr/JfrRollbackEvent.java | 0 .../jfr4jdbc/event/jfr/JfrStatementEvent.java | 0 .../jfr4jdbc/interceptor/CancelContext.java | 11 +- .../jfr4jdbc/interceptor/CloseContext.java | 11 +- .../jfr4jdbc/interceptor/CommitContext.java | 11 +- .../jfr4jdbc/interceptor}/ConnectionInfo.java | 2 +- .../interceptor/DataSourceContext.java | 18 +- .../jfr4jdbc/interceptor/DriverContext.java | 13 +- .../dev/jfr4jdbc/interceptor/Interceptor.java | 0 .../interceptor/InterceptorFactory.java | 4 +- .../interceptor/InterceptorManager.java | 16 +- .../jfr4jdbc/interceptor}/OperationInfo.java | 2 +- .../interceptor/ResultSetContext.java | 11 +- .../jfr4jdbc/interceptor/RollbackContext.java | 11 +- .../interceptor/StatementContext.java | 11 +- .../legacy/LegacyCancelInterceptor.java | 2 +- .../legacy/LegacyCloseInterceptor.java | 2 +- .../legacy/LegacyCommitInterceptor.java | 2 +- .../legacy/LegacyDataSourceInterceptor.java | 5 +- .../legacy/LegacyDriverInterceptor.java | 2 +- .../legacy/LegacyInterceptorFactory.java | 8 +- .../legacy/LegacyResultSetInterceptor.java | 2 +- .../legacy/LegacyRollbackInterceptor.java | 2 +- .../legacy/LegacyStatementInterceptor.java | 2 +- .../interceptor/std/CancelInterceptor.java | 60 ++ .../interceptor/std/CloseInterceptor.java | 60 ++ .../interceptor/std/CommitInterceptor.java | 60 ++ .../std/DataSourceInterceptor.java | 64 +++ .../std/DefaultInterceptorFactory.java | 26 +- .../interceptor/std/DriverInterceptor.java | 61 ++ .../interceptor/std/ResultSetInterceptor.java | 64 +++ .../interceptor/std/RollbackInterceptor.java | 60 ++ .../interceptor/std/StatementInterceptor.java | 80 +++ .../std/event}/CancelEndEvent.java | 13 +- .../std/event/CancelPeriodEvent.java | 12 +- .../std/event}/CancelStartEvent.java | 11 +- .../interceptor/std/event}/CloseEndEvent.java | 13 +- .../std/event/ClosePeriodEvent.java | 13 +- .../std/event}/CloseStartEvent.java | 11 +- .../std/event}/CommitEndEvent.java | 13 +- .../std/event/CommitPeriodEvent.java | 13 +- .../std/event}/CommitStartEvent.java | 11 +- .../std/event}/DataSourceEndEvent.java | 13 +- .../std/event/DataSourcePeriodEvent.java | 12 +- .../std/event}/DataSourceStartEvent.java | 11 +- .../std/event}/DriverEndEvent.java | 15 +- .../std/event/DriverPeriodEvent.java | 14 +- .../std/event}/DriverStartEvent.java | 13 +- .../std/event}/ResultSetEndEvent.java | 13 +- .../std/event/ResultSetPeriodEvent.java | 14 +- .../std/event}/ResultSetStartEvent.java | 11 +- .../std/event}/RollbackEndEvent.java | 13 +- .../std/event/RollbackPeriodEvent.java | 12 +- .../std/event}/RollbackStartEvent.java | 11 +- .../std/event}/StatementEndEvent.java | 13 +- .../std/event/StatementPeriodEvent.java | 12 +- .../std/event}/StatementStartEvent.java | 11 +- .../java/dev/jfr4jdbc/internal/Jfr4Jdbc.java | 0 .../internal/JfrConnectionResourceEvent.java | 0 .../jfr4jdbc/internal/JfrResourceWriter.java | 0 .../java/dev/jfr4jdbc/internal/Label.java | 0 .../jfr4jdbc/internal/ResourceMonitor.java | 2 - .../internal/ResourceMonitorManager.java | 3 +- .../StillUnassignedConnectionInfo.java | 12 + .../src/main/java/module-info.java | 8 +- .../META-INF/services/java.sql.Driver | 0 .../java/dev/jfr4jdbc/FlightRecording.java | 2 +- .../Jfr4JdbcTestRuntimeException.java | 0 .../dev/jfr4jdbc/Jfr4jdbcTestException.java | 0 .../jfr4jdbc/JfrCallableStatementTest.java | 0 .../java/dev/jfr4jdbc/JfrConnectionTest.java | 10 +- .../java/dev/jfr4jdbc/JfrDataSourceTest.java | 26 +- .../test/java/dev/jfr4jdbc/JfrDriverTest.java | 25 +- .../jfr4jdbc/JfrPreparedStatementTest.java | 3 - .../dev/jfr4jdbc}/JfrResourceMonitorTest.java | 15 +- .../java/dev/jfr4jdbc/JfrResultSetTest.java | 9 +- .../java/dev/jfr4jdbc/JfrStatementTest.java | 3 - .../test/java/dev/jfr4jdbc/LinkageIdTest.java | 4 - .../src/test/java/dev/jfr4jdbc/MockJDBC.java | 0 .../test/java/dev/jfr4jdbc/OneStopTest.java | 2 - .../test/java/dev/jfr4jdbc/ParameterTest.java | 3 - .../jfr4jdbc/interceptor/InterceptorTest.java | 538 ++++++++++++++++++ .../jfr4jdbc/interceptor/JfrTestHelper.java | 28 + .../jfr4jdbc/interceptor/MockInterceptor.java | 18 +- .../interceptor/MockInterceptorFactory.java | 9 +- .../test/resources/junit-platform.properties | 0 159 files changed, 1736 insertions(+), 2029 deletions(-) rename artifact-test/src/main/java/dev/jfr4jdbc/artifact/{NativeImageTest.java => DemoApplication.java} (71%) delete mode 100644 artifact-test/src/main/java/dev/jfr4jdbc/sample/DemoApplication.java rename artifact-test/src/test/java/dev/jfr4jdbc/{sample => artifact}/ModuleTest.java (96%) rename artifact-test/src/test/java/dev/jfr4jdbc/{sample/MultiReleaseJarTest.java => artifact/ReleaseJarTest.java} (63%) rename artifact-test/src/test/java/dev/jfr4jdbc/{sample => artifact}/ServiceLoaderTest.java (64%) delete mode 100644 jdbc42/pom.xml delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/JfrConnection.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/JfrDataSource.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/JfrStatement.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/ResourceMonitorContext.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/ResourceMonitorInterceptor.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantCancelInterceptor.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantCloseInterceptor.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantCommitInterceptor.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantDataSourceInterceptor.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantDriverInterceptor.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantResultSetInterceptor.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantRollbackInterceptor.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantStatementInterceptor.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCancelInterceptor.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCloseInterceptor.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCommitInterceptor.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodDataSourceInterceptor.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodDriverInterceptor.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodInterceptorFactory.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodResultSetInterceptor.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodRollbackInterceptor.java delete mode 100644 jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodStatementInterceptor.java delete mode 100644 jdbc43/pom.xml delete mode 100644 jdbc43/src/main/java/dev/jfr4jdbc/JfrConnection.java delete mode 100644 jdbc43/src/main/java/dev/jfr4jdbc/JfrConnection43.java delete mode 100644 jdbc43/src/main/java/dev/jfr4jdbc/JfrDataSource.java delete mode 100644 jdbc43/src/main/java/dev/jfr4jdbc/JfrDataSource43.java delete mode 100644 jdbc43/src/main/java/dev/jfr4jdbc/JfrStatement.java delete mode 100644 jdbc43/src/main/java/dev/jfr4jdbc/JfrStatement43.java delete mode 100644 jdbc43/src/test/java/dev/jfr4jdbc/JfrConnectionTest.java delete mode 100644 jdbc43/src/test/java/dev/jfr4jdbc/JfrDataSourceTest.java delete mode 100644 jdbc43/src/test/java/dev/jfr4jdbc/JfrStatementTest.java rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/ConnectionId.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/DataSourceLabel.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/EventFactory.java (98%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/Jfr4JdbcException.java (100%) create mode 100644 jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/Jfr4JdbcMetrics.java rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/Jfr4JdbcRuntimeException.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/JfrCallableStatement.java (99%) rename jdbc42/src/main/java/dev/jfr4jdbc/JfrConnection42.java => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrConnection.java (88%) rename jdbc42/src/main/java/dev/jfr4jdbc/JfrDataSource42.java => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrDataSource.java (75%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/JfrDriver.java (78%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/JfrPreparedStatement.java (99%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/JfrResultSet.java (99%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/JfrServiceLoadedDriver.java (86%) rename jdbc42/src/main/java/dev/jfr4jdbc/JfrStatement42.java => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrStatement.java (93%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/ResourceMetrics.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/WrappedConnectionId.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/event/CancelEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/event/CloseEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/event/CommitEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/event/ConnectEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/event/JdbcEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/event/ResultSetEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/event/RollbackEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/event/StatementEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/event/jfr/JfrCancelEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/event/jfr/JfrCloseEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/event/jfr/JfrCommitEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/event/jfr/JfrConnectionEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/event/jfr/JfrJdbcEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/event/jfr/JfrResultSetEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/event/jfr/JfrRollbackEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/event/jfr/JfrStatementEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/interceptor/CancelContext.java (89%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/interceptor/CloseContext.java (87%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/interceptor/CommitContext.java (88%) rename {jdbc42/src/main/java/dev/jfr4jdbc/internal => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor}/ConnectionInfo.java (97%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/interceptor/DataSourceContext.java (68%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/interceptor/DriverContext.java (61%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/interceptor/Interceptor.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/interceptor/InterceptorFactory.java (87%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/interceptor/InterceptorManager.java (65%) rename {jdbc42/src/main/java/dev/jfr4jdbc/internal => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor}/OperationInfo.java (95%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/interceptor/ResultSetContext.java (91%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/interceptor/RollbackContext.java (88%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/interceptor/StatementContext.java (95%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor}/legacy/LegacyCancelInterceptor.java (94%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor}/legacy/LegacyCloseInterceptor.java (94%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor}/legacy/LegacyCommitInterceptor.java (94%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor}/legacy/LegacyDataSourceInterceptor.java (96%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor}/legacy/LegacyDriverInterceptor.java (95%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor}/legacy/LegacyInterceptorFactory.java (86%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor}/legacy/LegacyResultSetInterceptor.java (95%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor}/legacy/LegacyRollbackInterceptor.java (94%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor}/legacy/LegacyStatementInterceptor.java (96%) create mode 100644 jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/CancelInterceptor.java create mode 100644 jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/CloseInterceptor.java create mode 100644 jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/CommitInterceptor.java create mode 100644 jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/DataSourceInterceptor.java rename jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantInterceptorFactory.java => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/DefaultInterceptorFactory.java (51%) create mode 100644 jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/DriverInterceptor.java create mode 100644 jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/ResultSetInterceptor.java create mode 100644 jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/RollbackInterceptor.java create mode 100644 jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/StatementInterceptor.java rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event}/CancelEndEvent.java (73%) rename jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCancelEvent.java => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CancelPeriodEvent.java (70%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event}/CancelStartEvent.java (68%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event}/CloseEndEvent.java (73%) rename jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCloseEvent.java => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/ClosePeriodEvent.java (70%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event}/CloseStartEvent.java (69%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event}/CommitEndEvent.java (72%) rename jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCommitEvent.java => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CommitPeriodEvent.java (70%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event}/CommitStartEvent.java (68%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event}/DataSourceEndEvent.java (72%) rename jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodDataSourceEvent.java => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DataSourcePeriodEvent.java (69%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event}/DataSourceStartEvent.java (61%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event}/DriverEndEvent.java (63%) rename jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodDriverEvent.java => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DriverPeriodEvent.java (59%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event}/DriverStartEvent.java (53%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event}/ResultSetEndEvent.java (74%) rename jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodResultSetEvent.java => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/ResultSetPeriodEvent.java (71%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event}/ResultSetStartEvent.java (67%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event}/RollbackEndEvent.java (72%) rename jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodRollbackEvent.java => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/RollbackPeriodEvent.java (69%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event}/RollbackStartEvent.java (67%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event}/StatementEndEvent.java (79%) rename jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodStatementEvent.java => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/StatementPeriodEvent.java (78%) rename {jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant => jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event}/StatementStartEvent.java (77%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/internal/Jfr4Jdbc.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/internal/JfrConnectionResourceEvent.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/internal/JfrResourceWriter.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/internal/Label.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/internal/ResourceMonitor.java (94%) rename {jdbc42 => jfr4jdbc-driver}/src/main/java/dev/jfr4jdbc/internal/ResourceMonitorManager.java (99%) create mode 100644 jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/StillUnassignedConnectionInfo.java rename {jdbc42 => jfr4jdbc-driver}/src/main/resources/META-INF/services/java.sql.Driver (100%) rename {jdbc42 => jfr4jdbc-driver}/src/test/java/dev/jfr4jdbc/FlightRecording.java (97%) rename {jdbc42 => jfr4jdbc-driver}/src/test/java/dev/jfr4jdbc/Jfr4JdbcTestRuntimeException.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/test/java/dev/jfr4jdbc/Jfr4jdbcTestException.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/test/java/dev/jfr4jdbc/JfrCallableStatementTest.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/test/java/dev/jfr4jdbc/JfrConnectionTest.java (99%) rename {jdbc42 => jfr4jdbc-driver}/src/test/java/dev/jfr4jdbc/JfrDataSourceTest.java (93%) rename {jdbc42 => jfr4jdbc-driver}/src/test/java/dev/jfr4jdbc/JfrDriverTest.java (89%) rename {jdbc42 => jfr4jdbc-driver}/src/test/java/dev/jfr4jdbc/JfrPreparedStatementTest.java (99%) rename {jdbc42/src/test/java/dev/jfr4jdbc/internal => jfr4jdbc-driver/src/test/java/dev/jfr4jdbc}/JfrResourceMonitorTest.java (91%) rename {jdbc42 => jfr4jdbc-driver}/src/test/java/dev/jfr4jdbc/JfrResultSetTest.java (99%) rename {jdbc42 => jfr4jdbc-driver}/src/test/java/dev/jfr4jdbc/JfrStatementTest.java (99%) rename {jdbc42 => jfr4jdbc-driver}/src/test/java/dev/jfr4jdbc/LinkageIdTest.java (95%) rename {jdbc42 => jfr4jdbc-driver}/src/test/java/dev/jfr4jdbc/MockJDBC.java (100%) rename {jdbc42 => jfr4jdbc-driver}/src/test/java/dev/jfr4jdbc/OneStopTest.java (98%) rename {jdbc42 => jfr4jdbc-driver}/src/test/java/dev/jfr4jdbc/ParameterTest.java (96%) create mode 100644 jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/interceptor/InterceptorTest.java create mode 100644 jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/interceptor/JfrTestHelper.java rename {jdbc42 => jfr4jdbc-driver}/src/test/java/dev/jfr4jdbc/interceptor/MockInterceptor.java (60%) rename {jdbc42 => jfr4jdbc-driver}/src/test/java/dev/jfr4jdbc/interceptor/MockInterceptorFactory.java (87%) rename {jdbc42 => jfr4jdbc-driver}/src/test/resources/junit-platform.properties (100%) diff --git a/artifact-test/pom.xml b/artifact-test/pom.xml index 7a53218..b12f9f5 100644 --- a/artifact-test/pom.xml +++ b/artifact-test/pom.xml @@ -13,9 +13,50 @@ 11 11 true + dev.jfr4jdbc.artifact.DemoApplication + + test-java11 + + true + + + + test-java8 + + + + org.apache.maven.plugins + maven-compiler-plugin + + + default-compile + + 1.8 + 1.8 + + module-info.java + + + + + default-testCompile + + 1.8 + 1.8 + + dev/jfr4jdbc/sample/ModuleTest.java + module-info.java + + + + + + + + native @@ -23,7 +64,7 @@ org.graalvm.buildtools native-maven-plugin - 0.9.7.1 + 0.10.1 true @@ -42,7 +83,7 @@ - dev.jfr4jdbc.artifact.NativeImageTest + dev.jfr4jdbc.artifact.DemoApplication --no-fallback --enable-monitoring @@ -79,19 +120,19 @@ org.postgresql postgresql - 42.5.4 + 42.7.3 org.junit.jupiter junit-jupiter-api - 5.9.2 + 5.10.1 test org.junit.jupiter junit-jupiter-engine - 5.9.2 + 5.10.1 test diff --git a/artifact-test/src/main/java/dev/jfr4jdbc/artifact/NativeImageTest.java b/artifact-test/src/main/java/dev/jfr4jdbc/artifact/DemoApplication.java similarity index 71% rename from artifact-test/src/main/java/dev/jfr4jdbc/artifact/NativeImageTest.java rename to artifact-test/src/main/java/dev/jfr4jdbc/artifact/DemoApplication.java index 91a52da..26a200a 100644 --- a/artifact-test/src/main/java/dev/jfr4jdbc/artifact/NativeImageTest.java +++ b/artifact-test/src/main/java/dev/jfr4jdbc/artifact/DemoApplication.java @@ -1,15 +1,26 @@ package dev.jfr4jdbc.artifact; import dev.jfr4jdbc.JfrDataSource; +import jdk.jfr.Recording; import org.postgresql.ds.PGPoolingDataSource; +import java.nio.file.Files; +import java.nio.file.Paths; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.SQLException; + +/* +java -XX:StartFlightRecording=disk=true,dumponexit=true,duration=60s,filename=DemoApp.jfr + */ +public class DemoApplication { -public class NativeImageTest { public static void main(String[] args) throws Exception { + Recording r = new Recording(); + r.start(); + PGPoolingDataSource postgreDs = new PGPoolingDataSource(); String hostname = System.getenv("POSTGRES_HOST"); @@ -30,6 +41,11 @@ public static void main(String[] args) throws Exception { rs.next(); System.out.println(rs.getString("datname")); + } catch (SQLException e) { + e.printStackTrace(); } + + r.stop(); + r.dump(Files.createFile(Paths.get("DemoApp.jfr"))); } -} +} \ No newline at end of file diff --git a/artifact-test/src/main/java/dev/jfr4jdbc/sample/DemoApplication.java b/artifact-test/src/main/java/dev/jfr4jdbc/sample/DemoApplication.java deleted file mode 100644 index 4b7bc42..0000000 --- a/artifact-test/src/main/java/dev/jfr4jdbc/sample/DemoApplication.java +++ /dev/null @@ -1,95 +0,0 @@ -package dev.jfr4jdbc.sample; - -import dev.jfr4jdbc.JfrDataSource; -import dev.jfr4jdbc.interceptor.impl.period.PeriodInterceptorFactory; -import jdk.jfr.Configuration; -import jdk.jfr.Recording; -import org.postgresql.ds.PGPoolingDataSource; - -import javax.sql.DataSource; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -/* -java -XX:StartFlightRecording=disk=true,dumponexit=true,duration=60s,filename=DemoApp.jfr - */ -public class DemoApplication { - - private static final int TASK_NUM = 10; - - public static void main(String[] args) throws Exception { - - Configuration c = Configuration.getConfiguration("default"); - Recording r = new Recording(c); - r.start(); - - PGPoolingDataSource postgreDs = new PGPoolingDataSource(); - - String hostname = System.getenv("POSTGRES_HOST"); - String password = System.getenv("POSTGRES_PASSWORD"); - - System.out.println("echo POSTGRES_HOST = " + hostname); - System.out.println("echo POSTGRES_PASSWORD = " + password); - - postgreDs.setUrl("jdbc:postgresql://" + hostname + ":5432/postgres"); - postgreDs.setUser("postgres"); - postgreDs.setPassword(password); - - JfrDataSource jfrDs = new JfrDataSource(postgreDs, new PeriodInterceptorFactory()); - List taskList = new ArrayList<>(TASK_NUM); - - ExecutorService executorService = Executors.newFixedThreadPool(2); - for (int i = 0; i < TASK_NUM; i++) { - Task t = new Task(jfrDs); - taskList.add(t); - executorService.submit(t); - } - - while (taskList.stream().filter(Task::isCompleted).count() != TASK_NUM) { - TimeUnit.MILLISECONDS.sleep(100); - } - executorService.shutdownNow(); - - r.stop(); - r.dump(Files.createFile(Paths.get("DemoApp.jfr"))); - } -} - -class Task implements Runnable { - - private volatile boolean completed = false; - - private final DataSource ds; - - public Task(DataSource ds) { - this.ds = ds; - } - - @Override - public void run() { - try (Connection con = this.ds.getConnection(); - PreparedStatement stmt = con.prepareStatement("SELECT datname FROM pg_database"); - ResultSet rs = stmt.executeQuery()) { - - rs.next(); - System.out.println(rs.getString("datname")); - } catch (SQLException e) { - e.printStackTrace(); - } finally { - completed = true; - } - } - - public boolean isCompleted() { - return completed; - } -} diff --git a/artifact-test/src/main/java/module-info.java b/artifact-test/src/main/java/module-info.java index 258bbd2..12df7fc 100644 --- a/artifact-test/src/main/java/module-info.java +++ b/artifact-test/src/main/java/module-info.java @@ -1,5 +1,5 @@ module artifact.app { - requires dev.jfr4jdbc; + requires transitive dev.jfr4jdbc; requires java.naming; requires org.postgresql.jdbc; } \ No newline at end of file diff --git a/artifact-test/src/test/java/dev/jfr4jdbc/sample/ModuleTest.java b/artifact-test/src/test/java/dev/jfr4jdbc/artifact/ModuleTest.java similarity index 96% rename from artifact-test/src/test/java/dev/jfr4jdbc/sample/ModuleTest.java rename to artifact-test/src/test/java/dev/jfr4jdbc/artifact/ModuleTest.java index 5326e39..5ca79e9 100644 --- a/artifact-test/src/test/java/dev/jfr4jdbc/sample/ModuleTest.java +++ b/artifact-test/src/test/java/dev/jfr4jdbc/artifact/ModuleTest.java @@ -1,4 +1,4 @@ -package dev.jfr4jdbc.sample; +package dev.jfr4jdbc.artifact; import dev.jfr4jdbc.JfrDataSource; import org.junit.jupiter.api.DisplayName; diff --git a/artifact-test/src/test/java/dev/jfr4jdbc/sample/MultiReleaseJarTest.java b/artifact-test/src/test/java/dev/jfr4jdbc/artifact/ReleaseJarTest.java similarity index 63% rename from artifact-test/src/test/java/dev/jfr4jdbc/sample/MultiReleaseJarTest.java rename to artifact-test/src/test/java/dev/jfr4jdbc/artifact/ReleaseJarTest.java index 9661b16..cfb9504 100644 --- a/artifact-test/src/test/java/dev/jfr4jdbc/sample/MultiReleaseJarTest.java +++ b/artifact-test/src/test/java/dev/jfr4jdbc/artifact/ReleaseJarTest.java @@ -1,4 +1,4 @@ -package dev.jfr4jdbc.sample; +package dev.jfr4jdbc.artifact; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -10,9 +10,13 @@ import java.util.jar.JarFile; import java.util.zip.ZipEntry; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -public class MultiReleaseJarTest { +public class ReleaseJarTest { + + private final int JAVA_8_VERSION = 52; + private final int JAVA_11_VERSION = 55; private JarFile open() throws IOException { File artifactDir = new File("../jfr4jdbc-driver/target"); @@ -21,13 +25,13 @@ private JarFile open() throws IOException { return new JarFile(files[0]); } - @DisplayName("Multi Release Jar") - @Test - void isMultiRelease() throws Exception { - - JarFile jarFile = open(); - assertTrue(jarFile.isMultiRelease()); - } +// @DisplayName("Multi Release Jar") +// @Test +// void isMultiRelease() throws Exception { +// +// JarFile jarFile = open(); +// assertTrue(!jarFile.isMultiRelease()); +// } @DisplayName("Service Loader File exists") @Test @@ -36,40 +40,26 @@ void hasServiceLoaderFile() throws IOException { assertNotNull(jarFile.getEntry("META-INF/services/java.sql.Driver")); } - @DisplayName("Java 11 Directory exists") - @Test - void hasJava11Directory() throws IOException { - JarFile jarFile = open(); - assertNotNull(jarFile.getEntry("META-INF/versions/11")); - } +// @DisplayName("Java 11 Directory exists") +// @Test +// void hasJava11Directory() throws IOException { +// JarFile jarFile = open(); +// assertNull(jarFile.getEntry("META-INF/versions/11")); +// } @DisplayName("Modular for Java 11") @Test void hasModuleInfo() throws IOException { JarFile jarFile = open(); -// assertNotNull(jarFile.getEntry("META-INF/versions/11/module-info.class")); assertNotNull(jarFile.getEntry("module-info.class")); } - private final int JAVA_8_VERSION = 52; - private final int JAVA_11_VERSION = 55; - - @DisplayName("Classes for JDBC 4.2 exists") + @DisplayName("Jar is compatible with Java 8") @Test - void hasJdbc42() throws IOException { + void isCompatibleWithJava8() throws IOException { JarFile jarFile = open(); assertEquals(JAVA_8_VERSION, readMajorVersion(jarFile, "dev/jfr4jdbc/JfrDataSource.class")); - assertEquals(JAVA_8_VERSION, readMajorVersion(jarFile, "dev/jfr4jdbc/JfrDataSource42.class")); - } - - @DisplayName("Classes for JDBC 4.3 exists") - @Test - void hasJdbc43() throws IOException { - JarFile jarFile = open(); - - assertEquals(JAVA_11_VERSION, readMajorVersion(jarFile, "META-INF/versions/11/dev/jfr4jdbc/JfrDataSource.class")); - assertEquals(JAVA_11_VERSION, readMajorVersion(jarFile, "META-INF/versions/11/dev/jfr4jdbc/JfrDataSource43.class")); } diff --git a/artifact-test/src/test/java/dev/jfr4jdbc/sample/ServiceLoaderTest.java b/artifact-test/src/test/java/dev/jfr4jdbc/artifact/ServiceLoaderTest.java similarity index 64% rename from artifact-test/src/test/java/dev/jfr4jdbc/sample/ServiceLoaderTest.java rename to artifact-test/src/test/java/dev/jfr4jdbc/artifact/ServiceLoaderTest.java index 22dd517..b1460df 100644 --- a/artifact-test/src/test/java/dev/jfr4jdbc/sample/ServiceLoaderTest.java +++ b/artifact-test/src/test/java/dev/jfr4jdbc/artifact/ServiceLoaderTest.java @@ -1,4 +1,4 @@ -package dev.jfr4jdbc.sample; +package dev.jfr4jdbc.artifact; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -13,7 +13,12 @@ public class ServiceLoaderTest { @Test void loadedTest() throws Exception { ServiceLoader loader = ServiceLoader.load(Driver.class); - long jfrDriverCount = loader.stream().filter(d -> d.get().getClass().getCanonicalName().equals("dev.jfr4jdbc.JfrServiceLoadedDriver")).count(); + int jfrDriverCount = 0; + for (Driver d : loader) { + if (d.getClass().getCanonicalName().equals("dev.jfr4jdbc.JfrServiceLoadedDriver")) { + jfrDriverCount++; + } + } assertEquals(1, jfrDriverCount); } diff --git a/artifact-test/src/test/java/module-info.java b/artifact-test/src/test/java/module-info.java index 8954432..9988111 100644 --- a/artifact-test/src/test/java/module-info.java +++ b/artifact-test/src/test/java/module-info.java @@ -1,5 +1,5 @@ open module artifact.test { - requires dev.jfr4jdbc; + requires transitive dev.jfr4jdbc; requires transitive org.junit.jupiter.engine; requires transitive org.junit.jupiter.api; diff --git a/bin/test.sh b/bin/test.sh index 1b59669..3b0eb5a 100644 --- a/bin/test.sh +++ b/bin/test.sh @@ -13,10 +13,8 @@ export WORK_DIR=$(cd ${SCRIPT_DIR}; cd ../ ; pwd) cd ${WORK_DIR} # Run unit test -mvn -B --no-transfer-progress clean test -f pom.xml - # install jfr4jdbc-driver for artifact test -mvn -B --no-transfer-progress -DskipTests -Dgpg.skip clean install -f jfr4jdbc-driver/pom.xml +mvn -B --no-transfer-progress -Dgpg.skip clean install -f jfr4jdbc-driver/pom.xml # Run artifact test mvn -B --no-transfer-progress clean test -f artifact-test/pom.xml diff --git a/jdbc42/pom.xml b/jdbc42/pom.xml deleted file mode 100644 index 9151195..0000000 --- a/jdbc42/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - project - dev.jfr4jdbc - 999-SNAPSHOT - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - legacy - - - - - - 4.0.0 - - jdbc42 - - - UTF-8 - 8 - 8 - true - - - - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.mockito - mockito-junit-jupiter - test - - - \ No newline at end of file diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/JfrConnection.java b/jdbc42/src/main/java/dev/jfr4jdbc/JfrConnection.java deleted file mode 100644 index 0712b68..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/JfrConnection.java +++ /dev/null @@ -1,30 +0,0 @@ -package dev.jfr4jdbc; - -import dev.jfr4jdbc.interceptor.InterceptorFactory; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.ResourceMonitor; - -import java.sql.Connection; - -public class JfrConnection extends JfrConnection42 implements Connection { - - public JfrConnection(Connection con) { - super(con); - } - - public JfrConnection(Connection con, String label) { - super(con, label); - } - - public JfrConnection(Connection con, InterceptorFactory factory) { - super(con, factory); - } - - public JfrConnection(Connection con, InterceptorFactory factory, String label) { - super(con, factory, label); - } - - JfrConnection(Connection con, InterceptorFactory factory, ResourceMonitor connectionMonitor, ConnectionInfo connectionInfo) { - super(con, factory, connectionMonitor, connectionInfo); - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/JfrDataSource.java b/jdbc42/src/main/java/dev/jfr4jdbc/JfrDataSource.java deleted file mode 100644 index e734e4f..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/JfrDataSource.java +++ /dev/null @@ -1,24 +0,0 @@ -package dev.jfr4jdbc; - -import dev.jfr4jdbc.interceptor.InterceptorFactory; - -import javax.sql.DataSource; - -public class JfrDataSource extends JfrDataSource42 implements DataSource { - - public JfrDataSource(DataSource datasource) { - super(datasource); - } - - public JfrDataSource(DataSource datasource, String label) { - super(datasource, label); - } - - public JfrDataSource(DataSource datasource, InterceptorFactory factory) { - super(datasource, factory); - } - - public JfrDataSource(DataSource datasource, InterceptorFactory factory, String label) { - super(datasource, factory, label); - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/JfrStatement.java b/jdbc42/src/main/java/dev/jfr4jdbc/JfrStatement.java deleted file mode 100644 index 2ed5fca..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/JfrStatement.java +++ /dev/null @@ -1,21 +0,0 @@ -package dev.jfr4jdbc; - -import dev.jfr4jdbc.interceptor.InterceptorFactory; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.OperationInfo; - -import java.sql.Statement; - -public class JfrStatement extends JfrStatement42 implements Statement { - public JfrStatement(Statement s) { - super(s); - } - - public JfrStatement(Statement s, InterceptorFactory factory) { - super(s, factory); - } - - JfrStatement(Statement s, InterceptorFactory factory, ConnectionInfo connectionInfo, OperationInfo operationInfo) { - super(s, factory, connectionInfo, operationInfo); - } -} \ No newline at end of file diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/ResourceMonitorContext.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/ResourceMonitorContext.java deleted file mode 100644 index a997be0..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/ResourceMonitorContext.java +++ /dev/null @@ -1,25 +0,0 @@ -package dev.jfr4jdbc.interceptor; - -import javax.sql.DataSource; -import java.sql.Driver; - -public class ResourceMonitorContext { - - public final DataSource dataSource; - - public final Driver driver; - - public final String dataSourceLabel; - - public final int usage; - - public final int wait; - - public ResourceMonitorContext(DataSource dataSource, Driver driver, String dataSourceLabel, int usage, int wait) { - this.dataSource = dataSource; - this.driver = driver; - this.dataSourceLabel = dataSourceLabel; - this.usage = usage; - this.wait = wait; - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/ResourceMonitorInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/ResourceMonitorInterceptor.java deleted file mode 100644 index 0bded31..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/ResourceMonitorInterceptor.java +++ /dev/null @@ -1,22 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl; - -import dev.jfr4jdbc.internal.JfrConnectionResourceEvent; -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.interceptor.ResourceMonitorContext; - -public class ResourceMonitorInterceptor implements Interceptor { - - private JfrConnectionResourceEvent event; - - @Override - public void preInvoke(ResourceMonitorContext context) { - } - - @Override - public void postInvoke(ResourceMonitorContext context) { - event = new JfrConnectionResourceEvent(context.dataSourceLabel, context.usage, context.wait); - if (event.isEnabled()) { - event.commit(); - } - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantCancelInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantCancelInterceptor.java deleted file mode 100644 index 6441e17..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantCancelInterceptor.java +++ /dev/null @@ -1,43 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.instant; - -import dev.jfr4jdbc.interceptor.CancelContext; -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; - -public class InstantCancelInterceptor implements Interceptor { - - private long start; - - @Override - public void preInvoke(CancelContext context) { - CancelStartEvent event = new CancelStartEvent(); - if (event.isEnabled()) { - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - event.commit(); - } - start = System.nanoTime(); - } - - @Override - public void postInvoke(CancelContext context) { - long end = System.nanoTime(); - CancelEndEvent event = new CancelEndEvent(); - if (event.isEnabled()) { - event.period = end - start; - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - if (context.getException() != null) { - event.exception = context.getException().getClass(); - event.exceptionMessage = context.getException().getMessage(); - } - event.commit(); - } - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantCloseInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantCloseInterceptor.java deleted file mode 100644 index 5a03e9e..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantCloseInterceptor.java +++ /dev/null @@ -1,43 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.instant; - -import dev.jfr4jdbc.interceptor.CloseContext; -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; - -public class InstantCloseInterceptor implements Interceptor { - - private long start; - - @Override - public void preInvoke(CloseContext context) { - CloseStartEvent event = new CloseStartEvent(); - if (event.isEnabled()) { - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - event.commit(); - } - start = System.nanoTime(); - } - - @Override - public void postInvoke(CloseContext context) { - long end = System.nanoTime(); - CloseEndEvent event = new CloseEndEvent(); - if (event.isEnabled()) { - event.period = end - start; - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - if (context.getException() != null) { - event.exception = context.getException().getClass(); - event.exceptionMessage = context.getException().getMessage(); - } - event.commit(); - } - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantCommitInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantCommitInterceptor.java deleted file mode 100644 index d93b1d1..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantCommitInterceptor.java +++ /dev/null @@ -1,43 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.instant; - -import dev.jfr4jdbc.interceptor.CommitContext; -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; - -public class InstantCommitInterceptor implements Interceptor { - - private long start; - - @Override - public void preInvoke(CommitContext context) { - CommitStartEvent event = new CommitStartEvent(); - if (event.isEnabled()) { - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - event.commit(); - } - start = System.nanoTime(); - } - - @Override - public void postInvoke(CommitContext context) { - long end = System.nanoTime(); - CommitEndEvent event = new CommitEndEvent(); - if (event.isEnabled()) { - event.period = end - start; - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - if (context.getException() != null) { - event.exception = context.getException().getClass(); - event.exceptionMessage = context.getException().getMessage(); - } - event.commit(); - } - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantDataSourceInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantDataSourceInterceptor.java deleted file mode 100644 index 1f2f6ef..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantDataSourceInterceptor.java +++ /dev/null @@ -1,45 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.instant; - -import dev.jfr4jdbc.interceptor.DataSourceContext; -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; - -public class InstantDataSourceInterceptor implements Interceptor { - - private long start; - - @Override - public void preInvoke(DataSourceContext context) { - DataSourceStartEvent event = new DataSourceStartEvent(); - if (event.isEnabled()) { - ConnectionInfo conInfo = context.getConnectionInfo(); - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.username = context.getUsername(); - event.password = context.getPassword(); - event.commit(); - } - start = System.nanoTime(); - } - - @Override - public void postInvoke(DataSourceContext context) { - long end = System.nanoTime(); - DataSourceEndEvent event = new DataSourceEndEvent(); - if (event.isEnabled()) { - event.period = end - start; - ConnectionInfo conInfo = context.getConnectionInfo(); - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.username = context.getUsername(); - event.password = context.getPassword(); - - if (context.getException() != null) { - event.exception = context.getException().getClass(); - event.exceptionMessage = context.getException().getMessage(); - } - event.commit(); - } - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantDriverInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantDriverInterceptor.java deleted file mode 100644 index 1445eb7..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantDriverInterceptor.java +++ /dev/null @@ -1,43 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.instant; - -import dev.jfr4jdbc.interceptor.DriverContext; -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; - -public class InstantDriverInterceptor implements Interceptor { - - private long start; - - @Override - public void preInvoke(DriverContext context) { - DriverStartEvent event = new DriverStartEvent(); - if (event.isEnabled()) { - ConnectionInfo conInfo = context.getConnectionInfo(); - event.driverLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.url = context.url; - event.commit(); - } - start = System.nanoTime(); - } - - @Override - public void postInvoke(DriverContext context) { - long end = System.nanoTime(); - DriverEndEvent event = new DriverEndEvent(); - if (event.isEnabled()) { - event.period = end - start; - ConnectionInfo conInfo = context.getConnectionInfo(); - event.driverLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.url = context.url; - - if (context.getException() != null) { - event.exception = context.getException().getClass(); - event.exceptionMessage = context.getException().getMessage(); - } - event.commit(); - } - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantResultSetInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantResultSetInterceptor.java deleted file mode 100644 index 0c5acda..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantResultSetInterceptor.java +++ /dev/null @@ -1,45 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.instant; - -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.interceptor.ResultSetContext; -import dev.jfr4jdbc.internal.ConnectionInfo; - -public class InstantResultSetInterceptor implements Interceptor { - - private long start; - - @Override - public void preInvoke(ResultSetContext context) { - ResultSetStartEvent event = new ResultSetStartEvent(); - if (event.isEnabled()) { - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - event.commit(); - } - start = System.nanoTime(); - } - - @Override - public void postInvoke(ResultSetContext context) { - long end = System.nanoTime(); - ResultSetEndEvent event = new ResultSetEndEvent(); - if (event.isEnabled()) { - event.period = end - start; - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - event.result = context.isResult(); - event.rowNo = context.getRowNo(); - if (context.getException() != null) { - event.exception = context.getException().getClass(); - event.exceptionMessage = context.getException().getMessage(); - } - event.commit(); - } - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantRollbackInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantRollbackInterceptor.java deleted file mode 100644 index 28e2804..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantRollbackInterceptor.java +++ /dev/null @@ -1,43 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.instant; - -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.interceptor.RollbackContext; -import dev.jfr4jdbc.internal.ConnectionInfo; - -public class InstantRollbackInterceptor implements Interceptor { - - private long start; - - @Override - public void preInvoke(RollbackContext context) { - RollbackStartEvent event = new RollbackStartEvent(); - if (event.isEnabled()) { - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - event.commit(); - } - start = System.nanoTime(); - } - - @Override - public void postInvoke(RollbackContext context) { - long end = System.nanoTime(); - RollbackEndEvent event = new RollbackEndEvent(); - if (event.isEnabled()) { - event.period = end - start; - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - if (context.getException() != null) { - event.exception = context.getException().getClass(); - event.exceptionMessage = context.getException().getMessage(); - } - event.commit(); - } - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantStatementInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantStatementInterceptor.java deleted file mode 100644 index aad6686..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantStatementInterceptor.java +++ /dev/null @@ -1,56 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.instant; - -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.interceptor.StatementContext; -import dev.jfr4jdbc.internal.ConnectionInfo; - -public class InstantStatementInterceptor implements Interceptor { - - private long start; - - @Override - public void preInvoke(StatementContext context) { - StatementStartEvent event = new StatementStartEvent(); - if (event.isEnabled()) { - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - event.inquiry = context.inquiry; - event.isPrepared = context.isPrepared; - event.inquiryParameter = context.getInquiryParameter(); - event.isStatementPoolable = context.isStatementPoolable(); - event.isStatementClosed = context.isStatementClosed(); - event.isAutoCommitted = context.isAutoCommitted(); - event.commit(); - } - start = System.nanoTime(); - } - - @Override - public void postInvoke(StatementContext context) { - long end = System.nanoTime(); - StatementEndEvent event = new StatementEndEvent(); - if (event.isEnabled()) { - event.period = end - start; - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - event.inquiry = context.inquiry; - event.isPrepared = context.isPrepared; - event.inquiryParameter = context.getInquiryParameter(); - event.isStatementPoolable = context.isStatementPoolable(); - event.isStatementClosed = context.isStatementClosed(); - event.isAutoCommitted = context.isAutoCommitted(); - - if (context.getException() != null) { - event.exception = context.getException().getClass(); - event.exceptionMessage = context.getException().getMessage(); - } - event.commit(); - } - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCancelInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCancelInterceptor.java deleted file mode 100644 index c224c27..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCancelInterceptor.java +++ /dev/null @@ -1,33 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.period; - -import dev.jfr4jdbc.interceptor.CancelContext; -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; - -public class PeriodCancelInterceptor implements Interceptor { - - private PeriodCancelEvent event; - - @Override - public void preInvoke(CancelContext context) { - event = new PeriodCancelEvent(); - event.begin(); - } - - @Override - public void postInvoke(CancelContext context) { - event.end(); - if (event.shouldCommit()) { - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - if (context.getException() != null) { - event.exception = context.getException().getClass(); - event.exceptionMessage = context.getException().getMessage(); - } - event.commit(); - } - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCloseInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCloseInterceptor.java deleted file mode 100644 index 60244b4..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCloseInterceptor.java +++ /dev/null @@ -1,33 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.period; - -import dev.jfr4jdbc.interceptor.CloseContext; -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; - -public class PeriodCloseInterceptor implements Interceptor { - - private PeriodCloseEvent event; - - @Override - public void preInvoke(CloseContext context) { - event = new PeriodCloseEvent(); - event.begin(); - } - - @Override - public void postInvoke(CloseContext context) { - event.end(); - if (event.shouldCommit()) { - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - if (context.getException() != null) { - event.exception = context.getException().getClass(); - event.exceptionMessage = context.getException().getMessage(); - } - event.commit(); - } - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCommitInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCommitInterceptor.java deleted file mode 100644 index 5ad0d50..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCommitInterceptor.java +++ /dev/null @@ -1,33 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.period; - -import dev.jfr4jdbc.interceptor.CommitContext; -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; - -public class PeriodCommitInterceptor implements Interceptor { - - private PeriodCommitEvent event; - - @Override - public void preInvoke(CommitContext context) { - event = new PeriodCommitEvent(); - event.begin(); - } - - @Override - public void postInvoke(CommitContext context) { - event.end(); - if (event.shouldCommit()) { - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - if (context.getException() != null) { - event.exception = context.getException().getClass(); - event.exceptionMessage = context.getException().getMessage(); - } - event.commit(); - } - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodDataSourceInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodDataSourceInterceptor.java deleted file mode 100644 index 2f80447..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodDataSourceInterceptor.java +++ /dev/null @@ -1,35 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.period; - -import dev.jfr4jdbc.interceptor.DataSourceContext; -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; - -public class PeriodDataSourceInterceptor implements Interceptor { - - private PeriodDataSourceEvent event; - - @Override - public void preInvoke(DataSourceContext context) { - event = new PeriodDataSourceEvent(); - event.begin(); - } - - @Override - public void postInvoke(DataSourceContext context) { - event.end(); - if (event.shouldCommit()) { - ConnectionInfo conInfo = context.getConnectionInfo(); - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.username = context.getUsername(); - event.password = context.getPassword(); - - if (context.getException() != null) { - event.exception = context.getException().getClass(); - event.exceptionMessage = context.getException().getMessage(); - } - event.commit(); - } - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodDriverInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodDriverInterceptor.java deleted file mode 100644 index 0614f57..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodDriverInterceptor.java +++ /dev/null @@ -1,34 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.period; - -import dev.jfr4jdbc.interceptor.DriverContext; -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; - -public class PeriodDriverInterceptor implements Interceptor { - - private PeriodDriverEvent event; - - @Override - public void preInvoke(DriverContext context) { - event = new PeriodDriverEvent(); - event.begin(); - } - - @Override - public void postInvoke(DriverContext context) { - event.end(); - if (event.shouldCommit()) { - ConnectionInfo conInfo = context.getConnectionInfo(); - event.driverLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.url = context.url; - - if (context.getException() != null) { - event.exception = context.getException().getClass(); - event.exceptionMessage = context.getException().getMessage(); - } - event.commit(); - } - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodInterceptorFactory.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodInterceptorFactory.java deleted file mode 100644 index 6541810..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodInterceptorFactory.java +++ /dev/null @@ -1,51 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.period; - -import dev.jfr4jdbc.interceptor.*; -import dev.jfr4jdbc.interceptor.impl.ResourceMonitorInterceptor; - -public class PeriodInterceptorFactory implements InterceptorFactory { - @Override - public Interceptor createDataSourceInterceptor() { - return new PeriodDataSourceInterceptor(); - } - - @Override - public Interceptor createDriverInterceptor() { - return new PeriodDriverInterceptor(); - } - - @Override - public Interceptor createCommitInterceptor() { - return new PeriodCommitInterceptor(); - } - - @Override - public Interceptor createRollbackInterceptor() { - return new PeriodRollbackInterceptor(); - } - - @Override - public Interceptor createCloseInterceptor() { - return new PeriodCloseInterceptor(); - } - - @Override - public Interceptor createStatementInterceptor() { - return new PeriodStatementInterceptor(); - } - - @Override - public Interceptor createCancelInterceptor() { - return new PeriodCancelInterceptor(); - } - - @Override - public Interceptor createResultSetInterceptor() { - return new PeriodResultSetInterceptor(); - } - - @Override - public Interceptor createResourceMonitorInterceptor() { - return new ResourceMonitorInterceptor(); - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodResultSetInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodResultSetInterceptor.java deleted file mode 100644 index 1c6815b..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodResultSetInterceptor.java +++ /dev/null @@ -1,35 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.period; - -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.interceptor.ResultSetContext; -import dev.jfr4jdbc.internal.ConnectionInfo; - -public class PeriodResultSetInterceptor implements Interceptor { - - private PeriodResultSetEvent event; - - @Override - public void preInvoke(ResultSetContext context) { - event = new PeriodResultSetEvent(); - event.begin(); - } - - @Override - public void postInvoke(ResultSetContext context) { - event.end(); - if (event.shouldCommit()) { - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - event.result = context.isResult(); - event.rowNo = context.getRowNo(); - if (context.getException() != null) { - event.exception = context.getException().getClass(); - event.exceptionMessage = context.getException().getMessage(); - } - event.commit(); - } - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodRollbackInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodRollbackInterceptor.java deleted file mode 100644 index 6fb9a72..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodRollbackInterceptor.java +++ /dev/null @@ -1,33 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.period; - -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.interceptor.RollbackContext; -import dev.jfr4jdbc.internal.ConnectionInfo; - -public class PeriodRollbackInterceptor implements Interceptor { - - private PeriodRollbackEvent event; - - @Override - public void preInvoke(RollbackContext context) { - event = new PeriodRollbackEvent(); - event.begin(); - } - - @Override - public void postInvoke(RollbackContext context) { - event.end(); - if (event.shouldCommit()) { - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - if (context.getException() != null) { - event.exception = context.getException().getClass(); - event.exceptionMessage = context.getException().getMessage(); - } - event.commit(); - } - } -} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodStatementInterceptor.java b/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodStatementInterceptor.java deleted file mode 100644 index 9301327..0000000 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodStatementInterceptor.java +++ /dev/null @@ -1,40 +0,0 @@ -package dev.jfr4jdbc.interceptor.impl.period; - -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.interceptor.StatementContext; -import dev.jfr4jdbc.internal.ConnectionInfo; - -public class PeriodStatementInterceptor implements Interceptor { - - private PeriodStatementEvent event; - - @Override - public void preInvoke(StatementContext context) { - event = new PeriodStatementEvent(); - event.begin(); - } - - @Override - public void postInvoke(StatementContext context) { - event.end(); - if (event.shouldCommit()) { - ConnectionInfo conInfo = context.connectionInfo; - event.dataSourceLabel = conInfo.dataSourceLabel; - event.connectionId = conInfo.conId; - event.wrappedConnectionId = conInfo.wrappedConId; - event.operationId = context.operationInfo.id; - event.inquiry = context.inquiry; - event.isPrepared = context.isPrepared; - event.inquiryParameter = context.getInquiryParameter(); - event.isStatementPoolable = context.isStatementPoolable(); - event.isStatementClosed = context.isStatementClosed(); - event.isAutoCommitted = context.isAutoCommitted(); - - if (context.getException() != null) { - event.exception = context.getException().getClass(); - event.exceptionMessage = context.getException().getMessage(); - } - event.commit(); - } - } -} diff --git a/jdbc43/pom.xml b/jdbc43/pom.xml deleted file mode 100644 index 98411a9..0000000 --- a/jdbc43/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - project - dev.jfr4jdbc - 999-SNAPSHOT - - 4.0.0 - - jdbc43 - - - UTF-8 - 11 - true - - - - - dev.jfr4jdbc - jdbc42 - ${project.version} - - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.mockito - mockito-junit-jupiter - test - - - \ No newline at end of file diff --git a/jdbc43/src/main/java/dev/jfr4jdbc/JfrConnection.java b/jdbc43/src/main/java/dev/jfr4jdbc/JfrConnection.java deleted file mode 100644 index 2cb4ae1..0000000 --- a/jdbc43/src/main/java/dev/jfr4jdbc/JfrConnection.java +++ /dev/null @@ -1,31 +0,0 @@ -package dev.jfr4jdbc; - -import dev.jfr4jdbc.interceptor.InterceptorFactory; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.ResourceMonitor; - -import java.sql.Connection; - -public class JfrConnection extends JfrConnection43 implements Connection { - - public JfrConnection(Connection con) { - super(con); - } - - public JfrConnection(Connection con, String dataSourceLabel) { - super(con, dataSourceLabel); - } - - public JfrConnection(Connection con, InterceptorFactory factory) { - super(con, factory); - } - - public JfrConnection(Connection con, InterceptorFactory factory, String dataSourceLabel) { - super(con, factory, dataSourceLabel); - } - - JfrConnection(Connection con, InterceptorFactory factory, ResourceMonitor connectionMonitor, ConnectionInfo connectionInfo) { - super(con, factory, connectionMonitor, connectionInfo); - } - -} diff --git a/jdbc43/src/main/java/dev/jfr4jdbc/JfrConnection43.java b/jdbc43/src/main/java/dev/jfr4jdbc/JfrConnection43.java deleted file mode 100644 index eb34425..0000000 --- a/jdbc43/src/main/java/dev/jfr4jdbc/JfrConnection43.java +++ /dev/null @@ -1,68 +0,0 @@ -package dev.jfr4jdbc; - -import dev.jfr4jdbc.interceptor.InterceptorFactory; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.ResourceMonitor; - -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.ShardingKey; - -abstract public class JfrConnection43 extends JfrConnection42 implements Connection { - - public JfrConnection43(Connection con) { - super(con); - } - - public JfrConnection43(Connection con, String dataSourceLabel) { - super(con, dataSourceLabel); - } - - public JfrConnection43(Connection con, InterceptorFactory factory) { - super(con, factory); - } - - public JfrConnection43(Connection con, InterceptorFactory factory, String dataSourceLabel) { - super(con, factory, dataSourceLabel); - } - - public JfrConnection43(Connection con, InterceptorFactory factory, ResourceMonitor connectionMonitor, ConnectionInfo connectionInfo) { - super(con, factory, connectionMonitor, connectionInfo); - } - - - @Override - public int getNetworkTimeout() throws SQLException { - return this.connection.getNetworkTimeout(); - } - - @Override - public void beginRequest() throws SQLException { - this.connection.beginRequest(); - } - - @Override - public void endRequest() throws SQLException { - this.connection.endRequest(); - } - - @Override - public boolean setShardingKeyIfValid(ShardingKey shardingKey, int timeout) throws SQLException { - return this.connection.setShardingKeyIfValid(shardingKey, timeout); - } - - @Override - public boolean setShardingKeyIfValid(ShardingKey shardingKey, ShardingKey superShardingKey, int timeout) throws SQLException { - return this.connection.setShardingKeyIfValid(shardingKey, superShardingKey, timeout); - } - - @Override - public void setShardingKey(ShardingKey shardingKey) throws SQLException { - this.connection.setShardingKey(shardingKey); - } - - @Override - public void setShardingKey(ShardingKey shardingKey, ShardingKey superShardingKey) throws SQLException { - this.connection.setShardingKey(shardingKey, superShardingKey); - } -} \ No newline at end of file diff --git a/jdbc43/src/main/java/dev/jfr4jdbc/JfrDataSource.java b/jdbc43/src/main/java/dev/jfr4jdbc/JfrDataSource.java deleted file mode 100644 index 04b9fe0..0000000 --- a/jdbc43/src/main/java/dev/jfr4jdbc/JfrDataSource.java +++ /dev/null @@ -1,24 +0,0 @@ -package dev.jfr4jdbc; - -import dev.jfr4jdbc.interceptor.InterceptorFactory; - -import javax.sql.DataSource; - -public class JfrDataSource extends JfrDataSource43 implements DataSource { - - public JfrDataSource(DataSource datasource) { - super(datasource); - } - - public JfrDataSource(DataSource datasource, String monitorLabel) { - super(datasource, monitorLabel); - } - - public JfrDataSource(DataSource datasource, InterceptorFactory factory) { - super(datasource, factory); - } - - public JfrDataSource(DataSource datasource, InterceptorFactory factory, String monitorLabel) { - super(datasource, factory, monitorLabel); - } -} \ No newline at end of file diff --git a/jdbc43/src/main/java/dev/jfr4jdbc/JfrDataSource43.java b/jdbc43/src/main/java/dev/jfr4jdbc/JfrDataSource43.java deleted file mode 100644 index 0bf3a0e..0000000 --- a/jdbc43/src/main/java/dev/jfr4jdbc/JfrDataSource43.java +++ /dev/null @@ -1,37 +0,0 @@ -package dev.jfr4jdbc; - -import dev.jfr4jdbc.interceptor.InterceptorFactory; - -import javax.sql.DataSource; -import java.sql.ConnectionBuilder; -import java.sql.SQLException; -import java.sql.ShardingKeyBuilder; - -abstract public class JfrDataSource43 extends JfrDataSource42 implements DataSource { - - protected JfrDataSource43(DataSource datasource) { - super(datasource); - } - - protected JfrDataSource43(DataSource datasource, String monitorLabel) { - super(datasource, monitorLabel); - } - - protected JfrDataSource43(DataSource datasource, InterceptorFactory factory) { - super(datasource, factory); - } - - protected JfrDataSource43(DataSource datasource, InterceptorFactory factory, String monitorLabel) { - super(datasource, factory, monitorLabel); - } - - @Override - public ShardingKeyBuilder createShardingKeyBuilder() throws SQLException { - return this.datasource.createShardingKeyBuilder(); - } - - @Override - public ConnectionBuilder createConnectionBuilder() throws SQLException { - return this.datasource.createConnectionBuilder(); - } -} diff --git a/jdbc43/src/main/java/dev/jfr4jdbc/JfrStatement.java b/jdbc43/src/main/java/dev/jfr4jdbc/JfrStatement.java deleted file mode 100644 index 94537cc..0000000 --- a/jdbc43/src/main/java/dev/jfr4jdbc/JfrStatement.java +++ /dev/null @@ -1,22 +0,0 @@ -package dev.jfr4jdbc; - -import dev.jfr4jdbc.interceptor.InterceptorFactory; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.OperationInfo; - -import java.sql.Statement; - -public class JfrStatement extends JfrStatement43 implements Statement { - - public JfrStatement(Statement s) { - super(s); - } - - public JfrStatement(Statement s, InterceptorFactory factory) { - super(s, factory); - } - - JfrStatement(Statement s, InterceptorFactory factory, ConnectionInfo connectionInfo, OperationInfo operationInfo) { - super(s, factory, connectionInfo, operationInfo); - } -} diff --git a/jdbc43/src/main/java/dev/jfr4jdbc/JfrStatement43.java b/jdbc43/src/main/java/dev/jfr4jdbc/JfrStatement43.java deleted file mode 100644 index 52e2c07..0000000 --- a/jdbc43/src/main/java/dev/jfr4jdbc/JfrStatement43.java +++ /dev/null @@ -1,43 +0,0 @@ -package dev.jfr4jdbc; - -import dev.jfr4jdbc.interceptor.InterceptorFactory; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.OperationInfo; - -import java.sql.SQLException; -import java.sql.Statement; - -public class JfrStatement43 extends JfrStatement42 implements Statement { - - protected JfrStatement43(Statement s) { - super(s); - } - - protected JfrStatement43(Statement s, InterceptorFactory factory) { - super(s, factory); - } - - protected JfrStatement43(Statement s, InterceptorFactory factory, ConnectionInfo connectionInfo, OperationInfo operationInfo) { - super(s, factory, connectionInfo, operationInfo); - } - - @Override - public String enquoteLiteral(String val) throws SQLException { - return this.jdbcStatement.enquoteLiteral(val); - } - - @Override - public String enquoteIdentifier(String identifier, boolean alwaysQuote) throws SQLException { - return this.jdbcStatement.enquoteIdentifier(identifier, alwaysQuote); - } - - @Override - public boolean isSimpleIdentifier(String identifier) throws SQLException { - return this.jdbcStatement.isSimpleIdentifier(identifier); - } - - @Override - public String enquoteNCharLiteral(String val) throws SQLException { - return this.jdbcStatement.enquoteNCharLiteral(val); - } -} diff --git a/jdbc43/src/test/java/dev/jfr4jdbc/JfrConnectionTest.java b/jdbc43/src/test/java/dev/jfr4jdbc/JfrConnectionTest.java deleted file mode 100644 index 659c20e..0000000 --- a/jdbc43/src/test/java/dev/jfr4jdbc/JfrConnectionTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package dev.jfr4jdbc; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.sql.Connection; -import java.sql.SQLException; - -import static org.mockito.Mockito.verify; - -@ExtendWith(MockitoExtension.class) -class JfrConnectionTest { - - @Mock - private Connection delegatedCon; - - @BeforeAll - static void initClass() throws Exception { - } - - @BeforeEach - void init() throws Exception { - MockitoAnnotations.initMocks(this); - } - - - @Test - void beginRequest() throws SQLException { - try (Connection con = new JfrConnection(this.delegatedCon)) { - con.beginRequest(); - } - - verify(this.delegatedCon).beginRequest(); - } - - @Test - void endRequest() throws SQLException { - try (Connection con = new JfrConnection(this.delegatedCon)) { - con.endRequest(); - } - - verify(this.delegatedCon).endRequest(); - } - - @Test - void setShardingKeyIfValid() throws SQLException { - try (Connection con = new JfrConnection(this.delegatedCon)) { - con.setShardingKeyIfValid(null, 0); - } - - verify(this.delegatedCon).setShardingKeyIfValid(null, 0); - } - - @Test - void setShardingKeyIfValid1() throws SQLException { - try (Connection con = new JfrConnection(this.delegatedCon)) { - con.setShardingKeyIfValid(null, null, 0); - } - - verify(this.delegatedCon).setShardingKeyIfValid(null, null, 0); - } - - @Test - void setShardingKey() throws SQLException { - try (Connection con = new JfrConnection(this.delegatedCon)) { - con.setShardingKey(null); - } - - verify(this.delegatedCon).setShardingKey(null); - } - - @Test - void setShardingKey1() throws SQLException { - try (Connection con = new JfrConnection(this.delegatedCon)) { - con.setShardingKey(null, null); - } - - verify(this.delegatedCon).setShardingKey(null, null); - } -} \ No newline at end of file diff --git a/jdbc43/src/test/java/dev/jfr4jdbc/JfrDataSourceTest.java b/jdbc43/src/test/java/dev/jfr4jdbc/JfrDataSourceTest.java deleted file mode 100644 index 9b02d21..0000000 --- a/jdbc43/src/test/java/dev/jfr4jdbc/JfrDataSourceTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package dev.jfr4jdbc; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.junit.jupiter.MockitoExtension; - -import javax.sql.DataSource; - -import static org.mockito.Mockito.verify; - -@ExtendWith(MockitoExtension.class) -class JfrDataSourceTest { - - @Mock - DataSource delegatedDs; - - @BeforeEach - void init() throws Exception { - MockitoAnnotations.initMocks(this); - } - - @Test - void createConnectionBuilder() throws Exception { - JfrDataSource dataSource = new JfrDataSource(delegatedDs); - dataSource.createConnectionBuilder(); - - verify(delegatedDs).createConnectionBuilder(); - } - - @Test - void createShardingKeyBuilder() throws Exception { - JfrDataSource dataSource = new JfrDataSource(delegatedDs); - dataSource.createShardingKeyBuilder(); - - verify(delegatedDs).createShardingKeyBuilder(); - } -} \ No newline at end of file diff --git a/jdbc43/src/test/java/dev/jfr4jdbc/JfrStatementTest.java b/jdbc43/src/test/java/dev/jfr4jdbc/JfrStatementTest.java deleted file mode 100644 index f549d36..0000000 --- a/jdbc43/src/test/java/dev/jfr4jdbc/JfrStatementTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package dev.jfr4jdbc; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.sql.SQLException; -import java.sql.Statement; - -import static org.mockito.Mockito.verify; - -@ExtendWith(MockitoExtension.class) -class JfrStatementTest { - - protected static final String SAMPLE_SQL = "SELECT 1"; - - @Mock - Statement delegateState; - - @BeforeAll - static void initClass() throws Exception { - } - - @BeforeEach - void init() throws Exception { - MockitoAnnotations.initMocks(this); - } - - - @DisplayName("enquoteIdentifier") - @Test - void enquoteIdentifier() throws SQLException { - JfrStatement statement = new JfrStatement(this.delegateState); - statement.enquoteIdentifier(null, false); - verify(this.delegateState).enquoteIdentifier(null, false); - } - - @DisplayName("enquoteLiteral") - @Test - void enquoteLiteral() throws SQLException { - JfrStatement statement = new JfrStatement(this.delegateState); - statement.enquoteLiteral(null); - verify(this.delegateState).enquoteLiteral(null); - } - - @DisplayName("enquoteNCharLiteral") - @Test - void enquoteNCharLiteral() throws SQLException { - JfrStatement statement = new JfrStatement(this.delegateState); - statement.enquoteNCharLiteral(null); - verify(this.delegateState).enquoteNCharLiteral(null); - } - - @DisplayName("isSimpleIdentifier") - @Test - void isSimpleIdentifier() throws SQLException { - JfrStatement statement = new JfrStatement(this.delegateState); - statement.isSimpleIdentifier(null); - verify(this.delegateState).isSimpleIdentifier(null); - } -} \ No newline at end of file diff --git a/jfr4jdbc-driver/pom.xml b/jfr4jdbc-driver/pom.xml index 4085d9e..df68cec 100644 --- a/jfr4jdbc-driver/pom.xml +++ b/jfr4jdbc-driver/pom.xml @@ -13,8 +13,8 @@ UTF-8 - 1.8 - 1.8 + 11 + 11 @@ -53,11 +53,31 @@ + + + org.junit.jupiter + junit-jupiter-api + 5.10.1 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.10.1 + test + + + org.mockito + mockito-junit-jupiter + 5.8.0 + test + + + - ${project.basedir}/target/generated-sources/copied-java - target/generated-sources/gen-resources + src/main/resources true @@ -71,110 +91,64 @@ org.apache.maven.plugins maven-compiler-plugin - 3.10.1 + 3.12.1 + + + org.apache.maven.plugins + maven-source-plugin + 3.2.1 + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.5.0 + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.13 + + + org.apache.maven.plugins + maven-gpg-plugin + 3.0.1 + + + maven-release-plugin + 3.0.0 - - org.apache.maven.plugins - maven-antrun-plugin - 1.8 - - - copy-source - generate-sources - - - - - - - - - - - - - - - - - - - - - run - - - - org.apache.maven.plugins maven-compiler-plugin - compile-java-8 + compile-as-java-8 compile 1.8 1.8 - - ${project.basedir}/target/generated-sources/copied-java - - ${project.build.outputDirectory} - - - - compile-java-11 - compile - - compile - - - 11 - 11 - 11 - - ${project.basedir}/target/generated-sources/copied-java11 - - true + + module-info.java + - compile-module-info - compile - - compile - + default-compile 11 - - ${project.basedir}/src/main/java - - ${project.build.outputDirectory} - - maven-jar-plugin - 3.2.0 - - - - true - - - - org.apache.maven.plugins maven-source-plugin - 3.2.0 attach-sources @@ -187,7 +161,6 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.2.0 attach-javadocs @@ -195,7 +168,7 @@ jar - ${project.basedir}/target/generated-sources/copied-java + ${project.basedir}/src/main/java @@ -203,7 +176,6 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.13 true ossrh @@ -214,7 +186,6 @@ org.apache.maven.plugins maven-gpg-plugin - 3.0.1 sign-artifacts @@ -233,7 +204,6 @@ maven-release-plugin - 3.0.0-M7 @{project.version} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/ConnectionId.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/ConnectionId.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/ConnectionId.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/ConnectionId.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/DataSourceLabel.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/DataSourceLabel.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/DataSourceLabel.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/DataSourceLabel.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/EventFactory.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/EventFactory.java similarity index 98% rename from jdbc42/src/main/java/dev/jfr4jdbc/EventFactory.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/EventFactory.java index 954821d..4ad4337 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/EventFactory.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/EventFactory.java @@ -3,6 +3,7 @@ import dev.jfr4jdbc.event.*; import dev.jfr4jdbc.event.jfr.*; +@Deprecated public abstract class EventFactory { private static EventFactory s_factory = new JfrEventFactory(); @@ -26,6 +27,7 @@ public static EventFactory getDefaultEventFactory() { public abstract RollbackEvent createRollbackEvent(); } +@Deprecated class JfrEventFactory extends EventFactory { @Override diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/Jfr4JdbcException.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/Jfr4JdbcException.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/Jfr4JdbcException.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/Jfr4JdbcException.java diff --git a/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/Jfr4JdbcMetrics.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/Jfr4JdbcMetrics.java new file mode 100644 index 0000000..5805d61 --- /dev/null +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/Jfr4JdbcMetrics.java @@ -0,0 +1,14 @@ +package dev.jfr4jdbc; + +import dev.jfr4jdbc.internal.ResourceMonitorManager; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class Jfr4JdbcMetrics { + + public static List getResourceMetrics() { + return Collections.unmodifiableList(ResourceMonitorManager.getInstance().getMonitors().stream().map(m -> m.getMetrics()).collect(Collectors.toList())); + } +} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/Jfr4JdbcRuntimeException.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/Jfr4JdbcRuntimeException.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/Jfr4JdbcRuntimeException.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/Jfr4JdbcRuntimeException.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/JfrCallableStatement.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrCallableStatement.java similarity index 99% rename from jdbc42/src/main/java/dev/jfr4jdbc/JfrCallableStatement.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrCallableStatement.java index 78c2116..3d0a8f8 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/JfrCallableStatement.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrCallableStatement.java @@ -2,8 +2,8 @@ import dev.jfr4jdbc.interceptor.InterceptorFactory; import dev.jfr4jdbc.interceptor.InterceptorManager; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.OperationInfo; +import dev.jfr4jdbc.interceptor.ConnectionInfo; +import dev.jfr4jdbc.interceptor.OperationInfo; import java.io.InputStream; import java.io.Reader; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/JfrConnection42.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrConnection.java similarity index 88% rename from jdbc42/src/main/java/dev/jfr4jdbc/JfrConnection42.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrConnection.java index 7b16e40..74b074b 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/JfrConnection42.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrConnection.java @@ -1,7 +1,9 @@ package dev.jfr4jdbc; import dev.jfr4jdbc.interceptor.*; -import dev.jfr4jdbc.internal.*; +import dev.jfr4jdbc.internal.Label; +import dev.jfr4jdbc.internal.ResourceMonitor; +import dev.jfr4jdbc.internal.ResourceMonitorManager; import java.sql.*; import java.util.Map; @@ -9,7 +11,7 @@ import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicInteger; -abstract public class JfrConnection42 implements Connection { +public class JfrConnection implements Connection { private static final String LABEL_IS_NOT_SPECIFIED = "userManagedConnection"; @@ -23,23 +25,24 @@ abstract public class JfrConnection42 implements Connection { private final AtomicInteger operationCounter = new AtomicInteger(1); - protected JfrConnection42(Connection con) { + + public JfrConnection(Connection con) { this(con, InterceptorManager.getDefaultInterceptorFactory(), LABEL_IS_NOT_SPECIFIED, ConnectionInfo.NO_INFO); } - protected JfrConnection42(Connection con, String label) { + public JfrConnection(Connection con, String label) { this(con, InterceptorManager.getDefaultInterceptorFactory(), label, ConnectionInfo.NO_INFO); } - protected JfrConnection42(Connection con, InterceptorFactory factory) { + public JfrConnection(Connection con, InterceptorFactory factory) { this(con, factory, LABEL_IS_NOT_SPECIFIED, ConnectionInfo.NO_INFO); } - protected JfrConnection42(Connection con, InterceptorFactory factory, String label) { + public JfrConnection(Connection con, InterceptorFactory factory, String label) { this(con, factory, label, ConnectionInfo.NO_INFO); } - private JfrConnection42(Connection con, InterceptorFactory factory, String label, ConnectionInfo connectionInfo) { + private JfrConnection(Connection con, InterceptorFactory factory, String label, ConnectionInfo connectionInfo) { super(); this.connection = con; this.interceptorFactory = factory; @@ -50,7 +53,7 @@ private JfrConnection42(Connection con, InterceptorFactory factory, String label } - public JfrConnection42(Connection con, InterceptorFactory factory, ResourceMonitor resourceMonitor, ConnectionInfo connectionInfo) { + public JfrConnection(Connection con, InterceptorFactory factory, ResourceMonitor resourceMonitor, ConnectionInfo connectionInfo) { super(); this.connection = con; this.interceptorFactory = factory; @@ -60,6 +63,7 @@ public JfrConnection42(Connection con, InterceptorFactory factory, ResourceMonit this.resourceMonitor.useResource(); } + public ResourceMetrics getResourceMetrics() { return this.resourceMonitor.getMetrics(); } @@ -217,13 +221,13 @@ public String nativeSQL(String sql) throws SQLException { } @Override - public void setAutoCommit(boolean autoCommit) throws SQLException { - this.connection.setAutoCommit(autoCommit); + public boolean getAutoCommit() throws SQLException { + return this.connection.getAutoCommit(); } @Override - public boolean getAutoCommit() throws SQLException { - return this.connection.getAutoCommit(); + public void setAutoCommit(boolean autoCommit) throws SQLException { + this.connection.setAutoCommit(autoCommit); } @Override @@ -236,19 +240,14 @@ public DatabaseMetaData getMetaData() throws SQLException { return this.connection.getMetaData(); } - @Override - public void setReadOnly(boolean readOnly) throws SQLException { - this.connection.setReadOnly(readOnly); - } - @Override public boolean isReadOnly() throws SQLException { return this.connection.isReadOnly(); } @Override - public void setCatalog(String catalog) throws SQLException { - this.connection.setCatalog(catalog); + public void setReadOnly(boolean readOnly) throws SQLException { + this.connection.setReadOnly(readOnly); } @Override @@ -257,8 +256,8 @@ public String getCatalog() throws SQLException { } @Override - public void setTransactionIsolation(int level) throws SQLException { - this.connection.setTransactionIsolation(level); + public void setCatalog(String catalog) throws SQLException { + this.connection.setCatalog(catalog); } @Override @@ -266,6 +265,11 @@ public int getTransactionIsolation() throws SQLException { return this.connection.getTransactionIsolation(); } + @Override + public void setTransactionIsolation(int level) throws SQLException { + this.connection.setTransactionIsolation(level); + } + @Override public SQLWarning getWarnings() throws SQLException { return this.connection.getWarnings(); @@ -287,13 +291,13 @@ public void setTypeMap(Map> map) throws SQLException { } @Override - public void setHoldability(int holdability) throws SQLException { - this.connection.setHoldability(holdability); + public int getHoldability() throws SQLException { + return this.connection.getHoldability(); } @Override - public int getHoldability() throws SQLException { - return this.connection.getHoldability(); + public void setHoldability(int holdability) throws SQLException { + this.connection.setHoldability(holdability); } @Override @@ -346,11 +350,6 @@ public void setClientInfo(String name, String value) throws SQLClientInfoExcepti this.connection.setClientInfo(name, value); } - @Override - public void setClientInfo(Properties properties) throws SQLClientInfoException { - this.connection.setClientInfo(properties); - } - @Override public String getClientInfo(String name) throws SQLException { return this.connection.getClientInfo(name); @@ -361,6 +360,11 @@ public Properties getClientInfo() throws SQLException { return this.connection.getClientInfo(); } + @Override + public void setClientInfo(Properties properties) throws SQLClientInfoException { + this.connection.setClientInfo(properties); + } + @Override public Array createArrayOf(String typeName, Object[] elements) throws SQLException { return this.connection.createArrayOf(typeName, elements); @@ -372,13 +376,13 @@ public Struct createStruct(String typeName, Object[] attributes) throws SQLExcep } @Override - public void setSchema(String schema) throws SQLException { - this.connection.setSchema(schema); + public String getSchema() throws SQLException { + return this.connection.getSchema(); } @Override - public String getSchema() throws SQLException { - return this.connection.getSchema(); + public void setSchema(String schema) throws SQLException { + this.connection.setSchema(schema); } @Override @@ -395,4 +399,34 @@ public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLExc public int getNetworkTimeout() throws SQLException { return this.connection.getNetworkTimeout(); } -} \ No newline at end of file + + @Override + public void beginRequest() throws SQLException { + this.connection.beginRequest(); + } + + @Override + public void endRequest() throws SQLException { + this.connection.endRequest(); + } + + @Override + public boolean setShardingKeyIfValid(ShardingKey shardingKey, int timeout) throws SQLException { + return this.connection.setShardingKeyIfValid(shardingKey, timeout); + } + + @Override + public boolean setShardingKeyIfValid(ShardingKey shardingKey, ShardingKey superShardingKey, int timeout) throws SQLException { + return this.connection.setShardingKeyIfValid(shardingKey, superShardingKey, timeout); + } + + @Override + public void setShardingKey(ShardingKey shardingKey) throws SQLException { + this.connection.setShardingKey(shardingKey); + } + + @Override + public void setShardingKey(ShardingKey shardingKey, ShardingKey superShardingKey) throws SQLException { + this.connection.setShardingKey(shardingKey, superShardingKey); + } +} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/JfrDataSource42.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrDataSource.java similarity index 75% rename from jdbc42/src/main/java/dev/jfr4jdbc/JfrDataSource42.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrDataSource.java index f0f5b4a..f908c59 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/JfrDataSource42.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrDataSource.java @@ -1,60 +1,50 @@ package dev.jfr4jdbc; -import dev.jfr4jdbc.interceptor.DataSourceContext; -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.interceptor.InterceptorFactory; -import dev.jfr4jdbc.interceptor.InterceptorManager; -import dev.jfr4jdbc.internal.ConnectionInfo; +import dev.jfr4jdbc.interceptor.*; import dev.jfr4jdbc.internal.Label; import dev.jfr4jdbc.internal.ResourceMonitor; import dev.jfr4jdbc.internal.ResourceMonitorManager; +import dev.jfr4jdbc.internal.StillUnassignedConnectionInfo; import javax.sql.DataSource; import java.io.PrintWriter; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Proxy; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; +import java.sql.*; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Logger; -abstract public class JfrDataSource42 implements DataSource { +public class JfrDataSource implements DataSource { private static final AtomicInteger defaultLabelCounter = new AtomicInteger(0); private static final AtomicInteger dataSourceIdCounter = new AtomicInteger(1); - + protected final DataSource datasource; + protected final String label; private final AtomicInteger connectionCounter = new AtomicInteger(1); - private final AtomicInteger wrappedConnectionCounter = new AtomicInteger(1); - - protected final DataSource datasource; - @Deprecated private final int datasourceId; - - protected final String label; - private final InterceptorFactory interceptorFactory; private final ResourceMonitor resourceMonitor; + Map wrappedConnectionIds = new HashMap<>(); - protected JfrDataSource42(DataSource datasource) { + public JfrDataSource(DataSource datasource) { this(datasource, InterceptorManager.getDefaultInterceptorFactory()); } - protected JfrDataSource42(DataSource datasource, String label) { + public JfrDataSource(DataSource datasource, String label) { this(datasource, InterceptorManager.getDefaultInterceptorFactory(), label); } - protected JfrDataSource42(DataSource datasource, InterceptorFactory interceptorFactory) { + public JfrDataSource(DataSource datasource, InterceptorFactory interceptorFactory) { this(datasource, interceptorFactory, "DataSource#" + defaultLabelCounter.incrementAndGet()); } - protected JfrDataSource42(DataSource datasource, InterceptorFactory interceptorFactory, String label) { + public JfrDataSource(DataSource datasource, InterceptorFactory interceptorFactory, String label) { super(); if (datasource == null) { throw new Jfr4JdbcRuntimeException("No delegate DataSource"); @@ -67,12 +57,11 @@ protected JfrDataSource42(DataSource datasource, InterceptorFactory interceptorF this.resourceMonitor = ResourceMonitorManager.getInstance().getOrCreateResourceMonitor(new Label(label)); } + public ResourceMetrics getResourceMetrics() { return this.resourceMonitor.getMetrics(); } - Map wrappedConnectionIds = new HashMap<>(); - private int getWrappedConnectionId(Connection con) { int objectId = 0; @@ -93,15 +82,19 @@ public Connection getConnection() throws SQLException { int connectionId = this.connectionCounter.getAndIncrement(); Interceptor interceptor = this.interceptorFactory.createDataSourceInterceptor(); - DataSourceContext context = new DataSourceContext(this.datasource, new ConnectionInfo(label, connectionId, 0), this.datasourceId); + StillUnassignedConnectionInfo stillUnassignedConnectionInfo = new StillUnassignedConnectionInfo(label, connectionId); + DataSourceContext context = new DataSourceContext(this.datasource, stillUnassignedConnectionInfo, this.datasourceId); Connection delegatedCon = null; + ConnectionInfo connectionInfo = null; try { this.resourceMonitor.waitAssigningResource(); interceptor.preInvoke(context); delegatedCon = this.datasource.getConnection(); - context.setConnection(delegatedCon, getWrappedConnectionId(delegatedCon)); + connectionInfo = new ConnectionInfo(stillUnassignedConnectionInfo.dataSourceLabel, stillUnassignedConnectionInfo.conId, getWrappedConnectionId(delegatedCon)); + context.setConnection(delegatedCon, connectionInfo); + } catch (SQLException | RuntimeException e) { context.setException(e); throw e; @@ -110,7 +103,7 @@ public Connection getConnection() throws SQLException { this.resourceMonitor.assignedResource(); } - return new JfrConnection(delegatedCon, this.interceptorFactory, this.resourceMonitor, context.getConnectionInfo()); + return new JfrConnection(delegatedCon, this.interceptorFactory, this.resourceMonitor, connectionInfo); } @Override @@ -118,16 +111,19 @@ public Connection getConnection(String username, String password) throws SQLExce int connectionId = this.connectionCounter.getAndIncrement(); Interceptor interceptor = this.interceptorFactory.createDataSourceInterceptor(); - DataSourceContext context = new DataSourceContext(this.datasource, new ConnectionInfo(label, connectionId, 0), this.datasourceId); + StillUnassignedConnectionInfo stillUnassignedConnectionInfo = new StillUnassignedConnectionInfo(label, connectionId); + DataSourceContext context = new DataSourceContext(this.datasource, stillUnassignedConnectionInfo, this.datasourceId); context.setAuth(username, password); Connection delegatedCon = null; + ConnectionInfo connectionInfo = null; try { this.resourceMonitor.waitAssigningResource(); interceptor.preInvoke(context); delegatedCon = this.datasource.getConnection(username, password); - context.setConnection(delegatedCon, getWrappedConnectionId(delegatedCon)); + connectionInfo = new ConnectionInfo(stillUnassignedConnectionInfo.dataSourceLabel, stillUnassignedConnectionInfo.conId, getWrappedConnectionId(delegatedCon)); + context.setConnection(delegatedCon, connectionInfo); } catch (SQLException | RuntimeException e) { context.setException(e); @@ -152,13 +148,13 @@ public void setLogWriter(PrintWriter out) throws SQLException { } @Override - public void setLoginTimeout(int seconds) throws SQLException { - this.datasource.setLoginTimeout(seconds); + public int getLoginTimeout() throws SQLException { + return this.datasource.getLoginTimeout(); } @Override - public int getLoginTimeout() throws SQLException { - return this.datasource.getLoginTimeout(); + public void setLoginTimeout(int seconds) throws SQLException { + this.datasource.setLoginTimeout(seconds); } @Override @@ -175,4 +171,14 @@ public T unwrap(Class iface) throws SQLException { public boolean isWrapperFor(Class iface) throws SQLException { return this.datasource.isWrapperFor(iface); } + + @Override + public ShardingKeyBuilder createShardingKeyBuilder() throws SQLException { + return this.datasource.createShardingKeyBuilder(); + } + + @Override + public ConnectionBuilder createConnectionBuilder() throws SQLException { + return this.datasource.createConnectionBuilder(); + } } diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/JfrDriver.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrDriver.java similarity index 78% rename from jdbc42/src/main/java/dev/jfr4jdbc/JfrDriver.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrDriver.java index 0af732c..685d7e3 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/JfrDriver.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrDriver.java @@ -1,13 +1,10 @@ package dev.jfr4jdbc; -import dev.jfr4jdbc.interceptor.DriverContext; -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.interceptor.InterceptorFactory; -import dev.jfr4jdbc.interceptor.InterceptorManager; -import dev.jfr4jdbc.internal.ConnectionInfo; +import dev.jfr4jdbc.interceptor.*; import dev.jfr4jdbc.internal.Label; import dev.jfr4jdbc.internal.ResourceMonitor; import dev.jfr4jdbc.internal.ResourceMonitorManager; +import dev.jfr4jdbc.internal.StillUnassignedConnectionInfo; import java.sql.*; import java.util.Properties; @@ -31,19 +28,19 @@ public class JfrDriver implements Driver { private final String label; - JfrDriver(Driver driver) { + public JfrDriver(Driver driver) { this(driver, InterceptorManager.getDefaultInterceptorFactory(), "Driver#" + defaultLabelCounter.incrementAndGet()); } - JfrDriver(Driver driver, InterceptorFactory interceptorFactory) { + public JfrDriver(Driver driver, InterceptorFactory interceptorFactory) { this(driver, interceptorFactory, "Driver#" + defaultLabelCounter.incrementAndGet()); } - JfrDriver(Driver driver, String label) { + public JfrDriver(Driver driver, String label) { this(driver, InterceptorManager.getDefaultInterceptorFactory(), label); } - JfrDriver(Driver driver, InterceptorFactory interceptorFactory, String label) { + public JfrDriver(Driver driver, InterceptorFactory interceptorFactory, String label) { this.wrappedDriver = driver; this.interceptorFactory = interceptorFactory; @@ -61,16 +58,19 @@ public boolean acceptsURL(String url) throws SQLException { public Connection connect(String url, Properties info) throws SQLException { int connectionId = connectionCounter.getAndIncrement(); - DriverContext context = new DriverContext(this.wrappedDriver, url, connectionId); + StillUnassignedConnectionInfo stillUnassignedConnectionInfo = new StillUnassignedConnectionInfo(this.label, connectionId); + DriverContext context = new DriverContext(this.wrappedDriver, stillUnassignedConnectionInfo, url); Interceptor interceptor = this.interceptorFactory.createDriverInterceptor(); Connection delegatedCon = null; + ConnectionInfo connectionInfo = null; try { this.resourceMonitor.waitAssigningResource(); interceptor.preInvoke(context); delegatedCon = this.wrappedDriver.connect(url, info); - context.setConnection(delegatedCon, 0); + connectionInfo = new ConnectionInfo(stillUnassignedConnectionInfo.dataSourceLabel, stillUnassignedConnectionInfo.conId, 0); + context.setConnection(delegatedCon, connectionInfo); } catch (SQLException | RuntimeException e) { context.setException(e); @@ -80,7 +80,7 @@ public Connection connect(String url, Properties info) throws SQLException { this.resourceMonitor.assignedResource(); } - return new JfrConnection(delegatedCon, interceptorFactory, this.resourceMonitor, new ConnectionInfo(this.label, connectionId, 0)); + return new JfrConnection(delegatedCon, interceptorFactory, this.resourceMonitor, connectionInfo); } @Override diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/JfrPreparedStatement.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrPreparedStatement.java similarity index 99% rename from jdbc42/src/main/java/dev/jfr4jdbc/JfrPreparedStatement.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrPreparedStatement.java index b6d55bc..e068202 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/JfrPreparedStatement.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrPreparedStatement.java @@ -4,8 +4,8 @@ import dev.jfr4jdbc.interceptor.InterceptorFactory; import dev.jfr4jdbc.interceptor.InterceptorManager; import dev.jfr4jdbc.interceptor.StatementContext; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.OperationInfo; +import dev.jfr4jdbc.interceptor.ConnectionInfo; +import dev.jfr4jdbc.interceptor.OperationInfo; import java.io.InputStream; import java.io.Reader; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/JfrResultSet.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrResultSet.java similarity index 99% rename from jdbc42/src/main/java/dev/jfr4jdbc/JfrResultSet.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrResultSet.java index a1ea5b2..adfadb4 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/JfrResultSet.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrResultSet.java @@ -4,8 +4,8 @@ import dev.jfr4jdbc.interceptor.InterceptorFactory; import dev.jfr4jdbc.interceptor.InterceptorManager; import dev.jfr4jdbc.interceptor.ResultSetContext; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.OperationInfo; +import dev.jfr4jdbc.interceptor.ConnectionInfo; +import dev.jfr4jdbc.interceptor.OperationInfo; import java.io.InputStream; import java.io.Reader; @@ -372,19 +372,14 @@ public boolean previous() throws SQLException { return this.resultSet.previous(); } - @Override - public void setFetchDirection(int direction) throws SQLException { - this.resultSet.setFetchDirection(direction); - } - @Override public int getFetchDirection() throws SQLException { return this.resultSet.getFetchDirection(); } @Override - public void setFetchSize(int rows) throws SQLException { - this.resultSet.setFetchSize(rows); + public void setFetchDirection(int direction) throws SQLException { + this.resultSet.setFetchDirection(direction); } @Override @@ -392,6 +387,11 @@ public int getFetchSize() throws SQLException { return this.resultSet.getFetchSize(); } + @Override + public void setFetchSize(int rows) throws SQLException { + this.resultSet.setFetchSize(rows); + } + @Override public int getType() throws SQLException { return this.resultSet.getType(); diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/JfrServiceLoadedDriver.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrServiceLoadedDriver.java similarity index 86% rename from jdbc42/src/main/java/dev/jfr4jdbc/JfrServiceLoadedDriver.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrServiceLoadedDriver.java index cfd6546..3391063 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/JfrServiceLoadedDriver.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrServiceLoadedDriver.java @@ -1,13 +1,10 @@ package dev.jfr4jdbc; -import dev.jfr4jdbc.interceptor.DriverContext; -import dev.jfr4jdbc.interceptor.Interceptor; -import dev.jfr4jdbc.interceptor.InterceptorFactory; -import dev.jfr4jdbc.interceptor.InterceptorManager; -import dev.jfr4jdbc.internal.ConnectionInfo; +import dev.jfr4jdbc.interceptor.*; import dev.jfr4jdbc.internal.Label; import dev.jfr4jdbc.internal.ResourceMonitor; import dev.jfr4jdbc.internal.ResourceMonitorManager; +import dev.jfr4jdbc.internal.StillUnassignedConnectionInfo; import java.sql.*; import java.util.HashMap; @@ -23,10 +20,6 @@ public class JfrServiceLoadedDriver implements Driver { private static final String INTERCEPTOR_FACTORY_ATTRIBUTE_NAME = "jfr-interceptor-factory"; - private final Map counterForUrl = new HashMap<>(1); - - private final Map driverCache = new HashMap<>(1); - static { try { DriverManager.registerDriver(new JfrServiceLoadedDriver()); @@ -35,14 +28,8 @@ public class JfrServiceLoadedDriver implements Driver { } } - /** - * @param url - * @return - */ - private static final String getDelegateUrl(String url) { - String delegateUrl = "jdbc" + url.substring(JFR4JDBC_URL_PREFIX_LENGTH); - return delegateUrl; - } + private final Map counterForUrl = new HashMap<>(1); + private final Map driverCache = new HashMap<>(1); /** * @@ -52,6 +39,15 @@ public JfrServiceLoadedDriver() { super(); } + /** + * @param url + * @return + */ + private static final String getDelegateUrl(String url) { + String delegateUrl = "jdbc" + url.substring(JFR4JDBC_URL_PREFIX_LENGTH); + return delegateUrl; + } + private InterceptorFactory loadInterceptorFactory(String url, Properties info) { return InterceptorManager.getDefaultInterceptorFactory(); } @@ -93,16 +89,17 @@ public Connection connect(String url, Properties info) throws SQLException { } // Get a delegated Driver - String delegeteUrl = JfrServiceLoadedDriver.getDelegateUrl(url); - Driver delegateDriver = this.getDelegatedDriver(delegeteUrl); + String delegateUrl = JfrServiceLoadedDriver.getDelegateUrl(url); + Driver delegateDriver = this.getDelegatedDriver(delegateUrl); if (delegateDriver == null) { return null; } - int connectionId = counterForUrl.computeIfAbsent(delegeteUrl, u -> new AtomicInteger(1)).getAndIncrement(); - DriverContext context = new DriverContext(delegateDriver, delegeteUrl, connectionId); + int connectionId = counterForUrl.computeIfAbsent(delegateUrl, u -> new AtomicInteger(1)).getAndIncrement(); + StillUnassignedConnectionInfo stillUnassignedConnectionInfo = new StillUnassignedConnectionInfo(url, connectionId); + DriverContext context = new DriverContext(delegateDriver, stillUnassignedConnectionInfo, delegateUrl); - Map urlAttributes = this.getUrlAttribute(delegeteUrl); + Map urlAttributes = this.getUrlAttribute(delegateUrl); InterceptorFactory interceptorFactory = null; if (urlAttributes.containsKey(INTERCEPTOR_FACTORY_ATTRIBUTE_NAME)) { interceptorFactory = InterceptorManager.getInterceptorFactory(urlAttributes.get(INTERCEPTOR_FACTORY_ATTRIBUTE_NAME)); @@ -112,20 +109,22 @@ public Connection connect(String url, Properties info) throws SQLException { Interceptor interceptor = interceptorFactory.createDriverInterceptor(); - Label label = new Label(delegeteUrl); + Label label = new Label(delegateUrl); ResourceMonitor monitor = ResourceMonitorManager.getInstance().getOrCreateResourceMonitor(label); // Connecting to delegated url and recording connect event. Connection delegatedCon = null; + ConnectionInfo connectionInfo = null; try { monitor.waitAssigningResource(); interceptor.preInvoke(context); - delegatedCon = delegateDriver.connect(delegeteUrl, info); + delegatedCon = delegateDriver.connect(delegateUrl, info); if (delegatedCon == null) { throw new SQLException("Invalid driver url: " + url); } - context.setConnection(delegatedCon, 0); + connectionInfo = new ConnectionInfo(stillUnassignedConnectionInfo.dataSourceLabel, stillUnassignedConnectionInfo.conId, 0); + context.setConnection(delegatedCon, connectionInfo); } catch (SQLException | RuntimeException e) { context.setException(e); @@ -135,7 +134,7 @@ public Connection connect(String url, Properties info) throws SQLException { monitor.assignedResource(); } - return new JfrConnection(delegatedCon, loadInterceptorFactory(url, info), monitor, new ConnectionInfo(delegeteUrl, connectionId, 0)); + return new JfrConnection(delegatedCon, loadInterceptorFactory(url, info), monitor, new ConnectionInfo(delegateUrl, connectionId, 0)); } @Override diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/JfrStatement42.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrStatement.java similarity index 93% rename from jdbc42/src/main/java/dev/jfr4jdbc/JfrStatement42.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrStatement.java index 2ea847d..b5d61e5 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/JfrStatement42.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/JfrStatement.java @@ -1,12 +1,12 @@ package dev.jfr4jdbc; import dev.jfr4jdbc.interceptor.*; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.OperationInfo; +import dev.jfr4jdbc.interceptor.ConnectionInfo; +import dev.jfr4jdbc.interceptor.OperationInfo; import java.sql.*; -abstract public class JfrStatement42 implements Statement { +public class JfrStatement implements Statement { protected final InterceptorFactory interceptorFactory; protected final Statement jdbcStatement; @@ -14,22 +14,17 @@ abstract public class JfrStatement42 implements Statement { private final ConnectionInfo connectionInfo; private final OperationInfo operationInfo; - - public OperationInfo getOperationInfo() { - return this.operationInfo; - } - private StringBuilder batchSql; - protected JfrStatement42(Statement s) { + public JfrStatement(Statement s) { this(s, InterceptorManager.getDefaultInterceptorFactory(), new ConnectionInfo(null, 0, 0), new OperationInfo(0)); } - protected JfrStatement42(Statement s, InterceptorFactory factory) { + public JfrStatement(Statement s, InterceptorFactory factory) { this(s, factory, new ConnectionInfo(null, 0, 0), new OperationInfo(0)); } - protected JfrStatement42(Statement s, InterceptorFactory factory, ConnectionInfo connectionInfo, OperationInfo operationInfo) { + public JfrStatement(Statement s, InterceptorFactory factory, ConnectionInfo connectionInfo, OperationInfo operationInfo) { super(); this.jdbcStatement = s; this.interceptorFactory = factory; @@ -37,6 +32,10 @@ protected JfrStatement42(Statement s, InterceptorFactory factory, ConnectionInfo this.operationInfo = operationInfo; } + public OperationInfo getOperationInfo() { + return this.operationInfo; + } + protected StatementContext createContext(String inquiry, boolean isPrepared) { StatementContext context = new StatementContext(this.jdbcStatement, this.connectionInfo, this.operationInfo, inquiry, isPrepared); @@ -420,12 +419,6 @@ public boolean getMoreResults() throws SQLException { return this.jdbcStatement.getMoreResults(); } - @Override - public void setFetchDirection(int direction) throws SQLException { - - this.jdbcStatement.setFetchDirection(direction); - } - @Override public int getFetchDirection() throws SQLException { @@ -433,8 +426,9 @@ public int getFetchDirection() throws SQLException { } @Override - public void setFetchSize(int rows) throws SQLException { - this.jdbcStatement.setFetchSize(rows); + public void setFetchDirection(int direction) throws SQLException { + + this.jdbcStatement.setFetchDirection(direction); } @Override @@ -442,6 +436,11 @@ public int getFetchSize() throws SQLException { return this.jdbcStatement.getFetchSize(); } + @Override + public void setFetchSize(int rows) throws SQLException { + this.jdbcStatement.setFetchSize(rows); + } + @Override public int getResultSetConcurrency() throws SQLException { return this.jdbcStatement.getResultSetConcurrency(); @@ -475,13 +474,13 @@ public boolean isClosed() throws SQLException { } @Override - public void setPoolable(boolean poolable) throws SQLException { - this.jdbcStatement.setPoolable(poolable); + public boolean isPoolable() throws SQLException { + return this.jdbcStatement.isPoolable(); } @Override - public boolean isPoolable() throws SQLException { - return this.jdbcStatement.isPoolable(); + public void setPoolable(boolean poolable) throws SQLException { + this.jdbcStatement.setPoolable(poolable); } @Override @@ -500,13 +499,13 @@ public long getLargeUpdateCount() throws SQLException { } @Override - public void setLargeMaxRows(long max) throws SQLException { - this.jdbcStatement.setLargeMaxRows(max); + public long getLargeMaxRows() throws SQLException { + return this.jdbcStatement.getLargeMaxRows(); } @Override - public long getLargeMaxRows() throws SQLException { - return this.jdbcStatement.getLargeMaxRows(); + public void setLargeMaxRows(long max) throws SQLException { + this.jdbcStatement.setLargeMaxRows(max); } @Override @@ -533,4 +532,24 @@ public long executeLargeUpdate(String sql, int[] columnIndexes) throws SQLExcept public long executeLargeUpdate(String sql, String[] columnNames) throws SQLException { return this.jdbcStatement.executeLargeUpdate(sql, columnNames); } -} + + @Override + public String enquoteLiteral(String val) throws SQLException { + return this.jdbcStatement.enquoteLiteral(val); + } + + @Override + public String enquoteIdentifier(String identifier, boolean alwaysQuote) throws SQLException { + return this.jdbcStatement.enquoteIdentifier(identifier, alwaysQuote); + } + + @Override + public boolean isSimpleIdentifier(String identifier) throws SQLException { + return this.jdbcStatement.isSimpleIdentifier(identifier); + } + + @Override + public String enquoteNCharLiteral(String val) throws SQLException { + return this.jdbcStatement.enquoteNCharLiteral(val); + } +} \ No newline at end of file diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/ResourceMetrics.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/ResourceMetrics.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/ResourceMetrics.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/ResourceMetrics.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/WrappedConnectionId.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/WrappedConnectionId.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/WrappedConnectionId.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/WrappedConnectionId.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/event/CancelEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/CancelEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/event/CancelEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/CancelEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/event/CloseEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/CloseEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/event/CloseEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/CloseEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/event/CommitEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/CommitEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/event/CommitEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/CommitEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/event/ConnectEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/ConnectEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/event/ConnectEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/ConnectEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/event/JdbcEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/JdbcEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/event/JdbcEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/JdbcEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/event/ResultSetEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/ResultSetEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/event/ResultSetEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/ResultSetEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/event/RollbackEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/RollbackEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/event/RollbackEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/RollbackEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/event/StatementEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/StatementEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/event/StatementEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/StatementEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/event/jfr/JfrCancelEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/jfr/JfrCancelEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/event/jfr/JfrCancelEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/jfr/JfrCancelEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/event/jfr/JfrCloseEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/jfr/JfrCloseEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/event/jfr/JfrCloseEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/jfr/JfrCloseEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/event/jfr/JfrCommitEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/jfr/JfrCommitEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/event/jfr/JfrCommitEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/jfr/JfrCommitEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/event/jfr/JfrConnectionEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/jfr/JfrConnectionEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/event/jfr/JfrConnectionEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/jfr/JfrConnectionEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/event/jfr/JfrJdbcEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/jfr/JfrJdbcEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/event/jfr/JfrJdbcEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/jfr/JfrJdbcEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/event/jfr/JfrResultSetEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/jfr/JfrResultSetEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/event/jfr/JfrResultSetEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/jfr/JfrResultSetEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/event/jfr/JfrRollbackEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/jfr/JfrRollbackEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/event/jfr/JfrRollbackEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/jfr/JfrRollbackEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/event/jfr/JfrStatementEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/jfr/JfrStatementEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/event/jfr/JfrStatementEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/event/jfr/JfrStatementEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/CancelContext.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/CancelContext.java similarity index 89% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/CancelContext.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/CancelContext.java index 7d0264e..43e3f69 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/CancelContext.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/CancelContext.java @@ -1,8 +1,5 @@ package dev.jfr4jdbc.interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.OperationInfo; - import java.sql.Connection; import java.sql.Statement; @@ -25,11 +22,11 @@ public CancelContext(Connection connection, Statement statement, ConnectionInfo this.operationInfo = operationInfo; } - public void setException(Exception e) { - this.exception = e; - } - public Exception getException() { return exception; } + + public void setException(Exception e) { + this.exception = e; + } } diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/CloseContext.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/CloseContext.java similarity index 87% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/CloseContext.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/CloseContext.java index 7989609..2882ab0 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/CloseContext.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/CloseContext.java @@ -1,8 +1,5 @@ package dev.jfr4jdbc.interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.OperationInfo; - import java.sql.Connection; public class CloseContext { @@ -21,11 +18,11 @@ public CloseContext(Connection connection, ConnectionInfo connectionInfo, Operat this.operationInfo = operationInfo; } - public void setException(Exception e) { - this.exception = e; - } - public Exception getException() { return exception; } + + public void setException(Exception e) { + this.exception = e; + } } diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/CommitContext.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/CommitContext.java similarity index 88% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/CommitContext.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/CommitContext.java index 04c20a6..c08800b 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/CommitContext.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/CommitContext.java @@ -1,8 +1,5 @@ package dev.jfr4jdbc.interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.OperationInfo; - import java.sql.Connection; public class CommitContext { @@ -21,11 +18,11 @@ public CommitContext(Connection connection, ConnectionInfo connectionInfo, Opera this.operationInfo = operationInfo; } - public void setException(Exception e) { - this.exception = e; - } - public Exception getException() { return exception; } + + public void setException(Exception e) { + this.exception = e; + } } diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/internal/ConnectionInfo.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/ConnectionInfo.java similarity index 97% rename from jdbc42/src/main/java/dev/jfr4jdbc/internal/ConnectionInfo.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/ConnectionInfo.java index 7f08155..046b91a 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/internal/ConnectionInfo.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/ConnectionInfo.java @@ -1,4 +1,4 @@ -package dev.jfr4jdbc.internal; +package dev.jfr4jdbc.interceptor; import java.util.Objects; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/DataSourceContext.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/DataSourceContext.java similarity index 68% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/DataSourceContext.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/DataSourceContext.java index 9c92c64..764c4e4 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/DataSourceContext.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/DataSourceContext.java @@ -1,6 +1,6 @@ package dev.jfr4jdbc.interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; +import dev.jfr4jdbc.internal.StillUnassignedConnectionInfo; import javax.sql.DataSource; import java.sql.Connection; @@ -9,10 +9,12 @@ public class DataSourceContext { public final DataSource dataSource; - private ConnectionInfo connectionInfo; - + @Deprecated public final int dataSourceId; + public final StillUnassignedConnectionInfo stillUnassignedConnectionInfo; + + private ConnectionInfo connectionInfo; private String username; private String password; @@ -21,10 +23,10 @@ public class DataSourceContext { private Exception exception; - public DataSourceContext(DataSource dataSource, ConnectionInfo connectionInfo, int dataSourceId) { + public DataSourceContext(DataSource dataSource, StillUnassignedConnectionInfo stillUnassignedConnectionInfo, int dataSourceId4Legacy) { this.dataSource = dataSource; - this.connectionInfo = connectionInfo; - this.dataSourceId = dataSourceId; + this.stillUnassignedConnectionInfo = stillUnassignedConnectionInfo; + this.dataSourceId = dataSourceId4Legacy; } public ConnectionInfo getConnectionInfo() { @@ -48,9 +50,9 @@ public Connection getConnection() { return connection; } - public void setConnection(Connection connection, int wrappedConnectionId) { + public void setConnection(Connection connection, ConnectionInfo connectionInfo) { this.connection = connection; - this.connectionInfo = new ConnectionInfo(this.connectionInfo.dataSourceLabel, this.connectionInfo.conId, wrappedConnectionId); + this.connectionInfo = connectionInfo; } public Exception getException() { diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/DriverContext.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/DriverContext.java similarity index 61% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/DriverContext.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/DriverContext.java index 8385914..8d6bcef 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/DriverContext.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/DriverContext.java @@ -1,6 +1,6 @@ package dev.jfr4jdbc.interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; +import dev.jfr4jdbc.internal.StillUnassignedConnectionInfo; import java.sql.Connection; import java.sql.Driver; @@ -10,17 +10,16 @@ public class DriverContext { public final Driver driver; public final String url; - + public final StillUnassignedConnectionInfo stillUnassignedConnectionInfo; private ConnectionInfo connectionInfo; - private Connection connection; private Exception exception; - public DriverContext(Driver driver, String url, int connectionId) { + public DriverContext(Driver driver, StillUnassignedConnectionInfo stillUnassignedConnectionInfo, String url) { this.driver = driver; this.url = url; - this.connectionInfo = new ConnectionInfo(url, connectionId, 0); + this.stillUnassignedConnectionInfo = stillUnassignedConnectionInfo; } public ConnectionInfo getConnectionInfo() { @@ -31,9 +30,9 @@ public Connection getConnection() { return connection; } - public void setConnection(Connection connection, int wrappedConnectionId) { + public void setConnection(Connection connection, ConnectionInfo connectionInfo) { this.connection = connection; - this.connectionInfo = new ConnectionInfo(url, this.connectionInfo.conId, wrappedConnectionId); + this.connectionInfo = connectionInfo; } public Exception getException() { diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/Interceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/Interceptor.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/Interceptor.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/Interceptor.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/InterceptorFactory.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/InterceptorFactory.java similarity index 87% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/InterceptorFactory.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/InterceptorFactory.java index becf766..557cad4 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/InterceptorFactory.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/InterceptorFactory.java @@ -1,7 +1,7 @@ package dev.jfr4jdbc.interceptor; public interface InterceptorFactory { - + Interceptor createDataSourceInterceptor(); Interceptor createDriverInterceptor(); @@ -17,6 +17,4 @@ public interface InterceptorFactory { Interceptor createCancelInterceptor(); Interceptor createResultSetInterceptor(); - - Interceptor createResourceMonitorInterceptor(); } diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/InterceptorManager.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/InterceptorManager.java similarity index 65% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/InterceptorManager.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/InterceptorManager.java index 7f4205b..12b43e3 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/InterceptorManager.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/InterceptorManager.java @@ -1,18 +1,17 @@ package dev.jfr4jdbc.interceptor; -import dev.jfr4jdbc.interceptor.impl.instant.InstantInterceptorFactory; -import dev.jfr4jdbc.interceptor.impl.legacy.LegacyInterceptorFactory; -import dev.jfr4jdbc.interceptor.impl.period.PeriodInterceptorFactory; +import dev.jfr4jdbc.interceptor.legacy.LegacyInterceptorFactory; +import dev.jfr4jdbc.interceptor.std.DefaultInterceptorFactory; import dev.jfr4jdbc.internal.Jfr4Jdbc; public class InterceptorManager { + private static InterceptorFactory defaultInterceptorFactory; + static { Jfr4Jdbc.initialize(); } - private static InterceptorFactory defaultInterceptorFactory; - public static InterceptorFactory getDefaultInterceptorFactory() { return defaultInterceptorFactory; } @@ -25,13 +24,10 @@ public static InterceptorFactory getInterceptorFactory(String defaultInterceptor if (defaultInterceptorParameter != null) { - if (defaultInterceptorParameter.toLowerCase().equals("instant")) { - return new InstantInterceptorFactory(); - - } else if (defaultInterceptorParameter.toLowerCase().equals("legacy")) { + if (defaultInterceptorParameter.toLowerCase().equals("legacy")) { return new LegacyInterceptorFactory(); } } - return new PeriodInterceptorFactory(); + return new DefaultInterceptorFactory(); } } diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/internal/OperationInfo.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/OperationInfo.java similarity index 95% rename from jdbc42/src/main/java/dev/jfr4jdbc/internal/OperationInfo.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/OperationInfo.java index 3b7d011..bf485a8 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/internal/OperationInfo.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/OperationInfo.java @@ -1,4 +1,4 @@ -package dev.jfr4jdbc.internal; +package dev.jfr4jdbc.interceptor; import java.util.Objects; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/ResultSetContext.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/ResultSetContext.java similarity index 91% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/ResultSetContext.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/ResultSetContext.java index 7de0801..a15c7ad 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/ResultSetContext.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/ResultSetContext.java @@ -1,8 +1,5 @@ package dev.jfr4jdbc.interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.OperationInfo; - import java.sql.ResultSet; public class ResultSetContext { @@ -42,11 +39,11 @@ public void setRowNo(int rowNo) { this.rowNo = rowNo; } - public void setException(Exception e) { - this.exception = e; - } - public Exception getException() { return exception; } + + public void setException(Exception e) { + this.exception = e; + } } diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/RollbackContext.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/RollbackContext.java similarity index 88% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/RollbackContext.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/RollbackContext.java index 4b7dd14..52b5ab2 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/RollbackContext.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/RollbackContext.java @@ -1,8 +1,5 @@ package dev.jfr4jdbc.interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.OperationInfo; - import java.sql.Connection; public class RollbackContext { @@ -21,11 +18,11 @@ public RollbackContext(Connection connection, ConnectionInfo connectionInfo, Ope this.operationInfo = operationInfo; } - public void setException(Exception e) { - this.exception = e; - } - public Exception getException() { return exception; } + + public void setException(Exception e) { + this.exception = e; + } } diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/StatementContext.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/StatementContext.java similarity index 95% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/StatementContext.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/StatementContext.java index a698196..7a7bea1 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/StatementContext.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/StatementContext.java @@ -1,25 +1,16 @@ package dev.jfr4jdbc.interceptor; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.OperationInfo; - import java.sql.Connection; import java.sql.Statement; public class StatementContext { - private Connection connection; - public final Statement statement; - public final ConnectionInfo connectionInfo; - public final OperationInfo operationInfo; - public final String inquiry; - public final boolean isPrepared; - + private Connection connection; private String inquiryParameter; private boolean isStatementPoolable; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyCancelInterceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyCancelInterceptor.java similarity index 94% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyCancelInterceptor.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyCancelInterceptor.java index 78e2703..cbf0bf2 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyCancelInterceptor.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyCancelInterceptor.java @@ -1,4 +1,4 @@ -package dev.jfr4jdbc.interceptor.impl.legacy; +package dev.jfr4jdbc.interceptor.legacy; import dev.jfr4jdbc.EventFactory; import dev.jfr4jdbc.event.CancelEvent; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyCloseInterceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyCloseInterceptor.java similarity index 94% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyCloseInterceptor.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyCloseInterceptor.java index 189454e..1c4977c 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyCloseInterceptor.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyCloseInterceptor.java @@ -1,4 +1,4 @@ -package dev.jfr4jdbc.interceptor.impl.legacy; +package dev.jfr4jdbc.interceptor.legacy; import dev.jfr4jdbc.EventFactory; import dev.jfr4jdbc.event.CloseEvent; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyCommitInterceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyCommitInterceptor.java similarity index 94% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyCommitInterceptor.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyCommitInterceptor.java index af8ec11..3429466 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyCommitInterceptor.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyCommitInterceptor.java @@ -1,4 +1,4 @@ -package dev.jfr4jdbc.interceptor.impl.legacy; +package dev.jfr4jdbc.interceptor.legacy; import dev.jfr4jdbc.EventFactory; import dev.jfr4jdbc.event.CommitEvent; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyDataSourceInterceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyDataSourceInterceptor.java similarity index 96% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyDataSourceInterceptor.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyDataSourceInterceptor.java index 7218199..ab59f65 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyDataSourceInterceptor.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyDataSourceInterceptor.java @@ -1,4 +1,4 @@ -package dev.jfr4jdbc.interceptor.impl.legacy; +package dev.jfr4jdbc.interceptor.legacy; import dev.jfr4jdbc.EventFactory; import dev.jfr4jdbc.event.ConnectEvent; @@ -8,13 +8,12 @@ public class LegacyDataSourceInterceptor implements Interceptor { private final EventFactory factory; + private ConnectEvent event; public LegacyDataSourceInterceptor(EventFactory factory) { this.factory = factory; } - private ConnectEvent event; - @Override public void preInvoke(DataSourceContext context) { this.event = factory.createConnectEvent(); diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyDriverInterceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyDriverInterceptor.java similarity index 95% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyDriverInterceptor.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyDriverInterceptor.java index 8c86bb4..3fcb5de 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyDriverInterceptor.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyDriverInterceptor.java @@ -1,4 +1,4 @@ -package dev.jfr4jdbc.interceptor.impl.legacy; +package dev.jfr4jdbc.interceptor.legacy; import dev.jfr4jdbc.EventFactory; import dev.jfr4jdbc.event.ConnectEvent; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyInterceptorFactory.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyInterceptorFactory.java similarity index 86% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyInterceptorFactory.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyInterceptorFactory.java index d0142c1..6767a7e 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyInterceptorFactory.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyInterceptorFactory.java @@ -1,8 +1,7 @@ -package dev.jfr4jdbc.interceptor.impl.legacy; +package dev.jfr4jdbc.interceptor.legacy; import dev.jfr4jdbc.EventFactory; import dev.jfr4jdbc.interceptor.*; -import dev.jfr4jdbc.interceptor.impl.ResourceMonitorInterceptor; public class LegacyInterceptorFactory implements InterceptorFactory { @@ -55,9 +54,4 @@ public Interceptor createCancelInterceptor() { public Interceptor createResultSetInterceptor() { return new LegacyResultSetInterceptor(this.eventFactory); } - - @Override - public Interceptor createResourceMonitorInterceptor() { - return new ResourceMonitorInterceptor(); - } } diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyResultSetInterceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyResultSetInterceptor.java similarity index 95% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyResultSetInterceptor.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyResultSetInterceptor.java index 0d0a895..4024f85 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyResultSetInterceptor.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyResultSetInterceptor.java @@ -1,4 +1,4 @@ -package dev.jfr4jdbc.interceptor.impl.legacy; +package dev.jfr4jdbc.interceptor.legacy; import dev.jfr4jdbc.EventFactory; import dev.jfr4jdbc.event.ResultSetEvent; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyRollbackInterceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyRollbackInterceptor.java similarity index 94% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyRollbackInterceptor.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyRollbackInterceptor.java index 99e7888..f9ba6e3 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyRollbackInterceptor.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyRollbackInterceptor.java @@ -1,4 +1,4 @@ -package dev.jfr4jdbc.interceptor.impl.legacy; +package dev.jfr4jdbc.interceptor.legacy; import dev.jfr4jdbc.EventFactory; import dev.jfr4jdbc.event.RollbackEvent; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyStatementInterceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyStatementInterceptor.java similarity index 96% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyStatementInterceptor.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyStatementInterceptor.java index ae13e46..3ec7253 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/legacy/LegacyStatementInterceptor.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/legacy/LegacyStatementInterceptor.java @@ -1,4 +1,4 @@ -package dev.jfr4jdbc.interceptor.impl.legacy; +package dev.jfr4jdbc.interceptor.legacy; import dev.jfr4jdbc.EventFactory; import dev.jfr4jdbc.event.StatementEvent; diff --git a/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/CancelInterceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/CancelInterceptor.java new file mode 100644 index 0000000..4eb9044 --- /dev/null +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/CancelInterceptor.java @@ -0,0 +1,60 @@ +package dev.jfr4jdbc.interceptor.std; + +import dev.jfr4jdbc.interceptor.CancelContext; +import dev.jfr4jdbc.interceptor.ConnectionInfo; +import dev.jfr4jdbc.interceptor.Interceptor; +import dev.jfr4jdbc.interceptor.std.event.CancelEndEvent; +import dev.jfr4jdbc.interceptor.std.event.CancelPeriodEvent; +import dev.jfr4jdbc.interceptor.std.event.CancelStartEvent; + +public class CancelInterceptor implements Interceptor { + + private CancelPeriodEvent periodEvent; + + @Override + public void preInvoke(CancelContext context) { + CancelStartEvent startEvent = new CancelStartEvent(); + if (startEvent.isEnabled()) { + ConnectionInfo conInfo = context.connectionInfo; + startEvent.dataSourceLabel = conInfo.dataSourceLabel; + startEvent.connectionId = conInfo.conId; + startEvent.wrappedConnectionId = conInfo.wrappedConId; + startEvent.operationId = context.operationInfo.id; + startEvent.commit(); + } + + periodEvent = new CancelPeriodEvent(); + periodEvent.begin(); + } + + @Override + public void postInvoke(CancelContext context) { + periodEvent.end(); + if (periodEvent.shouldCommit()) { + ConnectionInfo conInfo = context.connectionInfo; + periodEvent.dataSourceLabel = conInfo.dataSourceLabel; + periodEvent.connectionId = conInfo.conId; + periodEvent.wrappedConnectionId = conInfo.wrappedConId; + periodEvent.operationId = context.operationInfo.id; + if (context.getException() != null) { + periodEvent.exception = context.getException().getClass(); + periodEvent.exceptionMessage = context.getException().getMessage(); + } + periodEvent.commit(); + } + + CancelEndEvent endEvent = new CancelEndEvent(); + if (endEvent.isEnabled()) { + ConnectionInfo conInfo = context.connectionInfo; + endEvent.dataSourceLabel = conInfo.dataSourceLabel; + endEvent.connectionId = conInfo.conId; + endEvent.wrappedConnectionId = conInfo.wrappedConId; + endEvent.operationId = context.operationInfo.id; + if (context.getException() != null) { + endEvent.exception = context.getException().getClass(); + endEvent.exceptionMessage = context.getException().getMessage(); + } + endEvent.commit(); + } + } +} diff --git a/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/CloseInterceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/CloseInterceptor.java new file mode 100644 index 0000000..035d0f0 --- /dev/null +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/CloseInterceptor.java @@ -0,0 +1,60 @@ +package dev.jfr4jdbc.interceptor.std; + +import dev.jfr4jdbc.interceptor.CloseContext; +import dev.jfr4jdbc.interceptor.ConnectionInfo; +import dev.jfr4jdbc.interceptor.Interceptor; +import dev.jfr4jdbc.interceptor.std.event.CloseEndEvent; +import dev.jfr4jdbc.interceptor.std.event.ClosePeriodEvent; +import dev.jfr4jdbc.interceptor.std.event.CloseStartEvent; + +public class CloseInterceptor implements Interceptor { + + private ClosePeriodEvent periodEvent; + + @Override + public void preInvoke(CloseContext context) { + CloseStartEvent startEvent = new CloseStartEvent(); + if (startEvent.isEnabled()) { + ConnectionInfo conInfo = context.connectionInfo; + startEvent.dataSourceLabel = conInfo.dataSourceLabel; + startEvent.connectionId = conInfo.conId; + startEvent.wrappedConnectionId = conInfo.wrappedConId; + startEvent.operationId = context.operationInfo.id; + startEvent.commit(); + } + + periodEvent = new ClosePeriodEvent(); + periodEvent.begin(); + } + + @Override + public void postInvoke(CloseContext context) { + periodEvent.end(); + if (periodEvent.shouldCommit()) { + ConnectionInfo conInfo = context.connectionInfo; + periodEvent.dataSourceLabel = conInfo.dataSourceLabel; + periodEvent.connectionId = conInfo.conId; + periodEvent.wrappedConnectionId = conInfo.wrappedConId; + periodEvent.operationId = context.operationInfo.id; + if (context.getException() != null) { + periodEvent.exception = context.getException().getClass(); + periodEvent.exceptionMessage = context.getException().getMessage(); + } + periodEvent.commit(); + } + + CloseEndEvent endEvent = new CloseEndEvent(); + if (endEvent.isEnabled()) { + ConnectionInfo conInfo = context.connectionInfo; + endEvent.dataSourceLabel = conInfo.dataSourceLabel; + endEvent.connectionId = conInfo.conId; + endEvent.wrappedConnectionId = conInfo.wrappedConId; + endEvent.operationId = context.operationInfo.id; + if (context.getException() != null) { + endEvent.exception = context.getException().getClass(); + endEvent.exceptionMessage = context.getException().getMessage(); + } + endEvent.commit(); + } + } +} diff --git a/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/CommitInterceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/CommitInterceptor.java new file mode 100644 index 0000000..dad15a4 --- /dev/null +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/CommitInterceptor.java @@ -0,0 +1,60 @@ +package dev.jfr4jdbc.interceptor.std; + +import dev.jfr4jdbc.interceptor.CommitContext; +import dev.jfr4jdbc.interceptor.ConnectionInfo; +import dev.jfr4jdbc.interceptor.Interceptor; +import dev.jfr4jdbc.interceptor.std.event.CommitEndEvent; +import dev.jfr4jdbc.interceptor.std.event.CommitPeriodEvent; +import dev.jfr4jdbc.interceptor.std.event.CommitStartEvent; + +public class CommitInterceptor implements Interceptor { + + private CommitPeriodEvent periodEvent; + + @Override + public void preInvoke(CommitContext context) { + CommitStartEvent startEvent = new CommitStartEvent(); + if (startEvent.isEnabled()) { + ConnectionInfo conInfo = context.connectionInfo; + startEvent.dataSourceLabel = conInfo.dataSourceLabel; + startEvent.connectionId = conInfo.conId; + startEvent.wrappedConnectionId = conInfo.wrappedConId; + startEvent.operationId = context.operationInfo.id; + startEvent.commit(); + } + + periodEvent = new CommitPeriodEvent(); + periodEvent.begin(); + } + + @Override + public void postInvoke(CommitContext context) { + periodEvent.end(); + if (periodEvent.shouldCommit()) { + ConnectionInfo conInfo = context.connectionInfo; + periodEvent.dataSourceLabel = conInfo.dataSourceLabel; + periodEvent.connectionId = conInfo.conId; + periodEvent.wrappedConnectionId = conInfo.wrappedConId; + periodEvent.operationId = context.operationInfo.id; + if (context.getException() != null) { + periodEvent.exception = context.getException().getClass(); + periodEvent.exceptionMessage = context.getException().getMessage(); + } + periodEvent.commit(); + } + + CommitEndEvent endEvent = new CommitEndEvent(); + if (endEvent.isEnabled()) { + ConnectionInfo conInfo = context.connectionInfo; + endEvent.dataSourceLabel = conInfo.dataSourceLabel; + endEvent.connectionId = conInfo.conId; + endEvent.wrappedConnectionId = conInfo.wrappedConId; + endEvent.operationId = context.operationInfo.id; + if (context.getException() != null) { + endEvent.exception = context.getException().getClass(); + endEvent.exceptionMessage = context.getException().getMessage(); + } + endEvent.commit(); + } + } +} diff --git a/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/DataSourceInterceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/DataSourceInterceptor.java new file mode 100644 index 0000000..614d25e --- /dev/null +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/DataSourceInterceptor.java @@ -0,0 +1,64 @@ +package dev.jfr4jdbc.interceptor.std; + +import dev.jfr4jdbc.interceptor.ConnectionInfo; +import dev.jfr4jdbc.interceptor.DataSourceContext; +import dev.jfr4jdbc.interceptor.Interceptor; +import dev.jfr4jdbc.interceptor.std.event.DataSourceEndEvent; +import dev.jfr4jdbc.interceptor.std.event.DataSourcePeriodEvent; +import dev.jfr4jdbc.interceptor.std.event.DataSourceStartEvent; + +public class DataSourceInterceptor implements Interceptor { + + private DataSourcePeriodEvent periodEvent; + + @Override + public void preInvoke(DataSourceContext context) { + DataSourceStartEvent startEvent = new DataSourceStartEvent(); + if (startEvent.isEnabled()) { + ConnectionInfo conInfo = context.getConnectionInfo(); + startEvent.dataSourceLabel = conInfo.dataSourceLabel; + startEvent.connectionId = conInfo.conId; + startEvent.username = context.getUsername(); + startEvent.password = context.getPassword(); + startEvent.commit(); + } + + periodEvent = new DataSourcePeriodEvent(); + periodEvent.begin(); + } + + @Override + public void postInvoke(DataSourceContext context) { + periodEvent.end(); + if (periodEvent.shouldCommit()) { + ConnectionInfo conInfo = context.getConnectionInfo(); + periodEvent.dataSourceLabel = conInfo.dataSourceLabel; + periodEvent.connectionId = conInfo.conId; + periodEvent.wrappedConnectionId = conInfo.wrappedConId; + periodEvent.username = context.getUsername(); + periodEvent.password = context.getPassword(); + + if (context.getException() != null) { + periodEvent.exception = context.getException().getClass(); + periodEvent.exceptionMessage = context.getException().getMessage(); + } + periodEvent.commit(); + } + + DataSourceEndEvent endEvent = new DataSourceEndEvent(); + if (endEvent.isEnabled()) { + ConnectionInfo conInfo = context.getConnectionInfo(); + endEvent.dataSourceLabel = conInfo.dataSourceLabel; + endEvent.connectionId = conInfo.conId; + endEvent.wrappedConnectionId = conInfo.wrappedConId; + endEvent.username = context.getUsername(); + endEvent.password = context.getPassword(); + + if (context.getException() != null) { + endEvent.exception = context.getException().getClass(); + endEvent.exceptionMessage = context.getException().getMessage(); + } + endEvent.commit(); + } + } +} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantInterceptorFactory.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/DefaultInterceptorFactory.java similarity index 51% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantInterceptorFactory.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/DefaultInterceptorFactory.java index 5ae7a66..ca0dc69 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/InstantInterceptorFactory.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/DefaultInterceptorFactory.java @@ -1,51 +1,45 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std; import dev.jfr4jdbc.interceptor.*; -import dev.jfr4jdbc.interceptor.impl.ResourceMonitorInterceptor; -public class InstantInterceptorFactory implements InterceptorFactory { +public class DefaultInterceptorFactory implements InterceptorFactory { @Override public Interceptor createDataSourceInterceptor() { - return new InstantDataSourceInterceptor(); + return new DataSourceInterceptor(); } @Override public Interceptor createDriverInterceptor() { - return new InstantDriverInterceptor(); + return new DriverInterceptor(); } @Override public Interceptor createCommitInterceptor() { - return new InstantCommitInterceptor(); + return new CommitInterceptor(); } @Override public Interceptor createRollbackInterceptor() { - return new InstantRollbackInterceptor(); + return new RollbackInterceptor(); } @Override public Interceptor createCloseInterceptor() { - return new InstantCloseInterceptor(); + return new CloseInterceptor(); } @Override public Interceptor createStatementInterceptor() { - return new InstantStatementInterceptor(); + return new StatementInterceptor(); } @Override public Interceptor createCancelInterceptor() { - return new InstantCancelInterceptor(); + return new CancelInterceptor(); } @Override public Interceptor createResultSetInterceptor() { - return new InstantResultSetInterceptor(); - } - - @Override - public Interceptor createResourceMonitorInterceptor() { - return new ResourceMonitorInterceptor(); + return new ResultSetInterceptor(); } } diff --git a/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/DriverInterceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/DriverInterceptor.java new file mode 100644 index 0000000..11292dd --- /dev/null +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/DriverInterceptor.java @@ -0,0 +1,61 @@ +package dev.jfr4jdbc.interceptor.std; + +import dev.jfr4jdbc.interceptor.ConnectionInfo; +import dev.jfr4jdbc.interceptor.DriverContext; +import dev.jfr4jdbc.interceptor.Interceptor; +import dev.jfr4jdbc.interceptor.std.event.DriverEndEvent; +import dev.jfr4jdbc.interceptor.std.event.DriverPeriodEvent; +import dev.jfr4jdbc.interceptor.std.event.DriverStartEvent; + +public class DriverInterceptor implements Interceptor { + + private DriverPeriodEvent periodEvent; + + @Override + public void preInvoke(DriverContext context) { + DriverStartEvent startEvent = new DriverStartEvent(); + if (startEvent.isEnabled()) { + ConnectionInfo conInfo = context.getConnectionInfo(); + startEvent.label = conInfo.dataSourceLabel; + startEvent.connectionId = conInfo.conId; + startEvent.url = context.url; + startEvent.commit(); + } + + periodEvent = new DriverPeriodEvent(); + periodEvent.begin(); + } + + @Override + public void postInvoke(DriverContext context) { + periodEvent.end(); + if (periodEvent.shouldCommit()) { + ConnectionInfo conInfo = context.getConnectionInfo(); + periodEvent.label = conInfo.dataSourceLabel; + periodEvent.connectionId = conInfo.conId; + periodEvent.wrappedConnectionId = conInfo.wrappedConId; + periodEvent.url = context.url; + + if (context.getException() != null) { + periodEvent.exception = context.getException().getClass(); + periodEvent.exceptionMessage = context.getException().getMessage(); + } + periodEvent.commit(); + } + + DriverEndEvent endEvent = new DriverEndEvent(); + if (endEvent.isEnabled()) { + ConnectionInfo conInfo = context.getConnectionInfo(); + endEvent.label = conInfo.dataSourceLabel; + endEvent.connectionId = conInfo.conId; + endEvent.wrappedConnectionId = conInfo.wrappedConId; + endEvent.url = context.url; + + if (context.getException() != null) { + endEvent.exception = context.getException().getClass(); + endEvent.exceptionMessage = context.getException().getMessage(); + } + endEvent.commit(); + } + } +} diff --git a/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/ResultSetInterceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/ResultSetInterceptor.java new file mode 100644 index 0000000..37f56e0 --- /dev/null +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/ResultSetInterceptor.java @@ -0,0 +1,64 @@ +package dev.jfr4jdbc.interceptor.std; + +import dev.jfr4jdbc.interceptor.ConnectionInfo; +import dev.jfr4jdbc.interceptor.Interceptor; +import dev.jfr4jdbc.interceptor.ResultSetContext; +import dev.jfr4jdbc.interceptor.std.event.ResultSetEndEvent; +import dev.jfr4jdbc.interceptor.std.event.ResultSetPeriodEvent; +import dev.jfr4jdbc.interceptor.std.event.ResultSetStartEvent; + +public class ResultSetInterceptor implements Interceptor { + + private ResultSetPeriodEvent periodEvent; + + @Override + public void preInvoke(ResultSetContext context) { + ResultSetStartEvent startEvent = new ResultSetStartEvent(); + if (startEvent.isEnabled()) { + ConnectionInfo conInfo = context.connectionInfo; + startEvent.dataSourceLabel = conInfo.dataSourceLabel; + startEvent.connectionId = conInfo.conId; + startEvent.wrappedConnectionId = conInfo.wrappedConId; + startEvent.operationId = context.operationInfo.id; + startEvent.commit(); + } + + periodEvent = new ResultSetPeriodEvent(); + periodEvent.begin(); + } + + @Override + public void postInvoke(ResultSetContext context) { + periodEvent.end(); + if (periodEvent.shouldCommit()) { + ConnectionInfo conInfo = context.connectionInfo; + periodEvent.dataSourceLabel = conInfo.dataSourceLabel; + periodEvent.connectionId = conInfo.conId; + periodEvent.wrappedConnectionId = conInfo.wrappedConId; + periodEvent.operationId = context.operationInfo.id; + periodEvent.result = context.isResult(); + periodEvent.rowNo = context.getRowNo(); + if (context.getException() != null) { + periodEvent.exception = context.getException().getClass(); + periodEvent.exceptionMessage = context.getException().getMessage(); + } + periodEvent.commit(); + } + + ResultSetEndEvent endEvent = new ResultSetEndEvent(); + if (endEvent.isEnabled()) { + ConnectionInfo conInfo = context.connectionInfo; + endEvent.dataSourceLabel = conInfo.dataSourceLabel; + endEvent.connectionId = conInfo.conId; + endEvent.wrappedConnectionId = conInfo.wrappedConId; + endEvent.operationId = context.operationInfo.id; + endEvent.result = context.isResult(); + endEvent.rowNo = context.getRowNo(); + if (context.getException() != null) { + endEvent.exception = context.getException().getClass(); + endEvent.exceptionMessage = context.getException().getMessage(); + } + endEvent.commit(); + } + } +} diff --git a/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/RollbackInterceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/RollbackInterceptor.java new file mode 100644 index 0000000..19dd6f8 --- /dev/null +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/RollbackInterceptor.java @@ -0,0 +1,60 @@ +package dev.jfr4jdbc.interceptor.std; + +import dev.jfr4jdbc.interceptor.ConnectionInfo; +import dev.jfr4jdbc.interceptor.Interceptor; +import dev.jfr4jdbc.interceptor.RollbackContext; +import dev.jfr4jdbc.interceptor.std.event.RollbackEndEvent; +import dev.jfr4jdbc.interceptor.std.event.RollbackPeriodEvent; +import dev.jfr4jdbc.interceptor.std.event.RollbackStartEvent; + +public class RollbackInterceptor implements Interceptor { + + private RollbackPeriodEvent periodEvent; + + @Override + public void preInvoke(RollbackContext context) { + RollbackStartEvent startEvent = new RollbackStartEvent(); + if (startEvent.isEnabled()) { + ConnectionInfo conInfo = context.connectionInfo; + startEvent.dataSourceLabel = conInfo.dataSourceLabel; + startEvent.connectionId = conInfo.conId; + startEvent.wrappedConnectionId = conInfo.wrappedConId; + startEvent.operationId = context.operationInfo.id; + startEvent.commit(); + } + + periodEvent = new RollbackPeriodEvent(); + periodEvent.begin(); + } + + @Override + public void postInvoke(RollbackContext context) { + periodEvent.end(); + if (periodEvent.shouldCommit()) { + ConnectionInfo conInfo = context.connectionInfo; + periodEvent.dataSourceLabel = conInfo.dataSourceLabel; + periodEvent.connectionId = conInfo.conId; + periodEvent.wrappedConnectionId = conInfo.wrappedConId; + periodEvent.operationId = context.operationInfo.id; + if (context.getException() != null) { + periodEvent.exception = context.getException().getClass(); + periodEvent.exceptionMessage = context.getException().getMessage(); + } + periodEvent.commit(); + } + + RollbackEndEvent endEvent = new RollbackEndEvent(); + if (endEvent.isEnabled()) { + ConnectionInfo conInfo = context.connectionInfo; + endEvent.dataSourceLabel = conInfo.dataSourceLabel; + endEvent.connectionId = conInfo.conId; + endEvent.wrappedConnectionId = conInfo.wrappedConId; + endEvent.operationId = context.operationInfo.id; + if (context.getException() != null) { + endEvent.exception = context.getException().getClass(); + endEvent.exceptionMessage = context.getException().getMessage(); + } + endEvent.commit(); + } + } +} diff --git a/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/StatementInterceptor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/StatementInterceptor.java new file mode 100644 index 0000000..728df24 --- /dev/null +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/StatementInterceptor.java @@ -0,0 +1,80 @@ +package dev.jfr4jdbc.interceptor.std; + +import dev.jfr4jdbc.interceptor.ConnectionInfo; +import dev.jfr4jdbc.interceptor.Interceptor; +import dev.jfr4jdbc.interceptor.StatementContext; +import dev.jfr4jdbc.interceptor.std.event.StatementEndEvent; +import dev.jfr4jdbc.interceptor.std.event.StatementPeriodEvent; +import dev.jfr4jdbc.interceptor.std.event.StatementStartEvent; + +public class StatementInterceptor implements Interceptor { + + private StatementPeriodEvent periodEvent; + + @Override + public void preInvoke(StatementContext context) { + StatementStartEvent startEvent = new StatementStartEvent(); + if (startEvent.isEnabled()) { + ConnectionInfo conInfo = context.connectionInfo; + startEvent.dataSourceLabel = conInfo.dataSourceLabel; + startEvent.connectionId = conInfo.conId; + startEvent.wrappedConnectionId = conInfo.wrappedConId; + startEvent.operationId = context.operationInfo.id; + startEvent.inquiry = context.inquiry; + startEvent.isPrepared = context.isPrepared; + startEvent.inquiryParameter = context.getInquiryParameter(); + startEvent.isStatementPoolable = context.isStatementPoolable(); + startEvent.isStatementClosed = context.isStatementClosed(); + startEvent.isAutoCommitted = context.isAutoCommitted(); + startEvent.commit(); + } + + periodEvent = new StatementPeriodEvent(); + periodEvent.begin(); + } + + @Override + public void postInvoke(StatementContext context) { + periodEvent.end(); + if (periodEvent.shouldCommit()) { + ConnectionInfo conInfo = context.connectionInfo; + periodEvent.dataSourceLabel = conInfo.dataSourceLabel; + periodEvent.connectionId = conInfo.conId; + periodEvent.wrappedConnectionId = conInfo.wrappedConId; + periodEvent.operationId = context.operationInfo.id; + periodEvent.inquiry = context.inquiry; + periodEvent.isPrepared = context.isPrepared; + periodEvent.inquiryParameter = context.getInquiryParameter(); + periodEvent.isStatementPoolable = context.isStatementPoolable(); + periodEvent.isStatementClosed = context.isStatementClosed(); + periodEvent.isAutoCommitted = context.isAutoCommitted(); + + if (context.getException() != null) { + periodEvent.exception = context.getException().getClass(); + periodEvent.exceptionMessage = context.getException().getMessage(); + } + periodEvent.commit(); + } + + StatementEndEvent endEvent = new StatementEndEvent(); + if (endEvent.isEnabled()) { + ConnectionInfo conInfo = context.connectionInfo; + endEvent.dataSourceLabel = conInfo.dataSourceLabel; + endEvent.connectionId = conInfo.conId; + endEvent.wrappedConnectionId = conInfo.wrappedConId; + endEvent.operationId = context.operationInfo.id; + endEvent.inquiry = context.inquiry; + endEvent.isPrepared = context.isPrepared; + endEvent.inquiryParameter = context.getInquiryParameter(); + endEvent.isStatementPoolable = context.isStatementPoolable(); + endEvent.isStatementClosed = context.isStatementClosed(); + endEvent.isAutoCommitted = context.isAutoCommitted(); + + if (context.getException() != null) { + endEvent.exception = context.getException().getClass(); + endEvent.exceptionMessage = context.getException().getMessage(); + } + endEvent.commit(); + } + } +} diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CancelEndEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CancelEndEvent.java similarity index 73% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CancelEndEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CancelEndEvent.java index 5b93340..ea60519 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CancelEndEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CancelEndEvent.java @@ -1,18 +1,17 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; +@Name("jdbc.CancelEnd") +@Label("Cancel End") @Category("jdbc") -@Label("CancelEnd") +@Description("Statement was canceled") +@Enabled(false) public class CancelEndEvent extends Event { - public long period; - @DataSourceLabel public String dataSourceLabel; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCancelEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CancelPeriodEvent.java similarity index 70% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCancelEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CancelPeriodEvent.java index 9193ce3..3771ddc 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCancelEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CancelPeriodEvent.java @@ -1,15 +1,15 @@ -package dev.jfr4jdbc.interceptor.impl.period; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; -@Category("jdbc") +@Name("jdbc.Cancel") @Label("Cancel") -public class PeriodCancelEvent extends Event { +@Category("jdbc") +@Description("Statement was canceling") +public class CancelPeriodEvent extends Event { @DataSourceLabel public String dataSourceLabel; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CancelStartEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CancelStartEvent.java similarity index 68% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CancelStartEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CancelStartEvent.java index c8c06fc..9d0526d 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CancelStartEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CancelStartEvent.java @@ -1,14 +1,15 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; +@Name("jdbc.CancelStart") +@Label("Cancel Start") @Category("jdbc") -@Label("CancelStart") +@Description("Statement started canceling") +@Enabled(false) public class CancelStartEvent extends Event { @DataSourceLabel diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CloseEndEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CloseEndEvent.java similarity index 73% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CloseEndEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CloseEndEvent.java index 9382a09..431b478 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CloseEndEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CloseEndEvent.java @@ -1,18 +1,17 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; +@Name("jdbc.CloseEnd") +@Label("Close End") @Category("jdbc") -@Label("CloseStart") +@Description("Connection closed") +@Enabled(false) public class CloseEndEvent extends Event { - public long period; - @DataSourceLabel public String dataSourceLabel; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCloseEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/ClosePeriodEvent.java similarity index 70% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCloseEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/ClosePeriodEvent.java index 682aa53..11095ff 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCloseEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/ClosePeriodEvent.java @@ -1,15 +1,16 @@ -package dev.jfr4jdbc.interceptor.impl.period; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; -@Category("jdbc") +@Name("jdbc.Close") @Label("Close") -public class PeriodCloseEvent extends Event { +@Category("jdbc") +@Description("Connection was closing") +public class ClosePeriodEvent extends Event { + @DataSourceLabel public String dataSourceLabel; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CloseStartEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CloseStartEvent.java similarity index 69% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CloseStartEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CloseStartEvent.java index e8f216c..f8bcc4e 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CloseStartEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CloseStartEvent.java @@ -1,14 +1,15 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; +@Name("jdbc.CloseStart") +@Label("Close Start") @Category("jdbc") -@Label("CloseEnd") +@Description("Connection started closing") +@Enabled(false) public class CloseStartEvent extends Event { @DataSourceLabel diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CommitEndEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CommitEndEvent.java similarity index 72% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CommitEndEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CommitEndEvent.java index 099c8f5..e53b301 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CommitEndEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CommitEndEvent.java @@ -1,18 +1,17 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; +@Name("jdbc.CommitEnd") +@Label("Commit End") @Category("jdbc") -@Label("CommitStart") +@Description("Transaction was committed") +@Enabled(false) public class CommitEndEvent extends Event { - public long period; - @DataSourceLabel public String dataSourceLabel; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCommitEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CommitPeriodEvent.java similarity index 70% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCommitEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CommitPeriodEvent.java index 7029801..f16b62d 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodCommitEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CommitPeriodEvent.java @@ -1,15 +1,16 @@ -package dev.jfr4jdbc.interceptor.impl.period; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; -@Category("jdbc") +@Name("jdbc.Commit") @Label("Commit") -public class PeriodCommitEvent extends Event { +@Category("jdbc") +@Description("Transaction was committing") +public class CommitPeriodEvent extends Event { + @DataSourceLabel public String dataSourceLabel; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CommitStartEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CommitStartEvent.java similarity index 68% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CommitStartEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CommitStartEvent.java index 2c93076..aed998b 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/CommitStartEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/CommitStartEvent.java @@ -1,14 +1,15 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; +@Name("jdbc.CommitStart") +@Label("Commit Start") @Category("jdbc") -@Label("CommitEnd") +@Description("Transaction started committing") +@Enabled(false) public class CommitStartEvent extends Event { @DataSourceLabel diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/DataSourceEndEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DataSourceEndEvent.java similarity index 72% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/DataSourceEndEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DataSourceEndEvent.java index 0674d5e..9941ffb 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/DataSourceEndEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DataSourceEndEvent.java @@ -1,18 +1,17 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; +@Name("jdbc.DataSourceEnd") +@Label("DataSource End") @Category("jdbc") -@Label("DataSourceStart") +@Description("DataSource provided a connection") +@Enabled(false) public class DataSourceEndEvent extends Event { - public long period; - @DataSourceLabel public String dataSourceLabel; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodDataSourceEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DataSourcePeriodEvent.java similarity index 69% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodDataSourceEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DataSourcePeriodEvent.java index 211bd8c..af32b91 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodDataSourceEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DataSourcePeriodEvent.java @@ -1,15 +1,15 @@ -package dev.jfr4jdbc.interceptor.impl.period; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; -@Category("jdbc") +@Name("jdbc.DataSource") @Label("DataSource") -public class PeriodDataSourceEvent extends Event { +@Category("jdbc") +@Description("DataSource was providing a connection") +public class DataSourcePeriodEvent extends Event { @DataSourceLabel public String dataSourceLabel; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/DataSourceStartEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DataSourceStartEvent.java similarity index 61% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/DataSourceStartEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DataSourceStartEvent.java index 57ef75c..b635293 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/DataSourceStartEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DataSourceStartEvent.java @@ -1,13 +1,14 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; +@Name("jdbc.DataSourceStart") +@Label("DataSource Start") @Category("jdbc") -@Label("DataSourceEnd") +@Description("DataSource started providing a connection") +@Enabled(false) public class DataSourceStartEvent extends Event { @DataSourceLabel diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/DriverEndEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DriverEndEvent.java similarity index 63% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/DriverEndEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DriverEndEvent.java index 7b95efe..a9d7188 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/DriverEndEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DriverEndEvent.java @@ -1,19 +1,18 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; +@Name("jdbc.DriverEnd") +@Label("Driver End") @Category("jdbc") -@Label("DriverStart") +@Description("Driver provided a connection") +@Enabled(false) public class DriverEndEvent extends Event { - public long period; - @DataSourceLabel - public String driverLabel; + public String label; @ConnectionId public int connectionId; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodDriverEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DriverPeriodEvent.java similarity index 59% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodDriverEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DriverPeriodEvent.java index 16d01c3..09fe9b5 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodDriverEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DriverPeriodEvent.java @@ -1,17 +1,17 @@ -package dev.jfr4jdbc.interceptor.impl.period; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; -@Category("jdbc") +@Name("jdbc.Driver") @Label("Driver") -public class PeriodDriverEvent extends Event { +@Category("jdbc") +@Description("Driver was providing a connection") +public class DriverPeriodEvent extends Event { @DataSourceLabel - public String driverLabel; + public String label; @ConnectionId public int connectionId; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/DriverStartEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DriverStartEvent.java similarity index 53% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/DriverStartEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DriverStartEvent.java index 6f5d319..47d6970 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/DriverStartEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/DriverStartEvent.java @@ -1,17 +1,18 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; +@Name("jdbc.DriverStart") +@Label("Driver Start") @Category("jdbc") -@Label("DriverEnd") +@Description("Driver started providing a connection") +@Enabled(false) public class DriverStartEvent extends Event { @DataSourceLabel - public String driverLabel; + public String label; @ConnectionId public int connectionId; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/ResultSetEndEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/ResultSetEndEvent.java similarity index 74% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/ResultSetEndEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/ResultSetEndEvent.java index 07c24c3..fbcd212 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/ResultSetEndEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/ResultSetEndEvent.java @@ -1,18 +1,17 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; +@Name("jdbc.ResultSetEnd") +@Label("ResultSet End") @Category("jdbc") -@Label("ResultSetStart") +@Description("ResultSet moved next cursor") +@Enabled(false) public class ResultSetEndEvent extends Event { - public long period; - @DataSourceLabel public String dataSourceLabel; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodResultSetEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/ResultSetPeriodEvent.java similarity index 71% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodResultSetEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/ResultSetPeriodEvent.java index 8516dbc..7c0c236 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodResultSetEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/ResultSetPeriodEvent.java @@ -1,16 +1,16 @@ -package dev.jfr4jdbc.interceptor.impl.period; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; -@Category("jdbc") +@Name("jdbc.ResultSet") @Label("ResultSet") -public class PeriodResultSetEvent extends Event { - +@Category("jdbc") +@Description("ResultSet was moving next cursor") +public class ResultSetPeriodEvent extends Event { + @DataSourceLabel public String dataSourceLabel; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/ResultSetStartEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/ResultSetStartEvent.java similarity index 67% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/ResultSetStartEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/ResultSetStartEvent.java index e634446..1e39214 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/ResultSetStartEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/ResultSetStartEvent.java @@ -1,14 +1,15 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; +@Name("jdbc.ResultSetStart") +@Label("ResultSet Start") @Category("jdbc") -@Label("ResultSetEnd") +@Description("ResultSet started moving next cursor") +@Enabled(false) public class ResultSetStartEvent extends Event { @DataSourceLabel diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/RollbackEndEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/RollbackEndEvent.java similarity index 72% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/RollbackEndEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/RollbackEndEvent.java index 99584f1..d1b09ba 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/RollbackEndEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/RollbackEndEvent.java @@ -1,18 +1,17 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; +@Name("jdbc.RollbackEnd") +@Label("Rollback End") @Category("jdbc") -@Label("RollbackStart") +@Description("Transaction rollbacked") +@Enabled(false) public class RollbackEndEvent extends Event { - public long period; - @DataSourceLabel public String dataSourceLabel; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodRollbackEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/RollbackPeriodEvent.java similarity index 69% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodRollbackEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/RollbackPeriodEvent.java index 1d7781f..66b72cd 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodRollbackEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/RollbackPeriodEvent.java @@ -1,15 +1,15 @@ -package dev.jfr4jdbc.interceptor.impl.period; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; -@Category("jdbc") +@Name("jdbc.Rollback") @Label("Rollback") -public class PeriodRollbackEvent extends Event { +@Category("jdbc") +@Description("Transaction was rollbacking") +public class RollbackPeriodEvent extends Event { @DataSourceLabel public String dataSourceLabel; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/RollbackStartEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/RollbackStartEvent.java similarity index 67% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/RollbackStartEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/RollbackStartEvent.java index e890412..9c060c2 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/RollbackStartEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/RollbackStartEvent.java @@ -1,14 +1,15 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; +@Name("jdbc.RollbackStart") +@Label("Rollback Start") @Category("jdbc") -@Label("RollbackEnd") +@Description("Transaction started rollbacking") +@Enabled(false) public class RollbackStartEvent extends Event { @DataSourceLabel diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/StatementEndEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/StatementEndEvent.java similarity index 79% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/StatementEndEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/StatementEndEvent.java index 7edd26a..a97efbe 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/StatementEndEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/StatementEndEvent.java @@ -1,18 +1,17 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; +@Name("jdbc.StatementEnd") +@Label("Statement End") @Category("jdbc") -@Label("StatementStart") +@Description("Statement queried") +@Enabled(false) public class StatementEndEvent extends Event { - public long period; - @DataSourceLabel public String dataSourceLabel; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodStatementEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/StatementPeriodEvent.java similarity index 78% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodStatementEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/StatementPeriodEvent.java index abd74c3..6e35fe8 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/period/PeriodStatementEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/StatementPeriodEvent.java @@ -1,15 +1,15 @@ -package dev.jfr4jdbc.interceptor.impl.period; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; -@Category("jdbc") +@Name("jdbc.Statement") @Label("Statement") -public class PeriodStatementEvent extends Event { +@Category("jdbc") +@Description("Statement was querying") +public class StatementPeriodEvent extends Event { @DataSourceLabel public String dataSourceLabel; diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/StatementStartEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/StatementStartEvent.java similarity index 77% rename from jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/StatementStartEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/StatementStartEvent.java index 04f1081..d452e4e 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/interceptor/impl/instant/StatementStartEvent.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/interceptor/std/event/StatementStartEvent.java @@ -1,14 +1,15 @@ -package dev.jfr4jdbc.interceptor.impl.instant; +package dev.jfr4jdbc.interceptor.std.event; import dev.jfr4jdbc.ConnectionId; import dev.jfr4jdbc.DataSourceLabel; import dev.jfr4jdbc.WrappedConnectionId; -import jdk.jfr.Category; -import jdk.jfr.Event; -import jdk.jfr.Label; +import jdk.jfr.*; +@Name("jdbc.StatementStart") +@Label("Statement Start") @Category("jdbc") -@Label("StatementEnd") +@Description("Statement started querying") +@Enabled(false) public class StatementStartEvent extends Event { @DataSourceLabel diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/internal/Jfr4Jdbc.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/Jfr4Jdbc.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/internal/Jfr4Jdbc.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/Jfr4Jdbc.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/internal/JfrConnectionResourceEvent.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/JfrConnectionResourceEvent.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/internal/JfrConnectionResourceEvent.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/JfrConnectionResourceEvent.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/internal/JfrResourceWriter.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/JfrResourceWriter.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/internal/JfrResourceWriter.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/JfrResourceWriter.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/internal/Label.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/Label.java similarity index 100% rename from jdbc42/src/main/java/dev/jfr4jdbc/internal/Label.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/Label.java diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/internal/ResourceMonitor.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/ResourceMonitor.java similarity index 94% rename from jdbc42/src/main/java/dev/jfr4jdbc/internal/ResourceMonitor.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/ResourceMonitor.java index 7241cb5..486b5f4 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/internal/ResourceMonitor.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/ResourceMonitor.java @@ -2,8 +2,6 @@ import dev.jfr4jdbc.ResourceMetrics; -import javax.sql.DataSource; -import java.sql.Driver; import java.util.concurrent.atomic.AtomicInteger; public class ResourceMonitor { diff --git a/jdbc42/src/main/java/dev/jfr4jdbc/internal/ResourceMonitorManager.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/ResourceMonitorManager.java similarity index 99% rename from jdbc42/src/main/java/dev/jfr4jdbc/internal/ResourceMonitorManager.java rename to jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/ResourceMonitorManager.java index c181b99..caf919f 100644 --- a/jdbc42/src/main/java/dev/jfr4jdbc/internal/ResourceMonitorManager.java +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/ResourceMonitorManager.java @@ -8,13 +8,12 @@ public class ResourceMonitorManager { private static final ResourceMonitorManager instance = new ResourceMonitorManager(); + private final Map monitors = new ConcurrentHashMap<>(); public static final ResourceMonitorManager getInstance() { return instance; } - private final Map monitors = new ConcurrentHashMap<>(); - public ResourceMonitor getOrCreateResourceMonitor(Label label) { return instance.monitors.computeIfAbsent(label, l -> new ResourceMonitor(l)); } diff --git a/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/StillUnassignedConnectionInfo.java b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/StillUnassignedConnectionInfo.java new file mode 100644 index 0000000..0e5b90f --- /dev/null +++ b/jfr4jdbc-driver/src/main/java/dev/jfr4jdbc/internal/StillUnassignedConnectionInfo.java @@ -0,0 +1,12 @@ +package dev.jfr4jdbc.internal; + +public class StillUnassignedConnectionInfo { + + public final String dataSourceLabel; + public final int conId; + + public StillUnassignedConnectionInfo(String dataSourceLabel, int conId) { + this.dataSourceLabel = dataSourceLabel; + this.conId = conId; + } +} diff --git a/jfr4jdbc-driver/src/main/java/module-info.java b/jfr4jdbc-driver/src/main/java/module-info.java index 249dbf1..56f1341 100644 --- a/jfr4jdbc-driver/src/main/java/module-info.java +++ b/jfr4jdbc-driver/src/main/java/module-info.java @@ -3,8 +3,14 @@ requires transitive java.sql; exports dev.jfr4jdbc; + exports dev.jfr4jdbc.interceptor; + exports dev.jfr4jdbc.interceptor.std; exports dev.jfr4jdbc.event; - exports dev.jfr4jdbc.interceptor.impl.period; + exports dev.jfr4jdbc.event.jfr; provides java.sql.Driver with dev.jfr4jdbc.JfrServiceLoadedDriver; + + opens dev.jfr4jdbc; + opens dev.jfr4jdbc.interceptor; + opens dev.jfr4jdbc.interceptor.std; } \ No newline at end of file diff --git a/jdbc42/src/main/resources/META-INF/services/java.sql.Driver b/jfr4jdbc-driver/src/main/resources/META-INF/services/java.sql.Driver similarity index 100% rename from jdbc42/src/main/resources/META-INF/services/java.sql.Driver rename to jfr4jdbc-driver/src/main/resources/META-INF/services/java.sql.Driver diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/FlightRecording.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/FlightRecording.java similarity index 97% rename from jdbc42/src/test/java/dev/jfr4jdbc/FlightRecording.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/FlightRecording.java index 7dd9f30..8abe262 100644 --- a/jdbc42/src/test/java/dev/jfr4jdbc/FlightRecording.java +++ b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/FlightRecording.java @@ -35,7 +35,7 @@ public static FlightRecording start() throws Jfr4jdbcTestException { fr.recording.enable(JfrResultSetEvent.class); fr.recording.enable(JfrRollbackEvent.class); fr.recording.enable(JfrStatementEvent.class); - fr.recording.disable(JfrConnectionResourceEvent.class); + fr.recording.start(); } catch (Exception e) { throw new Jfr4jdbcTestException(e); diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/Jfr4JdbcTestRuntimeException.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/Jfr4JdbcTestRuntimeException.java similarity index 100% rename from jdbc42/src/test/java/dev/jfr4jdbc/Jfr4JdbcTestRuntimeException.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/Jfr4JdbcTestRuntimeException.java diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/Jfr4jdbcTestException.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/Jfr4jdbcTestException.java similarity index 100% rename from jdbc42/src/test/java/dev/jfr4jdbc/Jfr4jdbcTestException.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/Jfr4jdbcTestException.java diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/JfrCallableStatementTest.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrCallableStatementTest.java similarity index 100% rename from jdbc42/src/test/java/dev/jfr4jdbc/JfrCallableStatementTest.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrCallableStatementTest.java diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/JfrConnectionTest.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrConnectionTest.java similarity index 99% rename from jdbc42/src/test/java/dev/jfr4jdbc/JfrConnectionTest.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrConnectionTest.java index 7be4658..a81604e 100644 --- a/jdbc42/src/test/java/dev/jfr4jdbc/JfrConnectionTest.java +++ b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrConnectionTest.java @@ -1,8 +1,6 @@ package dev.jfr4jdbc; import dev.jfr4jdbc.interceptor.*; -import dev.jfr4jdbc.internal.ConnectionInfo; -import jdk.jfr.consumer.RecordedEvent; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -41,7 +39,7 @@ void createCommitEvent() throws Exception { MockInterceptorFactory mockInterceptorFactory = new MockInterceptorFactory(); JfrConnection connection = new JfrConnection(this.delegatedCon, mockInterceptorFactory); connection.commit(); - + MockInterceptor interceptor = mockInterceptorFactory.createCommitInterceptor(); List events = interceptor.getAllPostEvents(); assertEquals(1, events.size()); @@ -83,7 +81,7 @@ void createCommitEventThrowRuntimeException() throws Exception { } catch (RuntimeException e) { } finally { - } + } MockInterceptor interceptor = mockInterceptorFactory.createCommitInterceptor(); List events = interceptor.getAllPostEvents(); @@ -119,7 +117,7 @@ void createRollbackEventThrowSQLException() throws Exception { } catch (SQLException e) { } finally { - } + } MockInterceptor interceptor = mockInterceptorFactory.createRollbackInterceptor(); List events = interceptor.getAllPostEvents(); @@ -141,7 +139,7 @@ void createRollbackEventThrowRuntimeException() throws Exception { } catch (RuntimeException e) { } finally { - } + } MockInterceptor interceptor = mockInterceptorFactory.createRollbackInterceptor(); List events = interceptor.getAllPostEvents(); diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/JfrDataSourceTest.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrDataSourceTest.java similarity index 93% rename from jdbc42/src/test/java/dev/jfr4jdbc/JfrDataSourceTest.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrDataSourceTest.java index 9f4e845..546160b 100644 --- a/jdbc42/src/test/java/dev/jfr4jdbc/JfrDataSourceTest.java +++ b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrDataSourceTest.java @@ -1,9 +1,9 @@ package dev.jfr4jdbc; +import dev.jfr4jdbc.interceptor.ConnectionInfo; import dev.jfr4jdbc.interceptor.DataSourceContext; import dev.jfr4jdbc.interceptor.MockInterceptor; import dev.jfr4jdbc.interceptor.MockInterceptorFactory; -import dev.jfr4jdbc.internal.ConnectionInfo; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -54,6 +54,7 @@ void getConnection() throws Exception { @DisplayName("getConnection to create ConnectionEvent") @Test void getConnectionConnectEvent() throws Exception { + when(delegatedDs.getConnection()).thenReturn(delegatedCon); MockInterceptorFactory mockInterceptorFactory = new MockInterceptorFactory(); @@ -110,9 +111,9 @@ void getConnectionConnectEventThrowSQLException() throws Exception { assertNull(event.getUsername()); assertNull(event.getPassword()); assertNull(event.getConnection()); - assertEquals("ds", event.getConnectionInfo().dataSourceLabel); - assertEquals(1, event.getConnectionInfo().conId); - assertEquals(0, event.getConnectionInfo().wrappedConId); + assertEquals("ds", event.stillUnassignedConnectionInfo.dataSourceLabel); + assertEquals(1, event.stillUnassignedConnectionInfo.conId); + assertNull(event.getConnectionInfo()); } @DisplayName("getConnection to create ConnectionEvent throw exception as unexpected") @@ -143,7 +144,8 @@ void getConnectionConnectEventThrowRuntimeException() throws Exception { assertNull(event.getUsername()); assertNull(event.getPassword()); assertNull(event.getConnection()); - assertNotNull(event.getConnectionInfo()); + assertNotNull(event.stillUnassignedConnectionInfo); + assertNull(event.getConnectionInfo()); } @DisplayName("getConnection with User/Password") @@ -220,7 +222,8 @@ void getConnectionUserPassConnectEventThrowSQLException() throws Exception { assertEquals(user, event.getUsername()); assertEquals(password, event.getPassword()); assertNull(event.getConnection()); - assertNotNull(event.getConnectionInfo()); + assertNotNull(event.stillUnassignedConnectionInfo); + assertNull(event.getConnectionInfo()); assertNotEquals(ConnectionInfo.NO_INFO, event.getConnectionInfo()); assertNotNull(event.getException()); assertEquals(SQLException.class, exception.getClass()); @@ -254,7 +257,8 @@ void getConnectionUserPassConnectEventThrowRuntimeException() throws Exception { assertEquals(user, event.getUsername()); assertEquals(password, event.getPassword()); assertNull(event.getConnection()); - assertNotNull(event.getConnectionInfo()); + assertNotNull(event.stillUnassignedConnectionInfo); + assertNull(event.getConnectionInfo()); assertNotEquals(ConnectionInfo.NO_INFO, event.getConnectionInfo()); assertNotNull(event.getException()); assertEquals(RuntimeException.class, exception.getClass()); @@ -317,4 +321,12 @@ void isWrapperFor() throws Exception { verify(delegatedDs).isWrapperFor(null); } + + @Test + void createShardingKeyBuilder() throws Exception { + JfrDataSource dataSource = new JfrDataSource(delegatedDs); + dataSource.createShardingKeyBuilder(); + + verify(delegatedDs).createShardingKeyBuilder(); + } } \ No newline at end of file diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/JfrDriverTest.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrDriverTest.java similarity index 89% rename from jdbc42/src/test/java/dev/jfr4jdbc/JfrDriverTest.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrDriverTest.java index 1eda2fc..31d53d4 100644 --- a/jdbc42/src/test/java/dev/jfr4jdbc/JfrDriverTest.java +++ b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrDriverTest.java @@ -3,7 +3,6 @@ import dev.jfr4jdbc.interceptor.DriverContext; import dev.jfr4jdbc.interceptor.MockInterceptor; import dev.jfr4jdbc.interceptor.MockInterceptorFactory; -import jdk.jfr.consumer.RecordedEvent; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -82,7 +81,7 @@ void getConnectionConnectEvent() throws Exception { MockInterceptorFactory mockInterceptorFactory = new MockInterceptorFactory(); - Driver driver = new JfrDriver(delegateDriver, mockInterceptorFactory); + Driver driver = new JfrDriver(delegateDriver, mockInterceptorFactory, "label"); try (Connection con = driver.connect(DELEGATE_URL, null)) { // do @@ -99,7 +98,9 @@ void getConnectionConnectEvent() throws Exception { DriverContext event = connectionEvents.get(0); assertNotNull(event.getConnection()); - assertEquals(DELEGATE_URL, event.getConnectionInfo().dataSourceLabel); + assertNotNull(event.stillUnassignedConnectionInfo); + assertNotNull(event.getConnectionInfo()); + assertEquals("label", event.getConnectionInfo().dataSourceLabel); assertEquals(1, event.getConnectionInfo().conId); assertEquals(0, event.getConnectionInfo().wrappedConId); assertEquals(DELEGATE_URL, event.url); @@ -111,7 +112,7 @@ void getConnectionConnectEventThrowSQLException() throws Exception { when(delegateDriver.connect(DELEGATE_URL, null)).thenThrow(new SQLException()); MockInterceptorFactory mockInterceptorFactory = new MockInterceptorFactory(); - Driver driver = new JfrDriver(delegateDriver, mockInterceptorFactory); + Driver driver = new JfrDriver(delegateDriver, mockInterceptorFactory, "label"); try (Connection con = driver.connect(DELEGATE_URL, null)) { fail(); @@ -128,9 +129,10 @@ void getConnectionConnectEventThrowSQLException() throws Exception { DriverContext event = connectionEvents.get(0); assertNull(event.getConnection()); - assertEquals(DELEGATE_URL, event.getConnectionInfo().dataSourceLabel); - assertEquals(1, event.getConnectionInfo().conId); - assertEquals(0, event.getConnectionInfo().wrappedConId); + assertNotNull(event.stillUnassignedConnectionInfo); + assertNull(event.getConnectionInfo()); + assertEquals("label", event.stillUnassignedConnectionInfo.dataSourceLabel); + assertEquals(1, event.stillUnassignedConnectionInfo.conId); assertEquals(DELEGATE_URL, event.url); } @@ -140,7 +142,7 @@ void getConnectionConnectEventThrowRuntimeException() throws Exception { when(delegateDriver.connect(DELEGATE_URL, null)).thenThrow(new RuntimeException()); MockInterceptorFactory mockInterceptorFactory = new MockInterceptorFactory(); - Driver driver = new JfrDriver(delegateDriver, mockInterceptorFactory); + Driver driver = new JfrDriver(delegateDriver, mockInterceptorFactory, "label"); try (Connection con = driver.connect(DELEGATE_URL, null)) { fail(); @@ -157,9 +159,10 @@ void getConnectionConnectEventThrowRuntimeException() throws Exception { DriverContext event = connectionEvents.get(0); assertNull(event.getConnection()); - assertEquals(DELEGATE_URL, event.getConnectionInfo().dataSourceLabel); - assertEquals(1, event.getConnectionInfo().conId); - assertEquals(0, event.getConnectionInfo().wrappedConId); + assertNotNull(event.stillUnassignedConnectionInfo); + assertNull(event.getConnectionInfo()); + assertEquals("label", event.stillUnassignedConnectionInfo.dataSourceLabel); + assertEquals(1, event.stillUnassignedConnectionInfo.conId); assertEquals(DELEGATE_URL, event.url); } diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/JfrPreparedStatementTest.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrPreparedStatementTest.java similarity index 99% rename from jdbc42/src/test/java/dev/jfr4jdbc/JfrPreparedStatementTest.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrPreparedStatementTest.java index bea77ca..01648ed 100644 --- a/jdbc42/src/test/java/dev/jfr4jdbc/JfrPreparedStatementTest.java +++ b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrPreparedStatementTest.java @@ -1,10 +1,8 @@ package dev.jfr4jdbc; -import dev.jfr4jdbc.event.jfr.JfrStatementEvent; import dev.jfr4jdbc.interceptor.MockInterceptor; import dev.jfr4jdbc.interceptor.MockInterceptorFactory; import dev.jfr4jdbc.interceptor.StatementContext; -import jdk.jfr.consumer.RecordedEvent; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -15,7 +13,6 @@ import java.io.Reader; import java.sql.*; import java.util.List; -import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/internal/JfrResourceMonitorTest.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrResourceMonitorTest.java similarity index 91% rename from jdbc42/src/test/java/dev/jfr4jdbc/internal/JfrResourceMonitorTest.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrResourceMonitorTest.java index c0fd70b..be2b281 100644 --- a/jdbc42/src/test/java/dev/jfr4jdbc/internal/JfrResourceMonitorTest.java +++ b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrResourceMonitorTest.java @@ -1,8 +1,6 @@ -package dev.jfr4jdbc.internal; +package dev.jfr4jdbc; + -import com.sun.org.apache.xpath.internal.operations.Bool; -import dev.jfr4jdbc.*; -import jdk.jfr.consumer.RecordedEvent; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -10,8 +8,6 @@ import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; -import java.util.List; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -28,11 +24,9 @@ public class JfrResourceMonitorTest { void defaultDatasourceName() throws Exception { MockJDBC db = new MockJDBC(); - ResourceMonitorManager manager = ResourceMonitorManager.getInstance(); - JfrDataSource dataSource = new JfrDataSource(db.getDataSource(1)); - long count = manager.getMonitors().stream().filter(m -> m.getLabel().value.startsWith("DataSource#")).count(); + long count = Jfr4JdbcMetrics.getResourceMetrics().stream().filter(r -> r.label.startsWith("DataSource#")).count(); assertTrue(count > 0); // Data source may have been created before this test was run assertEquals(0, dataSource.getResourceMetrics().usage); } @@ -40,11 +34,10 @@ void defaultDatasourceName() throws Exception { @Test void defaultConnectionName() throws Exception { MockJDBC db = new MockJDBC(); - ResourceMonitorManager manager = ResourceMonitorManager.getInstance(); JfrConnection con = new JfrConnection(Mockito.mock(Connection.class)); con.close(); - long count = manager.getMonitors().stream().filter(m -> m.getLabel().value.equals("userManagedConnection")).count(); + long count = Jfr4JdbcMetrics.getResourceMetrics().stream().filter(r -> r.label.equals("userManagedConnection")).count(); assertEquals(1, count); } diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/JfrResultSetTest.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrResultSetTest.java similarity index 99% rename from jdbc42/src/test/java/dev/jfr4jdbc/JfrResultSetTest.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrResultSetTest.java index bd7acc5..a305294 100644 --- a/jdbc42/src/test/java/dev/jfr4jdbc/JfrResultSetTest.java +++ b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrResultSetTest.java @@ -1,12 +1,6 @@ package dev.jfr4jdbc; -import dev.jfr4jdbc.event.jfr.JfrResultSetEvent; -import dev.jfr4jdbc.interceptor.MockInterceptor; -import dev.jfr4jdbc.interceptor.MockInterceptorFactory; -import dev.jfr4jdbc.interceptor.ResultSetContext; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.OperationInfo; -import jdk.jfr.consumer.RecordedEvent; +import dev.jfr4jdbc.interceptor.*; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -18,7 +12,6 @@ import java.sql.*; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.verify; diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/JfrStatementTest.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrStatementTest.java similarity index 99% rename from jdbc42/src/test/java/dev/jfr4jdbc/JfrStatementTest.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrStatementTest.java index f2dc281..726e528 100644 --- a/jdbc42/src/test/java/dev/jfr4jdbc/JfrStatementTest.java +++ b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/JfrStatementTest.java @@ -1,9 +1,6 @@ package dev.jfr4jdbc; import dev.jfr4jdbc.interceptor.*; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.OperationInfo; -import jdk.jfr.consumer.RecordedEvent; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/LinkageIdTest.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/LinkageIdTest.java similarity index 95% rename from jdbc42/src/test/java/dev/jfr4jdbc/LinkageIdTest.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/LinkageIdTest.java index 21565e3..a448f15 100644 --- a/jdbc42/src/test/java/dev/jfr4jdbc/LinkageIdTest.java +++ b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/LinkageIdTest.java @@ -1,14 +1,10 @@ package dev.jfr4jdbc; import dev.jfr4jdbc.interceptor.*; -import dev.jfr4jdbc.internal.ConnectionInfo; -import dev.jfr4jdbc.internal.OperationInfo; -import jdk.jfr.consumer.RecordedEvent; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/MockJDBC.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/MockJDBC.java similarity index 100% rename from jdbc42/src/test/java/dev/jfr4jdbc/MockJDBC.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/MockJDBC.java diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/OneStopTest.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/OneStopTest.java similarity index 98% rename from jdbc42/src/test/java/dev/jfr4jdbc/OneStopTest.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/OneStopTest.java index 95b02f6..25fdc7b 100644 --- a/jdbc42/src/test/java/dev/jfr4jdbc/OneStopTest.java +++ b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/OneStopTest.java @@ -1,7 +1,6 @@ package dev.jfr4jdbc; import dev.jfr4jdbc.interceptor.*; -import jdk.jfr.consumer.RecordedEvent; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; @@ -9,7 +8,6 @@ import javax.sql.DataSource; import java.sql.*; import java.util.List; -import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/ParameterTest.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/ParameterTest.java similarity index 96% rename from jdbc42/src/test/java/dev/jfr4jdbc/ParameterTest.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/ParameterTest.java index e57d7b9..f5ca90b 100644 --- a/jdbc42/src/test/java/dev/jfr4jdbc/ParameterTest.java +++ b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/ParameterTest.java @@ -1,9 +1,7 @@ package dev.jfr4jdbc; -import dev.jfr4jdbc.event.jfr.JfrStatementEvent; import dev.jfr4jdbc.interceptor.MockInterceptorFactory; import dev.jfr4jdbc.interceptor.StatementContext; -import jdk.jfr.consumer.RecordedEvent; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -12,7 +10,6 @@ import java.sql.PreparedStatement; import java.util.List; -import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/interceptor/InterceptorTest.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/interceptor/InterceptorTest.java new file mode 100644 index 0000000..30c7222 --- /dev/null +++ b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/interceptor/InterceptorTest.java @@ -0,0 +1,538 @@ +package dev.jfr4jdbc.interceptor; + +import dev.jfr4jdbc.interceptor.std.*; +import dev.jfr4jdbc.interceptor.std.event.*; +import dev.jfr4jdbc.internal.StillUnassignedConnectionInfo; +import jdk.jfr.consumer.RecordedEvent; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.fail; + +class InterceptorTest { + + private ConnectionInfo CONNECTION_INFO = new ConnectionInfo("label", 1, 2); + private OperationInfo OPERATION_INFO = new OperationInfo(3); + + private StillUnassignedConnectionInfo STILL_UNASSIGNED_CONNECTION_INFO = new StillUnassignedConnectionInfo(CONNECTION_INFO.dataSourceLabel, CONNECTION_INFO.conId); + + @Test + public void defaultCancelEvent() throws Exception { + CancelInterceptor interceptor = new CancelInterceptor(); + CancelContext context = new CancelContext(null, null, CONNECTION_INFO, OPERATION_INFO); + + List recordedEvents = JfrTestHelper.record(interceptor, context); + + Assertions.assertEquals(1, recordedEvents.size()); + } + + @Test + public void defaultCloseEvent() throws Exception { + CloseInterceptor interceptor = new CloseInterceptor(); + CloseContext context = new CloseContext(null, CONNECTION_INFO, OPERATION_INFO); + + List recordedEvents = JfrTestHelper.record(interceptor, context); + + Assertions.assertEquals(1, recordedEvents.size()); + } + + @Test + public void defaultCommitEvent() throws Exception { + CommitInterceptor interceptor = new CommitInterceptor(); + CommitContext context = new CommitContext(null, CONNECTION_INFO, OPERATION_INFO); + + List recordedEvents = JfrTestHelper.record(interceptor, context); + + Assertions.assertEquals(1, recordedEvents.size()); + } + + @Test + public void defaultRollbackEvent() throws Exception { + RollbackInterceptor interceptor = new RollbackInterceptor(); + RollbackContext context = new RollbackContext(null, CONNECTION_INFO, OPERATION_INFO); + + List recordedEvents = JfrTestHelper.record(interceptor, context); + + Assertions.assertEquals(1, recordedEvents.size()); + } + + @Test + public void defaultDataSourceEvent() throws Exception { + DataSourceInterceptor interceptor = new DataSourceInterceptor(); + DataSourceContext context = new DataSourceContext(null, STILL_UNASSIGNED_CONNECTION_INFO, 0); + context.setConnection(null, CONNECTION_INFO); + + List recordedEvents = JfrTestHelper.record(interceptor, context); + + Assertions.assertEquals(1, recordedEvents.size()); + } + + @Test + public void defaultDriverEvent() throws Exception { + DriverInterceptor interceptor = new DriverInterceptor(); + DriverContext context = new DriverContext(null, STILL_UNASSIGNED_CONNECTION_INFO, "jdbc:xxx"); + context.setConnection(null, CONNECTION_INFO); + + List recordedEvents = JfrTestHelper.record(interceptor, context); + + Assertions.assertEquals(1, recordedEvents.size()); + } + + @Test + public void defaultResultSetEvent() throws Exception { + ResultSetInterceptor interceptor = new ResultSetInterceptor(); + ResultSetContext context = new ResultSetContext(null, CONNECTION_INFO, OPERATION_INFO); + + List recordedEvents = JfrTestHelper.record(interceptor, context); + + Assertions.assertEquals(1, recordedEvents.size()); + } + + @Test + public void defaultStatementEvent() throws Exception { + StatementInterceptor interceptor = new StatementInterceptor(); + StatementContext context = new StatementContext(null, CONNECTION_INFO, OPERATION_INFO, "", true); + + List recordedEvents = JfrTestHelper.record(interceptor, context); + + Assertions.assertEquals(1, recordedEvents.size()); + } + + + @Test + public void enabledAllCancelEvent() throws Exception { + CancelInterceptor interceptor = new CancelInterceptor(); + CancelContext context = new CancelContext(null, null, CONNECTION_INFO, OPERATION_INFO); + + List recordedEvents = JfrTestHelper.record(interceptor, context, CancelStartEvent.class, CancelPeriodEvent.class, CancelEndEvent.class); + + Assertions.assertEquals(3, recordedEvents.size()); + } + + @Test + public void enabledAllCloseEvent() throws Exception { + CloseInterceptor interceptor = new CloseInterceptor(); + CloseContext context = new CloseContext(null, CONNECTION_INFO, OPERATION_INFO); + + List recordedEvents = JfrTestHelper.record(interceptor, context, CloseStartEvent.class, ClosePeriodEvent.class, CloseEndEvent.class); + + Assertions.assertEquals(3, recordedEvents.size()); + } + + @Test + public void enabledAllCommitEvent() throws Exception { + CommitInterceptor interceptor = new CommitInterceptor(); + CommitContext context = new CommitContext(null, CONNECTION_INFO, OPERATION_INFO); + + List recordedEvents = JfrTestHelper.record(interceptor, context, CommitStartEvent.class, CommitPeriodEvent.class, CommitEndEvent.class); + + Assertions.assertEquals(3, recordedEvents.size()); + } + + @Test + public void enabledAllRollbackEvent() throws Exception { + RollbackInterceptor interceptor = new RollbackInterceptor(); + RollbackContext context = new RollbackContext(null, CONNECTION_INFO, OPERATION_INFO); + + List recordedEvents = JfrTestHelper.record(interceptor, context, RollbackStartEvent.class, RollbackPeriodEvent.class, RollbackEndEvent.class); + + Assertions.assertEquals(3, recordedEvents.size()); + } + + @Test + public void enabledAllDataSourceEvent() throws Exception { + DataSourceInterceptor interceptor = new DataSourceInterceptor(); + DataSourceContext context = new DataSourceContext(null, STILL_UNASSIGNED_CONNECTION_INFO, 0); + context.setConnection(null, CONNECTION_INFO); + + List recordedEvents = JfrTestHelper.record(interceptor, context, DataSourceStartEvent.class, DataSourcePeriodEvent.class, DataSourceEndEvent.class); + + Assertions.assertEquals(3, recordedEvents.size()); + } + + @Test + public void enabledAllDriverEvent() throws Exception { + DriverInterceptor interceptor = new DriverInterceptor(); + DriverContext context = new DriverContext(null, STILL_UNASSIGNED_CONNECTION_INFO, "jdbc:xxx"); + context.setConnection(null, CONNECTION_INFO); + + List recordedEvents = JfrTestHelper.record(interceptor, context, DriverStartEvent.class, DriverPeriodEvent.class, DriverEndEvent.class); + + Assertions.assertEquals(3, recordedEvents.size()); + } + + @Test + public void enabledAllResultSetEvent() throws Exception { + ResultSetInterceptor interceptor = new ResultSetInterceptor(); + ResultSetContext context = new ResultSetContext(null, CONNECTION_INFO, OPERATION_INFO); + + List recordedEvents = JfrTestHelper.record(interceptor, context, ResultSetStartEvent.class, ResultSetPeriodEvent.class, ResultSetEndEvent.class); + + Assertions.assertEquals(3, recordedEvents.size()); + } + + @Test + public void enabledAllStatementEvent() throws Exception { + StatementInterceptor interceptor = new StatementInterceptor(); + StatementContext context = new StatementContext(null, CONNECTION_INFO, OPERATION_INFO, "", true); + + List recordedEvents = JfrTestHelper.record(interceptor, context, StatementStartEvent.class, StatementPeriodEvent.class, StatementEndEvent.class); + + Assertions.assertEquals(3, recordedEvents.size()); + } + + + private RecordedEvent getStartEvent(List recordedEvents) { + for (RecordedEvent e : recordedEvents) { + if (e.getEventType().getName().endsWith("Start")) { + return e; + } + } + return null; + } + + private RecordedEvent getEndEvent(List recordedEvents) { + for (RecordedEvent e : recordedEvents) { + if (e.getEventType().getName().endsWith("End")) { + return e; + } + } + return null; + } + + private RecordedEvent getPeriodEvent(List recordedEvents) { + for (RecordedEvent e : recordedEvents) { + if (!e.getEventType().getName().endsWith("Start") && !e.getEventType().getName().endsWith("End")) { + return e; + } + } + return null; + } + + @Test + public void periodCancelEvent() throws Exception { + CancelInterceptor interceptor = new CancelInterceptor(); + CancelContext context = new CancelContext(null, null, CONNECTION_INFO, OPERATION_INFO); + context.setException(new RuntimeException("test")); + + List recordedEvents = JfrTestHelper.record(interceptor, context, CancelStartEvent.class, CancelPeriodEvent.class, CancelEndEvent.class); + + RecordedEvent startEvent = getStartEvent(recordedEvents); + RecordedEvent periodEvent = getPeriodEvent(recordedEvents); + RecordedEvent endEvent = getEndEvent(recordedEvents); + + if (startEvent == null || periodEvent == null || endEvent == null) { + fail(); + } + + Assertions.assertEquals("label", startEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, startEvent.getInt("connectionId")); + Assertions.assertEquals(2, startEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, startEvent.getInt("operationId")); + + Assertions.assertEquals("label", periodEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, periodEvent.getInt("connectionId")); + Assertions.assertEquals(2, periodEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, periodEvent.getInt("operationId")); + Assertions.assertEquals(RuntimeException.class.getCanonicalName(), periodEvent.getClass("exception").getName()); + Assertions.assertEquals("test", periodEvent.getString("exceptionMessage")); + + Assertions.assertEquals("label", endEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, endEvent.getInt("connectionId")); + Assertions.assertEquals(2, endEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, endEvent.getInt("operationId")); + Assertions.assertEquals(RuntimeException.class.getCanonicalName(), endEvent.getClass("exception").getName()); + Assertions.assertEquals("test", endEvent.getString("exceptionMessage")); + } + + @Test + public void periodCloseEvent() throws Exception { + CloseInterceptor interceptor = new CloseInterceptor(); + CloseContext context = new CloseContext(null, CONNECTION_INFO, OPERATION_INFO); + context.setException(new RuntimeException("test")); + + List recordedEvents = JfrTestHelper.record(interceptor, context, CloseStartEvent.class, ClosePeriodEvent.class, CloseEndEvent.class); + + RecordedEvent startEvent = getStartEvent(recordedEvents); + RecordedEvent periodEvent = getPeriodEvent(recordedEvents); + RecordedEvent endEvent = getEndEvent(recordedEvents); + + if (startEvent == null || periodEvent == null || endEvent == null) { + fail(); + } + + Assertions.assertEquals("label", startEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, startEvent.getInt("connectionId")); + Assertions.assertEquals(2, startEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, startEvent.getInt("operationId")); + + Assertions.assertEquals("label", periodEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, periodEvent.getInt("connectionId")); + Assertions.assertEquals(2, periodEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, periodEvent.getInt("operationId")); + Assertions.assertEquals(RuntimeException.class.getCanonicalName(), periodEvent.getClass("exception").getName()); + Assertions.assertEquals("test", periodEvent.getString("exceptionMessage")); + + Assertions.assertEquals("label", endEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, endEvent.getInt("connectionId")); + Assertions.assertEquals(2, endEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, endEvent.getInt("operationId")); + Assertions.assertEquals(RuntimeException.class.getCanonicalName(), endEvent.getClass("exception").getName()); + Assertions.assertEquals("test", endEvent.getString("exceptionMessage")); + } + + @Test + public void recordedCommitEvent() throws Exception { + CommitInterceptor interceptor = new CommitInterceptor(); + CommitContext context = new CommitContext(null, CONNECTION_INFO, OPERATION_INFO); + context.setException(new RuntimeException("test")); + + List recordedEvents = JfrTestHelper.record(interceptor, context, CommitStartEvent.class, CommitPeriodEvent.class, CommitEndEvent.class); + + RecordedEvent startEvent = getStartEvent(recordedEvents); + RecordedEvent periodEvent = getPeriodEvent(recordedEvents); + RecordedEvent endEvent = getEndEvent(recordedEvents); + + if (startEvent == null || periodEvent == null || endEvent == null) { + fail(); + } + + Assertions.assertEquals("label", startEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, startEvent.getInt("connectionId")); + Assertions.assertEquals(2, startEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, startEvent.getInt("operationId")); + + Assertions.assertEquals("label", periodEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, periodEvent.getInt("connectionId")); + Assertions.assertEquals(2, periodEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, periodEvent.getInt("operationId")); + Assertions.assertEquals(RuntimeException.class.getCanonicalName(), periodEvent.getClass("exception").getName()); + Assertions.assertEquals("test", periodEvent.getString("exceptionMessage")); + + Assertions.assertEquals("label", endEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, endEvent.getInt("connectionId")); + Assertions.assertEquals(2, endEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, endEvent.getInt("operationId")); + Assertions.assertEquals(RuntimeException.class.getCanonicalName(), endEvent.getClass("exception").getName()); + Assertions.assertEquals("test", endEvent.getString("exceptionMessage")); + } + + @Test + public void recordedRollbackEvent() throws Exception { + RollbackInterceptor interceptor = new RollbackInterceptor(); + RollbackContext context = new RollbackContext(null, CONNECTION_INFO, OPERATION_INFO); + context.setException(new RuntimeException("test")); + + List recordedEvents = JfrTestHelper.record(interceptor, context, RollbackStartEvent.class, RollbackPeriodEvent.class, RollbackEndEvent.class); + + RecordedEvent startEvent = getStartEvent(recordedEvents); + RecordedEvent periodEvent = getPeriodEvent(recordedEvents); + RecordedEvent endEvent = getEndEvent(recordedEvents); + + if (startEvent == null || periodEvent == null || endEvent == null) { + fail(); + } + + Assertions.assertEquals("label", startEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, startEvent.getInt("connectionId")); + Assertions.assertEquals(2, startEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, startEvent.getInt("operationId")); + + Assertions.assertEquals("label", periodEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, periodEvent.getInt("connectionId")); + Assertions.assertEquals(2, periodEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, periodEvent.getInt("operationId")); + Assertions.assertEquals(RuntimeException.class.getCanonicalName(), periodEvent.getClass("exception").getName()); + Assertions.assertEquals("test", periodEvent.getString("exceptionMessage")); + + Assertions.assertEquals("label", endEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, endEvent.getInt("connectionId")); + Assertions.assertEquals(2, endEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, endEvent.getInt("operationId")); + Assertions.assertEquals(RuntimeException.class.getCanonicalName(), endEvent.getClass("exception").getName()); + Assertions.assertEquals("test", endEvent.getString("exceptionMessage")); + } + + @Test + public void recordedDataSourceEvent() throws Exception { + DataSourceInterceptor interceptor = new DataSourceInterceptor(); + DataSourceContext context = new DataSourceContext(null, STILL_UNASSIGNED_CONNECTION_INFO, 0); + context.setAuth("user", "password"); + context.setConnection(null, CONNECTION_INFO); + context.setException(new RuntimeException("test")); + + List recordedEvents = JfrTestHelper.record(interceptor, context, DataSourceStartEvent.class, DataSourcePeriodEvent.class, DataSourceEndEvent.class); + + RecordedEvent startEvent = getStartEvent(recordedEvents); + RecordedEvent periodEvent = getPeriodEvent(recordedEvents); + RecordedEvent endEvent = getEndEvent(recordedEvents); + + if (startEvent == null || periodEvent == null || endEvent == null) { + fail(); + } + + Assertions.assertEquals("label", startEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, startEvent.getInt("connectionId")); + Assertions.assertEquals("user", startEvent.getString("username")); + Assertions.assertEquals("password", startEvent.getString("password")); + + Assertions.assertEquals("label", periodEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, periodEvent.getInt("connectionId")); + Assertions.assertEquals(2, periodEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals("user", periodEvent.getString("username")); + Assertions.assertEquals("password", periodEvent.getString("password")); + Assertions.assertEquals(RuntimeException.class.getCanonicalName(), periodEvent.getClass("exception").getName()); + Assertions.assertEquals("test", periodEvent.getString("exceptionMessage")); + + Assertions.assertEquals("label", endEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, endEvent.getInt("connectionId")); + Assertions.assertEquals(2, endEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals("user", endEvent.getString("username")); + Assertions.assertEquals("password", endEvent.getString("password")); + Assertions.assertEquals(RuntimeException.class.getCanonicalName(), endEvent.getClass("exception").getName()); + Assertions.assertEquals("test", endEvent.getString("exceptionMessage")); + } + + @Test + public void recordedDriverEvent() throws Exception { + DriverInterceptor interceptor = new DriverInterceptor(); + + DriverContext context = new DriverContext(null, STILL_UNASSIGNED_CONNECTION_INFO, "jdbc:xxx"); + context.setConnection(null, CONNECTION_INFO); + context.setException(new RuntimeException("test")); + + List recordedEvents = JfrTestHelper.record(interceptor, context, DriverStartEvent.class, DriverPeriodEvent.class, DriverEndEvent.class); + + RecordedEvent startEvent = getStartEvent(recordedEvents); + RecordedEvent periodEvent = getPeriodEvent(recordedEvents); + RecordedEvent endEvent = getEndEvent(recordedEvents); + + if (startEvent == null || periodEvent == null || endEvent == null) { + fail(); + } + + Assertions.assertEquals("label", startEvent.getString("label")); + Assertions.assertEquals(1, startEvent.getInt("connectionId")); + Assertions.assertEquals("jdbc:xxx", startEvent.getString("url")); + + Assertions.assertEquals("label", periodEvent.getString("label")); + Assertions.assertEquals(1, periodEvent.getInt("connectionId")); + Assertions.assertEquals(2, periodEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals("jdbc:xxx", startEvent.getString("url")); + Assertions.assertEquals(RuntimeException.class.getCanonicalName(), periodEvent.getClass("exception").getName()); + Assertions.assertEquals("test", periodEvent.getString("exceptionMessage")); + + Assertions.assertEquals("label", endEvent.getString("label")); + Assertions.assertEquals(1, endEvent.getInt("connectionId")); + Assertions.assertEquals(2, endEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals("jdbc:xxx", startEvent.getString("url")); + Assertions.assertEquals(RuntimeException.class.getCanonicalName(), endEvent.getClass("exception").getName()); + Assertions.assertEquals("test", endEvent.getString("exceptionMessage")); + } + + @Test + public void recordedResultSetEvent() throws Exception { + ResultSetInterceptor interceptor = new ResultSetInterceptor(); + ResultSetContext context = new ResultSetContext(null, CONNECTION_INFO, OPERATION_INFO); + context.setResult(false); + context.setRowNo(4); + context.setException(new RuntimeException("test")); + + List recordedEvents = JfrTestHelper.record(interceptor, context, ResultSetStartEvent.class, ResultSetPeriodEvent.class, ResultSetEndEvent.class); + + RecordedEvent startEvent = getStartEvent(recordedEvents); + RecordedEvent periodEvent = getPeriodEvent(recordedEvents); + RecordedEvent endEvent = getEndEvent(recordedEvents); + + if (startEvent == null || periodEvent == null || endEvent == null) { + fail(); + } + + Assertions.assertEquals("label", startEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, startEvent.getInt("connectionId")); + Assertions.assertEquals(2, startEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, startEvent.getInt("operationId")); + + Assertions.assertEquals("label", periodEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, periodEvent.getInt("connectionId")); + Assertions.assertEquals(2, periodEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, periodEvent.getInt("operationId")); + Assertions.assertEquals(false, periodEvent.getBoolean("result")); + Assertions.assertEquals(4, periodEvent.getInt("rowNo")); + Assertions.assertEquals(RuntimeException.class.getCanonicalName(), periodEvent.getClass("exception").getName()); + Assertions.assertEquals("test", periodEvent.getString("exceptionMessage")); + + Assertions.assertEquals("label", endEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, endEvent.getInt("connectionId")); + Assertions.assertEquals(2, endEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, endEvent.getInt("operationId")); + Assertions.assertEquals(false, endEvent.getBoolean("result")); + Assertions.assertEquals(4, endEvent.getInt("rowNo")); + Assertions.assertEquals(RuntimeException.class.getCanonicalName(), endEvent.getClass("exception").getName()); + Assertions.assertEquals("test", endEvent.getString("exceptionMessage")); + } + + @Test + public void recordedStatementEvent() throws Exception { + StatementInterceptor interceptor = new StatementInterceptor(); + StatementContext context = new StatementContext(null, CONNECTION_INFO, OPERATION_INFO, "SELECT *", false); + context.setAutoCommitted(false); + context.setConnection(null); + context.setInquiryParameter("param"); + context.setStatementClosed(false); + context.setStatementPoolable(false); + context.setException(new RuntimeException("test")); + + List recordedEvents = JfrTestHelper.record(interceptor, context, StatementStartEvent.class, StatementPeriodEvent.class, StatementEndEvent.class); + + RecordedEvent startEvent = getStartEvent(recordedEvents); + RecordedEvent periodEvent = getPeriodEvent(recordedEvents); + RecordedEvent endEvent = getEndEvent(recordedEvents); + + if (startEvent == null || periodEvent == null || endEvent == null) { + fail(); + } + + Assertions.assertEquals("label", startEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, startEvent.getInt("connectionId")); + Assertions.assertEquals(2, startEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, startEvent.getInt("operationId")); + Assertions.assertEquals("SELECT *", startEvent.getString("inquiry")); + Assertions.assertEquals(false, startEvent.getBoolean("isPrepared")); + Assertions.assertEquals("param", startEvent.getString("inquiryParameter")); + Assertions.assertEquals(false, startEvent.getBoolean("isStatementPoolable")); + Assertions.assertEquals(false, startEvent.getBoolean("isStatementClosed")); + Assertions.assertEquals(false, startEvent.getBoolean("isAutoCommitted")); + + + Assertions.assertEquals("label", periodEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, periodEvent.getInt("connectionId")); + Assertions.assertEquals(2, periodEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, periodEvent.getInt("operationId")); + Assertions.assertEquals("SELECT *", periodEvent.getString("inquiry")); + Assertions.assertEquals(false, periodEvent.getBoolean("isPrepared")); + Assertions.assertEquals("param", periodEvent.getString("inquiryParameter")); + Assertions.assertEquals(false, periodEvent.getBoolean("isStatementPoolable")); + Assertions.assertEquals(false, periodEvent.getBoolean("isStatementClosed")); + Assertions.assertEquals(false, periodEvent.getBoolean("isAutoCommitted")); + Assertions.assertEquals(RuntimeException.class.getCanonicalName(), periodEvent.getClass("exception").getName()); + Assertions.assertEquals("test", periodEvent.getString("exceptionMessage")); + + Assertions.assertEquals("label", endEvent.getString("dataSourceLabel")); + Assertions.assertEquals(1, endEvent.getInt("connectionId")); + Assertions.assertEquals(2, endEvent.getInt("wrappedConnectionId")); + Assertions.assertEquals(3, endEvent.getInt("operationId")); + Assertions.assertEquals("SELECT *", endEvent.getString("inquiry")); + Assertions.assertEquals(false, endEvent.getBoolean("isPrepared")); + Assertions.assertEquals("param", endEvent.getString("inquiryParameter")); + Assertions.assertEquals(false, endEvent.getBoolean("isStatementPoolable")); + Assertions.assertEquals(false, endEvent.getBoolean("isStatementClosed")); + Assertions.assertEquals(false, endEvent.getBoolean("isAutoCommitted")); + Assertions.assertEquals(RuntimeException.class.getCanonicalName(), endEvent.getClass("exception").getName()); + Assertions.assertEquals("test", endEvent.getString("exceptionMessage")); + } + + +} \ No newline at end of file diff --git a/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/interceptor/JfrTestHelper.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/interceptor/JfrTestHelper.java new file mode 100644 index 0000000..2c1edf9 --- /dev/null +++ b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/interceptor/JfrTestHelper.java @@ -0,0 +1,28 @@ +package dev.jfr4jdbc.interceptor; + +import jdk.jfr.Event; +import jdk.jfr.Recording; +import jdk.jfr.consumer.RecordedEvent; +import jdk.jfr.consumer.RecordingFile; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; + +public class JfrTestHelper { + public static List record(Interceptor interceptor, CONTEXT context, Class... enabledEventClasses) throws IOException { + Recording recording = new Recording(); + Arrays.stream(enabledEventClasses).forEach(c -> recording.enable(c)); + recording.start(); + + interceptor.preInvoke(context); + interceptor.postInvoke(context); + + recording.stop(); + Path dumpfilePath = Files.createTempFile("sample", ".jfr"); + recording.dump(dumpfilePath); + return RecordingFile.readAllEvents(dumpfilePath); + } +} diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/interceptor/MockInterceptor.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/interceptor/MockInterceptor.java similarity index 60% rename from jdbc42/src/test/java/dev/jfr4jdbc/interceptor/MockInterceptor.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/interceptor/MockInterceptor.java index 2cacd30..38b5106 100644 --- a/jdbc42/src/test/java/dev/jfr4jdbc/interceptor/MockInterceptor.java +++ b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/interceptor/MockInterceptor.java @@ -4,33 +4,33 @@ import java.util.Collections; import java.util.List; -public class MockInterceptor implements Interceptor{ +public class MockInterceptor implements Interceptor { private List preEvents = new ArrayList(); private List postEvents = new ArrayList(); @Override - public void preInvoke(CONTEXT cancelContext) { - addPreEvent(cancelContext); + public void preInvoke(CONTEXT context) { + addPreEvent(context); } @Override - public void postInvoke(CONTEXT cancelContext) { - addPostEvent(cancelContext); + public void postInvoke(CONTEXT context) { + addPostEvent(context); } - public void addPreEvent(CONTEXT event){ + public void addPreEvent(CONTEXT event) { preEvents.add(event); } - public List getAllPreEvents(){ + public List getAllPreEvents() { return Collections.unmodifiableList(preEvents); } - public void addPostEvent(CONTEXT event){ + public void addPostEvent(CONTEXT event) { postEvents.add(event); } - public List getAllPostEvents(){ + public List getAllPostEvents() { return Collections.unmodifiableList(postEvents); } } diff --git a/jdbc42/src/test/java/dev/jfr4jdbc/interceptor/MockInterceptorFactory.java b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/interceptor/MockInterceptorFactory.java similarity index 87% rename from jdbc42/src/test/java/dev/jfr4jdbc/interceptor/MockInterceptorFactory.java rename to jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/interceptor/MockInterceptorFactory.java index 4f892aa..308476c 100644 --- a/jdbc42/src/test/java/dev/jfr4jdbc/interceptor/MockInterceptorFactory.java +++ b/jfr4jdbc-driver/src/test/java/dev/jfr4jdbc/interceptor/MockInterceptorFactory.java @@ -1,6 +1,6 @@ package dev.jfr4jdbc.interceptor; -public class MockInterceptorFactory implements InterceptorFactory{ +public class MockInterceptorFactory implements InterceptorFactory { private MockInterceptor cancelInterceptor = new MockInterceptor(); @@ -18,8 +18,6 @@ public class MockInterceptorFactory implements InterceptorFactory{ private MockInterceptor resultSetInterceptor = new MockInterceptor(); - private MockInterceptor resourceMonitorInterceptor = new MockInterceptor(); - @Override public MockInterceptor createDataSourceInterceptor() { return dataSourceInterceptor; @@ -59,9 +57,4 @@ public MockInterceptor createCancelInterceptor() { public MockInterceptor createResultSetInterceptor() { return resultSetInterceptor; } - - @Override - public MockInterceptor createResourceMonitorInterceptor() { - return resourceMonitorInterceptor; - } } diff --git a/jdbc42/src/test/resources/junit-platform.properties b/jfr4jdbc-driver/src/test/resources/junit-platform.properties similarity index 100% rename from jdbc42/src/test/resources/junit-platform.properties rename to jfr4jdbc-driver/src/test/resources/junit-platform.properties