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
.AbstractSingleColumnUserType
;
25 import org
.jadira
.usertype
.dateandtime
.shared
.spi
.AbstractUserType
;
26 import org
.jadira
.usertype
.dateandtime
.shared
.spi
.ColumnMapper
;
33 public class UUIDUserType
extends AbstractUserType
implements UserType
{
34 static final long serialVersionUID
= -3959049831344758708L;
36 @SuppressWarnings("unused")
37 private static final Logger logger
= Logger
.getLogger(UUIDUserType
.class);
39 private static final int[] SQL_TYPES
= { Types
.VARCHAR
};
42 * @see org.hibernate.usertype.UserType#deepCopy(java.lang.Object)
44 public Object
deepCopy(Object o
) throws HibernateException
{
52 return UUID
.fromString(uuid
.toString());
53 } catch (IllegalArgumentException e
) {
54 throw new HibernateException(e
);
59 * @see org.hibernate.usertype.UserType#disassemble(java.lang.Object)
61 public Serializable
disassemble(Object value
) throws HibernateException
{
65 UUID uuid
= (UUID
) value
;
66 return uuid
.toString();
71 public UUID
nullSafeGet(ResultSet rs
, String
[] names
, SessionImplementor session
, Object owner
)
72 throws HibernateException
, SQLException
{
73 String val
= (String
) StandardBasicTypes
.STRING
.nullSafeGet(rs
, names
, session
, owner
);
80 return UUID
.fromString(val
);
81 } catch (IllegalArgumentException e
) {
82 throw new HibernateException(e
);
88 public void nullSafeSet(PreparedStatement statement
, Object value
, int index
, SessionImplementor session
)
89 throws HibernateException
, SQLException
{
91 // statement.setNull(index, Types.VARCHAR); old version
92 StandardBasicTypes
.STRING
.nullSafeSet(statement
, value
, index
, session
);
94 UUID uuid
= (UUID
)value
;
95 // statement.setString(index, uuid.toString()); //old version
96 StandardBasicTypes
.STRING
.nullSafeSet(statement
, uuid
.toString(), index
, session
);
102 * @see org.jadira.usertype.dateandtime.shared.spi.AbstractSingleColumnUserType#returnedClass()
105 public Class
returnedClass() {
110 public int[] sqlTypes() {