📄 componenttype.java
字号:
private Object[] nullSafeGetValues(Object value, EntityMode entityMode) throws HibernateException { if ( value == null ) { return new Object[propertySpan]; } else { return getPropertyValues( value, entityMode ); } } public Object nullSafeGet(ResultSet rs, String name, SessionImplementor session, Object owner) throws HibernateException, SQLException { return nullSafeGet( rs, new String[] {name}, session, owner ); } public Object getPropertyValue(Object component, int i, SessionImplementor session) throws HibernateException { return getPropertyValue( component, i, session.getEntityMode() ); } public Object getPropertyValue(Object component, int i, EntityMode entityMode) throws HibernateException { return tuplizerMapping.getTuplizer( entityMode ).getPropertyValue( component, i ); } public Object[] getPropertyValues(Object component, SessionImplementor session) throws HibernateException { return getPropertyValues( component, session.getEntityMode() ); } public Object[] getPropertyValues(Object component, EntityMode entityMode) throws HibernateException { return tuplizerMapping.getTuplizer( entityMode ).getPropertyValues( component ); } public void setPropertyValues(Object component, Object[] values, EntityMode entityMode) throws HibernateException { tuplizerMapping.getTuplizer( entityMode ).setPropertyValues( component, values ); } public Type[] getSubtypes() { return propertyTypes; } public String getName() { return "component" + ArrayHelper.toString( propertyNames ); } public String toLoggableString(Object value, SessionFactoryImplementor factory) throws HibernateException { if ( value == null ) { return "null"; } Map result = new HashMap(); EntityMode entityMode = tuplizerMapping.guessEntityMode( value ); if ( entityMode == null ) { throw new ClassCastException( value.getClass().getName() ); } Object[] values = getPropertyValues( value, entityMode ); for ( int i = 0; i < propertyTypes.length; i++ ) { result.put( propertyNames[i], propertyTypes[i].toLoggableString( values[i], factory ) ); } return StringHelper.unqualify( getName() ) + result.toString(); } public String[] getPropertyNames() { return propertyNames; } public Object deepCopy(Object component, EntityMode entityMode, SessionFactoryImplementor factory) throws HibernateException { if ( component == null ) { return null; } Object[] values = getPropertyValues( component, entityMode ); for ( int i = 0; i < propertySpan; i++ ) { values[i] = propertyTypes[i].deepCopy( values[i], entityMode, factory ); } Object result = instantiate( entityMode ); setPropertyValues( result, values, entityMode ); //not absolutely necessary, but helps for some //equals()/hashCode() implementations ComponentTuplizer ct = ( ComponentTuplizer ) tuplizerMapping.getTuplizer( entityMode ); if ( ct.hasParentProperty() ) { ct.setParent( result, ct.getParent( component ), factory ); } return result; } public Object replace( Object original, Object target, SessionImplementor session, Object owner, Map copyCache) throws HibernateException { if ( original == null ) { return null; } //if ( original == target ) return target; final Object result = target == null ? instantiate( owner, session ) : target; final EntityMode entityMode = session.getEntityMode(); Object[] values = TypeFactory.replace( getPropertyValues( original, entityMode ), getPropertyValues( result, entityMode ), propertyTypes, session, owner, copyCache ); setPropertyValues( result, values, entityMode ); return result; } public Object replace( Object original, Object target, SessionImplementor session, Object owner, Map copyCache, ForeignKeyDirection foreignKeyDirection) throws HibernateException { if ( original == null ) { return null; } //if ( original == target ) return target; final Object result = target == null ? instantiate( owner, session ) : target; final EntityMode entityMode = session.getEntityMode(); Object[] values = TypeFactory.replace( getPropertyValues( original, entityMode ), getPropertyValues( result, entityMode ), propertyTypes, session, owner, copyCache, foreignKeyDirection ); setPropertyValues( result, values, entityMode ); return result; } /** * This method does not populate the component parent */ public Object instantiate(EntityMode entityMode) throws HibernateException { return tuplizerMapping.getTuplizer( entityMode ).instantiate(); } public Object instantiate(Object parent, SessionImplementor session) throws HibernateException { Object result = instantiate( session.getEntityMode() ); ComponentTuplizer ct = ( ComponentTuplizer ) tuplizerMapping.getTuplizer( session.getEntityMode() ); if ( ct.hasParentProperty() && parent != null ) { ct.setParent( result, session.getPersistenceContext().proxyFor( parent ), session.getFactory() ); } return result; } public CascadeStyle getCascadeStyle(int i) { return cascade[i]; } public boolean isMutable() { return true; } public Serializable disassemble(Object value, SessionImplementor session, Object owner) throws HibernateException { if ( value == null ) { return null; } else { Object[] values = getPropertyValues( value, session.getEntityMode() ); for ( int i = 0; i < propertyTypes.length; i++ ) { values[i] = propertyTypes[i].disassemble( values[i], session, owner ); } return values; } } public Object assemble(Serializable object, SessionImplementor session, Object owner) throws HibernateException { if ( object == null ) { return null; } else { Object[] values = ( Object[] ) object; Object[] assembled = new Object[values.length]; for ( int i = 0; i < propertyTypes.length; i++ ) { assembled[i] = propertyTypes[i].assemble( ( Serializable ) values[i], session, owner ); } Object result = instantiate( owner, session ); setPropertyValues( result, assembled, session.getEntityMode() ); return result; } } public FetchMode getFetchMode(int i) { return joinedFetch[i]; } public Object hydrate( final ResultSet rs, final String[] names, final SessionImplementor session, final Object owner) throws HibernateException, SQLException { int begin = 0; boolean notNull = false; Object[] values = new Object[propertySpan]; for ( int i = 0; i < propertySpan; i++ ) { int length = propertyTypes[i].getColumnSpan( session.getFactory() ); String[] range = ArrayHelper.slice( names, begin, length ); //cache this Object val = propertyTypes[i].hydrate( rs, range, session, owner ); if ( val == null ) { if ( isKey ) { return null; //different nullability rules for pk/fk } } else { notNull = true; } values[i] = val; begin += length; } return notNull ? values : null; } public Object resolve(Object value, SessionImplementor session, Object owner) throws HibernateException { if ( value != null ) { Object result = instantiate( owner, session ); Object[] values = ( Object[] ) value; Object[] resolvedValues = new Object[values.length]; //only really need new array during semiresolve! for ( int i = 0; i < values.length; i++ ) { resolvedValues[i] = propertyTypes[i].resolve( values[i], session, owner ); } setPropertyValues( result, resolvedValues, session.getEntityMode() ); return result; } else { return null; } } public Object semiResolve(Object value, SessionImplementor session, Object owner) throws HibernateException { //note that this implementation is kinda broken //for components with many-to-one associations return resolve( value, session, owner ); } public boolean[] getPropertyNullability() { return propertyNullability; } public boolean isXMLElement() { return true; } public Object fromXMLNode(Node xml, Mapping factory) throws HibernateException { return xml; } public void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory) throws HibernateException { replaceNode( node, ( Element ) value ); } public boolean[] toColumnNullness(Object value, Mapping mapping) { boolean[] result = new boolean[ getColumnSpan( mapping ) ]; if ( value == null ) { return result; } Object[] values = getPropertyValues( value, EntityMode.POJO ); //TODO!!!!!!! int loc = 0; for ( int i = 0; i < propertyTypes.length; i++ ) { boolean[] propertyNullness = propertyTypes[i].toColumnNullness( values[i], mapping ); System.arraycopy( propertyNullness, 0, result, loc, propertyNullness.length ); loc += propertyNullness.length; } return result; } public boolean isEmbedded() { return false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -