arminw 2005/03/23 04:39:57
Modified: src/java/org/apache/ojb/broker/core Tag: OJB_1_0_RELEASE
IdentityFactoryImpl.java
src/java/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
Identity.java IdentityFactory.java
Log:
add missing Identity create method to IdentityFactory
minor performance improvements in Identity (add 'final' keyword if possible)
Revision Changes Path
No revision
No revision
1.2.2.2 +10 -2
db-ojb/src/java/org/apache/ojb/broker/core/IdentityFactoryImpl.java
Index: IdentityFactoryImpl.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/IdentityFactoryImpl.java,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -u -r1.2.2.1 -r1.2.2.2
--- IdentityFactoryImpl.java 27 Jul 2004 00:26:05 -0000 1.2.2.1
+++ IdentityFactoryImpl.java 23 Mar 2005 12:39:57 -0000 1.2.2.2
@@ -122,10 +122,18 @@
}
/**
+ * @see
org.apache.ojb.broker.IdentityFactory#buildIdentity(java.lang.Class,
java.lang.String[], java.lang.Object[])
+ */
+ public Identity buildIdentity(Class realClass, Class topLevelClass,
Object[] pkValues)
+ {
+ return new Identity(realClass, topLevelClass, pkValues);
+ }
+
+ /**
* @see
org.apache.ojb.broker.IdentityFactory#buildIdentity(java.lang.Class,
java.lang.Object)
*/
public Identity buildIdentity(Class realClass, Object pkValue)
{
- return buildIdentity(realClass, null, new Object[]{pkValue});
+ return buildIdentity(realClass, (String[]) null, new
Object[]{pkValue});
}
}
No revision
No revision
1.36.2.8 +27 -27 db-ojb/src/java/org/apache/ojb/broker/Identity.java
Index: Identity.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/Identity.java,v
retrieving revision 1.36.2.7
retrieving revision 1.36.2.8
diff -u -r1.36.2.7 -r1.36.2.8
--- Identity.java 15 Mar 2005 06:06:33 -0000 1.36.2.7
+++ Identity.java 23 Mar 2005 12:39:57 -0000 1.36.2.8
@@ -103,7 +103,7 @@
* interface (in the inheritance hierarchy) that the identified object
is an instance of
* @param pkValues (unique across the extents !)
*/
- public Identity(Class realClass, Class topLevel, Object[] pkValues)
+ public Identity(final Class realClass, final Class topLevel, final
Object[] pkValues)
{
m_objectsTopLevelClass = topLevel;
m_objectsRealClass = realClass;
@@ -111,28 +111,28 @@
checkForPrimaryKeys(null);
}
- public Identity(Object objectToIdentitify, PersistenceBroker
targetBroker)
+ public Identity(final Object objectToIdentitify, final PersistenceBroker
targetBroker)
{
init(objectToIdentitify, targetBroker, null);
}
- public Identity(Object objectToIdentitify, PersistenceBroker
targetBroker, ClassDescriptor cld)
+ public Identity(final Object objectToIdentitify, final PersistenceBroker
targetBroker, final ClassDescriptor cld)
{
init(objectToIdentitify, targetBroker, cld);
}
- private void init(Object objectToIdentify, PersistenceBroker
targetBroker, ClassDescriptor cld)
+ private void init(final Object objectToIdentify, final PersistenceBroker
targetBroker, ClassDescriptor cld)
{
if(objectToIdentify == null) throw new OJBRuntimeException("Can't
create Identity for 'null'-object");
try
{
- IndirectionHandler handler =
ProxyHelper.getIndirectionHandler(objectToIdentify);
+ final IndirectionHandler handler =
ProxyHelper.getIndirectionHandler(objectToIdentify);
synchronized(objectToIdentify)
{
if (handler != null)
{
- Identity sourceOID = handler.getIdentity();
+ final Identity sourceOID = handler.getIdentity();
m_objectsTopLevelClass =
sourceOID.m_objectsTopLevelClass;
m_objectsRealClass = sourceOID.m_objectsRealClass;
m_pkValues = sourceOID.m_pkValues;
@@ -150,8 +150,8 @@
// BRJ: definitely do NOT convertToSql
// conversion is done when binding the sql-statement
- BrokerHelper helper = targetBroker.serviceBrokerHelper();
- ValueContainer[] pkValues = helper.getKeyValues(cld,
objectToIdentify, false);
+ final BrokerHelper helper =
targetBroker.serviceBrokerHelper();
+ final ValueContainer[] pkValues =
helper.getKeyValues(cld, objectToIdentify, false);
if (pkValues == null || pkValues.length == 0)
{
throw createException("Can't extract PK value
fields", objectToIdentify, null);
@@ -176,17 +176,17 @@
* Factory method that returns an Identity object from the given
* byte array - see [EMAIL PROTECTED] #serialize}.
*/
- public static Identity fromByteArray(byte[] anArray) throws
PersistenceBrokerException
+ public static Identity fromByteArray(final byte[] anArray) throws
PersistenceBrokerException
{
// reverse of the serialize() algorithm:
// read from byte[] with a ByteArrayInputStream, decompress with
// a GZIPInputStream and then deserialize by reading from the
ObjectInputStream
try
{
- ByteArrayInputStream bais = new ByteArrayInputStream(anArray);
- GZIPInputStream gis = new GZIPInputStream(bais);
- ObjectInputStream ois = new ObjectInputStream(gis);
- Identity result = (Identity) ois.readObject();
+ final ByteArrayInputStream bais = new
ByteArrayInputStream(anArray);
+ final GZIPInputStream gis = new GZIPInputStream(bais);
+ final ObjectInputStream ois = new ObjectInputStream(gis);
+ final Identity result = (Identity) ois.readObject();
ois.close();
gis.close();
bais.close();
@@ -221,7 +221,7 @@
/**
* Set the objects real class
*/
- public void setObjectsRealClass(Class objectsRealClass)
+ public void setObjectsRealClass(final Class objectsRealClass)
{
this.m_objectsRealClass = objectsRealClass;
}
@@ -238,14 +238,14 @@
// the resulting byte[] is returned
try
{
- ByteArrayOutputStream bao = new ByteArrayOutputStream();
- GZIPOutputStream gos = new GZIPOutputStream(bao);
- ObjectOutputStream oos = new ObjectOutputStream(gos);
+ final ByteArrayOutputStream bao = new ByteArrayOutputStream();
+ final GZIPOutputStream gos = new GZIPOutputStream(bao);
+ final ObjectOutputStream oos = new ObjectOutputStream(gos);
oos.writeObject(this);
oos.close();
gos.close();
bao.close();
- byte[] result = bao.toByteArray();
+ final byte[] result = bao.toByteArray();
return result;
}
catch (Exception ignored)
@@ -262,7 +262,7 @@
{
if (m_stringRepresentation == null)
{
- StringBuffer buf = new StringBuffer();
+ final StringBuffer buf = new StringBuffer();
buf.append(m_objectsTopLevelClass.getName());
for (int i = 0; i < m_pkValues.length; i++)
{
@@ -282,7 +282,7 @@
* @exception ClassNotPersistenceCapableException thrown if no primary
key is
* specified for the objects class
*/
- protected void checkForPrimaryKeys(Object realObject) throws
ClassNotPersistenceCapableException
+ protected void checkForPrimaryKeys(final Object realObject) throws
ClassNotPersistenceCapableException
{
// if no PKs are specified OJB can't handle this class !
if (m_pkValues == null || m_pkValues.length == 0)
@@ -307,15 +307,15 @@
* Compare this Identity object to any other object. This comparison is
delegated
* to the super-class.
*/
- public boolean equals(Object obj)
+ public boolean equals(final Object obj)
{
if(this == obj) return true;
boolean result = false;
if (obj instanceof org.apache.ojb.broker.Identity)
{
- Identity id = (Identity) obj;
- Object[] otherPkValues = id.getPrimaryKeyValues();
+ final Identity id = (Identity) obj;
+ final Object[] otherPkValues = id.getPrimaryKeyValues();
result =
getObjectsTopLevelClass().equals(id.getObjectsTopLevelClass())
&& (m_pkValues.length == otherPkValues.length);
@@ -351,7 +351,7 @@
*/
if(m_hashCode == null)
{
- HashCodeBuilder hb = new HashCodeBuilder();
+ final HashCodeBuilder hb = new HashCodeBuilder();
for (int i = 0; i < m_pkValues.length; i++)
{
hb.append(m_pkValues[i]);
@@ -369,9 +369,9 @@
return m_hashCode.intValue();
}
- private ClassNotPersistenceCapableException createException(String msg,
Object objectToIdentify, Exception e)
+ private ClassNotPersistenceCapableException createException(String msg,
final Object objectToIdentify, final Exception e)
{
- String eol = SystemUtils.LINE_SEPARATOR;
+ final String eol = SystemUtils.LINE_SEPARATOR;
if(msg == null)
{
msg = "Unexpected error:";
1.2.2.2 +15 -3
db-ojb/src/java/org/apache/ojb/broker/IdentityFactory.java
Index: IdentityFactory.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/IdentityFactory.java,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -u -r1.2.2.1 -r1.2.2.2
--- IdentityFactory.java 27 Jul 2004 00:26:05 -0000 1.2.2.1
+++ IdentityFactory.java 23 Mar 2005 12:39:57 -0000 1.2.2.2
@@ -18,8 +18,8 @@
* with a valid UID before they are written to database - more info see
[EMAIL PROTECTED] org.apache.ojb.broker.Identity}.
* This should be
* used with care, because not all [EMAIL PROTECTED]
org.apache.ojb.broker.util.sequence.SequenceManager}
- * implementations returns the "real" UID value before the object was stored
(e.g. when database based
- * Identity columns were used a temporary placeholder was returned).
+ * implementations return the "real" UID value before the object was stored
(e.g. when database based
+ * Identity columns are used, a temporary placeholder is returned).
*
* @author <a href="mailto:[EMAIL PROTECTED]">Armin Waibel</a>
* @version $Id$
@@ -75,4 +75,16 @@
* @see #buildIdentity(java.lang.Class, java.lang.String[],
java.lang.Object[])
*/
Identity buildIdentity(Class realClass, Object pkValue);
+
+ /**
+ * Create a new [EMAIL PROTECTED] Identity} object based on given
arguments - NOTE: There
+ * will be no check to resolve the order of the PK values. This method
expect
+ * the correct order.
+ *
+ * @param realClass The class of the associated object.
+ * @param topLevelClass The top-level class of the associated object.
+ * @param pkValues The PK values.
+ * @return The a new created <em>Identity</em> object.
+ */
+ Identity buildIdentity(Class realClass, Class topLevelClass, Object[]
pkValues);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]