1717
1818import io .flamingock .internal .common .sql .SqlDialectFactory ;
1919import io .flamingock .internal .common .sql .SqlDialect ;
20- import io .flamingock .internal .core .external .store .lock .LockStatus ;
2120
2221import java .sql .*;
2322import java .time .LocalDateTime ;
@@ -254,14 +253,14 @@ public String getDeleteLockSqlString(String tableName) {
254253 }
255254 }
256255
257- public void upsertLockEntry (Connection conn , String tableName , String key , String owner , LocalDateTime expiresAt ) throws SQLException {
256+ public void upsertLockEntry (Connection conn , String tableName , String key , String owner , String lockStatus , LocalDateTime expiresAt ) throws SQLException {
258257 String sql = getInsertOrUpdateLockSqlString (tableName );
259258
260259 if (sqlDialect == SqlDialect .DB2 ) {
261260 // UPDATE first
262261 try (PreparedStatement update = conn .prepareStatement (
263262 "UPDATE " + tableName + " SET status = ?, owner = ?, expires_at = ? WHERE lock_key = ?" )) {
264- update .setString (1 , LockStatus . LOCK_HELD . name () );
263+ update .setString (1 , lockStatus );
265264 update .setString (2 , owner );
266265 update .setTimestamp (3 , Timestamp .valueOf (expiresAt ));
267266 update .setString (4 , key );
@@ -275,7 +274,7 @@ public void upsertLockEntry(Connection conn, String tableName, String key, Strin
275274 try (PreparedStatement insert = conn .prepareStatement (
276275 "INSERT INTO " + tableName + " (lock_key, status, owner, expires_at) VALUES (?, ?, ?, ?)" )) {
277276 insert .setString (1 , key );
278- insert .setString (2 , LockStatus . LOCK_HELD . name () );
277+ insert .setString (2 , lockStatus );
279278 insert .setString (3 , owner );
280279 insert .setTimestamp (4 , Timestamp .valueOf (expiresAt ));
281280 insert .executeUpdate ();
@@ -287,7 +286,7 @@ public void upsertLockEntry(Connection conn, String tableName, String key, Strin
287286 // Try UPDATE first
288287 try (PreparedStatement update = conn .prepareStatement (
289288 "UPDATE " + tableName + " SET status = ?, owner = ?, expires_at = ? WHERE lock_key = ?" )) {
290- update .setString (1 , LockStatus . LOCK_HELD . name () );
289+ update .setString (1 , lockStatus );
291290 update .setString (2 , owner );
292291 update .setTimestamp (3 , Timestamp .valueOf (expiresAt ));
293292 update .setString (4 , key );
@@ -301,7 +300,7 @@ public void upsertLockEntry(Connection conn, String tableName, String key, Strin
301300 try (PreparedStatement insert = conn .prepareStatement (
302301 "INSERT INTO " + tableName + " (lock_key, status, owner, expires_at) VALUES (?, ?, ?, ?)" )) {
303302 insert .setString (1 , key );
304- insert .setString (2 , LockStatus . LOCK_HELD . name () );
303+ insert .setString (2 , lockStatus );
305304 insert .setString (3 , owner );
306305 insert .setTimestamp (4 , Timestamp .valueOf (expiresAt ));
307306 insert .executeUpdate ();
@@ -313,12 +312,12 @@ public void upsertLockEntry(Connection conn, String tableName, String key, Strin
313312 // For SQL Server/Sybase, use Statement and format SQL
314313 try (Statement stmt = conn .createStatement ()) {
315314 String formattedSql = sql
316- .replaceFirst ("\\ ?" , "'" + LockStatus . LOCK_HELD . name () + "'" )
315+ .replaceFirst ("\\ ?" , "'" + lockStatus + "'" )
317316 .replaceFirst ("\\ ?" , "'" + owner + "'" )
318317 .replaceFirst ("\\ ?" , "'" + Timestamp .valueOf (expiresAt ) + "'" )
319318 .replaceFirst ("\\ ?" , "'" + key + "'" )
320319 .replaceFirst ("\\ ?" , "'" + key + "'" )
321- .replaceFirst ("\\ ?" , "'" + LockStatus . LOCK_HELD . name () + "'" )
320+ .replaceFirst ("\\ ?" , "'" + lockStatus + "'" )
322321 .replaceFirst ("\\ ?" , "'" + owner + "'" )
323322 .replaceFirst ("\\ ?" , "'" + Timestamp .valueOf (expiresAt ) + "'" );
324323 stmt .execute (formattedSql );
@@ -328,7 +327,7 @@ public void upsertLockEntry(Connection conn, String tableName, String key, Strin
328327
329328 if (sqlDialect == SqlDialect .FIREBIRD ) {
330329 try (PreparedStatement ps = conn .prepareStatement (sql )) {
331- ps .setString (1 , LockStatus . LOCK_HELD . name () );
330+ ps .setString (1 , lockStatus );
332331 ps .setString (2 , owner );
333332 ps .setTimestamp (3 , Timestamp .valueOf (expiresAt ));
334333 ps .setString (4 , key );
@@ -337,7 +336,7 @@ public void upsertLockEntry(Connection conn, String tableName, String key, Strin
337336 String insertSql = "INSERT INTO " + tableName + " (lock_key, status, owner, expires_at) VALUES (?, ?, ?, ?)" ;
338337 try (PreparedStatement ins = conn .prepareStatement (insertSql )) {
339338 ins .setString (1 , key );
340- ins .setString (2 , LockStatus . LOCK_HELD . name () );
339+ ins .setString (2 , lockStatus );
341340 ins .setString (3 , owner );
342341 ins .setTimestamp (4 , Timestamp .valueOf (expiresAt ));
343342 ins .executeUpdate ();
@@ -352,7 +351,7 @@ public void upsertLockEntry(Connection conn, String tableName, String key, Strin
352351 try (PreparedStatement insert = conn .prepareStatement (
353352 "INSERT INTO " + tableName + " (lock_key, status, owner, expires_at) VALUES (?, ?, ?, ?)" )) {
354353 insert .setString (1 , key );
355- insert .setString (2 , LockStatus . LOCK_HELD . name () );
354+ insert .setString (2 , lockStatus );
356355 insert .setString (3 , owner );
357356 insert .setTimestamp (4 , Timestamp .valueOf (expiresAt ));
358357 insert .executeUpdate ();
@@ -364,7 +363,7 @@ public void upsertLockEntry(Connection conn, String tableName, String key, Strin
364363 // Default case for other dialects
365364 try (PreparedStatement ps = conn .prepareStatement (sql )) {
366365 ps .setString (1 , key );
367- ps .setString (2 , LockStatus . LOCK_HELD . name () );
366+ ps .setString (2 , lockStatus );
368367 ps .setString (3 , owner );
369368 ps .setTimestamp (4 , Timestamp .valueOf (expiresAt ));
370369 ps .executeUpdate ();
0 commit comments