Skip to content

Commit

Permalink
Sonar cloud issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Sep 15, 2023
1 parent 03e158f commit f6e804f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 64 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- fj-daogen-version set to 1.2.1 in module fj-core-jvfs

## [8.3.1] - 2023-09-15

### Changed
Expand Down
2 changes: 1 addition & 1 deletion fj-core-jvfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</organization>

<properties>
<fj-daogen-version>1.1.9</fj-daogen-version>
<fj-daogen-version>1.2.1</fj-daogen-version>
<gen.base.dir>${project.basedir}</gen.base.dir>
<generated.source.daogen>target/generated-sources/daogen</generated.source.daogen>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
import org.fugerit.java.core.db.dao.DAOException;
import org.fugerit.java.core.db.metadata.DataBaseInfo;
import org.fugerit.java.core.function.UnsafeSupplier;
import org.fugerit.java.core.lang.helpers.BooleanUtils;
import org.fugerit.java.core.lang.helpers.StringUtils;
import org.fugerit.java.core.log.BasicLogObject;
import org.fugerit.java.core.util.PropsIO;
import org.fugerit.java.core.xml.dom.DOMUtils;
import org.fugerit.java.core.xml.dom.SearchDOM;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -175,11 +177,11 @@ public Connection getConnection() throws DAOException {
/**
* Parse a configuration Element looking for ConnectionFactory configuration
*
* @param cfConfig the Element
* @return the CfConfig
* @throws Exception in case of issues
* @param cfConfig the Element
* @return the CfConfig
* @throws DAOException in case of issues
*/
public static CfConfig parseCfConfig( Element cfConfig ) throws Exception {
public static CfConfig parseCfConfig( Element cfConfig ) throws DAOException {
CfConfig config = new CfConfig();
SearchDOM searchDOM = SearchDOM.newInstance( true , true );
List<Element> cfConfigEntryList = searchDOM.findAllTags( cfConfig , "cf-config-entry" );
Expand Down Expand Up @@ -215,21 +217,6 @@ public static String getDriverInfo( ConnectionFactory cf ) throws DAOException {
});
}

/**
* Helper method to create a property with prefix
*
* @param prefix the prefix
* @param name the property base name
* @return the property full name ( prefix-name, or name if prefix == null)
*/
private static String getParamName( String prefix, String name ) {
String res = name;
if ( StringUtils.isNotEmpty( prefix ) ) {
res = prefix+"-"+name;
}
return res;
}

/**
* Creates a ConnectionFactory from a property object
*
Expand All @@ -256,25 +243,24 @@ public static ConnectionFactory newInstance( Properties props, String propsPrefi
}
ConnectionFactory cf = null;
String prefix = props.getProperty( PROP_CF_MODE_DC_PREFIX, propsPrefix );
String mode = props.getProperty( getParamName( prefix, PROP_CF_MODE ) );
Properties prefixProps = props;
if ( StringUtils.isNotEmpty( prefix ) ) {
prefixProps = PropsIO.subProps( props , prefix+"-" );
log.info( "subProps : {} -> {}", prefix, prefixProps );
}
String mode = prefixProps.getProperty( PROP_CF_MODE );
log.info( "ConnectionFactory.newInstance() mode : {}", mode );
if ( PROP_CF_MODE_DC.equalsIgnoreCase( mode ) ) {
if ( "true".equalsIgnoreCase( props.getProperty( getParamName( prefix, PROP_CF_EXT_POOLED ) ) ) ) {
int sc = Integer.parseInt( props.getProperty( getParamName( prefix, PROP_CF_EXT_POOLED_SC ), "3" ) );
int ic = Integer.parseInt( props.getProperty( getParamName( prefix, PROP_CF_EXT_POOLED_IC ), "10" ) );
int mc = Integer.parseInt( props.getProperty( getParamName( prefix, PROP_CF_EXT_POOLED_MC ), "30" ) );
cf = new DbcpConnectionFactory( props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_DRV ) ),
props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_URL ) ),
props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_USR ) ),
props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_PWD ) ), sc, ic, mc, cl );
if ( BooleanUtils.isTrue( prefixProps.getProperty(PROP_CF_EXT_POOLED ) ) ) {
cf = new DbcpConnectionFactory(prefixProps, cl);
} else {
cf = newInstance( props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_DRV ) ),
props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_URL ) ),
props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_USR ) ),
props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_PWD ) ), cl );
cf = newInstance( prefixProps.getProperty( PROP_CF_MODE_DC_DRV ),
prefixProps.getProperty(PROP_CF_MODE_DC_URL ),
prefixProps.getProperty(PROP_CF_MODE_DC_USR ),
prefixProps.getProperty(PROP_CF_MODE_DC_PWD ), cl );
}
} else if ( PROP_CF_MODE_DS.equalsIgnoreCase( mode ) || PROP_CF_MODE_DS2.equalsIgnoreCase( mode ) ) {
String dsName = props.getProperty( PROP_CF_MODE_DS_NAME );
String dsName = prefixProps.getProperty( PROP_CF_MODE_DS_NAME );
log.info( "dsName -> {}", dsName );
cf = newInstance( dsName );
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package org.fugerit.java.core.db.connect;

import java.sql.Connection;
import java.util.Properties;

import org.apache.commons.dbcp2.BasicDataSource;
import org.fugerit.java.core.db.dao.DAOException;
Expand All @@ -36,41 +37,30 @@ public class DbcpConnectionFactory extends ConnectionFactoryImpl {
private BasicDataSource dataSource;

/**
* Constructor
*
* @param drv driver type
* @param url jdbc url
* @param usr user
* @param pwd password
* @param init initial connection
* @param min minimum connection
* @param max maximum connection
* @throws DAOException in case of issues
* @param cfProps connections parameters
* @throws DAOException in case of issues
*/
public DbcpConnectionFactory( String drv, String url, String usr, String pwd, int init, int min, int max ) throws DAOException {
this(drv, url, usr, pwd, init, min, max, null);
public DbcpConnectionFactory( Properties cfProps ) throws DAOException {
this(cfProps, null);
}

/**
* Constructor
*
* @param drv driver type
* @param url jdbc url
* @param usr user
* @param pwd password
* @param init initial connection
* @param min minimum connection
* @param max maximum connection
* @param cl the class loader
* @throws DAOException in case of issues
* @param cfProps connections parameters
* @param cl to use for driver class loading
* @throws DAOException in case of issues
*/
public DbcpConnectionFactory( String drv, String url, String usr, String pwd, int init, int min, int max, ClassLoader cl ) throws DAOException {
public DbcpConnectionFactory( Properties cfProps, ClassLoader cl ) throws DAOException {
DAOException.apply( () -> {
int init = Integer.parseInt( cfProps.getProperty( PROP_CF_EXT_POOLED_SC , "3" ) );
int min = Integer.parseInt( cfProps.getProperty( PROP_CF_EXT_POOLED_IC , "10" ) );
int max = Integer.parseInt( cfProps.getProperty( PROP_CF_EXT_POOLED_MC , "30" ) );
this.dataSource = new BasicDataSource();
this.dataSource.setDriverClassName( drv );
this.dataSource.setUrl( url );
this.dataSource.setUsername( usr );
this.dataSource.setPassword( pwd );
this.dataSource.setDriverClassName( cfProps.getProperty( PROP_CF_MODE_DC_DRV ) );
this.dataSource.setUrl( cfProps.getProperty( PROP_CF_MODE_DC_URL ) );
this.dataSource.setUsername( cfProps.getProperty( PROP_CF_MODE_DC_USR ) );
this.dataSource.setPassword( cfProps.getProperty( PROP_CF_MODE_DC_PWD ) );
this.dataSource.setMaxTotal( max );
this.dataSource.setMaxIdle( min );
this.dataSource.setInitialSize( init );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ private boolean worker( ConnectionFactory wrapped ) throws Exception {
try ( ConnectionFactoryCloseable cf = ConnectionFactoryImpl.wrap( wrapped );
Connection conn = cf.getConnection() ) {
log.info( "db info : {}", cf.getDataBaseInfo() );
log.info( "db info second time : {}", cf.getDataBaseInfo() );
log.info( "driver info : {}", ConnectionFactoryImpl.getDriverInfo( cf ) );
}
ok = (wrapped != null);
Expand All @@ -50,15 +51,15 @@ private boolean worker( ConnectionFactory wrapped ) throws Exception {
public void testCFProps() throws Exception {
String name = "wrapped";
Properties props= PropsIO.loadFromClassLoaderSafe( BasicDBHelper.DEFAULT_DB_CONN_PATH );
props.setProperty( ConnectionFactoryImpl.PROP_CF_EXT_POOLED_IC , "1" );
props.setProperty( ConnectionFactoryImpl.PROP_CF_EXT_POOLED_SC , "1" );
props.setProperty( ConnectionFactoryImpl.PROP_CF_EXT_POOLED_MC , "3" );
ConnectionFactory wrapped = ConnectionFactoryImpl.newInstance( props );
ConnectionFacade.registerFactory( name , wrapped );
boolean ok = this.worker( ConnectionFacade.getFactory( name ) );
Assert.assertTrue(ok);
// pooled
ok = this.worker( new DbcpConnectionFactory( props.getProperty( ConnectionFactoryImpl.PROP_CF_MODE_DC_DRV ),
props.getProperty( ConnectionFactoryImpl.PROP_CF_MODE_DC_URL ),
props.getProperty( ConnectionFactoryImpl.PROP_CF_MODE_DC_USR ),
props.getProperty( ConnectionFactoryImpl.PROP_CF_MODE_DC_PWD ), 1, 1, 3 ) );
ok = this.worker( new DbcpConnectionFactory( props ) );
Assert.assertTrue(ok);
}

Expand Down

0 comments on commit f6e804f

Please sign in to comment.