11package org .fugerit .java .daogen .base .gen ;
22
33import java .io .IOException ;
4+ import java .util .Optional ;
5+ import java .util .stream .Stream ;
46
57import org .fugerit .java .core .cfg .ConfigException ;
68import 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 ()+";" );
0 commit comments