revised usertype sect

git-svn-id: https://svn.jboss.org/repos/hibernate/trunk/Hibernate3/doc@5577 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Gavin King 2005-02-06 04:37:14 +00:00
parent fab3331333
commit e3bfdf4ec6
1 changed files with 29 additions and 24 deletions

View File

@ -2622,36 +2622,45 @@
Notice the use of <literal>&lt;column&gt;</literal> tags to map a property to multiple
columns.
</para>
<para>
You may also supply parameters to a UserType in the mapping file. To do this, your UserType
has to implement the <literal>org.hibernate.usertype.ParameterizedType</literal> interface.
To supply parameters to your UserType, you can use the <literal>&lt;type&gt;</literal> element
in your mapping files.
The <literal>CompositeUserType</literal>, <literal>EnhancedUserType</literal>,
and <literal>UserCollectionType</literal> and <literal>UserVersionType</literal>
interfaces provide support for more specialized uses.
</para>
<programlisting><![CDATA[<property name="primitiveWithNullValues" column="INT_COLUMN">
<type name="org.hibernate.test.typeparameters.NullMappingType">
<param name="default">1</param>
<para>
You may even supply parameters to a <literal>UserType</literal> in the mapping file. To
do this, your <literal>UserType</literal> must implement the
<literal>org.hibernate.usertype.ParameterizedType</literal> interface. To supply parameters
to your custom type, you can use the <literal>&lt;type&gt;</literal> element in your mapping
files.
</para>
<programlisting><![CDATA[<property name="priority">
<type name="com.mycompany.usertypes.DefaultValueIntegerType">
<param name="default">0</param>
</type>
</property>]]></programlisting>
<para>
The UserType can now retrieve the value for the parameter named <literal>default</literal>
from the Properties object passed to it.
The <literal>UserType</literal> can now retrieve the value for the parameter named
<literal>default</literal> from the <literal>Properties</literal> object passed to it.
</para>
<para>
If you use a certain UserType very often, it may be useful to define a shorter name for it.
You can do this using the <literal>&lt;typedef&gt;</literal> element in your mapping files.
Typedefs contain a UserType and a defined name for it, and may also contain a list of default
paramter values if the type defined implements <literal>ParameterizedType</literal>. After
defining the name, it can be used everywhere the original classname can be used.
If you use a certain <literal>UserType</literal> very often, it may be useful to define a
shorter name for it. You can do this using the <literal>&lt;typedef&gt;</literal> element.
Typedefs assign a name to a custom type, and may also contain a list of default
parameter values if the type is parameterized.
</para>
<programlisting><![CDATA[<typedef class="org.hibernate.test.typeparameters.NullMappingType" name="nullMapper">
<param name="default">2</param>
</typedef>
<programlisting><![CDATA[<typedef class="com.mycompany.usertypes.DefaultValueIntegerType" name="default_zero">
<param name="default">0</param>
</typedef>]]></programlisting>
<programlisting><![CDATA[<property name="priority" type="default_zero"/>]]></programlisting>
<property name="primitiveWithNullValues" column="INT_COLUMN">
<type name="nullMapper"/>
</property>]]></programlisting>
<para>
It is also possible to override the parameters supplied in a typedef on a case-by-case basis
by using type parameters on the property mapping.
@ -2669,10 +2678,6 @@
</para>
</sect2>
<para>
TODO: document parameterizable usertypes
</para>
</sect1>