1 package org.hibernate.type; 3 4 import java.io.Serializable ; 5 import java.sql.PreparedStatement ; 6 import java.sql.ResultSet ; 7 import java.sql.SQLException ; 8 9 import org.hibernate.HibernateException; 10 import org.hibernate.MappingException; 11 import org.hibernate.engine.EntityKey; 12 import org.hibernate.engine.Mapping; 13 import org.hibernate.engine.SessionImplementor; 14 import org.hibernate.persister.entity.EntityPersister; 15 import org.hibernate.util.ArrayHelper; 16 17 21 public class OneToOneType extends EntityType { 22 23 private final ForeignKeyDirection foreignKeyType; 24 private final String propertyName; 25 private final String entityName; 26 27 public String getPropertyName() { 28 return propertyName; 29 } 30 31 public boolean isNull(Object owner, SessionImplementor session) { 32 33 if ( propertyName != null ) { 34 35 EntityPersister ownerPersister = session.getFactory() 36 .getEntityPersister(entityName); 37 Serializable id = session.getContextEntityIdentifier(owner); 38 39 EntityKey entityKey = new EntityKey( id, ownerPersister, session.getEntityMode() ); 40 41 return session.getPersistenceContext() 42 .isPropertyNull( entityKey, getPropertyName() ); 43 44 } 45 else { 46 return false; 47 } 48 49 } 50 51 public int getColumnSpan(Mapping session) throws MappingException { 52 return 0; 53 } 54 55 public int[] sqlTypes(Mapping session) throws MappingException { 56 return ArrayHelper.EMPTY_INT_ARRAY; 57 } 58 59 public boolean[] toColumnNullness(Object value, Mapping mapping) { 60 return ArrayHelper.EMPTY_BOOLEAN_ARRAY; 61 } 62 63 public OneToOneType( 64 String referencedEntityName, 65 ForeignKeyDirection foreignKeyType, 66 String uniqueKeyPropertyName, 67 boolean lazy, 68 boolean unwrapProxy, 69 boolean isEmbeddedInXML, 70 String entityName, 71 String propertyName 72 ) { 73 super( 74 referencedEntityName, 75 uniqueKeyPropertyName, 76 !lazy, 77 isEmbeddedInXML, 78 unwrapProxy 79 ); 80 this.foreignKeyType = foreignKeyType; 81 this.propertyName = propertyName; 82 this.entityName = entityName; 83 } 84 85 public void nullSafeSet(PreparedStatement st, Object value, int index, boolean[] settable, SessionImplementor session) { 86 } 88 89 public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) { 90 } 92 93 public boolean isOneToOne() { 94 return true; 95 } 96 97 public boolean isDirty(Object old, Object current, SessionImplementor session) { 98 return false; 99 } 100 101 public boolean isModified(Object old, Object current, SessionImplementor session) { 102 return false; 103 } 104 105 public ForeignKeyDirection getForeignKeyDirection() { 106 return foreignKeyType; 107 } 108 109 public Object hydrate( 110 ResultSet rs, 111 String [] names, 112 SessionImplementor session, 113 Object owner) 114 throws HibernateException, SQLException { 115 116 return session.getContextEntityIdentifier(owner); 117 } 118 119 protected boolean isNullable() { 120 return foreignKeyType==ForeignKeyDirection.FOREIGN_KEY_TO_PARENT; 121 } 122 123 public boolean useLHSPrimaryKey() { 124 return true; 125 } 126 127 public Serializable disassemble(Object value, SessionImplementor session, Object owner) 128 throws HibernateException { 129 return null; 130 } 131 132 public Object assemble(Serializable oid, SessionImplementor session, Object owner) 133 throws HibernateException { 134 return resolve( session.getContextEntityIdentifier(owner), session, owner ); 138 } 139 140 public boolean isAlwaysDirtyChecked() { 141 return false; 142 } 146 147 } 148 149 | Popular Tags |