2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.hibernate
;
13 import java
.net
.URISyntaxException
;
14 import java
.sql
.PreparedStatement
;
15 import java
.sql
.ResultSet
;
16 import java
.sql
.SQLException
;
17 import java
.sql
.Types
;
19 import org
.hibernate
.HibernateException
;
20 import org
.hibernate
.TypeMismatchException
;
21 import org
.hibernate
.engine
.spi
.SessionImplementor
;
22 import org
.hibernate
.type
.StandardBasicTypes
;
23 import org
.hibernate
.usertype
.UserType
;
24 import org
.jadira
.usertype
.dateandtime
.shared
.spi
.AbstractUserType
;
27 * This class maps java.net.URI to varchar(255)
31 public class URIUserType
extends AbstractUserType
implements UserType
{
32 private static final long serialVersionUID
= -5825017496962569105L;
35 * SQL type for this usertype.
37 private static final int[] SQL_TYPES
= {Types
.CLOB
};
40 * @see org.jadira.usertype.dateandtime.shared.spi.AbstractSingleColumnUserType#returnedClass()
43 public Class
returnedClass() {
48 public int[] sqlTypes() {
54 public URI
nullSafeGet(ResultSet rs
, String
[] names
, SessionImplementor session
, Object owner
)
55 throws HibernateException
, SQLException
{
56 String val
= (String
) StandardBasicTypes
.STRING
.nullSafeGet(rs
, names
, session
, owner
);
63 } catch (URISyntaxException e
) {
64 throw new TypeMismatchException(e
);
72 public void nullSafeSet(PreparedStatement statement
, Object value
, int index
, SessionImplementor session
)
73 throws HibernateException
, SQLException
{
75 StandardBasicTypes
.STRING
.nullSafeSet(statement
, value
, index
, session
);
77 URI uri
= (URI
) value
;
78 StandardBasicTypes
.STRING
.nullSafeSet(statement
, uri
.toString(), index
, session
);
83 * @param value value being copied
84 * @return copied value
86 public Object
deepCopy(Object value
) {
91 return new URI(((URI
) value
).toString());
92 } catch (URISyntaxException e
) {
93 throw new TypeMismatchException(e
);