Skip to content

Commit 1c34825

Browse files
committed
Added daogen property : dao-finder-ng-mode
1 parent 4214746 commit 1c34825

File tree

16 files changed

+198
-49
lines changed

16 files changed

+198
-49
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
### Added
9+
10+
- daogen property : dao-finder-ng-mode ('dao.finder.ng' will be selected and no serialization)
11+
12+
### Changed
13+
14+
- fj-version set to 8.5.3
15+
816
## [1.7.3] - 2024-03-08
917

1018
### Added

fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/config/DaogenCatalogConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ private DaogenCatalogConstants() {}
8585
public static final String GEN_PROP_DAO_WRAPPER_NG_MODE_ENABLED = "enabled";
8686
public static final String GEN_PROP_DAO_WRAPPER_NG_MODE_DISABLED = "disabled";
8787

88+
public static final String GEN_PROP_DAO_FINDER_NG_MODE = "dao-finder-ng-mode";
89+
90+
public static final String GEN_PROP_DAO_FINDER_NG_MODE_ENABLED = "enabled";
91+
public static final String GEN_PROP_DAO_FINDER_NG_MODE_DISABLED = "disabled";
92+
8893
public static final String PREFIX_MODEL = "Model";
8994

9095
public static final String PREFIX_HELPER = "Helper";

fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/config/DaogenClassConfigHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ private DaogenClassConfigHelper() {}
2828

2929
public static final String DAO_WRAPPER_NG_BASE = "dao.wrapper.ng";
3030

31+
public static final String DAO_FINDER_NG_BASE = "dao.finder.ng";
32+
3133
public static final String DAO_DAOHELPER_BASE = "dao.daohelper";
3234
public static final String DAO_SELECTHELPER_BASE = "dao.selecthelper";
3335
public static final String DAO_DELETEHELPER_BASE = "dao.deletehelper";

fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/FinderGenerator.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.math.BigDecimal;
55

66
import org.fugerit.java.core.cfg.ConfigException;
7+
import org.fugerit.java.core.lang.helpers.StringUtils;
78
import org.fugerit.java.daogen.base.config.DaogenCatalogConfig;
89
import org.fugerit.java.daogen.base.config.DaogenCatalogConstants;
910
import org.fugerit.java.daogen.base.config.DaogenCatalogEntity;
@@ -30,21 +31,34 @@ public void init( DaogenCatalogConfig daogenConfig, DaogenCatalogEntity entity )
3031
fullObjectName( daogenConfig.getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_FACADE_DEF ), DaogenCatalogConstants.finderlName( entity ) ),
3132
STYLE_INTERFACE, daogenConfig, entity );
3233
this.setJavaStyle( STYLE_CLASS );
33-
DaogenCatalogField idField = entity.get( DaogenCatalogEntity.DEFAULT_ID_FIELD );
34+
String daoFinderNgMode = daogenConfig.getGeneralProp( DaogenCatalogConstants.GEN_PROP_DAO_FINDER_NG_MODE, DaogenCatalogConstants.GEN_PROP_DAO_FINDER_NG_MODE_DISABLED );
35+
logger.info( "{} -> {}", DaogenCatalogConstants.GEN_PROP_DAO_FINDER_NG_MODE, daoFinderNgMode );
3436
this.getImportList().add( this.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL )+"."+this.getEntityModelName() );
35-
if ( idField == null || this.getDaogenConfig().getTypeMapper().mapForModel( idField ).equalsIgnoreCase( BigDecimal.class.getName() ) ) {
36-
this.setClassBaseFinder( DaogenClassConfigHelper.addImport( daogenConfig , DaogenClassConfigHelper.DAO_BASEFINDER_BASE, this.getImportList() ) );
37-
this.setExtendsClass( this.getClassBaseFinder() );
37+
if ( DaogenCatalogConstants.GEN_PROP_DAO_FINDER_NG_MODE_DISABLED.equalsIgnoreCase( daoFinderNgMode ) ) {
38+
DaogenCatalogField idField = entity.get( DaogenCatalogEntity.DEFAULT_ID_FIELD );
39+
if ( idField == null || this.getDaogenConfig().getTypeMapper().mapForModel( idField ).equalsIgnoreCase( BigDecimal.class.getName() ) ) {
40+
this.setClassBaseFinder( DaogenClassConfigHelper.addImport( daogenConfig , DaogenClassConfigHelper.DAO_BASEFINDER_BASE, this.getImportList() ) );
41+
this.setExtendsClass( this.getClassBaseFinder() );
42+
} else {
43+
String type = this.getDaogenConfig().getTypeMapper().mapForModel( idField );
44+
this.setClassBaseFinder( DaogenClassConfigHelper.addImport( daogenConfig , DaogenClassConfigHelper.DAO_GENERICFINDER_BASE, this.getImportList() ) );
45+
this.setExtendsClass( this.getClassBaseFinder()+"<"+type+">" );
46+
}
47+
} else if ( DaogenCatalogConstants.GEN_PROP_DAO_FINDER_NG_MODE_ENABLED.equalsIgnoreCase( daoFinderNgMode ) ) {
48+
String finderNgClass = DaogenClassConfigHelper.findClassConfigProp( daogenConfig, DaogenClassConfigHelper.DAO_FINDER_NG_BASE, DaogenClassConfigHelper.DAO_BASE_CLASS );
49+
if ( StringUtils.isNotEmpty( finderNgClass ) ) {
50+
this.setClassBaseHelper( DaogenClassConfigHelper.addImport( daogenConfig , DaogenClassConfigHelper.DAO_FINDER_NG_BASE, this.getImportList() ) );
51+
this.setExtendsClass( this.getClassBaseHelper() );
52+
}
3853
} else {
39-
String type = this.getDaogenConfig().getTypeMapper().mapForModel( idField );
40-
this.setClassBaseFinder( DaogenClassConfigHelper.addImport( daogenConfig , DaogenClassConfigHelper.DAO_GENERICFINDER_BASE, this.getImportList() ) );
41-
this.setExtendsClass( this.getClassBaseFinder()+"<"+type+">" );
54+
throw new ConfigException( "Invalid "+DaogenCatalogConstants.GEN_PROP_DAO_FINDER_NG_MODE+" parameter : "+daoFinderNgMode );
4255
}
4356
}
4457

4558
@Override
4659
public void generateDaogenBody() throws IOException {
47-
this.addSerialVerUID();
60+
String daoFinderNgMode = this.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_DAO_FINDER_NG_MODE, DaogenCatalogConstants.GEN_PROP_DAO_FINDER_NG_MODE_DISABLED );
61+
this.generateSerial( DaogenCatalogConstants.GEN_PROP_DAO_FINDER_NG_MODE_DISABLED.equalsIgnoreCase( daoFinderNgMode ) );
4862
this.getWriter().println( TAB+"private "+this.getEntityModelName()+" model;" );
4963
this.getWriter().println();
5064
this.getWriter().println( TAB+"public void setModel( "+this.getEntityModelName()+" model ) {" );

fj-daogen-base/src/main/resources/config/daogen-config-1-0.xsd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ The entry point for daogen-config documentation is : https://marsdocs.fugerit.or
178178
<xsd:documentation>NOTE: when enabled, Wrapper entities will not be made serializable.</xsd:documentation>
179179
</xsd:annotation>
180180
</xsd:attribute>
181+
<xsd:attribute type="daogen:enabledDisabledType" name="dao-finder-ng-mode" use="optional" default="disabled">
182+
<xsd:annotation>
183+
<xsd:documentation>If set to 'enabled' the 'dao.finder.ng' property set will be selected.</xsd:documentation>
184+
<xsd:documentation>NOTE: when enabled, Finder entities will not be made serializable.</xsd:documentation>
185+
</xsd:annotation>
186+
</xsd:attribute>
181187
<xsd:attribute type="xsd:string" name="package-struct" use="optional">
182188
<xsd:annotation>
183189
<xsd:documentation>The package to be used for database java.sql.String classes, for each entity.</xsd:documentation>

fj-daogen-base/src/main/resources/config/daogen_default_class_config.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<entry key="dao.basefinder.class">BaseIdFinder</entry>
1616
<entry key="dao.genericfinder.package">org.fugerit.java.core.db.daogen</entry>
1717
<entry key="dao.genericfinder.class">GenericIdFinder</entry>
18+
<entry key="dao.finder.ng.package">org.fugerit.java.core.db.daogen</entry>
19+
<entry key="dao.finder.ng.class">IdFinderNG</entry>
1820
<!-- base result -->
1921
<entry key="dao.result.package">org.fugerit.java.core.db.daogen</entry>
2022
<entry key="dao.result.class">BasicDaoResult</entry>

fj-daogen-base/src/test/java/test/org/fugerit/java/daogen/base/config/TestDaogenRun.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ public void testDaoGenerationJdk17SpringBoot() throws IOException, ConfigExcepti
5151
Assert.assertEquals( Result.RESULT_CODE_OK, result );
5252
}
5353

54+
@Test
55+
public void testDaoGenerationClassicalEntity() throws IOException, ConfigException {
56+
File file = new File( "target/daogen-run-classical-entity" );
57+
Properties overrideProperties = new Properties();
58+
overrideProperties.setProperty(
59+
DaogenCatalogConstants.GEN_PROP_DAO_HELPER_NG_MODE ,
60+
DaogenCatalogConstants.GEN_PROP_DAO_HELPER_NG_MODE_DISABLED);
61+
overrideProperties.setProperty(
62+
DaogenCatalogConstants.GEN_PROP_DAO_WRAPPER_NG_MODE ,
63+
DaogenCatalogConstants.GEN_PROP_DAO_WRAPPER_NG_MODE_DISABLED );
64+
overrideProperties.setProperty(
65+
DaogenCatalogConstants.GEN_PROP_DAO_FINDER_NG_MODE ,
66+
DaogenCatalogConstants.GEN_PROP_DAO_FINDER_NG_MODE_DISABLED );
67+
int result = this.testDaoGenerationWorker(file, overrideProperties);
68+
Assert.assertTrue( file.exists() );
69+
Assert.assertEquals( Result.RESULT_CODE_OK, result );
70+
}
71+
5472
@Test
5573
public void testDaoGenerationFailHelperNg() throws IOException, ConfigException {
5674
File file = new File( "target/daogen-run-fail-helper-ng" );
@@ -71,6 +89,16 @@ public void testDaoGenerationFailWrapperNg() throws IOException, ConfigException
7189
Assert.assertEquals( Result.RESULT_CODE_KO, result );
7290
}
7391

92+
@Test
93+
public void testDaoGenerationFailFinderNg() throws IOException, ConfigException {
94+
File file = new File( "target/daogen-run-fail-finder-ng" );
95+
Properties overrideProperties = new Properties();
96+
overrideProperties.setProperty(
97+
DaogenCatalogConstants.GEN_PROP_DAO_FINDER_NG_MODE , "unknown" );
98+
int result = this.testDaoGenerationWorker(file, overrideProperties);
99+
Assert.assertEquals( Result.RESULT_CODE_KO, result );
100+
}
101+
74102
@Test
75103
public void testDaoGenerationDefault() throws IOException, ConfigException {
76104
File file = new File( "target/daogen-run" );

fj-daogen-base/src/test/resources/sample/daogenruntest-sample-daogen-config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package-helper="org.fugerit.java.daogen.sample.impl.helper"
2222
dao-helper-ng-mode="enabled"
2323
dao-wrapper-ng-mode="enabled"
24+
dao-finder-ng-mode="enabled"
2425
package-struct="org.fugerit.java.daogen.sample.impl.struct"
2526
package-rse="org.fugerit.java.daogen.sample.impl.rse"
2627
package-facade-def="org.fugerit.java.daogen.sample.def.facade"

fj-daogen-sample/src/main/java/org/fugerit/java/daogen/sample/def/facade/AddressFinder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ public class AddressFinder extends BaseIdFinder {
2222

2323
private static final long serialVersionUID = 991425775053L;
2424

25+
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
26+
// this class is conditionally serializable, depending on contained object
27+
// special situation can be handled using this method in future
28+
out.defaultWriteObject();
29+
}
30+
31+
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
32+
// this class is conditionally serializable, depending on contained object
33+
// special situation can be handled using this method in future
34+
in.defaultReadObject();
35+
}
36+
2537
private ModelAddress model;
2638

2739
public void setModel( ModelAddress model ) {

fj-daogen-sample/src/main/java/org/fugerit/java/daogen/sample/def/facade/LogDataFinder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ public class LogDataFinder extends BaseIdFinder {
2222

2323
private static final long serialVersionUID = 329810489228L;
2424

25+
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
26+
// this class is conditionally serializable, depending on contained object
27+
// special situation can be handled using this method in future
28+
out.defaultWriteObject();
29+
}
30+
31+
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
32+
// this class is conditionally serializable, depending on contained object
33+
// special situation can be handled using this method in future
34+
in.defaultReadObject();
35+
}
36+
2537
private ModelLogData model;
2638

2739
public void setModel( ModelLogData model ) {

0 commit comments

Comments
 (0)