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.
10 package eu
.etaxonomy
.cdm
.hibernate
;
12 import java
.io
.Serializable
;
13 import java
.sql
.PreparedStatement
;
14 import java
.sql
.ResultSet
;
15 import java
.sql
.SQLException
;
16 import java
.sql
.Types
;
17 import java
.util
.UUID
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.hibernate
.HibernateException
;
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
;
31 public class UUIDUserType
extends AbstractUserType
implements UserType
{
32 static final long serialVersionUID
= -3959049831344758708L;
34 @SuppressWarnings("unused")
35 private static final Logger logger
= Logger
.getLogger(UUIDUserType
.class);
37 private static final int[] SQL_TYPES
= { Types
.VARCHAR
};
40 * @see org.hibernate.usertype.UserType#deepCopy(java.lang.Object)
42 public Object
deepCopy(Object o
) throws HibernateException
{
50 return UUID
.fromString(uuid
.toString());
51 } catch (IllegalArgumentException e
) {
52 throw new HibernateException(e
);
57 * @see org.hibernate.usertype.UserType#disassemble(java.lang.Object)
59 public Serializable
disassemble(Object value
) throws HibernateException
{
63 UUID uuid
= (UUID
) value
;
64 return uuid
.toString();
69 public UUID
nullSafeGet(ResultSet rs
, String
[] names
, SessionImplementor session
, Object owner
)
70 throws HibernateException
, SQLException
{
71 String val
= (String
) StandardBasicTypes
.STRING
.nullSafeGet(rs
, names
, session
, owner
);
78 return UUID
.fromString(val
);
79 } catch (IllegalArgumentException e
) {
80 throw new HibernateException(e
);
86 public void nullSafeSet(PreparedStatement statement
, Object value
, int index
, SessionImplementor session
)
87 throws HibernateException
, SQLException
{
89 // statement.setNull(index, Types.VARCHAR); old version
90 StandardBasicTypes
.STRING
.nullSafeSet(statement
, value
, index
, session
);
92 UUID uuid
= (UUID
)value
;
93 // statement.setString(index, uuid.toString()); //old version
94 StandardBasicTypes
.STRING
.nullSafeSet(statement
, uuid
.toString(), index
, session
);
100 * @see org.jadira.usertype.dateandtime.shared.spi.AbstractSingleColumnUserType#returnedClass()
103 public Class
returnedClass() {
108 public int[] sqlTypes() {