labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simo...@apache.org
Subject svn commit: r1135415 - /labs/magma/trunk/database-mongodb/src/main/java/org/apache/magma/database/mongo/Transaction.java
Date Tue, 14 Jun 2011 08:55:21 GMT
Author: simoneg
Date: Tue Jun 14 08:55:20 2011
New Revision: 1135415

URL: http://svn.apache.org/viewvc?rev=1135415&view=rev
Log:
Cache per collection

Modified:
    labs/magma/trunk/database-mongodb/src/main/java/org/apache/magma/database/mongo/Transaction.java

Modified: labs/magma/trunk/database-mongodb/src/main/java/org/apache/magma/database/mongo/Transaction.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/database-mongodb/src/main/java/org/apache/magma/database/mongo/Transaction.java?rev=1135415&r1=1135414&r2=1135415&view=diff
==============================================================================
--- labs/magma/trunk/database-mongodb/src/main/java/org/apache/magma/database/mongo/Transaction.java
(original)
+++ labs/magma/trunk/database-mongodb/src/main/java/org/apache/magma/database/mongo/Transaction.java
Tue Jun 14 08:55:20 2011
@@ -83,7 +83,8 @@ public class Transaction {
 	
 	
 	public <T extends MongoEntity> T checkCache(Class<T> clazz, String id) {
-		T ret = (T) mainCache.get(id);
+		String collname = getCollectionName(clazz);
+		T ret = (T) mainCache.get(collname + "/" + id);
 		if (ret != null) return ret;
 		String mainid = subsCache.get(id);
 		if (mainid == null) return null;
@@ -95,21 +96,26 @@ public class Transaction {
 		return ret;
 	}
 	
-	public void cache(String id, MongoEntity obj) {		
-		mainCache.put(id, obj);
+	public <T extends MongoEntity> void cache(Class<T> clazz, String id, MongoEntity
obj) {
+		String collname = getCollectionName(clazz);
+		String okid = collname + "/" + id;
+		mainCache.put(okid, obj);
 		List<String> subIds = obj.getSubIds();
 		for (String subid : subIds) {
-			subsCache.put(subid, id);
+			subsCache.put(subid, okid);
 		}
 	}		
 	
+	private <T extends MongoEntity> String getCollectionName(Class<T> clazz) {
+		BeanData bd = BeanData.getFor(clazz);
+		return bd.getJpaTableName();
+	}
+	
 	
 	private <T extends MongoEntity> MongoCollection getCollection(Class<T> clazz)
{
-		BeanData bd = BeanData.getFor(clazz);
-		
-		String tn = bd.getJpaTableName();
-		return getCollection(tn);
+		return getCollection(getCollectionName(clazz));
 	}	
+	
 	private MongoCollection getCollection(String tn) {
 		String dbname = db.getDefdb();
 		if (tn.indexOf('.') > 1) {
@@ -139,7 +145,7 @@ public class Transaction {
 				ret = (T)MongoUtils.convertToObject(clazz, one);
 				ret.setFromDb(true);
 			}
-			cache(id, ret);
+			cache(clazz, id, ret);
 		}
 		if (ret == NOTFOUND) {
 			return null;
@@ -180,7 +186,7 @@ public class Transaction {
 					obj.setFromDb(true);
 					String oid = (String)dbo.get("_id");
 					retids.add(oid);
-					cache(oid, obj);
+					cache(clazz, oid, obj);
 					ret.add(obj);
 				}
 			} finally {
@@ -607,7 +613,7 @@ public class Transaction {
 		subent.setFromDb(main.isFromDb());
 		subent.joined(main);
 		String oid = (String)subobj.get("_id");
-		cache(oid, subent);
+		cache(clazz, oid, subent);
 		
 		return subent;
 	}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message