Skip to content

Commit a7727b4

Browse files
committed
Remove sonar cloud issues
1 parent d7e53b0 commit a7727b4

File tree

5 files changed

+51
-37
lines changed

5 files changed

+51
-37
lines changed

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.io.InputStream;
44

5+
import org.fugerit.java.core.cfg.ConfigRuntimeException;
6+
import org.fugerit.java.core.function.SafeFunction;
57
import org.fugerit.java.core.xml.dom.DOMIO;
68
import org.w3c.dom.Document;
79
import org.w3c.dom.Element;
@@ -58,18 +60,24 @@ public class DataListCatalogConfig extends GenericListCatalogConfig<String> {
5860
private static final long serialVersionUID = 60670717619176336L;
5961

6062
/**
61-
* Worker method for loading an xml from an input stream
63+
* <p>Configure an instance of DataListCatalogConfig</p>
6264
*
63-
* @param is input source
64-
* @param config config object
65-
* @return the object configured
66-
* @throws Exception in case of issues
65+
* <p>NOTE: starting from version 8.4.X java.lang.Exception removed in favor of org.fugerit.java.core.cfg.ConfigRuntimeException.</p>
66+
*
67+
* @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>
68+
*
69+
* @param is the input stream to load from
70+
* @param config the instance to be configured (will be configured by side effect too)
71+
* @return the configured instance
72+
* @throws ConfigRuntimeException in case of issues during loading
6773
*/
68-
protected static DataListCatalogConfig loadConfig( InputStream is, DataListCatalogConfig config ) throws Exception {
69-
Document doc = DOMIO.loadDOMDoc( is );
70-
Element root = doc.getDocumentElement();
71-
config.configure( root );
72-
return config;
74+
protected static DataListCatalogConfig loadConfig( InputStream is, DataListCatalogConfig config ) {
75+
return SafeFunction.get( () -> {
76+
Document doc = DOMIO.loadDOMDoc( is );
77+
Element root = doc.getDocumentElement();
78+
config.configure( root );
79+
return config;
80+
} );
7381
}
7482

7583
/**

fj-core/src/main/java/org/fugerit/java/core/db/dao/BasicDAO.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,7 @@ protected List<T> loadAll(String query, FieldList fields, RSExtractor<T> re) thr
308308
}
309309

310310
protected LoadResult<T> loadAllResult(String query, FieldList fields, RSExtractor<T> re) throws DAOException {
311-
return LoadResult.initResult(this, query, fields, re);
312-
311+
return DAOException.get( () -> LoadResult.initResult(this, query, fields, re) );
313312
}
314313

315314
protected void loadAll(List<T> l, String query, FieldList fields, RSExtractor<T> re) throws DAOException {

fj-core/src/main/java/org/fugerit/java/core/db/daogen/ByteArrayDataHandler.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ public abstract class ByteArrayDataHandler {
1515
public abstract byte[] getData();
1616

1717
public static ByteArrayDataHandler newHandlerByte( byte[] data ) throws DAOException {
18-
ByteArrayDataHandler r = null;
19-
if ( data != null ) {
20-
r = new PreloadByteArrayDataHandler( data );
21-
}
22-
return r;
18+
return DAOException.get( () -> {
19+
ByteArrayDataHandler r = null;
20+
if ( data != null ) {
21+
r = new PreloadByteArrayDataHandler( data );
22+
}
23+
return r;
24+
} );
2325
}
2426

2527
public static ByteArrayDataHandler newHandlerDefault( Blob b ) throws DAOException {

fj-core/src/main/java/org/fugerit/java/core/db/daogen/CharArrayDataHandler.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ public abstract class CharArrayDataHandler {
1616
public abstract char[] getData();
1717

1818
public static CharArrayDataHandler newHandlerByte( char[] data ) throws DAOException {
19-
CharArrayDataHandler r = null;
20-
if ( data != null ) {
21-
r = new PreloadCharArrayDataHandler( data );
22-
}
23-
return r;
19+
return DAOException.get( () -> {
20+
CharArrayDataHandler r = null;
21+
if ( data != null ) {
22+
r = new PreloadCharArrayDataHandler( data );
23+
}
24+
return r;
25+
} );
2426
}
2527

2628
public static CharArrayDataHandler newHandlerDefault( Clob c ) throws DAOException {
@@ -33,8 +35,8 @@ public String toString() {
3335
}
3436

3537
public static CharArrayDataHandler newHandlerPreload( Clob c ) throws DAOException {
36-
CharArrayDataHandler handler = null;
37-
try {
38+
return DAOException.get( () -> {
39+
CharArrayDataHandler handler = null;
3840
if ( c != null && c.length() > 0 ) {
3941
CharArrayWriter writer = new CharArrayWriter();
4042
StreamIO.pipeChar( c.getCharacterStream(), writer, StreamIO.MODE_CLOSE_BOTH );
@@ -43,10 +45,8 @@ public static CharArrayDataHandler newHandlerPreload( Clob c ) throws DAOExcepti
4345
handler = new PreloadCharArrayDataHandler( data );
4446
}
4547
}
46-
} catch (Exception e) {
47-
throw DAOException.convertExMethod( "newHandlerPreload" , e);
48-
}
49-
return handler;
48+
return handler;
49+
} );
5050
}
5151

5252
}

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.util.regex.Matcher;
1010
import java.util.regex.Pattern;
1111

12+
import org.fugerit.java.core.io.helper.HelperIOException;
13+
1214
public class SQLScriptFacade {
1315

1416
private SQLScriptFacade() {}
@@ -18,18 +20,21 @@ public static String[] parseScript( String script ) throws IOException {
1820
}
1921

2022
public static String removeSqlComments( String script ) throws IOException {
21-
return script.replaceAll("\\B--*\\B.*", "");
23+
return HelperIOException.get( () -> script.replaceAll("\\B--*\\B.*", "") );
2224
}
2325

2426
public static String[] parseSqlCommands( String script ) throws IOException {
25-
Pattern regex = Pattern.compile("/\\*[^;(\\*/)]*?(;)[^;]*?\\*/", Pattern.DOTALL | Pattern.MULTILINE);
26-
Matcher regexMatcher = regex.matcher( script );
27-
List<String> list = new ArrayList<>();
28-
while (regexMatcher.find()) {
29-
String match = regexMatcher.group();
30-
list.add( match );
31-
}
32-
return list.toArray( new String[0] );
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+
} );
37+
3338
}
3439

3540
public static int executeAll( SQLScriptReader reader, Connection conn ) throws SQLException, IOException {

0 commit comments

Comments
 (0)