Ejemplo n.º 1
0
        public EntityClass(EntityConstraintsClass eConsts, string module)
        {
            EntityConstraints = eConsts;
            Name    = eConsts.TableName.ToPascalCase() + "Entity";
            Package = $@"havelsan.kovan.{module}.service.entity";

            BaseClass = PredefinedClasses.HvlEntity;

            Annotations.Add(Entity());

            Annotations.Add(Table()
                            .SetParameter("name", eConsts.TableNameRef)
                            .SetParameter("schema", eConsts.TableSchema)
                            .SetParameter("indexes", eConsts.UniqueConstraintsRef.Select(u =>
                                                                                         Index()
                                                                                         .SetParameter("name", u.Name)
                                                                                         .SetParameter("unique", true)
                                                                                         .SetParameter("columnList", u.ColumnList)).ToList()

                                          ));

            IfPresent(eConsts.TableSequenceRef, ts => Annotations.Add(HvlEntitySequence().SetParameter("name", ts)));

            ClassMembers.AddRange(eConsts.Table.Columns.Select(col =>
            {
                var cm = new ClassMember(col.Name.ToCamelCase(), col.Type.ToJavaType(), null, AccessModifier.Private);
                cm.Annotations.Add(Column().SetParameter("name", eConsts.GetColumnName(col)));
                cm.Annotations.AddIfTrue(!col.Nullable, NotNull());

                IfPresent(col.Size, size =>
                {
                    if (cm.Type.BaseClass == PredefinedClasses.JavaNumber)
                    {
                        var da = Digits();
                        size.Max.IfPresent(max => da.SetParameter("integer", eConsts.GetColumnSizeMax(col)));
                        size.Min.IfPresent(min => da.SetParameter("fraction", eConsts.GetColumnSizeMin(col)));
                        cm.Annotations.Add(da);
                    }
                    else
                    {
                        var sa = Size();
                        size.Min.IfPresent(min => sa.SetParameter("min", eConsts.GetColumnSizeMin(col)));
                        size.Max.IfPresent(max => sa.SetParameter("max", eConsts.GetColumnSizeMax(col)));
                        cm.Annotations.Add(sa);
                    }
                });
                return(cm);
            }));
        }
Ejemplo n.º 2
0
        public EntityConstraintsClass(Table table, string module)
        {
            Table              = table;
            Name               = Table.SafeName.ToPascalCase() + "Constraints";
            Package            = $@"havelsan.kovan.{module}.common.constraints";
            NonAccessModifiers = new List <NonAccessModifier> {
                NonAccessModifier.Abstract
            };

            ClassMembers.Add(CreatePublicStaticFinalString("TABLE_NAME", Table.Name));
            IfPresent(Table.Sequence, ts => CreatePublicStaticFinalString("SEQ_NAME", ts.Name));

            ClassMembers
            .AddRange(Table.Columns.Select(x => CreatePublicStaticFinalString($@"COLUMN_{x.Name}", x.Name)))
            .AddRange(Table.UniqueContraints.Select(x => CreatePublicStaticFinalString($@"{(x.Name.StartsWith("UX_") ? x.Name : "UX_" + x.Name)}", x.Name)))
            .AddRange(Table.Columns.Where(x => x.Size != null).SelectMany(x =>
            {
                var list = new List <ClassMember>();
                x.Size.Min.IfPresent(min => list.Add(CreatePublicStaticFinalInt($@"{x.Name}_SIZE_MIN", min)));
                x.Size.Max.IfPresent(max => list.Add(CreatePublicStaticFinalInt($@"{x.Name}_SIZE_MAX", max)));
                return(list);
            }));
        }