Skip to content

Commit 02f0056

Browse files
committed
Fix sonar cloud issues
1 parent aea4eb2 commit 02f0056

File tree

4 files changed

+65
-20
lines changed

4 files changed

+65
-20
lines changed

fj-core/src/main/java/org/fugerit/java/core/cfg/xml/DataListCatalogConfig.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,17 @@ protected static DataListCatalogConfig loadConfig( InputStream is, DataListCatal
8181
}
8282

8383
/**
84-
* Worker method for loading an xml from an input stream
84+
* <p>Creates and configure an instance of DataListCatalogConfig</p>
8585
*
86-
* @param is input source
87-
* @return the object configured
88-
* @throws Exception in case of issues
86+
* <p>NOTE: starting from version 8.4.X java.lang.Exception removed in favor of org.fugerit.java.core.cfg.ConfigRuntimeException.</p>
87+
*
88+
* @see <a href="https://fuzzymemory.fugerit.org/src/docs/sonar_cloud/java-S112.html">Define and throw a dedicated exception instead of using a generic one.</a>
89+
*
90+
* @param is the input stream to load from
91+
* @return the configured instance
92+
* @throws ConfigRuntimeException in case of issues during loading
8993
*/
90-
public static DataListCatalogConfig loadConfig( InputStream is ) throws Exception {
94+
public static DataListCatalogConfig loadConfig( InputStream is ) {
9195
return loadConfig( is, new DataListCatalogConfig() );
9296
}
9397

fj-core/src/main/java/org/fugerit/java/core/db/helpers/SQLScriptFacade.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
import java.sql.Connection;
55
import java.sql.SQLException;
66
import java.sql.Statement;
7-
import java.util.ArrayList;
8-
import java.util.List;
9-
import java.util.regex.Matcher;
10-
import java.util.regex.Pattern;
117

128
import org.fugerit.java.core.io.helper.HelperIOException;
139

@@ -24,16 +20,7 @@ public static String removeSqlComments( String script ) throws IOException {
2420
}
2521

2622
public static String[] parseSqlCommands( String script ) throws IOException {
27-
return HelperIOException.get( () -> {
28-
Pattern regex = Pattern.compile("/\\*[^;(\\*/)]*?(;)[^;]*?\\*/", Pattern.DOTALL | Pattern.MULTILINE);
29-
Matcher regexMatcher = regex.matcher( script );
30-
List<String> list = new ArrayList<>();
31-
while (regexMatcher.find()) {
32-
String match = regexMatcher.group();
33-
list.add( match );
34-
}
35-
return list.toArray( new String[0] );
36-
} );
23+
return HelperIOException.get( () -> script.split( "(?<=;)\\s+" ) );
3724

3825
}
3926

fj-core/src/main/java/org/fugerit/java/core/xml/config/XMLSchemaCatalogConfig.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import javax.xml.validation.Validator;
2020

2121
import org.fugerit.java.core.cfg.ConfigException;
22+
import org.fugerit.java.core.cfg.ConfigRuntimeException;
2223
import org.fugerit.java.core.cfg.xml.DataListCatalogConfig;
2324
import org.fugerit.java.core.function.SafeFunction;
2425
import org.fugerit.java.core.io.helper.StreamHelper;
@@ -51,7 +52,18 @@ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassN
5152

5253
// code added to setup a basic conditional serialization - END
5354

54-
public static XMLSchemaCatalogConfig loadConfigSchema( InputStream is ) throws Exception {
55+
/**
56+
* <p>Creates and configure an instance of XMLSchemaCatalogConfig</p>
57+
*
58+
* <p>NOTE: starting from version 8.4.X java.lang.Exception removed in favor of org.fugerit.java.core.cfg.ConfigRuntimeException.</p>
59+
*
60+
* @see <a href="https://fuzzymemory.fugerit.org/src/docs/sonar_cloud/java-S112.html">Define and throw a dedicated exception instead of using a generic one.</a>
61+
*
62+
* @param is the input stream to load from
63+
* @return the configured instance
64+
* @throws ConfigRuntimeException in case of issues during loading
65+
*/
66+
public static XMLSchemaCatalogConfig loadConfigSchema( InputStream is ) {
5567
return (XMLSchemaCatalogConfig)loadConfig( is, new XMLSchemaCatalogConfig() );
5668
}
5769

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package test.org.fugerit.java.core.db.helpers;
2+
3+
import java.io.ByteArrayInputStream;
4+
import java.io.InputStream;
5+
import java.sql.Connection;
6+
7+
import org.fugerit.java.core.db.helpers.SQLScriptFacade;
8+
import org.fugerit.java.core.db.helpers.SQLScriptReader;
9+
import org.fugerit.java.core.function.SafeFunction;
10+
import org.fugerit.java.core.io.StreamIO;
11+
import org.fugerit.java.core.lang.helpers.ClassHelper;
12+
import org.junit.Assert;
13+
import org.junit.Test;
14+
15+
import lombok.extern.slf4j.Slf4j;
16+
import test.org.fugerit.java.core.db.TestBasicDBHelper;
17+
18+
@Slf4j
19+
public class TestSQLScriptFacade extends TestBasicDBHelper {
20+
21+
@Test
22+
public void testReadScripts() {
23+
SafeFunction.apply( () -> {
24+
try ( InputStream is = ClassHelper.loadFromDefaultClassLoader( "test/memdb/base_db_init.sql" ) ) {
25+
String script = StreamIO.readString( is );
26+
log.info( "script -> {}", script );
27+
String[] res = SQLScriptFacade.parseScript(script);
28+
for ( int k=0; k<res.length; k++ ) {
29+
log.info( "current {} -> {}", k, res[k] );
30+
}
31+
Assert.assertNotEquals( 0 , res.length );
32+
// test sql script
33+
try ( SQLScriptReader reader = new SQLScriptReader( new ByteArrayInputStream( "SELECT * FROM fugerit.user;".getBytes() ) );
34+
Connection conn = newConnection() ) {
35+
SQLScriptFacade.executeAll( reader , conn );
36+
}
37+
38+
}
39+
} );
40+
}
41+
42+
}

0 commit comments

Comments
 (0)