Skip to content

Commit d167b25

Browse files
author
maple
committed
spotless apply
1 parent e84a064 commit d167b25

File tree

6 files changed

+357
-357
lines changed

6 files changed

+357
-357
lines changed

rm-datasource/src/test/java/org/apache/seata/rm/datasource/undo/sqlserver/BaseSqlServerUndoExecutorTest.java

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -71,40 +71,40 @@ public void setUp() {
7171
private TableMeta createTableMeta() {
7272
TableMeta meta = new TableMeta();
7373
meta.setTableName("test_table");
74-
74+
7575
// Create column metadata
7676
Map<String, ColumnMeta> allColumns = new HashMap<>();
77-
77+
7878
ColumnMeta idColumn = new ColumnMeta();
7979
idColumn.setTableName("test_table");
8080
idColumn.setColumnName("id");
8181
idColumn.setDataType(Types.INTEGER);
8282
idColumn.setColumnSize(11);
8383
allColumns.put("id", idColumn);
84-
84+
8585
ColumnMeta nameColumn = new ColumnMeta();
8686
nameColumn.setTableName("test_table");
8787
nameColumn.setColumnName("name");
8888
nameColumn.setDataType(Types.VARCHAR);
8989
nameColumn.setColumnSize(255);
9090
allColumns.put("name", nameColumn);
91-
91+
9292
meta.getAllColumns().putAll(allColumns);
93-
93+
9494
// Create primary key index
9595
Map<String, IndexMeta> allIndexes = new HashMap<>();
9696
IndexMeta primaryIndex = new IndexMeta();
9797
primaryIndex.setIndexName("PRIMARY");
9898
primaryIndex.setNonUnique(false);
9999
primaryIndex.setIndextype(IndexType.PRIMARY);
100-
100+
101101
List<ColumnMeta> primaryColumns = new ArrayList<>();
102102
primaryColumns.add(idColumn);
103103
primaryIndex.setValues(primaryColumns);
104-
104+
105105
allIndexes.put("PRIMARY", primaryIndex);
106106
meta.getAllIndexes().putAll(allIndexes);
107-
107+
108108
return meta;
109109
}
110110

@@ -113,25 +113,23 @@ private SQLUndoLog createSQLUndoLog() {
113113
undoLog.setSqlType(SQLType.UPDATE);
114114
undoLog.setTableName("test_table");
115115
undoLog.setTableMeta(tableMeta);
116-
116+
117117
// Create before image
118118
TableRecords beforeImage = new TableRecords();
119119
beforeImage.setTableName("test_table");
120120
beforeImage.setTableMeta(tableMeta);
121-
122-
List<Field> fields = Arrays.asList(
123-
new Field("id", Types.INTEGER, 1),
124-
new Field("name", Types.VARCHAR, "John"));
125-
121+
122+
List<Field> fields = Arrays.asList(new Field("id", Types.INTEGER, 1), new Field("name", Types.VARCHAR, "John"));
123+
126124
// Set primary key for id field
127125
fields.get(0).setKeyType(KeyType.PRIMARY_KEY);
128-
126+
129127
Row row = new Row();
130128
row.setFields(fields);
131-
129+
132130
beforeImage.setRows(Arrays.asList(row));
133131
undoLog.setBeforeImage(beforeImage);
134-
132+
135133
return undoLog;
136134
}
137135

@@ -151,17 +149,17 @@ public void testConstructorWithNull() {
151149
public void testBuildCheckSql() {
152150
String tableName = "test_table";
153151
String whereCondition = "id = ?";
154-
152+
155153
String checkSql = executor.buildCheckSql(tableName, whereCondition);
156-
154+
157155
// Verify SQL Server specific check SQL with UPDLOCK hint
158156
Assertions.assertNotNull(checkSql);
159157
Assertions.assertTrue(checkSql.contains("SELECT * FROM"));
160158
Assertions.assertTrue(checkSql.contains(tableName));
161159
Assertions.assertTrue(checkSql.contains("WITH(UPDLOCK)"));
162160
Assertions.assertTrue(checkSql.contains("WHERE"));
163161
Assertions.assertTrue(checkSql.contains(whereCondition));
164-
162+
165163
// Verify exact format
166164
String expectedSql = "SELECT * FROM test_table WITH(UPDLOCK) WHERE id = ?";
167165
Assertions.assertEquals(expectedSql, checkSql);
@@ -171,17 +169,17 @@ public void testBuildCheckSql() {
171169
public void testBuildCheckSqlWithComplexWhereCondition() {
172170
String tableName = "user_orders";
173171
String whereCondition = "user_id = ? AND order_date > ?";
174-
172+
175173
String checkSql = executor.buildCheckSql(tableName, whereCondition);
176-
174+
177175
// Verify SQL Server specific check SQL
178176
Assertions.assertNotNull(checkSql);
179177
Assertions.assertTrue(checkSql.contains("SELECT * FROM"));
180178
Assertions.assertTrue(checkSql.contains(tableName));
181179
Assertions.assertTrue(checkSql.contains("WITH(UPDLOCK)"));
182180
Assertions.assertTrue(checkSql.contains("WHERE"));
183181
Assertions.assertTrue(checkSql.contains(whereCondition));
184-
182+
185183
String expectedSql = "SELECT * FROM user_orders WITH(UPDLOCK) WHERE user_id = ? AND order_date > ?";
186184
Assertions.assertEquals(expectedSql, checkSql);
187185
}
@@ -190,16 +188,16 @@ public void testBuildCheckSqlWithComplexWhereCondition() {
190188
public void testBuildCheckSqlWithEmptyWhereCondition() {
191189
String tableName = "test_table";
192190
String whereCondition = "";
193-
191+
194192
String checkSql = executor.buildCheckSql(tableName, whereCondition);
195-
193+
196194
// Should still work with empty where condition
197195
Assertions.assertNotNull(checkSql);
198196
Assertions.assertTrue(checkSql.contains("SELECT * FROM"));
199197
Assertions.assertTrue(checkSql.contains(tableName));
200198
Assertions.assertTrue(checkSql.contains("WITH(UPDLOCK)"));
201199
Assertions.assertTrue(checkSql.contains("WHERE"));
202-
200+
203201
String expectedSql = "SELECT * FROM test_table WITH(UPDLOCK) WHERE ";
204202
Assertions.assertEquals(expectedSql, checkSql);
205203
}
@@ -208,16 +206,16 @@ public void testBuildCheckSqlWithEmptyWhereCondition() {
208206
public void testBuildCheckSqlWithNullWhereCondition() {
209207
String tableName = "test_table";
210208
String whereCondition = null;
211-
209+
212210
String checkSql = executor.buildCheckSql(tableName, whereCondition);
213-
211+
214212
// Should handle null where condition
215213
Assertions.assertNotNull(checkSql);
216214
Assertions.assertTrue(checkSql.contains("SELECT * FROM"));
217215
Assertions.assertTrue(checkSql.contains(tableName));
218216
Assertions.assertTrue(checkSql.contains("WITH(UPDLOCK)"));
219217
Assertions.assertTrue(checkSql.contains("WHERE"));
220-
218+
221219
String expectedSql = "SELECT * FROM test_table WITH(UPDLOCK) WHERE null";
222220
Assertions.assertEquals(expectedSql, checkSql);
223221
}
@@ -226,15 +224,15 @@ public void testBuildCheckSqlWithNullWhereCondition() {
226224
public void testBuildCheckSqlWithSpecialTableName() {
227225
String tableName = "[dbo].[user_table]";
228226
String whereCondition = "id = ?";
229-
227+
230228
String checkSql = executor.buildCheckSql(tableName, whereCondition);
231-
229+
232230
// Should work with SQL Server style table names
233231
Assertions.assertNotNull(checkSql);
234232
Assertions.assertTrue(checkSql.contains("SELECT * FROM"));
235233
Assertions.assertTrue(checkSql.contains(tableName));
236234
Assertions.assertTrue(checkSql.contains("WITH(UPDLOCK)"));
237-
235+
238236
String expectedSql = "SELECT * FROM [dbo].[user_table] WITH(UPDLOCK) WHERE id = ?";
239237
Assertions.assertEquals(expectedSql, checkSql);
240238
}
@@ -251,7 +249,7 @@ public void testAbstractMethods() {
251249
// Verify that abstract methods are implemented in test class
252250
String undoSQL = executor.buildUndoSQL();
253251
Assertions.assertEquals("TEST SQL", undoSQL);
254-
252+
255253
TableRecords undoRows = executor.getUndoRows();
256254
Assertions.assertNotNull(undoRows);
257255
Assertions.assertEquals(sqlUndoLog.getBeforeImage(), undoRows);
@@ -261,10 +259,10 @@ public void testAbstractMethods() {
261259
public void testSqlServerSpecificFeatures() {
262260
// Test that the buildCheckSql method provides SQL Server specific functionality
263261
String checkSql = executor.buildCheckSql("orders", "status = 'PENDING'");
264-
262+
265263
// SQL Server uses WITH(UPDLOCK) for row-level locking during SELECT
266264
Assertions.assertTrue(checkSql.contains("WITH(UPDLOCK)"));
267-
265+
268266
// This is different from other databases that might use different locking mechanisms
269267
Assertions.assertFalse(checkSql.contains("FOR UPDATE")); // MySQL/PostgreSQL style
270268
Assertions.assertFalse(checkSql.contains("WITH (ROWLOCK)")); // Alternative SQL Server syntax
@@ -275,13 +273,14 @@ public void testBuildCheckSqlFormat() {
275273
// Test the exact format of the generated SQL
276274
String tableName = "products";
277275
String whereCondition = "category_id = ? AND price > ?";
278-
276+
279277
String checkSql = executor.buildCheckSql(tableName, whereCondition);
280-
278+
281279
// Verify the exact format matches SQL Server conventions
282-
String expectedPattern = "SELECT \\* FROM " + tableName + " WITH\\(UPDLOCK\\) WHERE " + whereCondition.replace("?", "\\?");
280+
String expectedPattern =
281+
"SELECT \\* FROM " + tableName + " WITH\\(UPDLOCK\\) WHERE " + whereCondition.replace("?", "\\?");
283282
Assertions.assertTrue(checkSql.matches(expectedPattern));
284-
283+
285284
// Verify no extra spaces or formatting issues
286285
Assertions.assertFalse(checkSql.contains(" ")); // No double spaces
287286
Assertions.assertTrue(checkSql.startsWith("SELECT * FROM"));
@@ -294,13 +293,13 @@ public void testMultipleInstancesIndependence() {
294293
SQLUndoLog anotherUndoLog = new SQLUndoLog();
295294
anotherUndoLog.setSqlType(SQLType.DELETE);
296295
anotherUndoLog.setTableName("another_table");
297-
296+
298297
TestBaseSqlServerUndoExecutor anotherExecutor = new TestBaseSqlServerUndoExecutor(anotherUndoLog);
299-
298+
300299
// Both executors should work independently
301300
String checkSql1 = executor.buildCheckSql("table1", "id = 1");
302301
String checkSql2 = anotherExecutor.buildCheckSql("table2", "id = 2");
303-
302+
304303
Assertions.assertNotEquals(checkSql1, checkSql2);
305304
Assertions.assertTrue(checkSql1.contains("table1"));
306305
Assertions.assertTrue(checkSql2.contains("table2"));

0 commit comments

Comments
 (0)