Author: tv
Date: Tue Feb 2 17:57:21 2016
New Revision: 1728164
URL: http://svn.apache.org/viewvc?rev=1728164&view=rev
Log:
Further simplify API with better encapsulation, update docs
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java
db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/AbstractBaseManagerTest.java
db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/managers-cache.xml
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java?rev=1728164&r1=1728163&r2=1728164&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java
(original)
+++
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java
Tue Feb 2 17:57:21 2016
@@ -86,7 +86,7 @@ public abstract class AbstractBaseManage
private CopyOnWriteArraySet<Column> validFields = new
CopyOnWriteArraySet<Column>();
/** The listeners for this manager. */
- protected ConcurrentMap<Column, CopyOnWriteArrayList<CacheListener<?>>>
listenersMap =
+ private ConcurrentMap<Column, CopyOnWriteArrayList<CacheListener<?>>>
listenersMap =
new ConcurrentHashMap<Column,
CopyOnWriteArrayList<CacheListener<?>>>();
/**
@@ -571,17 +571,18 @@ public abstract class AbstractBaseManage
}
/**
- * Notify all listeners in the list that an object has changed
+ * Notify all listeners associated to the column that an object has changed
*
- * @param listeners the list of listeners
+ * @param column the column related to the listeners
* @param oldOm the previous object, null if the object has been added
* @param om the new object, null if the object has been removed
*/
protected <TT extends Persistent> void notifyListeners(
- final List<CacheListener<?>> listeners,
+ final Column column,
final TT oldOm,
final TT om)
{
+ List<CacheListener<?>> listeners = listenersMap.get(column);
if (listeners != null)
{
for (CacheListener<?> cl : listeners)
Modified:
db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/AbstractBaseManagerTest.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/AbstractBaseManagerTest.java?rev=1728164&r1=1728163&r2=1728164&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/AbstractBaseManagerTest.java
(original)
+++
db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/AbstractBaseManagerTest.java
Tue Feb 2 17:57:21 2016
@@ -187,7 +187,7 @@ public class AbstractBaseManagerTest ext
this.removedObjectCalled = false;
TestPersistent test1 = new TestPersistent();
TestPersistent test2 = new TestPersistent();
- manager.notifyListeners(manager.listenersMap.get(new
ColumnImpl("test1")), (TestPersistent)null, test1);
+ manager.notifyListeners(new ColumnImpl("test1"),
(TestPersistent)null, test1);
assertTrue("Should call addedObject", addedObjectCalled);
assertFalse("Should not call refreshedObject",
refreshedObjectCalled);
assertFalse("Should not call removedObject", removedObjectCalled);
@@ -195,7 +195,7 @@ public class AbstractBaseManagerTest ext
this.addedObjectCalled = false;
this.refreshedObjectCalled = false;
this.removedObjectCalled = false;
- manager.notifyListeners(manager.listenersMap.get(new
ColumnImpl("test2")), test2, test1);
+ manager.notifyListeners(new ColumnImpl("test2"), test2, test1);
assertFalse("Should not call addedObject", addedObjectCalled);
assertTrue("Should call refreshedObject",
refreshedObjectCalled);
assertFalse("Should not call removedObject", removedObjectCalled);
@@ -203,7 +203,7 @@ public class AbstractBaseManagerTest ext
this.addedObjectCalled = false;
this.refreshedObjectCalled = false;
this.removedObjectCalled = false;
- manager.notifyListeners(manager.listenersMap.get(new
ColumnImpl("test2")), test2, null);
+ manager.notifyListeners(new ColumnImpl("test2"), test2, null);
assertFalse("Should not call addedObject", addedObjectCalled);
assertFalse("Should not call refreshedObject", refreshedObjectCalled);
assertTrue("Should call removedObject", removedObjectCalled);
Modified:
db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/managers-cache.xml
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/managers-cache.xml?rev=1728164&r1=1728163&r2=1728164&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/managers-cache.xml
(original)
+++
db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/managers-cache.xml
Tue Feb 2 17:57:21 2016
@@ -57,7 +57,7 @@ List foos = FooManager.getInstances(ids)
<p>
Note that the cache is global and is not Transaction-aware.
This implies that isolation of different transactions will be difficult
- to achieve. For example, you might read uncommited data out of the
+ to achieve. For example, you might read uncommitted data out of the
cache even if you database transaction isolation is set to
<code>READ_COMMITTED</code>.
</p>
@@ -67,7 +67,7 @@ List foos = FooManager.getInstances(ids)
<section name="Business Object Cache">
<p>
- If no-arg constructor of FooManager,
+ If the no-arg constructor of FooManager
calls setRegion(region) where the String region is the key used to
determine the cache, the manager will cache instances of Foo retrieved
via the getInstance(ObjectKey id) and getInstances(List ids) methods.
@@ -95,10 +95,10 @@ public FooManager()
<source><![CDATA[
jcs.region.net_bar_om_Foo=
jcs.region.net_bar_om_Foo.cacheattributes=
- org.apache.jcs.engine.CompositeCacheAttributes
+ org.apache.commons.jcs.engine.CompositeCacheAttributes
jcs.region.net_bar_om_Foo.cacheattributes.MaxObjects=1200
jcs.region.net_bar_om_Foo.cacheattributes.MemoryCacheName=
- org.apache.jcs.engine.memory.lru.LRUMemoryCache
+ org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache
]]></source>
<p>
@@ -122,7 +122,7 @@ jcs.region.net_bar_om_Foo.cacheattribute
<p>
The above fk relationship will also generate a Bar.getFoos(Criteria). It
- would be preferrable that repeated requests to this method returned
+ would be preferable that repeated requests to this method returned
cached results as opposed to hitting the db for each call. It could be
possible to add such caching to the generated method, and Criteria
implements an equals() method that would make this possible. But
@@ -163,7 +163,7 @@ public List getFoos(FooType type, boolea
<source><![CDATA[
public List getFoos(FooType type, boolean deleted)
{
- List result = null;
+ List<Foo> result = null;
Boolean b = (deleted ? Boolean.TRUE : Boolean.FALSE);
Object obj = BarManager.getMethodResult().get(this, "getFoos", type, b);
if ( obj == null )
@@ -177,7 +177,7 @@ public List getFoos(FooType type, boolea
}
else
{
- result = (List)obj;
+ result = (List<Foo>)obj;
}
return result;
}
@@ -190,15 +190,9 @@ public List getFoos(FooType type, boolea
object on which the method was called. If the object is not Serializable
or the method is static, a String as given by Object.toString() method or
the className might be used. The second argument is the method name.
- There are versions of the get method that take up to 3 additional
+ The get method takes a variable number of additional
arguments that will be the arguments to the method, or if they are not
- Serializable some Serializable proxy.
- There is also a get method that takes an Object[] that can be used for
- methods that have more than 3 arguments; the
- first two objects in the array should be the instance and method name.
- The reason for not just having the Object[] format is that keys are
pooled
- and since most methods will be less than 4 arguments, object creation
- related to the cache is minimized. Now the method will return cached
+ Serializable some Serializable proxy. Now the method will return cached
results as long as the results remain in the cache. So there must be some
way to invalidate these results, if the database changes in a way that
is likely to affect the result that should be returned by the method.
@@ -254,7 +248,7 @@ public void refreshedObject(Persistent o
/** fields which interest us with respect to cache events */
public List getInterestedFields()
{
- List interestedCacheFields = new LinkedList();
+ List<Column> interestedCacheFields = new LinkedList<>();
interestedCacheFields.add(FooPeer.BAR_ID);
interestedCacheFields.add(XPeer.X_ID);
...
@@ -279,16 +273,14 @@ public FooManager()
throws TorqueException
{
setRegion("net_bar_om_Foo");
- validFields = new HashMap();
- validFields.put(FooPeer.BAR_ID, null);
+ addValidField(FooPeer.BAR_ID);
}
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
- List listeners = (List)listenersMap.get(FooPeer.BAR_ID);
- notifyListeners(listeners, oldOm, om);
+ notifyListeners(FooPeer.BAR_ID, oldOm, om);
return oldOm;
}
]]></source>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]