openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r708980 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/datacache/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/ openjpa-project/src/doc/manual/
Date Wed, 29 Oct 2008 19:06:59 GMT
Author: faywang
Date: Wed Oct 29 12:06:58 2008
New Revision: 708980

URL: http://svn.apache.org/viewvc?rev=708980&view=rev
Log:
OPENJPA-738: query cache performance improvement. Commit 
the change in OPENJPA-738.11.patch on behalf of Sandhya 
Turaga.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/ConcurrentQueryCache.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Part.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/PartBase.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/PartComposite.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Supplier.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Usage.java
    openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_caching.xml

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java?rev=708980&r1=708979&r2=708980&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java
Wed Oct 29 12:06:58 2008
@@ -58,6 +58,8 @@
     private static final Localizer s_loc =
         Localizer.forPackage(AbstractQueryCache.class);
 
+    private static final String TIMESTAMP = "timestamp";
+    public enum EvictPolicy {DEFAULT, TIMESTAMP};
     /**
      * The configuration set by the system.
      */
@@ -70,11 +72,11 @@
 
     protected ConcurrentHashMap<String,Long> entityTimestampMap = null;
     private boolean _closed = false;
-
-    protected String evictPolicy = "default";
+    // default evict policy
+    public EvictPolicy evictPolicy = EvictPolicy.DEFAULT;
 
     public void initialize(DataCacheManager manager) {
-        if(evictPolicy.equalsIgnoreCase("timestamp")) {
+        if (evictPolicy == EvictPolicy.TIMESTAMP) {
             entityTimestampMap = new ConcurrentHashMap<String,Long>();
         
             // Get all persistence types to pre-load the entityTimestamp Map
@@ -94,7 +96,7 @@
     public void onTypesChanged(TypesChangedEvent ev) {
         writeLock();
         Collection keys = null;
-        if (!evictPolicy.equalsIgnoreCase("timestamp")) {
+        if (evictPolicy == EvictPolicy.DEFAULT) {
             try {
                 if (hasListeners())
                     fireEvent(ev);
@@ -126,7 +128,7 @@
                         new Long(System.currentTimeMillis()));
             }           
             // Now update entity timestamp map
-            updateEntityTimestampMap(changedClasses);
+            updateEntityTimestamp(changedClasses);
         }
     }
 
@@ -362,22 +364,23 @@
      * @param evictPolicy -- String value that specifies the eviction policy
      */
     public void setEvictPolicy(String evictPolicy) {
-        this.evictPolicy = evictPolicy;
+        if (evictPolicy.equalsIgnoreCase(TIMESTAMP))
+            this.evictPolicy = EvictPolicy.TIMESTAMP;
     }
 
     /**
      * Returns the evictionPolicy for QueryCache
      * @return -- returns a String value of evictPolicy attribute
      */
-    public String getEvictPolicy() {
-        return null;
+    public EvictPolicy getEvictPolicy() {
+        return this.evictPolicy;
     }
 
     /**
      * Updates the entity timestamp map with the current time in milliseconds
      * @param timestampMap -- a map that contains entityname and its last updated timestamp
      */
-    protected void updateEntityTimestampMap(Map<String,Long> timestampMap) {
+    protected void updateEntityTimestamp(Map<String,Long> timestampMap) {
         if (entityTimestampMap != null)
             entityTimestampMap.putAll(timestampMap);
      }
@@ -389,7 +392,7 @@
      * @param keyList -- List of entity names 
      * @return -- Returns a list that has the timestamp for the given entities
      */
-    public List<Long> getAllEntityTimestampFromMap(List<String> keyList) { 
+    public List<Long> getAllEntityTimestamp(List<String> keyList) { 
         ArrayList<Long> tmval = null;
         if (entityTimestampMap != null) {
             for (String s: keyList) {

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/ConcurrentQueryCache.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/ConcurrentQueryCache.java?rev=708980&r1=708979&r2=708980&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/ConcurrentQueryCache.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/ConcurrentQueryCache.java
Wed Oct 29 12:06:58 2008
@@ -141,7 +141,7 @@
     /**
      * Returns the eviction policy of the query cache
      */
-    public String getEvictPolicy() {
+    public EvictPolicy getEvictPolicy() {
         return super.evictPolicy;
     }
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java?rev=708980&r1=708979&r2=708980&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java
Wed Oct 29 12:06:58 2008
@@ -32,6 +32,7 @@
 import java.util.TreeMap;
 
 import org.apache.commons.collections.map.LinkedMap;
+import org.apache.openjpa.datacache.AbstractQueryCache.EvictPolicy;
 import org.apache.openjpa.kernel.FetchConfiguration;
 import org.apache.openjpa.kernel.LockLevels;
 import org.apache.openjpa.kernel.OpenJPAStateManager;
@@ -127,13 +128,13 @@
         // this if block is invoked if the evictOnTimestamp is set to true
         if (_cache instanceof AbstractQueryCache) {
             AbstractQueryCache qcache = (AbstractQueryCache) _cache;
-            if (qcache.getEvictPolicy().equalsIgnoreCase("timestamp")) {
+            if (qcache.getEvictPolicy() == EvictPolicy.TIMESTAMP) {
                 Set<String> classNames = qk.getAcessPathClassNames();
                 List<String> keyList = new ArrayList<String>();      
                 keyList.addAll(classNames);
 
                 List<Long> timestamps = 
-                    qcache.getAllEntityTimestampFromMap(keyList);
+                    qcache.getAllEntityTimestamp(keyList);
                 long queryTS = res.getTimestamp();
                 if (timestamps != null) {
                     for (Long ts: timestamps) {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Part.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Part.java?rev=708980&r1=708979&r2=708980&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Part.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Part.java
Wed Oct 29 12:06:58 2008
@@ -40,42 +40,41 @@
 
 @DataCache
 abstract public class Part {
-	
-	@Id  int partno;
-	@Column(length=20)
-	String name;
-	int inventory;
-	
-	@OneToMany(mappedBy="child",cascade=CascadeType.PERSIST)
-	protected Collection<Usage> usedIn = new ArrayList<Usage>();
-	
-	@Version
-	long version;
-	
-	
-	public String getName() {
-		return name;
-	}
-	public void setName(String name) {
-		this.name = name;
-	}
-	public int getPartno() {
-		return partno;
-	}
-	public void setPartno(int partno) {
-		this.partno = partno;
-	}
-	public Collection<Usage> getUsedIn() {
-		return usedIn;
-	}
-	public void setUsedIn(Collection<Usage> usedIn) {
-		this.usedIn = usedIn;
-	}
-	public int getInventory() {
-		return inventory;
-	}
-	public void setInventory(int inventory) {
-		this.inventory = inventory;
-	}
 
+    @Id  int partno;
+    @Column(length=20)
+    String name;
+    int inventory;
+
+    @OneToMany(mappedBy="child",cascade=CascadeType.PERSIST)
+    protected Collection<Usage> usedIn = new ArrayList<Usage>();
+
+    @Version
+    long version;
+
+
+    public String getName() {
+        return name;
+    }
+    public void setName(String name) {
+        this.name = name;
+    }
+    public int getPartno() {
+        return partno;
+    }
+    public void setPartno(int partno) {
+        this.partno = partno;
+    }
+    public Collection<Usage> getUsedIn() {
+        return usedIn;
+    }
+    public void setUsedIn(Collection<Usage> usedIn) {
+        this.usedIn = usedIn;
+    }
+    public int getInventory() {
+        return inventory;
+    }
+    public void setInventory(int inventory) {
+        this.inventory = inventory;
+    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/PartBase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/PartBase.java?rev=708980&r1=708979&r2=708980&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/PartBase.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/PartBase.java
Wed Oct 29 12:06:58 2008
@@ -30,64 +30,64 @@
 @Entity
 @DataCache
 public class PartBase extends Part  {
-	
-	 double cost;
-	 double mass;
-	 int backOrder;
-	
-	@ManyToMany(mappedBy="supplies")
-	protected List<Supplier> suppliers = new ArrayList<Supplier>();
-	
-	public PartBase() {}
-	
-  public PartBase(int partno, String name, double cost, double mass){
-  	this.partno=partno;
-  	this.name = name;
-  	this.cost = cost;
-  	this.mass= mass;
-  	this.backOrder=0;
-  	this.inventory=0;
-  }
-
-	public double getCost() {
-		return cost;
-	}
-
-	public void setCost(double cost) {
-		this.cost = cost;
-	}
-
-	public double getMass() {
-		return mass;
-	}
-
-	public void setMass(double mass) {
-		this.mass = mass;
-	}
-
-	public Collection<Supplier> getSuppliers() {
-		return suppliers;
-	}
-
-	public void setSuppliers(List<Supplier> suppliers) {
-		this.suppliers = suppliers;
-	}
-	
-	public String toString() {
-		String sup= "";
-		if (getSuppliers()!=null)
-			for (Supplier s : getSuppliers()){
-				sup= sup+s.sid+",";
-			}
-		return "PartBase:"+partno+" name:+"+name+" cost:"+cost+" mass:"+mass+" supplies=["+sup+"]";
-	}
-
-	public int getBackOrder() {
-		return backOrder;
-	}
-
-	public void setBackOrder(int backOrder) {
-		this.backOrder = backOrder;
-	}
 
+    double cost;
+    double mass;
+    int backOrder;
+
+    @ManyToMany(mappedBy="supplies")
+    protected List<Supplier> suppliers = new ArrayList<Supplier>();
+
+    public PartBase() {}
+
+    public PartBase(int partno, String name, double cost, double mass){
+        this.partno=partno;
+        this.name = name;
+        this.cost = cost;
+        this.mass= mass;
+        this.backOrder=0;
+        this.inventory=0;
+    }
+
+    public double getCost() {
+        return cost;
+    }
+
+    public void setCost(double cost) {
+        this.cost = cost;
+    }
+
+    public double getMass() {
+        return mass;
+    }
+
+    public void setMass(double mass) {
+        this.mass = mass;
+    }
+
+    public Collection<Supplier> getSuppliers() {
+        return suppliers;
+    }
+
+    public void setSuppliers(List<Supplier> suppliers) {
+        this.suppliers = suppliers;
+    }
+
+    public String toString() {
+        String sup= "";
+        if (getSuppliers()!=null)
+            for (Supplier s : getSuppliers()){
+                sup= sup+s.sid+",";
+            }
+        return "PartBase:"+partno+" name:+"+name+" cost:"+cost+" mass:"+
+            mass+" supplies=["+sup+"]";
+    }
+
+    public int getBackOrder() {
+        return backOrder;
+    }
+
+    public void setBackOrder(int backOrder) {
+        this.backOrder = backOrder;
+    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/PartComposite.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/PartComposite.java?rev=708980&r1=708979&r2=708980&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/PartComposite.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/PartComposite.java
Wed Oct 29 12:06:58 2008
@@ -32,65 +32,65 @@
 @DataCache
 public class PartComposite extends  Part  {
 
-	 double assemblyCost;
-	 double assemblyTime;
-	 double massIncrement;
-	 
-	 @OneToMany( mappedBy="parent")
-	 Collection<Usage> partsUsed = new ArrayList<Usage>();
-	
-	public PartComposite() {}
-	
-	public PartComposite(int partno, String name, double asmCost, double massInc) {
-		this.partno=partno;
-		this.name=name;
-		assemblyCost=asmCost;
-		massIncrement=massInc;
-		inventory=0;
-	}
-	
-	public PartComposite addSubPart(EntityManager em,  int quantity, Part subpart) {
-		Usage use = new Usage( this, quantity, subpart);
-		em.persist(use);
-		return this;
-	}
-
-	public double getAssemblyCost() {
-		return assemblyCost;
-	}
-
-	public void setAssemblyCost(double assemblyCost) {
-		this.assemblyCost = assemblyCost;
-	}
-
-
-	public double getMassIncrement() {
-		return massIncrement;
-	}
-
-	public void setMassIncrement(double massIncrement) {
-		this.massIncrement = massIncrement;
-	}
-	
-	public String toString() {
-	
-		return "PartComposite:"+partno+" name:+"+name+" assemblyCost:"+assemblyCost+" massIncrement:"+massIncrement;
-	}
-
-	public Collection<Usage> getPartsUsed() {
-		return partsUsed;
-	}
-
-	public void setPartsUsed(Collection<Usage> partsUsed) {
-		this.partsUsed = partsUsed;
-	}
-
-	public double getAssemblyTime() {
-		return assemblyTime;
-	}
-
-	public void setAssemblyTime(double assemblyTime) {
-		this.assemblyTime = assemblyTime;
-	}
-
+    double assemblyCost;
+    double assemblyTime;
+    double massIncrement;
+
+    @OneToMany( mappedBy="parent")
+    Collection<Usage> partsUsed = new ArrayList<Usage>();
+
+    public PartComposite() {}
+
+    public PartComposite(int partno, String name, double asmCost, double massInc) {
+        this.partno=partno;
+        this.name=name;
+        assemblyCost=asmCost;
+        massIncrement=massInc;
+        inventory=0;
+    }
+
+    public PartComposite addSubPart(EntityManager em,  int quantity, Part subpart) {
+        Usage use = new Usage( this, quantity, subpart);
+        em.persist(use);
+        return this;
+    }
+
+    public double getAssemblyCost() {
+        return assemblyCost;
+    }
+
+    public void setAssemblyCost(double assemblyCost) {
+        this.assemblyCost = assemblyCost;
+    }
+
+
+    public double getMassIncrement() {
+        return massIncrement;
+    }
+
+    public void setMassIncrement(double massIncrement) {
+        this.massIncrement = massIncrement;
+    }
+
+    public String toString() {
+
+        return "PartComposite:"+partno+" name:+"+name+" assemblyCost:"+
+            assemblyCost+" massIncrement:"+massIncrement;
+    }
+
+    public Collection<Usage> getPartsUsed() {
+        return partsUsed;
+    }
+
+    public void setPartsUsed(Collection<Usage> partsUsed) {
+        this.partsUsed = partsUsed;
+    }
+
+    public double getAssemblyTime() {
+        return assemblyTime;
+    }
+
+    public void setAssemblyTime(double assemblyTime) {
+        this.assemblyTime = assemblyTime;
+    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Supplier.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Supplier.java?rev=708980&r1=708979&r2=708980&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Supplier.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Supplier.java
Wed Oct 29 12:06:58 2008
@@ -29,59 +29,56 @@
 @DataCache
 
 public class Supplier {
-	
-	@Id  int sid;
-	@Column(length=20)
-	 String name;
-	
-	@ManyToMany
-	List<PartBase> supplies = new ArrayList<PartBase>();
-	
-	@Version 
-	long version;
-	
-	public Supplier(){}
-	
-	public Supplier(int sid, String name){
-		this.sid=sid;
-		this.name=name;
-	}
-	
-	public Supplier addPart( PartBase p ) {
-		supplies.add(p);
-		p.getSuppliers().add(this);
-		return this;
-	}
-
-	public String getName() {
-		return name;
-	}
-
-	public void setName(String name) {
-		this.name = name;
-	}
-
-	public int getSid() {
-		return sid;
-	}
-
-	public void setSid(int sid) {
-		this.sid = sid;
-	}
-
-	public Collection<PartBase> getSupplies() {
-		return supplies;
-	}
-
-	public void setSupplies(List<PartBase> supplies) {
-		this.supplies = supplies;
-	}
-	
-	public String toString() {
 
-		return "Supplier:"+sid+" name:+"+name;
-	}
+    @Id  int sid;
+    @Column(length=20)
+    String name;
 
-	
+    @ManyToMany
+    List<PartBase> supplies = new ArrayList<PartBase>();
 
+    @Version 
+    long version;
+
+    public Supplier(){}
+
+    public Supplier(int sid, String name){
+        this.sid=sid;
+        this.name=name;
+    }
+
+    public Supplier addPart( PartBase p ) {
+        supplies.add(p);
+        p.getSuppliers().add(this);
+        return this;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getSid() {
+        return sid;
+    }
+
+    public void setSid(int sid) {
+        this.sid = sid;
+    }
+
+    public Collection<PartBase> getSupplies() {
+        return supplies;
+    }
+
+    public void setSupplies(List<PartBase> supplies) {
+        this.supplies = supplies;
+    }
+
+    public String toString() {
+
+        return "Supplier:"+sid+" name:+"+name;
+    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java?rev=708980&r1=708979&r2=708980&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java
Wed Oct 29 12:06:58 2008
@@ -18,8 +18,6 @@
  */
 package org.apache.openjpa.persistence.jdbc.query.cache;
 
-import java.util.List;
-
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
@@ -33,11 +31,11 @@
 public class TestQueryTimestampEviction extends SingleEMFTestCase {
     public void setUp() throws Exception {
         super.setUp(Part.class, PartBase.class, PartComposite.class,
-            Supplier.class, Usage.class,
-            "openjpa.DataCache", "true",
-            "openjpa.QueryCache",
-            "CacheSize=1000, evictPolicy='timestamp'",
-            "openjpa.RemoteCommitProvider", "sjvm");
+                Supplier.class, Usage.class,
+                "openjpa.DataCache", "true",
+                "openjpa.QueryCache",
+                "CacheSize=1000, EvictPolicy='timestamp'",
+                "openjpa.RemoteCommitProvider", "sjvm");
 
         if (recreateData) {
             // deletes any data leftover data in the database due to the failed
@@ -59,10 +57,7 @@
 
         // If evictPolicy is timestamp the querycache size should be equal to
         // cacheSizeBeforeUpdate value.
-        String evictPolicy = getQueryCache().getEvictPolicy();
-
-        if(evictPolicy.equalsIgnoreCase("timestamp")) 
-            assertEquals(cacheSizeBeforeUpdate, cacheSizeAfterUpdate);
+        assertEquals(cacheSizeBeforeUpdate, cacheSizeAfterUpdate);
 
         this.recreateData = false;
     }
@@ -94,7 +89,7 @@
 
         String sql = "select partno from part where cost > 120 ";
         Query nativeq = em.createNativeQuery(sql);
-        List nativelist = nativeq.getResultList();
+        int nativelistSize = nativeq.getResultList().size();
 
         em.getTransaction().commit();
         em.close();
@@ -103,14 +98,14 @@
         em.getTransaction().begin();
         Query q = em.createQuery("select p from PartBase p where p.cost>?1");
         q.setParameter(1, new Double(120));
-        List jpalist = q.getResultList();
+        int jpalistSize = q.getResultList().size();
 
         em.getTransaction().commit();
         em.close();
 
         // The resultlist of nativelist and jpalist should be the same 
         // in both eviction policies(dafault/timestamp)
-        assertEquals(nativelist.size(),jpalist.size());
+        assertEquals(nativelistSize,jpalistSize);
 
         this.deleteData = true;
         this.recreateData = true;
@@ -146,7 +141,7 @@
     private ConcurrentQueryCache getQueryCache() {
         OpenJPAEntityManagerFactory oemf = OpenJPAPersistence.cast(emf);
         QueryResultCacheImpl scache = (QueryResultCacheImpl) oemf.
-            getQueryResultCache();
+        getQueryResultCache();
 
         return (ConcurrentQueryCache ) scache.getDelegate();
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Usage.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Usage.java?rev=708980&r1=708979&r2=708980&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Usage.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/Usage.java
Wed Oct 29 12:06:58 2008
@@ -26,70 +26,66 @@
 @DataCache(timeout=100000)
 
 public class Usage {
-	@Id  
-	@GeneratedValue(strategy=GenerationType.IDENTITY)
-	 int id;
-	 int quantity;
-	 
-	@ManyToOne
-	 Part child;
-	@ManyToOne
-	 PartComposite parent ;
-	
-	@Version
-	long version;
-	
-	
-	public Usage(PartComposite p, int quantity, Part subpart) {
-		parent=p;
-		this.quantity=quantity;
-		parent.getPartsUsed().add(this);
-		setChild(subpart);
-		subpart.getUsedIn().add(this);
-	}
-	
-	// JPA entity needs a public no-arg constructor ! 
-	public Usage() {}
-
-
-	public int getId() {
-		return id;
-	}
-
-	public void setId(int id) {
-		this.id = id;
-	}
-
-	public Part getParent() {
-		return parent;
-	}
-
-	public void setParent(PartComposite parent) {
-		this.parent = parent;
-	}
-
-	public int getQuantity() {
-		return quantity;
-	}
-
-	public void setQuantity(int quantity) {
-		this.quantity = quantity;
-	}
-
-	public Part getChild() {
-		return child;
-	}
-
-	public void setChild(Part child) {
-		this.child = child;
-	}
-
-	public String toString() {
-		return "Usage:"+id+" quantity:"+quantity+" child:"+child.getPartno()+" parent"+parent.getPartno();
-	}
-
-	
-	
-	
-
+    @Id  
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    int id;
+    int quantity;
+
+    @ManyToOne
+    Part child;
+    @ManyToOne
+    PartComposite parent ;
+
+    @Version
+    long version;
+
+
+    public Usage(PartComposite p, int quantity, Part subpart) {
+        parent=p;
+        this.quantity=quantity;
+        parent.getPartsUsed().add(this);
+        setChild(subpart);
+        subpart.getUsedIn().add(this);
+    }
+
+    // JPA entity needs a public no-arg constructor ! 
+    public Usage() {}
+
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public Part getParent() {
+        return parent;
+    }
+
+    public void setParent(PartComposite parent) {
+        this.parent = parent;
+    }
+
+    public int getQuantity() {
+        return quantity;
+    }
+
+    public void setQuantity(int quantity) {
+        this.quantity = quantity;
+    }
+
+    public Part getChild() {
+        return child;
+    }
+
+    public void setChild(Part child) {
+        this.child = child;
+    }
+
+    public String toString() {
+        return "Usage:"+id+" quantity:"+quantity+" child:"+child.getPartno()+
+            " parent"+parent.getPartno();
+    }
 }

Modified: openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_caching.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_caching.xml?rev=708980&r1=708979&r2=708980&view=diff
==============================================================================
--- openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_caching.xml (original)
+++ openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_caching.xml Wed Oct 29 12:06:58
2008
@@ -541,6 +541,29 @@
 &lt;property name="openjpa.QueryCache" value="false"/&gt;
 </programlisting>
             </example>
+       <para>
+Query Cache's default behaviour on eviction is to evict all the queries from
+the cache if any of the entities that are in the access path of the query are 
+modified. Scanning through the whole query cache to evict the queries upon an 
+entity update slows down the entity updation. 
+
+The configurable eviction policy "timestamp" is to track the timestamp of the
+query and the timestamp of last update for each entity class and compare the 
+timestamps when retrieving the query for reuse.  If the timestamp of the query 
+result is older than the last update time of any entity in the access path of 
+the query, the query result would not be reused and the query result would be 
+evicted from the query cache.
+To configure the <literal>EvictPolicy</literal> to timestamp, 
+here is an example:
+       </para>
+            <example id="ref_guide_cache_evictionPolicy">
+                <title>
+                    Query Cache Eviction Policy
+                </title>
+<programlisting>
+&lt;property name="openjpa.QueryCache" value="EvictPolicy='timestamp'"/&gt;
+</programlisting>
+            </example>
             <para>
 There are certain situations in which the query cache is bypassed:
             </para>



Mime
View raw message