9
9
import org .springframework .beans .factory .annotation .Autowired ;
10
10
import org .springframework .beans .factory .annotation .Value ;
11
11
import org .springframework .stereotype .Service ;
12
+ import org .springframework .util .CollectionUtils ;
12
13
import org .springframework .util .StringUtils ;
13
14
14
15
import jakarta .annotation .Resource ;
15
16
import javax .naming .ConfigurationException ;
16
17
import java .sql .*;
17
- import java .util .ArrayList ;
18
- import java .util .Arrays ;
19
- import java .util .Collection ;
20
- import java .util .List ;
18
+ import java .util .*;
21
19
import java .util .concurrent .*;
22
20
import java .util .regex .Pattern ;
23
21
26
24
public class AssertionExecutionService {
27
25
28
26
private static final String FAILED_TO_FIND_RVF_DB_SCHEMA = "Failed to find rvf db schema for " ;
27
+ private static final String NOT_SUPPLIED = "NOT_SUPPLIED" ;
28
+
29
29
@ Autowired
30
30
private AssertionService assertionService ;
31
31
@ Resource (name = "dataSource" )
@@ -232,19 +232,14 @@ private List<String> transformSql(List<String> parts, Assertion assertion, Mysql
232
232
String prospectiveSchema = config .getProspectiveVersion ();
233
233
final String [] nameParts = config .getProspectiveVersion ().split ("_" );
234
234
String defaultModuleId = StringUtils .hasLength (config .getDefaultModuleId ()) ? config .getDefaultModuleId () : getModuleId (nameParts );
235
- String includedModules = String .join ("," , config .getIncludedModules ());
236
- String version = (nameParts .length >= 3 ? nameParts [2 ] : " NOT_SUPPLIED" );
235
+ String includedModules = CollectionUtils . isEmpty ( config . getIncludedModules ()) ? "NULL" : String .join ("," , config .getIncludedModules ());
236
+ String version = (nameParts .length >= 3 ? nameParts [2 ] : NOT_SUPPLIED );
237
237
238
238
String previousReleaseSchema = config .getPreviousVersion ();
239
239
String dependencyReleaseSchema = config .getExtensionDependencyVersion ();
240
240
validateSchemas (config , prospectiveSchema , previousReleaseSchema );
241
241
242
242
for ( String part : parts ) {
243
- if ((part .contains ("<PREVIOUS>" ) && previousReleaseSchema == null )
244
- || (part .contains ("<DEPENDENCY>" ) && dependencyReleaseSchema == null )) {
245
- continue ;
246
- }
247
-
248
243
logger .debug ("Original sql statement: {}" , part );
249
244
final Pattern commentPattern = Pattern .compile ("/\\ *.*?\\ */" , Pattern .DOTALL );
250
245
part = commentPattern .matcher (part ).replaceAll ("" );
@@ -259,12 +254,8 @@ private List<String> transformSql(List<String> parts, Assertion assertion, Mysql
259
254
part = part .replace ("<PROSPECTIVE>" , prospectiveSchema );
260
255
part = part .replace ("<TEMP>" , prospectiveSchema );
261
256
part = part .replace ("<INTERNATIONAL_MODULES>" , internationalModules );
262
- if (previousReleaseSchema != null ) {
263
- part = part .replace ("<PREVIOUS>" , previousReleaseSchema );
264
- }
265
- if (dependencyReleaseSchema != null ) {
266
- part = part .replace ("<DEPENDENCY>" , dependencyReleaseSchema );
267
- }
257
+ part = part .replace ("<PREVIOUS>" , previousReleaseSchema );
258
+ part = part .replace ("<DEPENDENCY>" , dependencyReleaseSchema );
268
259
part = part .replace ("<DELTA>" , DELTA_TABLE_SUFFIX );
269
260
part = part .replace ("<SNAPSHOT>" , SNAPSHOT_TABLE_SUFFIX );
270
261
part = part .replace ("<FULL>" , FULL_TABLE_SUFFIX );
@@ -276,7 +267,7 @@ private List<String> transformSql(List<String> parts, Assertion assertion, Mysql
276
267
}
277
268
278
269
private static String getModuleId (String [] nameParts ) {
279
- return nameParts .length >= 2 ? ProductName .toModuleId (nameParts [1 ]) : " NOT_SUPPLIED" ;
270
+ return nameParts .length >= 2 ? ProductName .toModuleId (nameParts [1 ]) : NOT_SUPPLIED ;
280
271
}
281
272
282
273
private static void validateSchemas (MysqlExecutionConfig config , String prospectiveSchema , String previousReleaseSchema ) throws ConfigurationException {
0 commit comments