Return-Path:
Delivered-To: apmail-db-ojb-dev-archive@www.apache.org
Received: (qmail 54042 invoked from network); 4 Aug 2004 00:12:47 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199)
by minotaur-2.apache.org with SMTP; 4 Aug 2004 00:12:47 -0000
Received: (qmail 45643 invoked by uid 500); 4 Aug 2004 00:12:45 -0000
Delivered-To: apmail-db-ojb-dev-archive@db.apache.org
Received: (qmail 45412 invoked by uid 500); 4 Aug 2004 00:12:43 -0000
Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm
Precedence: bulk
List-Unsubscribe:
List-Subscribe:
List-Help:
List-Post:
List-Id: "OJB Developers List"
Reply-To: "OJB Developers List"
Delivered-To: mailing list ojb-dev@db.apache.org
Received: (qmail 45399 invoked by uid 500); 4 Aug 2004 00:12:42 -0000
Received: (qmail 45393 invoked by uid 99); 4 Aug 2004 00:12:42 -0000
X-ASF-Spam-Status: No, hits=0.5 required=10.0
tests=ALL_TRUSTED,NO_REAL_NAME
X-Spam-Check-By: apache.org
Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194)
by apache.org (qpsmtpd/0.27.1) with SMTP; Tue, 03 Aug 2004 17:12:42 -0700
Received: (qmail 53980 invoked by uid 1510); 4 Aug 2004 00:12:41 -0000
Date: 4 Aug 2004 00:12:41 -0000
Message-ID: <20040804001241.53979.qmail@minotaur.apache.org>
From: arminw@apache.org
To: db-ojb-cvs@apache.org
Subject: cvs commit: db-ojb/src/test/org/apache/ojb repository_database.xml
X-Virus-Checked: Checked
X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N
arminw 2004/08/03 17:12:41
Modified: src/doc/forrest/src/documentation/content/xdocs/docu/guides
objectcache.xml
src/java/org/apache/ojb/broker/cache
ObjectCacheDefaultImpl.java
src/test/org/apache/ojb repository_database.xml
Log:
add new flag for ObjectCacheDefaultImpl, allows to determine how
the used key for cached objects will be build.
Revision Changes Path
1.2 +19 -2 db-ojb/src/doc/forrest/src/documentation/content/xdocs/docu/guides/objectcache.xml
Index: objectcache.xml
===================================================================
RCS file: /home/cvs/db-ojb/src/doc/forrest/src/documentation/content/xdocs/docu/guides/objectcache.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- objectcache.xml 20 Jun 2004 09:12:33 -0000 1.1
+++ objectcache.xml 4 Aug 2004 00:12:41 -0000 1.2
@@ -295,11 +295,28 @@
+
+ cachingKeyType |
+
+ Determines how the key was build for the cached objects:
+
+ 0 - Identity object was used as key, this was the default setting.
+
+ 1 - Idenity + jcdAlias name was used as key. Useful when the same object metadata model
+ (DescriptorRepository instance) are used for different databases (JdbcConnectionDescriptor)
+
+ 2 - Identity + model (DescriptorRepository) was used as key. Useful when different metadata
+ model (DescriptorRepository instance) are used for the same database. Keep in mind that there
+ was no synchronization between cached objects with same Identity but different metadata model.
+
+ 3 - all together (Idenity + jcdAlias + model)
+ |
+
- Recommendation:
+ Recommendation:
If you take care of cache synchronization and be aware of dirty
reads, this implementation is useful for read-only or less update
centric classes.
1.25 +64 -8 db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheDefaultImpl.java
Index: ObjectCacheDefaultImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheDefaultImpl.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- ObjectCacheDefaultImpl.java 11 Jun 2004 22:04:47 -0000 1.24
+++ ObjectCacheDefaultImpl.java 4 Aug 2004 00:12:41 -0000 1.25
@@ -26,10 +26,12 @@
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
+import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.ojb.broker.Identity;
import org.apache.ojb.broker.PBStateEvent;
import org.apache.ojb.broker.PBStateListener;
import org.apache.ojb.broker.PersistenceBroker;
+import org.apache.ojb.broker.OJBRuntimeException;
import org.apache.ojb.broker.util.logging.LoggerFactory;
/**
@@ -50,11 +52,13 @@
* Implementation configuration properties:
*
*
+ *
*
*
* Property Key |
* Property Values |
*
+ *
*
* timeout |
*
@@ -69,6 +73,7 @@
*
* |
*
+ *
*
* autoSync |
*
@@ -90,6 +95,24 @@
*
* |
*
+ *
+ *
+ * cachingKeyType |
+ *
+ * Determines how the key was build for the cached objects:
+ *
+ * 0 - Identity object was used as key, this was the default setting.
+ *
+ * 1 - Idenity + jcdAlias name was used as key. Useful when the same object metadata model
+ * (DescriptorRepository instance) are used for different databases (JdbcConnectionDescriptor)
+ *
+ * 2 - Identity + model (DescriptorRepository) was used as key. Useful when different metadata
+ * model (DescriptorRepository instance) are used for the same database. Keep in mind that there
+ * was no synchronization between cached objects with same Identity but different metadata model.
+ *
+ * 3 - all together (1+2)
+ * |
+ *
*
*
*
@@ -101,6 +124,7 @@
{
public static final String TIMEOUT_PROP = "timeout";
public static final String AUTOSYNC_PROP = "autoSync";
+ public static final String CACHING_KEY_TYPE_PROP = "cachingKeyType";
/**
* static Map held all cached objects
*/
@@ -120,12 +144,21 @@
private long timeout = 1000 * 60 * 15;
/**
- *
+ * Determines how the key was build for the cached objects:
+ *
+ * 0 - Identity object was used as key
+ * 1 - Idenity + jcdAlias name was used as key
+ * 2 - Identity + model (DescriptorRepository) was used as key
+ * 3 - all together (1+2)
*/
+ private int cachingKeyType;
+
+
public ObjectCacheDefaultImpl(PersistenceBroker broker, Properties prop)
{
this.broker = broker;
timeout = prop == null ? timeout : (Long.parseLong(prop.getProperty(TIMEOUT_PROP, "" + (60 * 15))) * 1000);
+ cachingKeyType = prop == null ? 0 : (Integer.parseInt(prop.getProperty(CACHING_KEY_TYPE_PROP, "0")));
useAutoSync = prop == null ?
false : (Boolean.valueOf((prop.getProperty(AUTOSYNC_PROP, "false")).trim())).booleanValue();
@@ -163,7 +196,7 @@
if ((obj != null))
{
traceIdentity(oid);
- objectTable.put(oid, new CacheEntry(obj, oid, queue));
+ objectTable.put(buildKey(oid), new CacheEntry(obj, oid, queue));
}
}
@@ -177,8 +210,8 @@
hitCount++;
Object result = null;
- CacheEntry entry = (CacheEntry) objectTable.get(oid);
- if (entry != null)
+ CacheEntry entry = (CacheEntry) objectTable.get(buildKey(oid));
+ if (entry != null && entry.oid.getObjectsTopLevelClass().equals(oid.getObjectsTopLevelClass()))
{
result = entry.get();
if (result == null || entry.lifetime < System.currentTimeMillis())
@@ -217,7 +250,7 @@
if (oid != null)
{
removeTracedIdentity(oid);
- objectTable.remove(oid);
+ objectTable.remove(buildKey(oid));
}
}
@@ -257,8 +290,31 @@
for (Iterator iterator = identitiesInWork.iterator(); iterator.hasNext();)
{
oid = (Identity) iterator.next();
- objectTable.remove(oid);
+ objectTable.remove(buildKey(oid));
+ }
+ }
+
+ private Integer buildKey(Identity oid)
+ {
+ int key = 0;
+ switch(cachingKeyType)
+ {
+ case 0:
+ key = oid.hashCode();
+ break;
+ case 1:
+ key = new HashCodeBuilder().append(broker.getPBKey().getAlias().hashCode()).append(oid.hashCode()).toHashCode();
+ break;
+ case 2:
+ key = new HashCodeBuilder().append(broker.getDescriptorRepository().hashCode()).append(oid.hashCode()).toHashCode();
+ break;
+ case 3:
+ key = new HashCodeBuilder().append(broker.getDescriptorRepository().hashCode()).append(broker.getPBKey().getAlias().hashCode()).append(oid.hashCode()).toHashCode();
+ break;
+ default:
+ throw new OJBRuntimeException("Unexpected error, 'cacheType ="+cachingKeyType+"' was not supported");
}
+ return new Integer(key);
}
public void beforeRollback(PBStateEvent event)
@@ -302,7 +358,7 @@
while ((sv = (CacheEntry) queue.poll()) != null)
{
removeTracedIdentity(sv.oid);
- objectTable.remove(sv.oid); // we can access private data!
+ objectTable.remove(buildKey(sv.oid)); // we can access private data!
}
}
1.24 +2 -1 db-ojb/src/test/org/apache/ojb/repository_database.xml
Index: repository_database.xml
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_database.xml,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- repository_database.xml 29 Jun 2004 17:20:04 -0000 1.23
+++ repository_database.xml 4 Aug 2004 00:12:41 -0000 1.24
@@ -49,6 +49,7 @@
+