@Override public Object[] getPropertyValues(Object component, SharedSessionContractImplementor session) throws HibernateException { return new Object[] { session.bestGuessEntityName( component ), getIdentifier( component, session ) }; }
protected String resolveEntityName(Object val) { if ( val == null ) { throw new IllegalArgumentException( "entity for parameter binding cannot be null" ); } return getProducer().bestGuessEntityName( val ); }
@Override public Object getPropertyValue(Object component, int i, SharedSessionContractImplementor session) throws HibernateException { return i==0 ? session.bestGuessEntityName( component ) : getIdentifier( component, session ); }
private Serializable getIdentifier(Object value, SharedSessionContractImplementor session) throws HibernateException { try { return ForeignKeys.getEntityIdentifierIfNotUnsaved( session.bestGuessEntityName( value ), value, session ); } catch (TransientObjectException toe) { return null; } }
@Override public Serializable disassemble(Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException { if ( value == null ) { return null; } else { return new ObjectTypeCacheEntry( session.bestGuessEntityName( value ), ForeignKeys.getEntityIdentifierIfNotUnsaved( session.bestGuessEntityName( value ), value, session ) ); } }
/** * Build a loggable representation of the paths tracked here at the moment. * * @param session The session (used to resolve entity names) * * @return The loggable representation */ public String toLoggableString(SharedSessionContractImplementor session) { final StringBuilder sb = new StringBuilder( getClass().getSimpleName() ).append( '[' ); if ( propertyPathsByTransientEntity != null ) { for ( Map.Entry<Object,Set<String>> entry : propertyPathsByTransientEntity.entrySet() ) { sb.append( "transientEntityName=" ).append( session.bestGuessEntityName( entry.getKey() ) ); sb.append( " requiredBy=" ).append( entry.getValue() ); } } sb.append( ']' ); return sb.toString(); } }
@Override public boolean isModified(Object old, Object current, boolean[] checkable, SharedSessionContractImplementor session) throws HibernateException { if ( current == null ) { return old != null; } else if ( old == null ) { return true; } final ObjectTypeCacheEntry holder = (ObjectTypeCacheEntry) old; final boolean[] idCheckable = new boolean[checkable.length-1]; System.arraycopy( checkable, 1, idCheckable, 0, idCheckable.length ); return ( checkable[0] && !holder.entityName.equals( session.bestGuessEntityName( current ) ) ) || identifierType.isModified( holder.id, getIdentifier( current, session ), idCheckable, session ); }
@Override public Object replace(Object original, Object target, SharedSessionContractImplementor session, Object owner, Map copyCache) throws HibernateException { if ( original == null ) { return null; } else { final String entityName = session.bestGuessEntityName( original ); final Serializable id = ForeignKeys.getEntityIdentifierIfNotUnsaved( entityName, original, session ); return session.internalLoad( entityName, id, eager, false ); } }
@Override public void nullSafeSet(PreparedStatement st, Object value, int index, boolean[] settable, SharedSessionContractImplementor session) throws HibernateException, SQLException { Serializable id; String entityName; if ( value == null ) { id = null; entityName = null; } else { entityName = session.bestGuessEntityName( value ); id = ForeignKeys.getEntityIdentifierIfNotUnsaved( entityName, value, session ); } // discriminatorType is assumed to be single-column type if ( settable == null || settable[0] ) { discriminatorType.nullSafeSet( st, entityName, index, session ); } if ( settable == null ) { identifierType.nullSafeSet( st, id, index+1, session ); } else { final boolean[] idSettable = new boolean[ settable.length-1 ]; System.arraycopy( settable, 1, idSettable, 0, idSettable.length ); identifierType.nullSafeSet( st, id, index+1, idSettable, session ); } }
/** * Build a loggable representation of the paths tracked here at the moment. * * @param session The session (used to resolve entity names) * * @return The loggable representation */ public String toLoggableString(SharedSessionContractImplementor session) { final StringBuilder sb = new StringBuilder( getClass().getSimpleName() ).append( '[' ); if ( propertyPathsByTransientEntity != null ) { for ( Map.Entry<Object,Set<String>> entry : propertyPathsByTransientEntity.entrySet() ) { sb.append( "transientEntityName=" ).append( session.bestGuessEntityName( entry.getKey() ) ); sb.append( " requiredBy=" ).append( entry.getValue() ); } } sb.append( ']' ); return sb.toString(); } }