arminw 2005/02/07 12:42:43
Modified: src/java/org/apache/ojb/broker/cache Tag: OJB_1_0_RELEASE
CacheDistributor.java ObjectCache.java
ObjectCacheInternal.java
ObjectCacheTwoLevelImpl.java
src/java/org/apache/ojb/broker/util Tag: OJB_1_0_RELEASE
BrokerHelper.java
src/java/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
ObjectEnvelope.java ObjectEnvelopeOrdering.java
. Tag: OJB_1_0_RELEASE release-notes.txt
Log:
move new method from ObjectCache to ObjectCacheInternal, this prevent changes
in user-api
fix in ObjectEnvelope, add 'null' in object image if collection is empty
move array/collection handling to BrokerHelper helper-method
Revision Changes Path
No revision
No revision
1.7.2.2 +9 -8
db-ojb/src/java/org/apache/ojb/broker/cache/Attic/CacheDistributor.java
Index: CacheDistributor.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/Attic/CacheDistributor.java,v
retrieving revision 1.7.2.1
retrieving revision 1.7.2.2
diff -u -r1.7.2.1 -r1.7.2.2
--- CacheDistributor.java 23 Jan 2005 03:07:31 -0000 1.7.2.1
+++ CacheDistributor.java 7 Feb 2005 20:42:42 -0000 1.7.2.2
@@ -71,7 +71,7 @@
private Map caches = new HashMap();
private List excludedPackages;
- private PersistenceBroker broker;
+ private final PersistenceBroker broker;
/**
* If <code>true</code> the class name of the object is used
* to find a per class [EMAIL PROTECTED] ObjectCache} implementation.
@@ -83,7 +83,7 @@
/**
* public Default Constructor
*/
- public CacheDistributor(PersistenceBroker broker)
+ public CacheDistributor(final PersistenceBroker broker)
{
this.broker = broker;
this.descriptorBasedCaches =
OjbConfigurator.getInstance().getConfigurationFor(null)
@@ -143,10 +143,10 @@
log.error("Error while call method 'clear()' on '" + oc
+ "'", e);
}
}
- /**
- * then call clear on the caches hashmap.
- */
- caches.clear();
+// /**
+// * then call clear on the caches hashmap.
+// */
+// caches.clear();
}
}
@@ -375,7 +375,8 @@
public boolean cacheIfNew(Identity oid, Object obj)
{
- return cache.cacheIfNew(oid, obj);
+ cache.cache(oid, obj);
+ return true;
}
public Object lookup(Identity oid)
1.9.2.2 +1 -24
db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCache.java
Index: ObjectCache.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCache.java,v
retrieving revision 1.9.2.1
retrieving revision 1.9.2.2
diff -u -r1.9.2.1 -r1.9.2.2
--- ObjectCache.java 23 Jan 2005 03:07:31 -0000 1.9.2.1
+++ ObjectCache.java 7 Feb 2005 20:42:42 -0000 1.9.2.2
@@ -80,27 +80,4 @@
* Clear the cache.
*/
public void clear();
-
- /**
- * For internal use within <em>ObjectCache</em> implementations or to
- * build two-level caches. Handle with care.
- * <p>
- * Used to cache new objects (not already cached) by it's
- * [EMAIL PROTECTED] org.apache.ojb.broker.Identity}. This method was
used to
- * cache new materialized objects and should work as a "atomic" method
- * (the check and the put of the object should be atomic) to avoid
- * concurrency problems.
- * </p>
- * <p>
- * Currently it's not mandatory that all <em>ObjectCache</em>
implementations
- * support this method, so in some cases it's allowed to delegate this
- * method call to the standard [EMAIL PROTECTED]
#cache(org.apache.ojb.broker.Identity, Object) cache}
- * method or throw an [EMAIL PROTECTED] UnsupportedOperationException}.
- * </p>
- *
- * @param oid Identity of the object to cache.
- * @param obj The object to cache.
- * @return If object was added <em>true</em>, else <em>false</em>.
- */
- public boolean cacheIfNew(Identity oid, Object obj);
}
1.1.2.2 +26 -1
db-ojb/src/java/org/apache/ojb/broker/cache/Attic/ObjectCacheInternal.java
Index: ObjectCacheInternal.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/Attic/ObjectCacheInternal.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- ObjectCacheInternal.java 23 Jan 2005 03:07:31 -0000 1.1.2.1
+++ ObjectCacheInternal.java 7 Feb 2005 20:42:42 -0000 1.1.2.2
@@ -43,7 +43,32 @@
public static final int TYPE_UNKNOWN = 0;
/**
+ * For internal use.
* This method have to be used by all OJB classes to cache objects.
+ * It allows to decide if an object should be cached or not. Useful
+ * for two level caches to reduce object copy costs.
*/
public void doInternalCache(Identity oid, Object obj, int type);
+
+ /**
+ * For internal use within <em>ObjectCache</em> implementations or to
+ * build two-level caches. Handle with care.
+ * <p>
+ * Used to cache new objects (not already cached) by it's
+ * [EMAIL PROTECTED] org.apache.ojb.broker.Identity}. This method was
used to
+ * cache new materialized objects and should work as a "atomic" method
+ * (the check and the put of the object should be atomic) to avoid
+ * concurrency problems.
+ * </p>
+ * <p>
+ * Currently it's not mandatory that all <em>ObjectCache</em>
implementations
+ * support this method, so in some cases it's allowed to delegate this
+ * method call to the standard [EMAIL PROTECTED]
#cache(org.apache.ojb.broker.Identity, Object) cache}.
+ * </p>
+ *
+ * @param oid Identity of the object to cache.
+ * @param obj The object to cache.
+ * @return If object was added <em>true</em>, else <em>false</em>.
+ */
+ public boolean cacheIfNew(Identity oid, Object obj);
}
1.1.2.2 +17 -6
db-ojb/src/java/org/apache/ojb/broker/cache/Attic/ObjectCacheTwoLevelImpl.java
Index: ObjectCacheTwoLevelImpl.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/Attic/ObjectCacheTwoLevelImpl.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- ObjectCacheTwoLevelImpl.java 23 Jan 2005 03:07:31 -0000 1.1.2.1
+++ ObjectCacheTwoLevelImpl.java 7 Feb 2005 20:42:42 -0000 1.1.2.2
@@ -102,7 +102,7 @@
// private boolean enabledReadCache;
private int invokeCounter;
private ReferenceQueue queue = new ReferenceQueue();
- private ObjectCache applicationCache;
+ private ObjectCacheInternal applicationCache;
private CopyStrategy copyStrategy;
private PersistenceBrokerImpl broker;
@@ -161,7 +161,14 @@
// this property doesn't make sense in context of two-level
cache
prop.setProperty(ObjectCacheDefaultImpl.AUTOSYNC_PROP,
"false");
}
- this.applicationCache = (ObjectCache)
ClassHelper.newInstance(target, type, objects);
+ ObjectCache temp = (ObjectCache) ClassHelper.newInstance(target,
type, objects);
+ if(!(temp instanceof ObjectCacheInternal))
+ {
+ log.warn("Specified application cache class doesn't
implement '" + ObjectCacheInternal.class.getName()
+ + "'. For best interaction only specify caches
implementing the internal object cache interface.");
+ temp = new CacheDistributor.ObjectCacheInternalWrapper(temp);
+ }
+ this.applicationCache = (ObjectCacheInternal) temp;
}
catch(Exception e)
{
@@ -170,7 +177,7 @@
}
}
- private ObjectCache getApplicationCache()
+ private ObjectCacheInternal getApplicationCache()
{
return applicationCache;
}
@@ -294,7 +301,10 @@
Object result = null;
// 1. lookup an instance in session cache
CacheEntry entry = (CacheEntry) sessionCache.get(oid);
- if(entry != null) result = entry.get();
+ if(entry != null)
+ {
+ result = entry.get();
+ }
if(result == null)
{
result = lookupFromApplicationCache(oid);
@@ -371,7 +381,7 @@
{
if(onlyIfNew)
{
- // no synchronization needed, because session cache was used per
thread
+ // no synchronization needed, because session cache was used per
broker instance
if(!sessionCache.containsKey(oid)) sessionCache.put(oid, entry);
}
else
@@ -411,6 +421,7 @@
}
try
{
+ // we only push "really modified objects" to the application
cache
pushToApplicationCache(TYPE_WRITE, TYPE_CACHED_READ);
}
finally
No revision
No revision
1.57.2.7 +79 -5
db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java
Index: BrokerHelper.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java,v
retrieving revision 1.57.2.6
retrieving revision 1.57.2.7
diff -u -r1.57.2.6 -r1.57.2.7
--- BrokerHelper.java 27 Jan 2005 00:07:17 -0000 1.57.2.6
+++ BrokerHelper.java 7 Feb 2005 20:42:42 -0000 1.57.2.7
@@ -24,8 +24,10 @@
import java.util.Map;
import java.util.StringTokenizer;
import java.util.WeakHashMap;
+import java.util.ArrayList;
import org.apache.commons.collections.iterators.ArrayIterator;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.ojb.broker.Identity;
import org.apache.ojb.broker.ManageableCollection;
import org.apache.ojb.broker.OJBRuntimeException;
@@ -870,8 +872,10 @@
/**
- * Answer the Iterator for Collection or Array.
- * @param collectionOrArray a none null object of type [EMAIL PROTECTED]
java.util.Collection},
+ * Returns an Iterator instance for [EMAIL PROTECTED]
java.util.Collection}, object Array or
+ * [EMAIL PROTECTED] org.apache.ojb.broker.ManageableCollection}
instances.
+ *
+ * @param collectionOrArray a none <em>null</em> object of type [EMAIL
PROTECTED] java.util.Collection},
* Array or [EMAIL PROTECTED]
org.apache.ojb.broker.ManageableCollection}.
* @return Iterator able to handle given collection object
*/
@@ -892,9 +896,79 @@
}
else
{
- throw new OJBRuntimeException( "Given object collection of type
" + collectionOrArray.getClass()
- + " can not be managed by OJB. Use Array, Collection or
ManageableCollection instead!");
+ throw new OJBRuntimeException( "Given object collection of type
'"
+ + (collectionOrArray != null ?
collectionOrArray.getClass().toString() : "null")
+ + "' can not be managed by OJB. Use Array, Collection or
ManageableCollection instead!");
}
return colIterator;
}
+
+ /**
+ * Returns an object array for [EMAIL PROTECTED] java.util.Collection},
array or
+ * [EMAIL PROTECTED] org.apache.ojb.broker.ManageableCollection}
instances.
+ *
+ * @param collectionOrArray a none <em>null</em> object of type [EMAIL
PROTECTED] java.util.Collection},
+ * Array or [EMAIL PROTECTED]
org.apache.ojb.broker.ManageableCollection}.
+ * @return Object array able to handle given collection or array object
+ */
+ public static Object[] getCollectionArray(Object collectionOrArray)
+ {
+ Object[] result = null;
+ if (collectionOrArray instanceof Collection)
+ {
+ result = ((Collection) collectionOrArray).toArray();
+ }
+ else if (collectionOrArray instanceof ManageableCollection)
+ {
+ Collection newCol = new ArrayList();
+ CollectionUtils.addAll(newCol, ((ManageableCollection)
collectionOrArray).ojbIterator());
+ result = newCol.toArray();
+ }
+ else if (collectionOrArray.getClass().isArray())
+ {
+ result = (Object[]) collectionOrArray;
+ }
+ else
+ {
+ throw new OJBRuntimeException( "Given object collection of type
'"
+ + (collectionOrArray != null ?
collectionOrArray.getClass().toString() : "null")
+ + "' can not be managed by OJB. Use Array, Collection or
ManageableCollection instead!");
+ }
+ return result;
+ }
+
+// /**
+// * Returns a [EMAIL PROTECTED] java.util.List} instance of the
specified object in method argument,
+// * in which the argument must be of type [EMAIL PROTECTED]
java.util.Collection}, array or
+// * [EMAIL PROTECTED] org.apache.ojb.broker.ManageableCollection}.
+// *
+// * @param collectionOrArray a none <em>null</em> object of type [EMAIL
PROTECTED] java.util.Collection},
+// * Array or [EMAIL PROTECTED]
org.apache.ojb.broker.ManageableCollection}.
+// * @return Object array able to handle given collection or array object
+// */
+// public static List getCollectionList(Object collectionOrArray)
+// {
+// List result = null;
+// if (collectionOrArray instanceof Collection)
+// {
+// result = ((Collection) collectionOrArray).toArray();
+// }
+// else if (collectionOrArray instanceof ManageableCollection)
+// {
+// Collection newCol = new ArrayList();
+// CollectionUtils.addAll(newCol, ((ManageableCollection)
collectionOrArray).ojbIterator());
+// result = newCol.toArray();
+// }
+// else if (collectionOrArray.getClass().isArray())
+// {
+// result = (Object[]) collectionOrArray;
+// }
+// else
+// {
+// throw new OJBRuntimeException( "Given object collection of
type '"
+// + (collectionOrArray != null ?
collectionOrArray.getClass().toString() : "null")
+// + "' can not be managed by OJB. Use Array, Collection or
ManageableCollection instead!");
+// }
+// return result;
+// }
}
No revision
No revision
1.32.2.5 +6 -3 db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelope.java
Index: ObjectEnvelope.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelope.java,v
retrieving revision 1.32.2.4
retrieving revision 1.32.2.5
diff -u -r1.32.2.4 -r1.32.2.5
--- ObjectEnvelope.java 16 Nov 2004 17:45:35 -0000 1.32.2.4
+++ ObjectEnvelope.java 7 Feb 2005 20:42:42 -0000 1.32.2.5
@@ -312,9 +312,12 @@
{
referencesId = Arrays.asList((Object[])
collectionOrArray);
}
-
fieldValues.put(collectionDescriptor, referencesId);
}
+ else
+ {
+ fieldValues.put(collectionDescriptor, null);
+ }
}
return fieldValues;
}
@@ -483,7 +486,7 @@
*/
private void markDelete(Collection oldCol, Collection newCol)
{
- if (oldCol == null)
+ if (oldCol == null || oldCol.size() == 0)
{
return;
}
@@ -516,7 +519,7 @@
while (newIter.hasNext())
{
Object newObj = newIter.next();
- if ((oldCol != null) && (!oldCol.contains(newObj)))
+ if ((oldCol == null) || (!oldCol.contains(newObj)))
{
ObjectEnvelope mod = buffer.get(newObj, true);
mod.setModificationState(mod.getModificationState().markNew());
1.1.2.3 +5 -28
db-ojb/src/java/org/apache/ojb/odmg/Attic/ObjectEnvelopeOrdering.java
Index: ObjectEnvelopeOrdering.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/odmg/Attic/ObjectEnvelopeOrdering.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- ObjectEnvelopeOrdering.java 21 Nov 2004 09:26:23 -0000 1.1.2.2
+++ ObjectEnvelopeOrdering.java 7 Feb 2005 20:42:42 -0000 1.1.2.3
@@ -16,21 +16,18 @@
*/
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import org.apache.commons.collections.CollectionUtils;
import org.apache.ojb.broker.Identity;
-import org.apache.ojb.broker.ManageableCollection;
-import org.apache.ojb.broker.OJBRuntimeException;
import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.core.proxy.ProxyHelper;
import org.apache.ojb.broker.metadata.ClassDescriptor;
import org.apache.ojb.broker.metadata.CollectionDescriptor;
import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
+import org.apache.ojb.broker.util.BrokerHelper;
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
import org.apache.ojb.odmg.states.ModificationState;
@@ -126,7 +123,7 @@
// set up the vertex array in the order the envelopes were added
List vertexList = new ArrayList(originalOrder.size());
- int vertexIndex = 0;
+ // int vertexIndex = 0;
for (Iterator it = originalOrder.iterator(); it.hasNext();)
{
ObjectEnvelope envelope = (ObjectEnvelope)
envelopes.get(it.next());
@@ -272,7 +269,7 @@
for (int i = 0; i < vertices.length; i++)
{
Edge edge = null;
- ObjectEnvelope envelope = vertex.getEnvelope();
+ // ObjectEnvelope envelope = vertex.getEnvelope();
Vertex refVertex = vertices[i];
ObjectEnvelope refEnvelope = refVertex.getEnvelope();
if (refObject == refEnvelope.getObject())
@@ -315,27 +312,7 @@
}
else
{
- if (col instanceof ManageableCollection)
- {
- Collection newCol = new ArrayList();
- CollectionUtils.addAll(newCol, ((ManageableCollection)
col).ojbIterator());
-
- refObjects = newCol.toArray();
- }
- else if (col instanceof Collection)
- {
- refObjects = ((Collection) col).toArray();
-
- }
- else if (col instanceof Object[])
- {
- refObjects = (Object[]) col;
- }
- else
- {
- throw new OJBRuntimeException("Given object collection of
type " + col.getClass()
- + " can not be managed by OJB. Use Array, Collection
or ManageableCollection instead!");
- }
+ refObjects = BrokerHelper.getCollectionArray(col);
}
Class refClass = cds.getItemClass();
No revision
No revision
1.54.2.24 +13 -13 db-ojb/release-notes.txt
Index: release-notes.txt
===================================================================
RCS file: /home/cvs/db-ojb/release-notes.txt,v
retrieving revision 1.54.2.23
retrieving revision 1.54.2.24
diff -u -r1.54.2.23 -r1.54.2.24
--- release-notes.txt 23 Jan 2005 03:09:14 -0000 1.54.2.23
+++ release-notes.txt 7 Feb 2005 20:42:43 -0000 1.54.2.24
@@ -25,20 +25,21 @@
J2SE 1.4. Use instead the version of Sun's J2EE reference implementation
that
correspond to your J2SE version. E.g. for J2SE 1.3 use the J2EE 1.3 SDK
which
you can get from here: http://java.sun.com/j2ee/1.3/index.jsp
-- ODMG-api improved, up to 30% better performance
- Performance improvement in handling of m:n relations
- Add new property 'sequenceStart' for SequenceManagerHighLowImpl and
SequeceManagerInMemoryImpl
+ more info see docs section 'sequence manager'
- Recommended to read the updated 'object cache' reference guide to reflect
on the changes made in
caching behavior.
CHANGES:
- Minor changes in the repository.dtd. Add element object-cache to metadata
interface and abstract class
- declaration in class-descriptor.
+ declaration in class-descriptor. So replacement of old repository.dtd is
needed.
- Remove object-cache declaration from OJB.properties file. Use the
'object-cache' element in
- repository file (example see repository_database.xml file shipped with
OJB) to set the cache.
- More detailed information see caching reference guide in docs.
-- Remove redundant ObjectCache implementations.
-- Remove undocumented 'ObjectCacheFilter' to filter out whole packages or
classes from being cached.
+ repository file (example see repository_database.xml file shipped with
OJB) to specify the cache
+ implementation. More detailed information see caching reference guide in
docs.
+- Remove redundant ObjectCache implementations (ObjectCacheSoftImpl,
ObjectCacheUnlimitiedImpl), same
+ behavior is possible with ObjectCacheDefaultImpl.
+- Remove undocumented 'ObjectCacheFilter' (used to filter out whole packages
or classes from being cached).
Filter out packages or classes is still possible, please see 'object
cache' reference guide.
- !!!In managed enviroments the org.odmg.Transaction#abort() call no longer
throws an
TransactionAbortedExceptionOJB, instead OJB does internal cleanup and set
used
@@ -49,17 +50,16 @@
associated class were performed in RowReader instead invoking all fields
of the table used by
the mapped classes.
- Introduce new locking-package in kernel api, adapt odmg-locking stuff and
remove unused
- classes from org.apache.ojb.odmg.locking package.
+ classes from org.apache.ojb.odmg.locking package. Adapt own LockMap
implementations to new
+ package of LockMap.
- Use of database identity column (SequenceManagerNativeImpl). Move assign
of PK values from
PersistenceBrokerImpl to JdbcAccessImpl#executeInsert. Remove usage of
SequenceManager#setReferenceFKs,
will be handled by OJB in same way as without usage of database identity
column.
- Method signature changes in
- org.apache.ojb.broker.locking.LockMap#removeWriter/Reader. Take care when
using own
- LockMap implementations.
-- odmg-api: Introduced new object reodering implementation (replaces old
algorithm
+ org.apache.ojb.broker.locking.LockMap#removeWriter/Reader. Adapt own
LockMap implementations.
+- odmg-api: Introduced new object reordering implementation (replaces old
algorithm
in ObjectEnvelopeTable).
-- Remove redundant ObjectCache implementations (ObjectCacheSoftImpl,
ObjectCacheUnlimitiedImpl), same
- behavior is possible with ObjectCacheDefaultImpl.
+
BUG FIXES:
Please refer to our Bug tracking site
(http://issues.apache.org/scarab/servlet/scarab/)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]