diff --git a/CHANGELOG.md b/CHANGELOG.md index ab66e4e9..3ff2b791 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/fj-core-jvfs/pom.xml b/fj-core-jvfs/pom.xml index e930288e..724a7fd5 100644 --- a/fj-core-jvfs/pom.xml +++ b/fj-core-jvfs/pom.xml @@ -30,7 +30,7 @@ - 1.1.9 + 1.2.1 ${project.basedir} target/generated-sources/daogen diff --git a/fj-core/src/main/java/org/fugerit/java/core/db/connect/ConnectionFactoryImpl.java b/fj-core/src/main/java/org/fugerit/java/core/db/connect/ConnectionFactoryImpl.java index 0941f675..ce68b94e 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/db/connect/ConnectionFactoryImpl.java +++ b/fj-core/src/main/java/org/fugerit/java/core/db/connect/ConnectionFactoryImpl.java @@ -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; @@ -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 cfConfigEntryList = searchDOM.findAllTags( cfConfig , "cf-config-entry" ); @@ -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 * @@ -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 { diff --git a/fj-core/src/main/java/org/fugerit/java/core/db/connect/DbcpConnectionFactory.java b/fj-core/src/main/java/org/fugerit/java/core/db/connect/DbcpConnectionFactory.java index 6e11b75b..9f91c2a6 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/db/connect/DbcpConnectionFactory.java +++ b/fj-core/src/main/java/org/fugerit/java/core/db/connect/DbcpConnectionFactory.java @@ -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; @@ -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 ); diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/db/connect/TestConnectionFactory.java b/fj-core/src/test/java/test/org/fugerit/java/core/db/connect/TestConnectionFactory.java index fa73f81f..16265ddf 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/db/connect/TestConnectionFactory.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/db/connect/TestConnectionFactory.java @@ -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); @@ -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); }