Skip to content

Commit b4d90c8

Browse files
davidfrigoletdieppa
authored andcommitted
feat: disable hsqldb dialect(#730)
1 parent 9df44c1 commit b4d90c8

File tree

26 files changed

+1095
-114
lines changed

26 files changed

+1095
-114
lines changed

.gitignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,13 @@ dynamodb-local-metadata*
9292
# Claude Code configuration files
9393
.claude/settings.local.json
9494

95-
/flamingock-cli-dist
95+
/flamingock-cli-dist
96+
97+
# SQLite test DB files generated by tests
98+
test_*.db
99+
test_*.db-wal
100+
test_*.db-shm
101+
102+
# Generic SQLite artifacts
103+
*.db-wal
104+
*.db-shm

community/flamingock-auditstore-sql/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ dependencies {
1919
testImplementation("com.h2database:h2:2.2.224")
2020
testImplementation("org.mockito:mockito-inline:4.11.0")
2121
testImplementation("org.xerial:sqlite-jdbc:3.41.2.1")
22+
testImplementation("com.ibm.informix:jdbc:4.50.10")
23+
testImplementation("org.firebirdsql.jdbc:jaybird:4.0.10.java8")
2224
}
2325

2426
description = "SQL audit store implementation for distributed change auditing"

community/flamingock-auditstore-sql/src/main/java/io/flamingock/community/sql/internal/SqlAuditor.java

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.flamingock.internal.common.core.audit.AuditEntry;
1919
import io.flamingock.internal.common.core.audit.AuditReader;
2020
import io.flamingock.internal.common.core.audit.AuditTxType;
21+
import io.flamingock.internal.common.sql.SqlDialect;
2122
import io.flamingock.internal.core.store.audit.LifecycleAuditWriter;
2223
import io.flamingock.internal.util.Result;
2324

@@ -46,42 +47,70 @@ public void initialize() {
4647
Statement stmt = conn.createStatement()) {
4748
stmt.executeUpdate(dialectHelper.getCreateTableSqlString(auditTableName));
4849
} catch (SQLException e) {
50+
// Firebird throws an error when table already exists; ignore that specific case
51+
if (dialectHelper.getSqlDialect() == io.flamingock.internal.common.sql.SqlDialect.FIREBIRD) {
52+
int errorCode = e.getErrorCode();
53+
String sqlState = e.getSQLState();
54+
String msg = e.getMessage() != null ? e.getMessage().toLowerCase() : "";
55+
56+
if (errorCode == 335544351 || "42000".equals(sqlState) || msg.contains("already exists")) {
57+
return;
58+
}
59+
}
4960
throw new RuntimeException("Failed to initialize audit table", e);
5061
}
5162
}
5263
}
5364

5465
@Override
5566
public Result writeEntry(AuditEntry auditEntry) {
56-
try (Connection conn = dataSource.getConnection();
57-
PreparedStatement ps = conn.prepareStatement(
58-
dialectHelper.getInsertSqlString(auditTableName))) {
59-
ps.setString(1, auditEntry.getExecutionId());
60-
ps.setString(2, auditEntry.getStageId());
61-
ps.setString(3, auditEntry.getTaskId());
62-
ps.setString(4, auditEntry.getAuthor());
63-
ps.setTimestamp(5, Timestamp.valueOf(auditEntry.getCreatedAt()));
64-
ps.setString(6, auditEntry.getState() != null ? auditEntry.getState().name() : null);
65-
ps.setString(7, auditEntry.getClassName());
66-
ps.setString(8, auditEntry.getMethodName());
67-
ps.setString(9, auditEntry.getMetadata() != null ? auditEntry.getMetadata().toString() : null);
68-
ps.setLong(10, auditEntry.getExecutionMillis());
69-
ps.setString(11, auditEntry.getExecutionHostname());
70-
ps.setString(12, auditEntry.getErrorTrace());
71-
ps.setString(13, auditEntry.getType() != null ? auditEntry.getType().name() : null);
72-
ps.setString(14, auditEntry.getTxType() != null ? auditEntry.getTxType().name() : null);
73-
ps.setString(15, auditEntry.getTargetSystemId());
74-
ps.setString(16, auditEntry.getOrder());
75-
ps.setString(17, auditEntry.getRecoveryStrategy() != null ? auditEntry.getRecoveryStrategy().name() : null);
76-
ps.setObject(18, auditEntry.getTransactionFlag());
77-
ps.setObject(19, auditEntry.getSystemChange());
78-
ps.executeUpdate();
67+
Connection conn = null;
68+
try {
69+
conn = dataSource.getConnection();
70+
71+
// For Informix, ensure autoCommit is enabled for audit writes
72+
if (dialectHelper.getSqlDialect() == SqlDialect.INFORMIX) {
73+
conn.setAutoCommit(true);
74+
}
75+
76+
try (PreparedStatement ps = conn.prepareStatement(
77+
dialectHelper.getInsertSqlString(auditTableName))) {
78+
ps.setString(1, auditEntry.getExecutionId());
79+
ps.setString(2, auditEntry.getStageId());
80+
ps.setString(3, auditEntry.getTaskId());
81+
ps.setString(4, auditEntry.getAuthor());
82+
ps.setTimestamp(5, Timestamp.valueOf(auditEntry.getCreatedAt()));
83+
ps.setString(6, auditEntry.getState() != null ? auditEntry.getState().name() : null);
84+
ps.setString(7, auditEntry.getClassName());
85+
ps.setString(8, auditEntry.getMethodName());
86+
ps.setString(9, auditEntry.getMetadata() != null ? auditEntry.getMetadata().toString() : null);
87+
ps.setLong(10, auditEntry.getExecutionMillis());
88+
ps.setString(11, auditEntry.getExecutionHostname());
89+
ps.setString(12, auditEntry.getErrorTrace());
90+
ps.setString(13, auditEntry.getType() != null ? auditEntry.getType().name() : null);
91+
ps.setString(14, auditEntry.getTxType() != null ? auditEntry.getTxType().name() : null);
92+
ps.setString(15, auditEntry.getTargetSystemId());
93+
ps.setString(16, auditEntry.getOrder());
94+
ps.setString(17, auditEntry.getRecoveryStrategy() != null ? auditEntry.getRecoveryStrategy().name() : null);
95+
ps.setObject(18, auditEntry.getTransactionFlag());
96+
ps.setObject(19, auditEntry.getSystemChange());
97+
ps.executeUpdate();
98+
}
7999
return Result.OK();
80100
} catch (SQLException e) {
81101
return new Result.Error(e);
102+
} finally {
103+
if (conn != null) {
104+
try {
105+
conn.close();
106+
} catch (SQLException e) {
107+
// Log but don't throw
108+
}
109+
}
82110
}
83111
}
84112

113+
85114
@Override
86115
public List<AuditEntry> getAuditHistory() {
87116
List<AuditEntry> entries = new ArrayList<>();

community/flamingock-auditstore-sql/src/main/java/io/flamingock/community/sql/internal/SqlAuditorDialectHelper.java

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ public String getCreateTableSqlString(String tableName) {
3535
case MYSQL:
3636
case MARIADB:
3737
case H2:
38-
case HSQLDB:
39-
case FIREBIRD:
40-
case INFORMIX:
4138
return String.format(
4239
"CREATE TABLE IF NOT EXISTS %s (" +
4340
"id %s PRIMARY KEY, " +
@@ -61,6 +58,30 @@ public String getCreateTableSqlString(String tableName) {
6158
"transaction_flag %s, " +
6259
"system_change %s" +
6360
")", tableName, getAutoIncrementType(), getClobType(), getBigIntType(), getClobType(), getBooleanType(), getBooleanType());
61+
case FIREBIRD:
62+
return String.format(
63+
"CREATE TABLE %s (" +
64+
"id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, " +
65+
"execution_id VARCHAR(255), " +
66+
"stage_id VARCHAR(255), " +
67+
"task_id VARCHAR(255), " +
68+
"author VARCHAR(255), " +
69+
"created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, " +
70+
"state VARCHAR(255), " +
71+
"class_name VARCHAR(255), " +
72+
"method_name VARCHAR(255), " +
73+
"metadata BLOB SUB_TYPE TEXT, " +
74+
"execution_millis BIGINT, " +
75+
"execution_hostname VARCHAR(255), " +
76+
"error_trace BLOB SUB_TYPE TEXT, " +
77+
"type VARCHAR(50), " +
78+
"tx_type VARCHAR(50), " +
79+
"target_system_id VARCHAR(255), " +
80+
"order_col VARCHAR(50), " +
81+
"recovery_strategy VARCHAR(50), " +
82+
"transaction_flag SMALLINT, " +
83+
"system_change SMALLINT" +
84+
")", tableName);
6485
case POSTGRESQL:
6586
return String.format(
6687
"CREATE TABLE IF NOT EXISTS %s (" +
@@ -87,7 +108,6 @@ public String getCreateTableSqlString(String tableName) {
87108
")", tableName);
88109

89110
case SQLSERVER:
90-
case SYBASE:
91111
return String.format(
92112
"IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='%s' AND xtype='U') " +
93113
"CREATE TABLE %s (" +
@@ -112,6 +132,35 @@ public String getCreateTableSqlString(String tableName) {
112132
"transaction_flag %s, " +
113133
"system_change %s" +
114134
")", tableName, tableName, getAutoIncrementType(), getClobType(), getBigIntType(), getClobType(), getBooleanType(), getBooleanType());
135+
case SYBASE:
136+
return String.format(
137+
"IF NOT EXISTS (SELECT 1 FROM sysobjects WHERE name='%s' AND type='U') " +
138+
"BEGIN " +
139+
" EXEC('CREATE TABLE %s (" +
140+
" id BIGINT IDENTITY PRIMARY KEY, " +
141+
" execution_id VARCHAR(255), " +
142+
" stage_id VARCHAR(255), " +
143+
" task_id VARCHAR(255), " +
144+
" author VARCHAR(255), " +
145+
" created_at DATETIME, " +
146+
" state VARCHAR(32), " +
147+
" class_name VARCHAR(255), " +
148+
" method_name VARCHAR(255), " +
149+
" metadata TEXT, " +
150+
" execution_millis BIGINT, " +
151+
" execution_hostname VARCHAR(255), " +
152+
" error_trace TEXT, " +
153+
" type VARCHAR(64), " +
154+
" tx_type VARCHAR(64), " +
155+
" target_system_id VARCHAR(255), " +
156+
" order_col VARCHAR(255), " +
157+
" recovery_strategy VARCHAR(64), " +
158+
" transaction_flag BIT NOT NULL, " +
159+
" system_change BIT NOT NULL" +
160+
" )') " +
161+
"END",
162+
tableName, tableName
163+
);
115164
case ORACLE:
116165
return String.format(
117166
"BEGIN EXECUTE IMMEDIATE 'CREATE TABLE %s (" +
@@ -189,6 +238,32 @@ public String getCreateTableSqlString(String tableName) {
189238
"transaction_flag INTEGER, " +
190239
"system_change INTEGER" +
191240
")", tableName);
241+
case INFORMIX:
242+
return String.format(
243+
"CREATE TABLE IF NOT EXISTS %s (" +
244+
"id SERIAL8 PRIMARY KEY, " +
245+
"execution_id VARCHAR(100), " +
246+
"stage_id VARCHAR(100), " +
247+
"task_id VARCHAR(100), " +
248+
"author VARCHAR(100), " +
249+
"created_at DATETIME YEAR TO FRACTION(3) DEFAULT CURRENT YEAR TO FRACTION(3), " +
250+
"state VARCHAR(50), " +
251+
"class_name VARCHAR(200), " +
252+
"method_name VARCHAR(100), " +
253+
"metadata LVARCHAR(8000), " +
254+
"execution_millis BIGINT, " +
255+
"execution_hostname VARCHAR(100), " +
256+
"error_trace LVARCHAR(8000), " +
257+
"type VARCHAR(50), " +
258+
"tx_type VARCHAR(50), " +
259+
"target_system_id VARCHAR(100), " +
260+
"order_col VARCHAR(50), " +
261+
"recovery_strategy VARCHAR(50), " +
262+
"transaction_flag BOOLEAN, " +
263+
"system_change BOOLEAN" +
264+
")", tableName);
265+
266+
192267
default:
193268
throw new UnsupportedOperationException("Dialect not supported for CREATE TABLE: " + sqlDialect.name());
194269
}
@@ -217,7 +292,6 @@ private String getAutoIncrementType() {
217292
return "BIGSERIAL";
218293
case SQLITE:
219294
case H2:
220-
case HSQLDB:
221295
case DB2:
222296
case FIREBIRD:
223297
return "BIGINT GENERATED BY DEFAULT AS IDENTITY";
@@ -242,7 +316,6 @@ private String getClobType() {
242316
return "LONGTEXT";
243317
case SQLITE:
244318
case H2:
245-
case HSQLDB:
246319
case FIREBIRD:
247320
case INFORMIX:
248321
case ORACLE:
@@ -273,7 +346,6 @@ private String getBooleanType() {
273346
return "TINYINT(1)";
274347
case POSTGRESQL:
275348
case H2:
276-
case HSQLDB:
277349
case FIREBIRD:
278350
case INFORMIX:
279351
return "BOOLEAN";

0 commit comments

Comments
 (0)