/** * Check if the association is a one to one in the logical model (either a shared-pk * or unique fk). * * @param type The type representing the attribute metadata * * @return True if the attribute represents a logical one to one association */ private static boolean isLogicalOneToOne(Type type) { return type.isEntityType() && ( (EntityType) type ).isLogicalOneToOne(); }
private boolean isOneToOne() { if ( joinableType.isEntityType() ) { EntityType etype = (EntityType) joinableType; return etype.isOneToOne() /*&& etype.isReferenceToPrimaryKey()*/; } else { return false; } }
@Override public int getHashCode(final Object x) { int result = 17; for ( int i = 0; i < propertySpan; i++ ) { Object y = getPropertyValue( x, i ); result *= 37; if ( y != null ) { result += propertyTypes[i].getHashCode( y ); } } return result; }
@Override public boolean isDirty( Object old, Object current, SharedSessionContractImplementor session) throws HibernateException { if ( isSame( old, current ) ) { return false; } Object oldid = getIdentifier( old, session ); Object newid = getIdentifier( current, session ); return getIdentifierType( session ).isDirty( oldid, newid, session ); }
@Override public boolean isEqual(final Object x, final Object y) throws HibernateException { if ( x == y ) { return true; } // null value and empty component are considered equivalent for ( int i = 0; i < propertySpan; i++ ) { if ( !propertyTypes[i].isEqual( getPropertyValue( x, i ), getPropertyValue( y, i ) ) ) { return false; } } return true; }
@Override public int[] sqlTypes(Mapping mapping) throws MappingException { //Not called at runtime so doesn't matter if its slow :) int[] sqlTypes = new int[getColumnSpan( mapping )]; int n = 0; for ( int i = 0; i < propertySpan; i++ ) { int[] subtypes = propertyTypes[i].sqlTypes( mapping ); for ( int subtype : subtypes ) { sqlTypes[n++] = subtype; } } return sqlTypes; }
@Override public Object assemble(Serializable oid, SharedSessionContractImplementor session, Object owner) throws HibernateException { //TODO: currently broken for unique-key references (does not detect // change to unique key property of the associated object) Serializable id = (Serializable) getIdentifierType(session).assemble(oid, session, null); //the owner of the association is not the owner of the id if (id==null) { return null; } else { return resolveIdentifier(id, session); } }
@Override public boolean isDirty(final Object x, final Object y, final SharedSessionContractImplementor session) throws HibernateException { if ( x == y ) { return false; } // null value and empty component are considered equivalent for ( int i = 0; i < propertySpan; i++ ) { if ( propertyTypes[i].isDirty( getPropertyValue( x, i ), getPropertyValue( y, i ), session ) ) { return true; } } return false; }
@Override public int[] sqlTypes(Mapping mapping) throws MappingException { return requireIdentifierOrUniqueKeyType( mapping ).sqlTypes( mapping ); }
@Override public int compare(final Object x, final Object y) { if ( x == y ) { return 0; } for ( int i = 0; i < propertySpan; i++ ) { int propertyCompare = propertyTypes[i].compare( getPropertyValue( x, i ), getPropertyValue( y, i ) ); if ( propertyCompare != 0 ) { return propertyCompare; } } return 0; }
private int getColumnSpan(Type type, SessionFactoryImplementor sfi) { int columnSpan = type.getColumnSpan( sfi ); if ( columnSpan == 0 && type instanceof OneToOneType ) { columnSpan = ( (OneToOneType) type ).getIdentifierOrUniqueKeyType( sfi ).getColumnSpan( sfi ); } return columnSpan; }
private Serializable assembleId(Serializable oid, SharedSessionContractImplementor session) { //the owner of the association is not the owner of the id return ( Serializable ) getIdentifierType( session ).assemble( oid, session, null ); }
@Override public Type entity(String entityName) { return typeResolver.getTypeFactory().manyToOne( entityName ); }
@Override public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { return resolveAny( (String) discriminatorType.nullSafeGet( rs, names[0], session, owner ), (Serializable) identifierType.nullSafeGet( rs, names[1], session, owner ), session ); }
@Override public Object hydrate(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { final String entityName = (String) discriminatorType.nullSafeGet( rs, names[0], session, owner ); final Serializable id = (Serializable) identifierType.nullSafeGet( rs, names[1], session, owner ); return new ObjectTypeCacheEntry( entityName, id ); }
@Override public Type any(Type metaType, Type identifierType) { return typeResolver.getTypeFactory().any( metaType, identifierType ); } }
@Override public Size[] defaultSizes(Mapping mapping) throws MappingException { return super.getIdentifierOrUniqueKeyType( mapping ).defaultSizes( mapping ); }
@Override public int getColumnSpan(Mapping mapping) throws MappingException { return requireIdentifierOrUniqueKeyType( mapping ).getColumnSpan( mapping ); }
@Override public Size[] dictatedSizes(Mapping mapping) throws MappingException { return super.getIdentifierOrUniqueKeyType( mapping ).dictatedSizes( mapping ); }
@Override public int getHashCode(final Object x, final SessionFactoryImplementor factory) { int result = 17; for ( int i = 0; i < propertySpan; i++ ) { Object y = getPropertyValue( x, i ); result *= 37; if ( y != null ) { result += propertyTypes[i].getHashCode( y, factory ); } } return result; }