Re: generate enum from db at runtime

Thomas Fox <[email protected]> Wed, 8 Oct 2014 14:36:12 +0200 (CEST)
Newsgroups gmane.comp.jakarta.turbine.torque.user
Message-ID <[email protected]>
Hi Youngho,

currently it is not possible to generate enums. This would be an interestin=
g 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 whi=
ch take and return strings and on top of that hand-written methods which ta=
ke and return the enum. It looks something like:

in the schema:
<column name=3D"role" type=3D"VARCHAR" javaName=3D"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=C3=BCngliche Mail -----
Von: "Youngho Cho" <[email protected]>
An: "Thomas Fox" <[email protected]>, "Apache Torque Users List" <to=
[email protected]>
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/f=
ulcrum-turbine-schema.xml?revision=3D1575232&view=3Dmarkup

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: [email protected]
For additional commands, e-mail: [email protected]