Skip to content

Commit e2e8616

Browse files
authored
Merge pull request #20 from fugerit-org/feature/issue_17_stream
1.3.0 rc.1
2 parents d23bbd0 + 5ad0d9f commit e2e8616

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+187
-317
lines changed

.github/workflows/codeql.yml

Lines changed: 0 additions & 76 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.3.0] - 2023-09-24
11+
1012
### Added
1113

1214
- Code of conduct badge and file
1315

1416
### Changed
1517

1618
- [Sonar cloud workflow merged in maven build](.github/workflows/deploy_maven_package.yml)
17-
- fj-bom version set to 1.4.4
18-
- fj-core version set to 8.3.8
19+
- fj-bom version set to 1.4.5
20+
- fj-core version set to 8.3.9
1921
- fj-doc version set to 3.0.9
22+
- Removed javax.ejb.Stateles annotation from default rest generator
23+
- Fixed typo on FactoryDefGenerator
24+
- Stream loadAll method added to FacadeDefGenerator and FacadeImplDataGenerator (#17)
25+
- Added loadById Optional to FacadeDefGenerator and FacadeImplDataGenerator (#17)
26+
- Sample stub for finder, facade and rest load classes regenerated.
27+
- column size attribute from short to int daogen-config-1-0.xsd
28+
- definition of mapToTable entity attribute daogen-config-1-0.xsd
29+
- code optimization
2030

2131
### Removed
2232

fj-daogen-base/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-daogen</artifactId>
10-
<version>1.3.0-SNAPSHOT</version>
10+
<version>1.3.0</version>
1111
</parent>
1212

1313
<name>fj-daogen-base</name>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public abstract class DaogenBasicGenerator extends SimpleJavaGenerator implement
3333

3434
protected static final String JD_THROWS = " * @throws ";
3535

36+
protected static final String CLOSE_AND_THROWS = " ) throws ";
37+
3638
protected static final String AT_OVERRIDE = "@Override";
3739

3840
protected static final String REAL_CLASS_COMMENT = TAB+"// [HELPER/IMPL MODEL] this class is a stub and can be modified as you see fit (it will not been overwritten)";
@@ -73,6 +75,8 @@ public abstract class DaogenBasicGenerator extends SimpleJavaGenerator implement
7375

7476
protected static final String PUBLIC_STATIC_SPACE_LIT = "public static ";
7577

78+
protected static final String IN_CASE_OF_ERRORS_LIT = "in case of errors";
79+
7680
@Override
7781
protected void customPartWorker( String startTag, String endTag, String indent ) throws IOException {
7882
if ( !this.isNoCustomComment() ) {

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

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.fugerit.java.daogen.base.gen;
22

33
import java.io.IOException;
4+
import java.util.Optional;
5+
import java.util.stream.Stream;
46

57
import org.fugerit.java.core.cfg.ConfigException;
68
import org.fugerit.java.core.lang.helpers.StringUtils;
@@ -54,6 +56,10 @@ public void init( DaogenCatalogConfig daogenConfig, DaogenCatalogEntity entity )
5456
this.setClassDaoException( DaogenClassConfigHelper.addImport( daogenConfig , DaogenClassConfigHelper.DAO_EXCEPTION_BASE, this.getImportList() ) );
5557
this.setClassBaseResult( DaogenClassConfigHelper.addImport( daogenConfig , DaogenClassConfigHelper.DAO_RESULT_BASE, this.getImportList() ) );
5658
this.getImportList().add( this.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL )+"."+this.getEntityModelName() );
59+
this.getImportList().add( Stream.class.getName() );
60+
if ( StringUtils.isNotEmpty( this.getCurrentEntity().getPrimaryKey() ) ) {
61+
this.getImportList().add( Optional.class.getName() );
62+
}
5763
}
5864
}
5965

@@ -65,19 +71,39 @@ private void methodByKey( GeneratorKeyHelper keyHelper, String methodName, Strin
6571
this.getWriter().println( keyHelper.getJavadocParams() );
6672
this.getWriter().println( TAB+" *" );
6773
this.getWriter().println( TAB+" * @return "+returnJavadoc );
68-
this.getWriter().println( TAB+JD_THROWS+this.getClassDaoException()+TAB_3+"in case of errors" );
74+
this.getWriter().println( TAB+JD_THROWS+this.getClassDaoException()+TAB_3+IN_CASE_OF_ERRORS_LIT );
6975
this.getWriter().println( TAB+" */" );
7076
this.getWriter().println( TAB+""+returnType+" "+methodName+"( "+this.getClassDaogenContext()+CONTEXT_LIT+keyHelper.getKeyParams()+" ) throws "+this.getClassDaoException()+";" );
7177
this.getWriter().println();
7278
}
7379

80+
private void loadAllCommentHelper( boolean stream ) {
81+
String addOn = "";
82+
if ( stream ) {
83+
addOn = " (as a stream)";
84+
}
85+
this.getWriter().println( TAB+"/**" );
86+
this.getWriter().println( TAB+" * Method to load all the items for entity : "+this.getEntityModelName()+addOn );
87+
this.getWriter().println( TAB+" *" );
88+
this.getWriter().println( TAB+PARAM_CONTEXT_LIT+TAB+"DAOContext" );
89+
this.getWriter().println( TAB+" * @param finder"+TAB+"the finder encapsulating search params" );
90+
this.getWriter().println( TAB+" *" );
91+
if ( stream ) {
92+
this.getWriter().println( TAB+" * @return stream on the result" );
93+
} else {
94+
this.getWriter().println( TAB+" * @return search result" );
95+
}
96+
this.getWriter().println( TAB+JD_THROWS+this.getClassDaoException()+TAB_3+IN_CASE_OF_ERRORS_LIT );
97+
this.getWriter().println( TAB+" */" );
98+
}
99+
74100
@Override
75101
public void generateDaogenBody() throws IOException {
76102
if ( this.isModeReal() ) {
77103
this.generateRealClass();
78104
} else {
79105
this.getWriter().println( TAB+"/*");
80-
this.getWriter().println( TAB+" * NOTE: It is advised to use a finder for incapsulating search params, except searches for primary key.");
106+
this.getWriter().println( TAB+" * NOTE: It is advised to use a finder for encapsulating search params, except searches for primary key.");
81107
this.getWriter().println( TAB+" */");
82108
this.getWriter().println();
83109
this.getWriter().println( TAB+"/**" );
@@ -86,24 +112,22 @@ public void generateDaogenBody() throws IOException {
86112
this.getWriter().println( TAB+PARAM_CONTEXT_LIT+TAB+"DAOContext" );
87113
this.getWriter().println( TAB+" *" );
88114
this.getWriter().println( TAB+" * @return search result" );
89-
this.getWriter().println( TAB+JD_THROWS+this.getClassDaoException()+TAB_3+"in case of errors" );
115+
this.getWriter().println( TAB+JD_THROWS+this.getClassDaoException()+TAB_3+IN_CASE_OF_ERRORS_LIT );
90116
this.getWriter().println( TAB+" */" );
91117
this.getWriter().println( TAB+""+this.getClassBaseResult()+"<"+this.getEntityModelName()+"> loadAll( "+this.getClassDaogenContext()+" context ) throws "+this.getClassDaoException()+";" );
92118
this.getWriter().println();
93-
this.getWriter().println( TAB+"/**" );
94-
this.getWriter().println( TAB+" * Method to load all the items for entity : "+this.getEntityModelName() );
95-
this.getWriter().println( TAB+" *" );
96-
this.getWriter().println( TAB+PARAM_CONTEXT_LIT+TAB+"DAOContext" );
97-
this.getWriter().println( TAB+" * @param finder"+TAB+"the finder incapsulating search params" );
98-
this.getWriter().println( TAB+" *" );
99-
this.getWriter().println( TAB+" * @return search result" );
100-
this.getWriter().println( TAB+JD_THROWS+this.getClassDaoException()+TAB_3+"in caso di errori" );
101-
this.getWriter().println( TAB+" */" );
119+
this.loadAllCommentHelper( false );
102120
this.getWriter().println( TAB+""+this.getClassBaseResult()+"<"+this.getEntityModelName()+"> loadAllByFinder( "+this.getClassDaogenContext()+CONTEXT_LIT+this.getEntityFinderName()+" finder ) throws "+this.getClassDaoException()+";" );
103121
this.getWriter().println();
122+
this.loadAllCommentHelper( true );
123+
this.getWriter().println( TAB+""+Stream.class.getSimpleName()+"<"+this.getEntityModelName()+"> loadAllByFinderStream( "+this.getClassDaogenContext()+CONTEXT_LIT+this.getEntityFinderName()+" finder ) throws "+this.getClassDaoException()+";" );
124+
this.getWriter().println();
104125
if ( StringUtils.isNotEmpty( this.getCurrentEntity().getPrimaryKey() ) ) {
105126
GeneratorKeyHelper primaryKeyHelper = new GeneratorKeyHelper( this.getDaogenConfig() , this.getCurrentEntity(), this.getCurrentEntity().getPrimaryKey() );
127+
// load by id
106128
methodByKey( primaryKeyHelper.setForLoadInterface(), METHOD_LOAD_BY_PK, this.getEntityModelName(), "The found object or <code>null</code>", "Load method by "+PRIMARY_KEY+FOR_ENTITY_LIT+this.getEntityModelName() );
129+
// load by id optional
130+
methodByKey( primaryKeyHelper.setForLoadInterface(), METHOD_LOAD_BY_PK+Optional.class.getSimpleName(), Optional.class.getSimpleName()+"<"+this.getEntityModelName()+">", "The found object or <code>null</code>", "Load method by "+PRIMARY_KEY+FOR_ENTITY_LIT+this.getEntityModelName() );
107131
if ( FacadeGeneratorUtils.isFacadeModeInsert( this.getCurrentEntity() ) ) {
108132
DaogenCustomCode.addCommentFacadeDef( "facade.def.create" , DaogenCustomCode.INDENT_1, this.getWriter(), this.getEntityModelName() );
109133
this.getWriter().println( TAB+""+this.getClassBaseResult()+"<"+this.getEntityModelName()+"> create( "+this.getClassDaogenContext()+CONTEXT_LIT+this.getEntityModelName()+" model ) throws "+this.getClassDaoException()+";" );

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.fugerit.java.daogen.base.gen;
22

33
import java.io.IOException;
4+
import java.util.Optional;
5+
import java.util.stream.Stream;
46

57
import org.fugerit.java.core.cfg.ConfigException;
68
import org.fugerit.java.core.javagen.GeneratorNameHelper;
@@ -56,6 +58,10 @@ private void initConfigHelperMode( DaogenCatalogConfig daogenConfig) {
5658
this.getImportList().add( this.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_FACADE_DEF )+"."+DaogenHelperGenerator.toHelperClassName( this.getEntityFacadeDefName() ) );
5759
this.setImplementsInterface( DaogenHelperGenerator.toHelperClassName( this.getEntityFacadeDefName() ) );
5860
}
61+
this.getImportList().add( Stream.class.getName() );
62+
if ( StringUtils.isNotEmpty( this.getCurrentEntity().getPrimaryKey() ) ) {
63+
this.getImportList().add( Optional.class.getName() );
64+
}
5965
this.setExtendsClass( this.getClassDataFacade()+LT_LIT+this.getEntityModelName()+">" );
6066
}
6167

@@ -179,6 +185,14 @@ private void generateHelperClassLoadAll( String defaultOrderBy ) {
179185
this.getWriter().println();
180186
}
181187

188+
private void generateHelperClassLoadAllStream() {
189+
this.getWriter().println( TAB+AT_OVERRIDE );
190+
this.getWriter().println( TAB+PUBLIC_LIT+Stream.class.getSimpleName()+LT_LIT+this.getEntityModelName()+"> loadAllByFinderStream( "+this.getClassDaogenContext()+CONTEXT_LIT+this.getEntityFinderName()+" finder ) throws DAOException {" );
191+
this.getWriter().println( TAB_2+"return this.loadAllByFinder( context, finder ).stream();" );
192+
this.getWriter().println( TAB+"}" );
193+
this.getWriter().println();
194+
}
195+
182196
private void generateHelperClassInsertColumnHandler( DaogenCatalogField colData, DaogenCatalogField colDataUpdate ) {
183197
if ( colData != null || colDataUpdate != null ) {
184198
this.getWriter().println( TAB_2+"java.sql.Timestamp currentTime = new java.sql.Timestamp( System.currentTimeMillis() );" );
@@ -231,7 +245,7 @@ private void generateHelperClassInsert( DaogenCatalogField colData, DaogenCatalo
231245
private void generateHelperClassLoadPk( GeneratorKeyHelper primaryKeyHelper ) {
232246
// load by primary key
233247
this.getWriter().println( TAB+AT_OVERRIDE );
234-
this.getWriter().println( TAB+PUBLIC_LIT+this.getEntityModelName()+" "+FacadeDefGenerator.METHOD_LOAD_BY_PK+"( "+this.getClassDaogenContext()+CONTEXT_LIT+primaryKeyHelper.setForLoadInterface().getKeyParams()+" ) throws "+this.getClassDaoException()+" {" );
248+
this.getWriter().println( TAB+PUBLIC_LIT+this.getEntityModelName()+" "+FacadeDefGenerator.METHOD_LOAD_BY_PK+"( "+this.getClassDaogenContext()+CONTEXT_LIT+primaryKeyHelper.setForLoadInterface().getKeyParams()+CLOSE_AND_THROWS+this.getClassDaoException()+" {" );
235249
this.getWriter().println( TAB_2+this.getEntityModelName()+" result = null;" );
236250
this.getWriter().println( TAB_2+this.getClassDaoHelper()+LT_LIT+this.getEntityModelName()+GT_LIT+DAO_HELPER_LIT+this.getClassDaoHelper()+CONTEXT_GEN_LIT );
237251
this.getWriter().println( TAB_2+"SelectHelper query = daoHelper.newSelectHelper( this.getQueryView(), this.getTableName() );" );
@@ -258,13 +272,18 @@ private void generateHelperClassLoadPk( GeneratorKeyHelper primaryKeyHelper ) {
258272
this.getWriter().println( TAB_2+RETURN_RESULT_LIT );
259273
this.getWriter().println( TAB+"}" );
260274
this.getWriter().println();
275+
// load by primary key optional
276+
this.getWriter().println( TAB+AT_OVERRIDE );
277+
this.getWriter().println( TAB+PUBLIC_LIT+Optional.class.getSimpleName()+"<"+this.getEntityModelName()+"> "+FacadeDefGenerator.METHOD_LOAD_BY_PK+"Optional( "+this.getClassDaogenContext()+CONTEXT_LIT+primaryKeyHelper.setForLoadInterface().getKeyParams()+CLOSE_AND_THROWS+this.getClassDaoException()+" {" );
278+
this.getWriter().println( TAB_2+"return "+Optional.class.getSimpleName()+".ofNullable( "+FacadeDefGenerator.METHOD_LOAD_BY_PK+"("+CONTEXT_LIT+primaryKeyHelper.getFieldNames()+") );" );
279+
this.getWriter().println( TAB+"}" );
280+
this.getWriter().println();
261281
}
262282

263283
private void generateHelperClassDelete(GeneratorKeyHelper primaryKeyHelper) {
264284
if ( FacadeGeneratorUtils.isFacadeModeDelete( this.getCurrentEntity() ) ) {
265285
// delete by primary key
266-
this.getWriter().println( TAB+AT_OVERRIDE );
267-
this.getWriter().println( TAB+PUBLIC_LIT+this.getEntityBaseResult()+" "+FacadeDefGenerator.METHOD_DELETE_BY_PK+"( "+this.getClassDaogenContext()+CONTEXT_LIT+primaryKeyHelper.setForLoadInterface().getKeyParams()+" ) throws "+this.getClassDaoException()+" {" );
286+
this.getWriter().println( TAB+AT_OVERRIDE ); this.getWriter().println( TAB+PUBLIC_LIT+this.getEntityBaseResult()+" "+FacadeDefGenerator.METHOD_DELETE_BY_PK+"( "+this.getClassDaogenContext()+CONTEXT_LIT+primaryKeyHelper.setForLoadInterface().getKeyParams()+CLOSE_AND_THROWS+this.getClassDaoException()+" {" );
268287
this.getWriter().println( TAB_2+this.getEntityBaseResult()+" result = new "+this.getClassBaseResult()+GENERIC_LIT );
269288
this.getWriter().println( TAB_2+this.getClassDaoHelper()+LT_LIT+this.getEntityModelName()+GT_LIT+DAO_HELPER_LIT+this.getClassDaoHelper()+CONTEXT_GEN_LIT );
270289
this.getWriter().println( TAB_2+"DeleteHelper query = daoHelper.newDeleteHelper( this.getTableName() );" );
@@ -317,6 +336,7 @@ private void generateHelperClass() {
317336
String sequenceName = this.generateHelperClassSetupAndSequenceName();
318337
String defaultOrderBy = this.generateHelperClassSetupAndDefaultOrderBy();
319338
this.generateHelperClassLoadAll(defaultOrderBy);
339+
this.generateHelperClassLoadAllStream();
320340
if ( StringUtils.isNotEmpty( this.getCurrentEntity().getPrimaryKey() ) ) {
321341
GeneratorKeyHelper primaryKeyHelper = new GeneratorKeyHelper( this.getDaogenConfig() , this.getCurrentEntity(), this.getCurrentEntity().getPrimaryKey() );
322342
DaogenCatalogField colData = null;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void generateDaogenBody() throws IOException {
5454
String facadeName = DaogenCatalogConstants.facadeDefName( current );
5555
String packageFacade = this.getDaogenConfig().getGeneralProp(DaogenCatalogConstants.GEN_PROP_PACKAGE_FACADE_DEF );
5656
this.getWriter().println( TAB+"/**" );
57-
this.getWriter().println( TAB+" * Facade incapsulating persistance for entity : "+current.getName() );
57+
this.getWriter().println( TAB+" * Facade encapsulating persistance for entity : "+current.getName() );
5858
this.getWriter().println( TAB+" *" );
5959
this.getWriter().println( TAB+" * @return"+TAB+"the facade" );
6060
this.getWriter().println( TAB+" * @throws "+this.getClassDaoException()+TAB+"in case of problems" );

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.Serializable;
44
import java.util.Set;
55
import java.util.TreeSet;
6+
import java.util.stream.Collectors;
67

78
import org.fugerit.java.core.javagen.GeneratorNameHelper;
89
import org.fugerit.java.core.lang.helpers.StringUtils;
@@ -42,6 +43,10 @@ public class GeneratorKeyHelper implements Serializable {
4243

4344
private Set<String> keyFields;
4445

46+
public String getFieldNames() {
47+
return StringUtils.concat( "," , this.keyFields.stream().map( GeneratorNameHelper::toPropertyName ).collect( Collectors.toList() ) );
48+
}
49+
4550
public GeneratorKeyHelper( DaogenCatalogConfig config, DaogenCatalogEntity entity, String key ) {
4651
this.config = config;
4752
this.entity = entity;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private void generateDaogenBodyStart() {
6060
// obj mapper impl
6161
this.getWriter().println( TAB+AT_OVERRIDE );
6262
this.getWriter().println( TAB+"public Map<String, Class<?>> newTypeMapper() throws SQLException {" );
63-
this.getWriter().println( TAB_2+"Map<String, Class<?>> map = new HashMap<String, Class<?>>();" );
63+
this.getWriter().println( TAB_2+"Map<String, Class<?>> map = new HashMap<>();" );
6464
this.getWriter().println( TAB_2+"map.put( SQL_TYPE_NAME, "+this.getEntityStructName()+".class );" );
6565
this.getWriter().println( TAB_2+"return map;" );
6666
this.getWriter().println( TAB+"}" );
@@ -146,9 +146,7 @@ private void generateDaogenBodyLob( boolean containsBlob, boolean containsClob,
146146
// wrapper helpers
147147
this.getWriter().println( TAB+PUBLIC_STATIC_SPACE_LIT+this.getEntityStructName()+" wrap( "+this.getEntityModelName()+" model, java.sql.Connection conn ) throws SQLException {" );
148148
this.getWriter().println( TAB_2+""+this.getEntityStructName()+" res = wrap( model );" );
149-
this.getWriter().println( TAB_2+"if ( res != null ) {" );
150149
this.getWriter().println( TAB_3+"res.setupLobs( conn );" );
151-
this.getWriter().println( TAB_2+"}" );
152150
this.getWriter().println( TAB_2+RETURN_RES_LIT );
153151
this.getWriter().println( TAB+"}" );
154152
this.getWriter().println();

0 commit comments

Comments
 (0)