db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Fox (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (TORQUE-331) Make enum generation possible
Date Sun, 26 Oct 2014 03:17:34 GMT

    [ https://issues.apache.org/jira/browse/TORQUE-331?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14184375#comment-14184375

Thomas Fox commented on TORQUE-331:

For being able to use enum values in select like
Criteria criteria = new Criteria()
      .where(new ColumnImpl("table.column1"), EnumWithValueMethod.A)
      .and(EnumWithValueMethod.B, new ColumnImpl("table.column2"))
I tried to define the interface ValueHolder (see below) to check whether an argument is an
enum and needs to be converted to its inner value.
However, as generation also depends on the static method getByValue() which cannot be defined
in an interface,
and to let torque user be more free when defining custom enums, I did not commit the interface
Instead, now the SqlBuilder checks whether an argument is an enum, and if yes, it is required
that the enum has a parameterless getValue() method which is called to convert the enum into
a SQL value, see org.apache.torque.sql.whereclausebuilder.EnumValueBuilder.

P.S code for the ValueHolder interface:
 * An interface for an object that has an inner SQLvalue.
 * The value object can be retrieved using the getValue() method.
 * It is also required that there exists a static method
 * getByValue(T value), which returns a ValueHolder<T> object for
 * a specific value. The existence of this method cannot be enforced
 * by this interface but it is required nonetheless by Torque.
 * @param <T> the class of the internal value.
public interface ValueHolder<T>
     * Returns the SQL value represented by this instance.
     * @return the represented value, not null.
    T getValue();

    // Returns a ValueHolder<T> object for a specific value.
    // @param value the value to return the ValueHolder object for.
    // @return the ValueHolder object, only null if value was null.
    // static ValueHolder<T> getByValue(T value);

> Make enum generation possible
> -----------------------------
>                 Key: TORQUE-331
>                 URL: https://issues.apache.org/jira/browse/TORQUE-331
>             Project: Torque
>          Issue Type: New Feature
>          Components: Templates
>    Affects Versions: 4.0
>            Reporter: Thomas Fox
>            Assignee: Thomas Fox
>             Fix For: 4.1
> It should be possible to generate an enum for a value.
> In the schema, this would look like
> <column name="role" type="VARCHAR>
>   <enum-value value="Admin" />
>   <enum-value value="User" />
> </column>
> There should be an optional javaName Attribute for the enum-value element determining
the java name for the enum value.
> There should be an optional description Attribute for the enum-value element determining
the javadoc for the enum value.
> There should be an optional enumName Attribute for the column element determining the
type name for the enum. Its value can be either fully qualified or unqualified to create a
new enum.
> If there are enum-value elements present, the enum type should be generated, otherwise,
it is assumed to exist already and is not generated.
> The data object getters and setters signatures would then be
> public RoleEnum getRole();
> private void setRole(RoleEnum role);
> The generated enum like would look like
> public enum RoleEnum
> {
>   ADMIN("Admin"),
>   USER("User");
>   private String value;
>   private RoleEnum(String value) {...}
>   private Sting getValue() {...}
> }

This message was sent by Atlassian JIRA

To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org

View raw message