db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <fisc...@seitenbau.net>
Subject Re: Question on using enums.
Date Mon, 28 Nov 2005 09:27:17 GMT




Christian,

You are probably best off if you do that manually, I know no way to
implement that in Torque. Have you tried to create an "alter table" sql
script changing the varchar column to enum and run it after you create the
database ? I would guess that this does not matter to Torque as long as the
constraints are fulfilled.

    Thomas

"Christian Stamm" <stammi@Mathematik.Uni-Marburg.de> schrieb am 28.11.2005
08:14:35:

> Hi Ivor,
>
> Thanks dor your answer. As the java application is not the only programm
> accessing this database, I would prefer a constraint in the
databaselayer.
> If I don't find any other solution I'm considering just using integer or
> something, especially as the enumerations are ordered (0 to 5 / A to E).
> Is there a way to specify a valuerange for e.g. integer?
>
> mfg
> Christian
>
>
>
> Ivor Clarke wrote:
> > Christian,
> >
> > We've been mapping MySQL ENUMs to a CHAR with the length set to the
> > number of characters in your longest value.  So if you have the
> > following MySQL column definition:
> > Status enum('NEW','PROCESSED') NOT NULL default 'NEW'
> >
> > It would be represented in Torque as:
> > <column default="NEW" name="Status" required="true" size="9"
> > type="CHAR"/>
> >
> > You then of course also have to add some code in your Torque classes
> > to statically define the ENUM values and to enforce them in the
> > Torque layer.
> >
> > -Ivor
> >
> > On Nov 25, 2005, at 5:00 AM, Christian Stamm wrote:
> >
> >> Hi,
> >>
> >> thanks for the answer so far and sorry for the unprecise question.
> >> I'd like to know how the SQL ENUM type is implemented.
> >>
> >> http://dev.mysql.com/doc/refman/4.1/en/enum.html
> >>
> >> i.e. a column in a database table is allowed to have only n values.
> >> My problem is not so much on the java side, but rather how to
> >> express it
> >> in  project-schema.xml.
> >>
> >> mfg
> >> Christian
> >>
> >> Thomas Fischer wrote:
> >>>
> >>> Hi,
> >>>
> >>> Assuming you mean java.util.enumeration:
> >>> As far as I know, enumerations are just an older version of
> >>> java.util.iterator. You would not want to store the iterator in
> >>> the DB,
> >>> you
> >>> usually store the underlying collection. This is in most cases
> >>> modelled by
> >>> other tables referenced by a foreign key, which can be accessed in
> >>> Torque
> >>> via a list.
> >>> Should you need other collection types, they would have to be
> >>> hand-modelled
> >>> out of the list.
> >>>
> >>> Assuming you mean the new jdk 1.5 enum type:
> >>> Sorry, JDK 1.5 specific features are not supported yet. You would
> >>> have to
> >>> provide a custom mapper which maps the enum e.g. to an int. You would
> >>> probably do that best in a mapper class. Then, overload the getter
> >>> and
> >>> setter method in the DB object class to accept the enum type, and
> >>> map them
> >>> internally to the int value, which is then stored in the database.
> >>> Deprecate the original getters and setters to prevent the user
> >>> from using
> >>> them (I would guess throwing exceptions in the original methods is no
> >>> good,
> >>> as they are needed internally by Torque).
> >>>
> >>>       Thomas
> >>>
> >>>
> >>> "Christian Stamm" <stammi@Mathematik.Uni-Marburg.de> schrieb am
> >>> 24.11.2005
> >>> 21:24:13:
> >>>
> >>>> Hi,
> >>>>
> >>>> I didn't find any documentation on how to declare enumerations in
> >>>> project-schema.xml. If anyone could post example, that would be
> >>>> fine.
> >>>>
> >>>> Consider this as a noob question, so examples on usage would be also
> >>>> appreciated.
> >>>>
> >>>> thx
> >>>> Christian Stamm
> >>>>
> >>>> P.S.: After working a little with torque, I'm absolutely
> >>>> impressed. Nice
> >>>> work!
> >>>>
> >>>>
> >>>> --------------------------------------------------------------------
> >>>> -
> >>>> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> >>>> For additional commands, e-mail: torque-user-help@db.apache.org
> >>>>
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> >>> For additional commands, e-mail: torque-user-help@db.apache.org
> >>>
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> >> For additional commands, e-mail: torque-user-help@db.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>


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


Mime
View raw message