1 package org.hibernate.type; 3 4 import java.io.Serializable ; 5 import java.sql.ResultSet ; 6 import java.sql.SQLException ; 7 8 import org.hibernate.AssertionFailure; 9 import org.hibernate.HibernateException; 10 import org.hibernate.MappingException; 11 import org.hibernate.engine.ForeignKeys; 12 import org.hibernate.engine.Mapping; 13 import org.hibernate.engine.SessionImplementor; 14 15 21 public class SpecialOneToOneType extends OneToOneType { 22 23 public SpecialOneToOneType( 24 String referencedEntityName, 25 ForeignKeyDirection foreignKeyType, 26 String uniqueKeyPropertyName, 27 boolean lazy, 28 boolean unwrapProxy, 29 String entityName, 30 String propertyName 31 ) { 32 super( 33 referencedEntityName, 34 foreignKeyType, 35 uniqueKeyPropertyName, 36 lazy, 37 unwrapProxy, 38 true, 39 entityName, 40 propertyName 41 ); 42 } 43 44 public int getColumnSpan(Mapping mapping) throws MappingException { 45 return super.getIdentifierOrUniqueKeyType(mapping).getColumnSpan(mapping); 46 } 47 48 public int[] sqlTypes(Mapping mapping) throws MappingException { 49 return super.getIdentifierOrUniqueKeyType(mapping).sqlTypes(mapping); 50 } 51 52 public boolean useLHSPrimaryKey() { 53 return false; 54 } 55 56 public Object hydrate(ResultSet rs, String [] names, SessionImplementor session, Object owner) 57 throws HibernateException, SQLException { 58 return super.getIdentifierOrUniqueKeyType( session.getFactory() ) 59 .nullSafeGet(rs, names, session, owner); 60 } 61 62 64 public Serializable disassemble(Object value, SessionImplementor session, Object owner) 65 throws HibernateException { 66 67 if ( isNotEmbedded(session) ) { 68 return getIdentifierType(session).disassemble(value, session, owner); 69 } 70 71 if (value==null) { 72 return null; 73 } 74 else { 75 Object id = ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session ); 78 if (id==null) { 79 throw new AssertionFailure( 80 "cannot cache a reference to an object with a null id: " + 81 getAssociatedEntityName() 82 ); 83 } 84 return getIdentifierType(session).disassemble(id, session, owner); 85 } 86 } 87 88 public Object assemble(Serializable oid, SessionImplementor session, Object owner) 89 throws HibernateException { 90 Serializable id = (Serializable ) getIdentifierType(session).assemble(oid, session, null); 94 if ( isNotEmbedded(session) ) return id; 95 96 if (id==null) { 97 return null; 98 } 99 else { 100 return resolveIdentifier(id, session); 101 } 102 } 103 104 105 106 } 107 | Popular Tags |