Hello Thomas, Yes current column enums is enough I think. This cool feature is one of reason why I have to migrate 4.1 more quickly !.
Thanks, Youngho 2014-10-15 19:54 GMT+09:00 Thomas Fox <thomas....@seitenbau.com>: > Ok so the agreement is that colum enums should be supported but table enmus > should not. > > Thomas > > ________________________________ > Von: "Youngho Cho" <youngho1...@gmail.com> > An: "Thomas Fox" <thomas....@seitenbau.com> > Gesendet: Mittwoch, 15. Oktober 2014 12:18:33 > Betreff: Re: Fwd: generate enum from db at runtime > > > Hello Thomas > you are right ! > I don't need primary value in the enum. > I have.getByName Method in the manager. > So only NameValue is ABSOLUTELY right! > > Thanks. > > Youngho > > 2014. 10. 15. 오후 4:53에 "Thomas Fox" <thomas....@seitenbau.com>님이 작성: >> >> ----- Forwarded Mail ----- >> Von: "Thomas Fox" <thomas....@seitenbau.com> >> An: "Apache Torque Users List" <torque-user@db.apache.org> >> Gesendet: Mittwoch, 15. Oktober 2014 09:52:13 >> Betreff: Re: generate enum from db at runtime >> >> Hi Youngho, >> >> I am afraid my current draft does not allow TABLE enums (as you use), only >> COLUMN enums (which was my primary use case). >> I now see that your use case also makes sense, I did not think of it >> before. >> >> For your current ROLE table, do you need the ROLE_NAME in database? >> If not, you could still use the column enum solution for the id column. >> >> I need to think about whether it would be possible to make Tables enum. >> Perhaps something like this >> >> <table name="TURBINE_ROLE" idMethod="idbroker" isEnum="true"> >> <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER"> >> <enum-value value="1"/> >> <enum-value value="2"/> >> <enum-value value="3"/> >> </column> >> <column name="ROLE_NAME" required="true" size="99" type="VARCHAR" >> javaName="Name"> >> <enum-value value="Guest"/> >> <enum-value value="Member"/> >> <enum-value value="Owner"/> >> <column> >> <unique> >> <unique-column name="ROLE_NAME"/> >> </unique> >> </table> >> >> Obviously, there needs to be the same number of <enum-value> elements for >> each column for this to work. >> >> About primary keys: in most databases you can define primary key values >> although the database can determine it itself. >> So in your case It should be possible to fill the TURBINE_ROLE table by a >> manual SQL where you determine the id (and not the database). >> Besides: is there any reason you use idbroker? All currently supported >> databases have a native mechanism to create ids. >> >> Thomas >> >> ----- Ursprüngliche Mail ----- >> Von: "Youngho Cho" <youngho1...@gmail.com> >> An: "Thomas Fox" <thomas....@seitenbau.com> >> CC: "Apache Torque Users List" <torque-user@db.apache.org> >> Gesendet: Mittwoch, 15. Oktober 2014 09:25:25 >> Betreff: Re: generate enum from db at runtime >> >> Hello Thomas, >> >> Ah now I understand your previous message regarding reverse engineering. >> >> The primary key information is allocated by the inserting the role >> therefore torque generator has no way to know the primary key value >> when it generate the enum >> >> Umm.. >> >> But we can set the primary key value in the schema enum-value, don't you ? >> >> also the description value is also needed as you mentioned in the jira. >> >> >> Thanks, >> >> Youngho >> >> 2014-10-15 15:52 GMT+09:00 Youngho Cho <youngho1...@gmail.com>: >> > Hello Thomas, >> > >> > I generate enum with your working draft for TORQUE-331. >> > Looks very cool feature !. >> > >> > I would like to give to my enum usage with om object. >> > ( I am not sure how you use enum with om but please let me know you my >> > usage ) >> > >> > For the role table >> > >> > <table name="TURBINE_ROLE" idMethod="idbroker"> >> > <column name="ROLE_ID" required="true" primaryKey="true" >> > type="INTEGER"/> >> > <column name="ROLE_NAME" required="true" size="99" type="VARCHAR" >> > javaName="Name"/> >> > <unique> >> > <unique-column name="ROLE_NAME"/> >> > </unique> >> > </table> >> > >> > I made RoleEnum.java manually likes >> > ( enum members are existing column values in the database) >> > >> > public enum RoleEnum >> > { >> > Guest(1, "Guest"), >> > Member(2, "Member"), >> > Owner(3, "Owner"); >> > >> > private Integer id; >> > private String name; >> > >> > private RoleEnum(final Integer id, final String name) >> > { >> > this.id = id; >> > this.name = name; >> > } >> > >> > public Integer getId() >> > { >> > return this.id; >> > } >> > >> > public String getName() >> > { >> > return this.name; >> > } >> > >> > public TurbineRole getInstance() >> > throws TorqueException >> > { >> > return TurbineRoleManager.getInstance(getId()); >> > } >> > >> > public boolean represent(TurbineRole role) >> > { >> > return this.id.equals(role.getRoleId()); >> > } >> > >> > public static Set<RoleEnum> getAllEnum() >> > { >> > return EnumSet.allOf(RoleEnum.class); >> > } >> > } >> > >> > ---------------------------------------- >> > And add method in TurbineRole.java >> > >> > public RoleEnum getEnum() >> > { >> > return RoleEnum.valueOf(getName()); >> > } >> > >> > >> > ---------------------------------------------------------------- >> > At the java code or template I use >> > >> > Role role = RoleEnum.valueOf(cond.getValue()).getInstance(); >> > .... >> > >> > or >> > >> > if(RoleEnum.Guest.represent(role)){ >> > .... >> > } >> > >> > .. >> > >> > using custom template, we can add custom method for their usage. >> > But for the the enum private fields, I hope that >> > we need unique name and their primary key value also I think. >> > >> > Thanks, >> > >> > Youngho >> > >> > >> > 2014-10-10 16:49 GMT+09:00 Thomas Fox <thomas....@seitenbau.com>: >> >> Hi Youngo >> >> >> >> Torque is built on the idea that the database schema is static, i.e. >> >> does not change at runtime, and that the database structure is defined in >> >> the schema file, not in the database. >> >> There is some benefit in reverse-engineering from the database, however >> >> it is also a very difficult and large field. The "Torque main path" is to >> >> define the structure in the schema xml file and then re-run the generator, >> >> not to change the database and re-engineer it. >> >> Therefore, to support enums, I have created a ticket in Jira >> >> https://issues.apache.org/jira/browse/TORQUE-331, which supports enum >> >> definition in the schema.xml. I'm currently working on it, because I have >> >> also missed the enum feature. >> >> >> >> To elaborate the reverse engineering from the database: The generator >> >> can generate a schema file from the database, but it is not in the core >> >> focus of the Torque team and only works for very coarse features. See >> >> http://db.apache.org/torque/torque-4.0/documentation/orm-reference/running-the-generator.html#Generation_of_XML_schema_from_an_existing_database. >> >> However, if you'd like to improve it, please go ahead. >> >> >> >> Thomas >> >> >> >> ----- Ursprüngliche Mail ----- >> >> Von: "Youngho Cho" <youngho1...@gmail.com> >> >> An: "Thomas Fox" <thomas....@seitenbau.com> >> >> CC: "Apache Torque Users List" <torque-user@db.apache.org> >> >> Gesendet: Donnerstag, 9. Oktober 2014 09:06:17 >> >> Betreff: Re: generate enum from db at runtime >> >> >> >> Hello Thomas, >> >> >> >> I think "generated at runtime" was a little exaggerated expression >> >> because of my lack of english expression. >> >> >> >> It means that >> >> If ROLE table changed by adding a new role such as 'Owner' Role, >> >> than some task run torque generator to generate new RoleEnum class >> >> which is include the Owner. >> >> >> >> If torque has an ability to read database and generate corresponding >> >> enum, I think it is very useful feature. >> >> ( It is very cumbersome work to add/remove by hand whenever some kind >> >> of type table changed) >> >> >> >> And your eum with om usage tip is very helpful to me. >> >> Thanks a lot. >> >> >> >> Thanks, >> >> >> >> Youngho >> >> >> >> >> >> 2014-10-08 21:36 GMT+09:00 Thomas Fox <thomas....@seitenbau.com>: >> >>> Hi Youngho, >> >>> >> >>> currently it is not possible to generate enums. This would be an >> >>> interesting feature in my opinion. >> >>> It needs to be seen whether this requires a schema change. >> >>> >> >>> I'm not sure what you mean by "generated at runtime". >> >>> >> >>> What I currently do when I need an enum is to define "internal" >> >>> methods which take and return strings and on top of that hand-written >> >>> methods which take and return the enum. It looks something like: >> >>> >> >>> in the schema: >> >>> <column name="role" type="VARCHAR" javaName="roleInternal" /> >> >>> >> >>> in the data object (assuming Role is an enum): >> >>> public void setRole(Role role) >> >>> { >> >>> super.setRoleInternal(Role.toString()); >> >>> } >> >>> >> >>> public Role getRole() >> >>> { >> >>> return Role.valueOf(super.getRoleInternal()); >> >>> } >> >>> >> >>> // only for torque's internal use >> >>> @Deprecated >> >>> @Override >> >>> public String getRoleInternal() >> >>> { >> >>> return super.getRoleInternal(); >> >>> } >> >>> >> >>> // only for torque's internal use >> >>> @Deprecated >> >>> @Override >> >>> public void setRoleInternal(String role) >> >>> { >> >>> super.setRoleInternal(role); >> >>> } >> >>> >> >>> Thomas >> >>> >> >>> ----- Ursprüngliche Mail ----- >> >>> Von: "Youngho Cho" <youngho1...@gmail.com> >> >>> An: "Thomas Fox" <thomas....@seitenbau.com>, "Apache Torque Users >> >>> List" <torque-user@db.apache.org> >> >>> Gesendet: Mittwoch, 8. Oktober 2014 08:32:10 >> >>> Betreff: generate enum from db at runtime >> >>> >> >>> Hello Thomas, >> >>> >> >>> Can torque generate enum class from database ? >> >>> >> >>> For example, >> >>> >> >>> following turbine-fucrum-torque security model >> >>> >> >>> >> >>> http://svn.apache.org/viewvc/turbine/fulcrum/trunk/security/torque/schema/fulcrum-turbine-schema.xml?revision=1575232&view=markup >> >>> >> >>> has Role, Permission table. >> >>> >> >>> And It can be added during system running. >> >>> >> >>> When those table column added/removed, >> >>> I hope to running maven-plugin or ant target etc.. to generate >> >>> corresponding enum class. >> >>> >> >>> Is it possible senario ? >> >>> >> >>> >> >>> Thanks, >> >>> >> >>> Youngho >> >>> >> >>> --------------------------------------------------------------------- >> >>> To unsubscribe, e-mail: torque-user-unsubscr...@db.apache.org >> >>> For additional commands, e-mail: torque-user-h...@db.apache.org >> >>> >> >> >> >> --------------------------------------------------------------------- >> >> To unsubscribe, e-mail: torque-user-unsubscr...@db.apache.org >> >> For additional commands, e-mail: torque-user-h...@db.apache.org >> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: torque-user-unsubscr...@db.apache.org >> For additional commands, e-mail: torque-user-h...@db.apache.org >> > --------------------------------------------------------------------- To unsubscribe, e-mail: torque-user-unsubscr...@db.apache.org For additional commands, e-mail: torque-user-h...@db.apache.org