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
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.hibernate
.HibernateException
;
20 import org
.hibernate
.engine
.spi
.SessionImplementor
;
21 import org
.hibernate
.type
.StandardBasicTypes
;
22 import org
.hibernate
.usertype
.UserType
;
23 import org
.jadira
.usertype
.dateandtime
.shared
.spi
.AbstractUserType
;
25 import eu
.etaxonomy
.cdm
.common
.DOI
;
28 * Hibernate user type for the {@link DOI} class.
32 public class DOIUserType
extends AbstractUserType
implements UserType
{
33 private static final long serialVersionUID
= 2227841000128722278L;
35 @SuppressWarnings("unused")
36 private static final Logger logger
= Logger
.getLogger(DOIUserType
.class);
38 private static final int[] SQL_TYPES
= { Types
.VARCHAR
};
41 public Object
deepCopy(Object o
) throws HibernateException
{
49 return DOI
.fromString(doi
.toString());
50 } catch (IllegalArgumentException e
) {
51 throw new HibernateException(e
);
57 public Serializable
disassemble(Object value
) throws HibernateException
{
61 DOI doi
= (DOI
) value
;
62 return doi
.toString();
67 public DOI
nullSafeGet(ResultSet rs
, String
[] names
, SessionImplementor session
, Object owner
)
68 throws HibernateException
, SQLException
{
69 String val
= (String
) StandardBasicTypes
.STRING
.nullSafeGet(rs
, names
, session
, owner
);
76 return DOI
.fromString(val
);
77 } catch (IllegalArgumentException e
) {
78 throw new HibernateException(e
);
84 public void nullSafeSet(PreparedStatement statement
, Object value
, int index
, SessionImplementor session
)
85 throws HibernateException
, SQLException
{
87 StandardBasicTypes
.STRING
.nullSafeSet(statement
, value
, index
, session
);
90 StandardBasicTypes
.STRING
.nullSafeSet(statement
, doi
.toString(), index
, session
);
96 * @see org.jadira.usertype.dateandtime.shared.spi.AbstractSingleColumnUserType#returnedClass()
99 public Class
returnedClass() {
104 public int[] sqlTypes() {