22
33import static dev .sassine .api .structure .export .builder .function .ImportBeanFunction .importJavaTime ;
44import static dev .sassine .api .structure .export .builder .function .StoreClassFuncation .store ;
5+ import static dev .sassine .api .structure .type .TypeConverter .TYPE_LOCAL_DATE ;
6+ import static dev .sassine .api .structure .type .TypeConverter .TYPE_LOCAL_DATE_TIME ;
7+ import static dev .sassine .api .structure .type .TypeConverter .TYPE_LOCAL_TIME ;
58import static java .lang .String .format ;
69import static java .lang .reflect .Modifier .PRIVATE ;
710import static java .lang .reflect .Modifier .PUBLIC ;
11+ import static java .util .Objects .nonNull ;
812import static java .util .Optional .ofNullable ;
913import static org .apache .commons .lang3 .StringUtils .isNotBlank ;
1014import static org .apache .logging .log4j .LogManager .getLogger ;
1115
16+ import java .util .Map ;
17+
1218import javax .persistence .Column ;
1319import javax .persistence .Entity ;
1420import javax .persistence .GeneratedValue ;
@@ -42,6 +48,11 @@ public class EntityFactory implements Factory {
4248 private static final String PARAM_NULLABLE = "nullable" ;
4349 private static final String PARAM_NAME = "name" ;
4450
51+ Map <String , String > defaultValueLocal = Map .of (
52+ TYPE_LOCAL_DATE , "LocalDate.now()" ,
53+ TYPE_LOCAL_TIME , "LocalTime.now()" ,
54+ TYPE_LOCAL_DATE_TIME , "LocalDateTime.now()" );
55+
4556 @ Override
4657 public void execute (EntityModel entityModel , boolean isAutoGenerated , String nameClass , String packageName ) {
4758 log .debug ("ClassName: ({}) - PackageName: ({}) " , nameClass , packageName );
@@ -66,6 +77,8 @@ public void execute(EntityModel entityModel, boolean isAutoGenerated, String nam
6677
6778 private void setDefaultValue (VariableSourceGenerator field , FieldModel fieldModel ) {
6879 if (isNotBlank (fieldModel .getDefaultValue ())) {
80+ var value = defaultValueLocal .get (fieldModel .getType ());
81+ if (nonNull (value )) field .setValue (defaultValueLocal .get (fieldModel .getType ()));
6982 field .addAnnotation (AnnotationSourceGenerator .create (ColumnDefault .class ).addParameter ("value" ,
7083 VariableSourceGenerator .create (format (FORMAT_STRING_FIELDS , fieldModel .getDefaultValue ()))));
7184 }
0 commit comments