1 package org.hibernate.type; 3 4 import java.io.Serializable ; 5 import java.sql.ResultSet ; 6 import java.sql.SQLException ; 7 import java.util.Map ; 8 9 import org.dom4j.Element; 10 import org.dom4j.Node; 11 import org.hibernate.EntityMode; 12 import org.hibernate.HibernateException; 13 import org.hibernate.engine.SessionFactoryImplementor; 14 import org.hibernate.engine.SessionImplementor; 15 import org.hibernate.util.EqualsHelper; 16 17 21 public abstract class AbstractType implements Type { 22 23 public boolean isAssociationType() { 24 return false; 25 } 26 27 public boolean isCollectionType() { 28 return false; 29 } 30 31 public boolean isComponentType() { 32 return false; 33 } 34 35 public boolean isEntityType() { 36 return false; 37 } 38 39 public boolean isXMLElement() { 40 return false; 41 } 42 43 public int compare(Object x, Object y, EntityMode entityMode) { 44 return ( (Comparable ) x ).compareTo(y); 45 } 46 47 public Serializable disassemble(Object value, SessionImplementor session, Object owner) 48 throws HibernateException { 49 50 if (value==null) { 51 return null; 52 } 53 else { 54 return (Serializable ) deepCopy( value, session.getEntityMode(), session.getFactory() ); 55 } 56 } 57 58 public Object assemble(Serializable cached, SessionImplementor session, Object owner) 59 throws HibernateException { 60 if ( cached==null ) { 61 return null; 62 } 63 else { 64 return deepCopy( cached, session.getEntityMode(), session.getFactory() ); 65 } 66 } 67 68 public boolean isDirty(Object old, Object current, SessionImplementor session) 69 throws HibernateException { 70 return !isSame( old, current, session.getEntityMode() ); 71 } 72 73 public Object hydrate( 74 ResultSet rs, 75 String [] names, 76 SessionImplementor session, 77 Object owner) 78 throws HibernateException, SQLException { 79 return nullSafeGet(rs, names, session, owner); 82 } 83 84 public Object resolve(Object value, SessionImplementor session, Object owner) 85 throws HibernateException { 86 return value; 87 } 88 89 public Object semiResolve(Object value, SessionImplementor session, Object owner) 90 throws HibernateException { 91 return value; 92 } 93 94 public boolean isAnyType() { 95 return false; 96 } 97 98 public boolean isModified(Object old, Object current, SessionImplementor session) 99 throws HibernateException { 100 return isDirty(old, current, session); 101 } 102 103 public boolean isSame(Object x, Object y, EntityMode entityMode) throws HibernateException { 104 return isEqual(x, y, entityMode); 105 } 106 107 public boolean isEqual(Object x, Object y, EntityMode entityMode) { 108 return EqualsHelper.equals(x, y); 109 } 110 111 public int getHashCode(Object x, EntityMode entityMode) { 112 return x.hashCode(); 113 } 114 115 public boolean isEqual(Object x, Object y, EntityMode entityMode, SessionFactoryImplementor factory) { 116 return isEqual(x, y, entityMode); 117 } 118 119 public int getHashCode(Object x, EntityMode entityMode, SessionFactoryImplementor factory) { 120 return getHashCode(x, entityMode); 121 } 122 123 protected static void replaceNode(Node container, Element value) { 124 if ( container!=value ) { Element parent = container.getParent(); 126 container.detach(); 127 value.setName( container.getName() ); 128 value.detach(); 129 parent.add(value); 130 } 131 } 132 133 public Type getSemiResolvedType(SessionFactoryImplementor factory) { 134 return this; 135 } 136 137 public Object replace( 138 Object original, 139 Object target, 140 SessionImplementor session, 141 Object owner, 142 Map copyCache, 143 ForeignKeyDirection foreignKeyDirection) 144 throws HibernateException { 145 boolean include; 146 if ( isAssociationType() ) { 147 AssociationType atype = (AssociationType) this; 148 include = atype.getForeignKeyDirection()==foreignKeyDirection; 149 } 150 else { 151 include = ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT==foreignKeyDirection; 152 } 153 return include ? replace(original, target, session, owner, copyCache) : target; 154 } 155 156 161 162 } 163 | Popular Tags |