[hibernate-commits] Hibernate SVN: r20022 - in core/trunk: documentation/manual/src/main/docbook/en-US/content and 1 other directory.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Fri Jul 23 13:00:21 EDT 2010
Author: steve.ebersole at jboss.com
Date: 2010-07-23 13:00:19 -0400 (Fri, 23 Jul 2010)
New Revision: 20022
Added:
core/trunk/core/src/main/java/org/hibernate/type/UrlType.java
Modified:
core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java
core/trunk/documentation/manual/src/main/docbook/en-US/content/type.xml
Log:
HHH-5283 - Add BasicType handling of java.net.URL
Modified: core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java 2010-07-23 16:42:36 UTC (rev 20021)
+++ core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java 2010-07-23 17:00:19 UTC (rev 20022)
@@ -63,6 +63,7 @@
register( BigIntegerType.INSTANCE );
register( StringType.INSTANCE );
+ register( UrlType.INSTANCE );
register( DateType.INSTANCE );
register( TimeType.INSTANCE );
Added: core/trunk/core/src/main/java/org/hibernate/type/UrlType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/UrlType.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/UrlType.java 2010-07-23 17:00:19 UTC (rev 20022)
@@ -0,0 +1,65 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.type;
+
+import java.net.URL;
+
+import org.hibernate.dialect.Dialect;
+import org.hibernate.type.descriptor.java.UrlTypeDescriptor;
+import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
+
+/**
+ * A type that maps between {@link java.sql.Types#VARCHAR VARCHAR} and {@link URL}
+ *
+ * @author Steve Ebersole
+ */
+public class UrlType extends AbstractSingleColumnStandardBasicType<URL> implements DiscriminatorType<URL> {
+ public static final UrlType INSTANCE = new UrlType();
+
+ public UrlType() {
+ super( VarcharTypeDescriptor.INSTANCE, UrlTypeDescriptor.INSTANCE );
+ }
+
+ public String getName() {
+ return "url";
+ }
+
+ @Override
+ protected boolean registerUnderJavaType() {
+ return true;
+ }
+
+ @Override
+ public String toString(URL value) {
+ return UrlTypeDescriptor.INSTANCE.toString( value );
+ }
+
+ public String objectToSQLString(URL value, Dialect dialect) throws Exception {
+ return StringType.INSTANCE.objectToSQLString( toString( value ), dialect );
+ }
+
+ public URL stringToObject(String xml) throws Exception {
+ return UrlTypeDescriptor.INSTANCE.fromString( xml );
+ }
+}
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/type.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/type.xml 2010-07-23 16:42:36 UTC (rev 20021)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/type.xml 2010-07-23 17:00:19 UTC (rev 20022)
@@ -452,6 +452,23 @@
</varlistentry>
</variablelist>
</section>
+ <section id="types-basic-value-url">
+ <title><classname>java.net.URL</classname></title>
+ <variablelist>
+ <varlistentry>
+ <term><classname>org.hibernate.type.UrlType</classname></term>
+ <listitem>
+ <para>
+ Maps a <classname>java.net.URL</classname> to a JDBC VARCHAR (using the external form)
+ </para>
+ <para>
+ Registered under <literal>url</literal> and <literal>java.net.URL</literal> in the
+ type registry (see <xref linkend="types-registry"/>).
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
<section id="types-basic-value-class">
<title><classname>java.lang.Class</classname></title>
<variablelist>
More information about the hibernate-commits
mailing list