| 1 | /* |
|---|
| 2 | * $Id$ |
|---|
| 3 | * |
|---|
| 4 | * Copyright 2006, The jCoderZ.org Project. All rights reserved. |
|---|
| 5 | * |
|---|
| 6 | * Redistribution and use in source and binary forms, with or without |
|---|
| 7 | * modification, are permitted provided that the following conditions are |
|---|
| 8 | * met: |
|---|
| 9 | * |
|---|
| 10 | * * Redistributions of source code must retain the above copyright |
|---|
| 11 | * notice, this list of conditions and the following disclaimer. |
|---|
| 12 | * * Redistributions in binary form must reproduce the above |
|---|
| 13 | * copyright notice, this list of conditions and the following |
|---|
| 14 | * disclaimer in the documentation and/or other materials |
|---|
| 15 | * provided with the distribution. |
|---|
| 16 | * * Neither the name of the jCoderZ.org Project nor the names of |
|---|
| 17 | * its contributors may be used to endorse or promote products |
|---|
| 18 | * derived from this software without specific prior written |
|---|
| 19 | * permission. |
|---|
| 20 | * |
|---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND |
|---|
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|---|
| 24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS |
|---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
|---|
| 28 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|---|
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|---|
| 30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|---|
| 31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 32 | */ |
|---|
| 33 | package org.jcoderz.commons.util; |
|---|
| 34 | |
|---|
| 35 | import java.io.Serializable; |
|---|
| 36 | import java.sql.PreparedStatement; |
|---|
| 37 | import java.sql.ResultSet; |
|---|
| 38 | import java.sql.SQLException; |
|---|
| 39 | |
|---|
| 40 | import org.hibernate.HibernateException; |
|---|
| 41 | import org.hibernate.usertype.UserType; |
|---|
| 42 | |
|---|
| 43 | /** |
|---|
| 44 | * |
|---|
| 45 | * Base class for Hibernate User Types. This class is used by the |
|---|
| 46 | * Hibernate binding for StrongTypes. There exist subclasses for |
|---|
| 47 | * the specific kinds of StrongTypes like RestrictedString. |
|---|
| 48 | * |
|---|
| 49 | * @author thomas.bodemer |
|---|
| 50 | */ |
|---|
| 51 | public abstract class UserTypeBase implements UserType, Serializable |
|---|
| 52 | { |
|---|
| 53 | private static final long serialVersionUID = 1L; |
|---|
| 54 | |
|---|
| 55 | /** |
|---|
| 56 | * {@inheritDoc} |
|---|
| 57 | */ |
|---|
| 58 | public abstract int[] sqlTypes (); |
|---|
| 59 | |
|---|
| 60 | /** |
|---|
| 61 | * {@inheritDoc} |
|---|
| 62 | */ |
|---|
| 63 | public abstract Class returnedClass (); |
|---|
| 64 | |
|---|
| 65 | /** |
|---|
| 66 | * {@inheritDoc} |
|---|
| 67 | */ |
|---|
| 68 | public boolean equals (Object x, Object y) |
|---|
| 69 | { |
|---|
| 70 | return ObjectUtil.equals(x, y); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | /** |
|---|
| 74 | * {@inheritDoc} |
|---|
| 75 | */ |
|---|
| 76 | public Object deepCopy (Object value) |
|---|
| 77 | { |
|---|
| 78 | return value; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | /** |
|---|
| 82 | * {@inheritDoc} |
|---|
| 83 | */ |
|---|
| 84 | public boolean isMutable () |
|---|
| 85 | { |
|---|
| 86 | return false; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | /** |
|---|
| 90 | * {@inheritDoc} |
|---|
| 91 | */ |
|---|
| 92 | public abstract Object nullSafeGet (ResultSet resultSet, String[] types, |
|---|
| 93 | Object owner) |
|---|
| 94 | throws HibernateException, SQLException; |
|---|
| 95 | |
|---|
| 96 | /** |
|---|
| 97 | * {@inheritDoc} |
|---|
| 98 | */ |
|---|
| 99 | public abstract void nullSafeSet (PreparedStatement statement, Object value, |
|---|
| 100 | int index) |
|---|
| 101 | throws HibernateException, SQLException; |
|---|
| 102 | |
|---|
| 103 | /** |
|---|
| 104 | * {@inheritDoc} |
|---|
| 105 | */ |
|---|
| 106 | public int hashCode (Object x) throws HibernateException |
|---|
| 107 | { |
|---|
| 108 | return x.hashCode(); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | /** |
|---|
| 112 | * {@inheritDoc} |
|---|
| 113 | */ |
|---|
| 114 | public Serializable disassemble (Object value) |
|---|
| 115 | throws HibernateException |
|---|
| 116 | { |
|---|
| 117 | return (Serializable) value; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | /** |
|---|
| 121 | * {@inheritDoc} |
|---|
| 122 | */ |
|---|
| 123 | public Object assemble (Serializable cached, Object owner) |
|---|
| 124 | throws HibernateException |
|---|
| 125 | { |
|---|
| 126 | return cached; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | /** |
|---|
| 130 | * {@inheritDoc} |
|---|
| 131 | */ |
|---|
| 132 | public Object replace (Object original, Object target, Object owner) |
|---|
| 133 | throws HibernateException |
|---|
| 134 | { |
|---|
| 135 | return original; |
|---|
| 136 | } |
|---|
| 137 | } |
|---|