Author: arminw Date: Tue May 15 08:26:16 2007 New Revision: 538212 URL: http://svn.apache.org/viewvc?view=rev&rev=538212 Log: optimize imports, comments, source
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/Identity.java db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/ValueContainer.java Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/Identity.java URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/Identity.java?view=diff&rev=538212&r1=538211&r2=538212 ============================================================================== --- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/Identity.java (original) +++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/Identity.java Tue May 15 08:26:16 2007 @@ -109,7 +109,7 @@ differs in different JVM */ private transient String m_stringRepresentation = null; - private transient Integer m_hashCode; + private transient int m_hashCode; /** * For internal use only! @@ -268,9 +268,16 @@ } /** - * Determines whether the identity is transient. + * Determines whether the identity is transient or not - NOTE: It + * could happen that the <tt>Identity</tt> is not transient but the + * associated object is transient! For example, the object mapping doesn't + * use a primary key managed by OJB and the user set the PK values before + * insert the object, then the Identity of the object isn't transient (because + * OJB can extract the PK values from the object) but the object is still transient + * (because it's not insert yet). Use class [EMAIL PROTECTED] PersistenceChecker} to determine + * transient objects (via [EMAIL PROTECTED] PersistenceBrokerInternal#getPersistenceChecker()}). * - * @return <code>true</code> if the identity is transient + * @return <code>true</code> if the identity is transient. */ public boolean isTransient() { @@ -440,7 +447,7 @@ identity is quasi immutable (toplevel class and PK fields never change), thus we can note hashCode */ - if(m_hashCode == null) + if(m_hashCode == 0) { int iTotal = persistenceState; Object obj; @@ -450,16 +457,16 @@ if(obj instanceof byte[]) { iTotal = iTotal * iConstant + ((byte[]) obj).length; - } + } else { - iTotal = iTotal * iConstant + (obj != null ? obj.hashCode() : 0); - } + iTotal += (obj != null ? obj.hashCode() : 0); + } } - iTotal = iTotal * iConstant + m_objectsTopLevelClass.hashCode(); - m_hashCode = new Integer(iTotal); + iTotal += m_objectsTopLevelClass.hashCode(); + m_hashCode = iTotal; } - return m_hashCode.intValue(); + return m_hashCode; } private ClassNotPersistenceCapableException createException(String msg, final Object objectToIdentify, final Exception e) Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/ValueContainer.java URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/ValueContainer.java?view=diff&rev=538212&r1=538211&r2=538212 ============================================================================== --- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/ValueContainer.java (original) +++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/ValueContainer.java Tue May 15 08:26:16 2007 @@ -17,32 +17,40 @@ import java.io.Serializable; +import org.apache.commons.lang.ClassUtils; import org.apache.ojb.broker.metadata.JdbcType; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; +/** + * Encapsulates a persistent object field value (expects the java to sql conversion object, see + * [EMAIL PROTECTED] org.apache.ojb.broker.accesslayer.conversions.FieldConversion}) and its associated + * [EMAIL PROTECTED] JdbcType}. + * <br/> + * For internal use only! + * + * @version $Id$ + */ public final class ValueContainer implements Serializable { private static final long serialVersionUID = 3689069556052340793L; - - private final JdbcType m_jdbcType; - private final Object m_value; + + private final JdbcType jdbcType; + private final Object value; private int hc; public ValueContainer(Object value, JdbcType jdbcType) { - this.m_jdbcType = jdbcType; - this.m_value = value; + this.jdbcType = jdbcType; + this.value = value; } public JdbcType getJdbcType() { - return m_jdbcType; + return jdbcType; } public Object getValue() { - return m_value; + return value; } public boolean equals(Object obj) @@ -53,10 +61,10 @@ { final ValueContainer container = (ValueContainer) obj; // if jdbcType was null, we can't compare - result = this.m_jdbcType != null ? this.m_jdbcType.equals(container.getJdbcType()) : false; + result = this.jdbcType != null && this.jdbcType.equals(container.jdbcType); if(result) { - result = new EqualsBuilder().append(this.m_value, container.getValue()).isEquals(); + result = this.value != null ? this.value.equals(container.value) : container.value == null; } } return result; @@ -64,18 +72,19 @@ public int hashCode() { -// int hash = m_value != null ? m_value.hashCode() : 0; -// hash += m_jdbcType != null ? m_jdbcType.hashCode() : 0; -// return hash; - if(hc == 0) hc = new HashCodeBuilder().append(m_jdbcType).append(m_value).toHashCode(); + if(hc == 0) + { + int hash = value != null ? value.hashCode() : 0; + hash += jdbcType != null ? jdbcType.hashCode() : 0; + hc = hash; + } return hc; } public String toString() { - return this.getClass().getName() + "[jdbcType: " - + m_jdbcType - + ", value: " + m_value + "]"; + return "[" + ClassUtils.getShortClassName(this.getClass()) + ": jdbcType=" + + jdbcType + + ", value=" + value + "]"; } - } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]