Skip to content

Commit

Permalink
add event testcases.
Browse files Browse the repository at this point in the history
  • Loading branch information
HidekiSugimoto189 committed Mar 3, 2024
1 parent ebb73bd commit 284c5ac
Show file tree
Hide file tree
Showing 49 changed files with 1,200 additions and 354 deletions.
29 changes: 17 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>jp.co.future</groupId>
Expand All @@ -16,6 +17,10 @@
<distribution>repo</distribution>
</license>
</licenses>
<organization>
<name>Future Corporation</name>
<url>https://www.future.co.jp/</url>
</organization>
<url>https://future-architect.github.io/uroborosql-doc/</url>
<scm>
<connection>scm:git:https://github.com/future-architect/uroborosql.git</connection>
Expand Down Expand Up @@ -62,22 +67,22 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<version>3.12.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<version>3.2.5</version>
<configuration>
<argLine>-Duroborosql.sql.coverage=true ${jacocoArgs}</argLine>
<additionalClasspathElements>
Expand All @@ -88,12 +93,12 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<version>1.6.13</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
<version>0.8.11</version>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
Expand All @@ -120,12 +125,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>com.mycila</groupId>
Expand All @@ -135,7 +140,7 @@
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>4.38.0</version>
<version>5.22.0</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down Expand Up @@ -296,8 +301,8 @@ LICENSE file in the root directory of this source tree.
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-testing-frameworks</artifactId>
<version>1.32.0</version>
<artifactId>rewrite-testing-frameworks</artifactId>
<version>2.3.2</version>
</dependency>
</dependencies>
</plugin>
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/jp/co/future/uroborosql/SqlAgentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ public ResultSet query(final ExecutionContext executionContext) throws SQLExcept
rs = stmt.executeQuery();
// Query実行後イベント発行
if (getSqlConfig().getEventListenerHolder().hasSqlQueryListener()) {
var eventObj = new SqlQueryEvent(executionContext, rs, stmt);
var eventObj = new SqlQueryEvent(executionContext, rs, stmt.getConnection(), stmt);
for (var listener : getSqlConfig().getEventListenerHolder().getSqlQueryListeners()) {
listener.accept(eventObj);
}
Expand Down Expand Up @@ -1451,7 +1451,7 @@ public int update(final ExecutionContext executionContext) throws SQLException {
var count = stmt.executeUpdate();
// Update実行後イベント発行
if (getSqlConfig().getEventListenerHolder().hasSqlUpdateListener()) {
var eventObj = new SqlUpdateEvent(executionContext, count, stmt);
var eventObj = new SqlUpdateEvent(executionContext, count, stmt.getConnection(), stmt);
for (var listener : getSqlConfig().getEventListenerHolder().getSqlUpdateListeners()) {
listener.accept(eventObj);
}
Expand Down Expand Up @@ -1580,7 +1580,7 @@ public int[] batch(final ExecutionContext executionContext) throws SQLException
var counts = stmt.executeBatch();
// Batch実行後イベント発行
if (getSqlConfig().getEventListenerHolder().hasSqlBatchListener()) {
var eventObj = new SqlBatchEvent(executionContext, counts, stmt);
var eventObj = new SqlBatchEvent(executionContext, counts, stmt.getConnection(), stmt);
for (var listener : getSqlConfig().getEventListenerHolder().getSqlBatchListeners()) {
listener.accept(eventObj);
}
Expand Down Expand Up @@ -1705,7 +1705,8 @@ public Map<String, Object> procedure(final ExecutionContext executionContext) th
var result = callableStatement.execute();
// Procedure実行後イベント発行
if (getSqlConfig().getEventListenerHolder().hasProcedureListener()) {
var eventObj = new ProcedureEvent(executionContext, result, callableStatement);
var eventObj = new ProcedureEvent(executionContext, result, callableStatement.getConnection(),
callableStatement);
for (var listener : getSqlConfig().getEventListenerHolder().getProcedureListeners()) {
listener.accept(eventObj);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public boolean contains(final Object o) {

/** where句の直後にくるANDやORを除外するための正規表現 */
private static final Pattern WHERE_CLAUSE_PATTERN = Pattern.compile(
"(?i)(?<clause>(\\bWHERE\\s+(--.*|/\\*[^(/\\*|\\*/)]+?\\*/\\s*)*\\s*))((AND|OR)\\s+)");
"(?i)(?<clause>(\\bWHERE\\s+(--.*|/\\*[\\s\\S]*\\*/\\s*)*\\s*))((AND|OR)\\s+)");

/** 各句の最初に現れるカンマを除去するための正規表現 */
private static final Pattern REMOVE_FIRST_COMMA_PATTERN = Pattern.compile(
Expand Down Expand Up @@ -234,24 +234,24 @@ public String getExecutableSql() {
executableSqlCache = executableSql.toString();
if (executableSqlCache.toUpperCase().contains("WHERE")) {
// where句の直後に来るANDやORの除去
var buff = new StringBuilder();
var builder = new StringBuilder();
var matcher = WHERE_CLAUSE_PATTERN.matcher(executableSqlCache);
while (matcher.find()) {
var whereClause = matcher.group("clause");
matcher.appendReplacement(buff, whereClause);
matcher.appendReplacement(builder, whereClause);
}
matcher.appendTail(buff);
executableSqlCache = buff.toString();
matcher.appendTail(builder);
executableSqlCache = builder.toString();
}
// 各句の直後に現れる不要なカンマの除去
var buff = new StringBuilder();
var builder = new StringBuilder();
var removeCommaMatcher = REMOVE_FIRST_COMMA_PATTERN.matcher(executableSqlCache);
while (removeCommaMatcher.find()) {
var clauseWords = removeCommaMatcher.group("keyword");
removeCommaMatcher.appendReplacement(buff, clauseWords);
removeCommaMatcher.appendReplacement(builder, clauseWords);
}
removeCommaMatcher.appendTail(buff);
executableSqlCache = buff.toString();
removeCommaMatcher.appendTail(builder);
executableSqlCache = builder.toString();

// 空行の除去
executableSqlCache = CLEAR_BLANK_PATTERN.matcher(executableSqlCache).replaceAll("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package jp.co.future.uroborosql.event;

import java.sql.Connection;

import jp.co.future.uroborosql.tx.TransactionContext;

/**
Expand All @@ -15,13 +17,25 @@
* @since v1.0.0
*/
public class AfterCommitEvent extends TransactionEvent {
/** Connection. */
private final Connection connection;

/**
* コンストラクタ.
*
* @param transactionContext TransactionContext
* @param connection Connection
*/
public AfterCommitEvent(final TransactionContext transactionContext) {
public AfterCommitEvent(final TransactionContext transactionContext, final Connection connection) {
super(transactionContext);
this.connection = connection;
}

/**
* Connectionの取得.
* @return Connection
*/
public Connection getConnection() {
return connection;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package jp.co.future.uroborosql.event;

import java.sql.CallableStatement;
import java.sql.Connection;

import jp.co.future.uroborosql.context.ExecutionContext;

Expand All @@ -17,21 +18,35 @@
* @since v1.0.0
*/
public class AfterCreateCallableStatementEvent extends ExecutionEvent {
/** Connection. */
private final Connection connection;

/** CallableStatement. */
private CallableStatement callableStatement;

/**
* コンストラクタ.
*
* @param executionContext ExecutionContext
* @param connectino Connection
* @param callableStatement CallableStatement
*/
public AfterCreateCallableStatementEvent(final ExecutionContext executionContext,
final Connection connection,
final CallableStatement callableStatement) {
super(executionContext);
this.connection = connection;
this.callableStatement = callableStatement;
}

/**
* Connectionの取得.
* @return Connection
*/
public Connection getConnection() {
return connection;
}

/**
* CallableStatementの取得.
* @return CallableStatement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package jp.co.future.uroborosql.event;

import java.sql.Connection;
import java.sql.PreparedStatement;

import jp.co.future.uroborosql.context.ExecutionContext;
Expand All @@ -17,21 +18,35 @@
* @since v1.0.0
*/
public class AfterCreatePreparedStatementEvent extends ExecutionEvent {
/** Connection. */
private final Connection connection;

/** PreparedStatement. */
private PreparedStatement preparedStatement;

/**
* コンストラクタ.
*
* @param executionContext ExecutionContext
* @param connection Connection
* @param preparedStatement PreparedStatement
*/
public AfterCreatePreparedStatementEvent(final ExecutionContext executionContext,
final Connection connection,
final PreparedStatement preparedStatement) {
super(executionContext);
this.connection = connection;
this.preparedStatement = preparedStatement;
}

/**
* Connectionの取得.
* @return Connection
*/
public Connection getConnection() {
return connection;
}

/**
* PreparedStatementの取得.
* @return PreparedStatement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package jp.co.future.uroborosql.event;

import java.sql.Connection;

import jp.co.future.uroborosql.tx.TransactionContext;

/**
Expand All @@ -15,12 +17,26 @@
* @since v1.0.0
*/
public class AfterRollbackEvent extends TransactionEvent {
/** Connection. */
private final Connection connection;

/**
* コンストラクタ.
*
* @param transactionContext TransactionContext
* @param connection Connection
*/
public AfterRollbackEvent(final TransactionContext transactionContext) {
public AfterRollbackEvent(final TransactionContext transactionContext, final Connection connection) {
super(transactionContext);
this.connection = connection;
}

/**
* Connectionの取得.
* @return Connection
*/
public Connection getConnection() {
return connection;
}

}

This file was deleted.

Loading

0 comments on commit 284c5ac

Please sign in to comment.