You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2007/11/21 09:37:28 UTC
svn commit: r596986 - in
/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src:
main/java/org/apache/cayenne/ main/java/org/apache/cayenne/access/
main/java/org/apache/cayenne/map/ main/java/org/apache/cayenne/reflect/
test/java/org/apache/cayen...
Author: aadamchik
Date: Wed Nov 21 00:37:26 2007
New Revision: 596986
URL: http://svn.apache.org/viewvc?rev=596986&view=rev
Log:
CAY-922 Convert non-type-safe enums to Java 5 enums
(lifecycleevent enum)
Added:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/LifecycleEvent.java
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/LifecycleListener.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataChannelSyncCallbackAction.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContextDeleteAction.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/AshwoodEntitySorter.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/CallbackDescriptor.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/CallbackMap.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntitySorter.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/Procedure.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/QueryBuilder.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/LifecycleCallbackRegistry.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextWithDataContextTest.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextCallbacksTest.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLQueryTest.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainCallbacksTest.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/CallbackDescriptorTest.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/CallbackMapTest.java
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/LifecycleListener.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/LifecycleListener.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/LifecycleListener.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/LifecycleListener.java Wed Nov 21 00:37:26 2007
@@ -31,14 +31,6 @@
*/
public interface LifecycleListener {
- public static final int PRE_PERSIST = 0;
- public static final int PRE_REMOVE = 1;
- public static final int PRE_UPDATE = 2;
- public static final int POST_PERSIST = 3;
- public static final int POST_REMOVE = 4;
- public static final int POST_UPDATE = 5;
- public static final int POST_LOAD = 6;
-
void prePersist(Object entity);
void postPersist(Object entity);
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataChannelSyncCallbackAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataChannelSyncCallbackAction.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataChannelSyncCallbackAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataChannelSyncCallbackAction.java Wed Nov 21 00:37:26 2007
@@ -24,10 +24,10 @@
import java.util.Set;
import org.apache.cayenne.DataChannel;
-import org.apache.cayenne.LifecycleListener;
import org.apache.cayenne.graph.GraphChangeHandler;
import org.apache.cayenne.graph.GraphDiff;
import org.apache.cayenne.graph.GraphManager;
+import org.apache.cayenne.map.LifecycleEvent;
import org.apache.cayenne.reflect.LifecycleCallbackRegistry;
/**
@@ -78,7 +78,7 @@
abstract void applyPostCommit();
- void apply(int callbackType, Collection objects) {
+ void apply(LifecycleEvent callbackType, Collection<?> objects) {
if (seenIds != null && objects != null) {
callbackRegistry.performCallbacks(callbackType, objects);
}
@@ -158,20 +158,20 @@
}
protected boolean hasListeners() {
- return !(callbackRegistry.isEmpty(LifecycleListener.PRE_UPDATE)
- && callbackRegistry.isEmpty(LifecycleListener.POST_UPDATE)
- && callbackRegistry.isEmpty(LifecycleListener.POST_REMOVE) && callbackRegistry
- .isEmpty(LifecycleListener.POST_PERSIST));
+ return !(callbackRegistry.isEmpty(LifecycleEvent.PRE_UPDATE)
+ && callbackRegistry.isEmpty(LifecycleEvent.POST_UPDATE)
+ && callbackRegistry.isEmpty(LifecycleEvent.POST_REMOVE) && callbackRegistry
+ .isEmpty(LifecycleEvent.POST_PERSIST));
}
void applyPreCommit() {
- apply(LifecycleListener.PRE_UPDATE, updated);
+ apply(LifecycleEvent.PRE_UPDATE, updated);
}
void applyPostCommit() {
- apply(LifecycleListener.POST_UPDATE, updated);
- apply(LifecycleListener.POST_REMOVE, removed);
- apply(LifecycleListener.POST_PERSIST, persisted);
+ apply(LifecycleEvent.POST_UPDATE, updated);
+ apply(LifecycleEvent.POST_REMOVE, removed);
+ apply(LifecycleEvent.POST_PERSIST, persisted);
}
}
@@ -183,7 +183,7 @@
}
protected boolean hasListeners() {
- return !callbackRegistry.isEmpty(LifecycleListener.POST_LOAD);
+ return !callbackRegistry.isEmpty(LifecycleEvent.POST_LOAD);
}
void applyPreCommit() {
@@ -191,8 +191,8 @@
}
void applyPostCommit() {
- apply(LifecycleListener.POST_LOAD, updated);
- apply(LifecycleListener.POST_LOAD, removed);
+ apply(LifecycleEvent.POST_LOAD, updated);
+ apply(LifecycleEvent.POST_LOAD, removed);
}
}
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java Wed Nov 21 00:37:26 2007
@@ -39,7 +39,6 @@
import org.apache.cayenne.DataRow;
import org.apache.cayenne.DeleteDenyException;
import org.apache.cayenne.Fault;
-import org.apache.cayenne.LifecycleListener;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.ObjectId;
import org.apache.cayenne.PersistenceState;
@@ -57,6 +56,7 @@
import org.apache.cayenne.map.DbJoin;
import org.apache.cayenne.map.DbRelationship;
import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.map.LifecycleEvent;
import org.apache.cayenne.map.ObjAttribute;
import org.apache.cayenne.map.ObjEntity;
import org.apache.cayenne.map.ObjRelationship;
@@ -772,7 +772,7 @@
// invoke callbacks
getEntityResolver().getCallbackRegistry().performCallbacks(
- LifecycleListener.PRE_PERSIST,
+ LifecycleEvent.PRE_PERSIST,
object);
return object;
@@ -907,7 +907,7 @@
// invoke callbacks
getEntityResolver().getCallbackRegistry().performCallbacks(
- LifecycleListener.PRE_PERSIST,
+ LifecycleEvent.PRE_PERSIST,
persistent);
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContextDeleteAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContextDeleteAction.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContextDeleteAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContextDeleteAction.java Wed Nov 21 00:37:26 2007
@@ -23,15 +23,14 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import org.apache.cayenne.CayenneRuntimeException;
import org.apache.cayenne.DeleteDenyException;
-import org.apache.cayenne.LifecycleListener;
import org.apache.cayenne.PersistenceState;
import org.apache.cayenne.Persistent;
import org.apache.cayenne.map.DeleteRule;
+import org.apache.cayenne.map.LifecycleEvent;
import org.apache.cayenne.map.ObjRelationship;
import org.apache.cayenne.reflect.ArcProperty;
import org.apache.cayenne.reflect.AttributeProperty;
@@ -101,7 +100,7 @@
throws DeleteDenyException {
dataContext.getEntityResolver().getCallbackRegistry().performCallbacks(
- LifecycleListener.PRE_REMOVE,
+ LifecycleEvent.PRE_REMOVE,
object);
object.setPersistenceState(PersistenceState.DELETED);
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java Wed Nov 21 00:37:26 2007
@@ -30,7 +30,6 @@
import org.apache.cayenne.CayenneException;
import org.apache.cayenne.CayenneRuntimeException;
import org.apache.cayenne.DataRow;
-import org.apache.cayenne.LifecycleListener;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.ObjectId;
import org.apache.cayenne.Persistent;
@@ -39,6 +38,7 @@
import org.apache.cayenne.cache.QueryCacheEntryFactory;
import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.map.DbRelationship;
+import org.apache.cayenne.map.LifecycleEvent;
import org.apache.cayenne.map.ObjEntity;
import org.apache.cayenne.map.ObjRelationship;
import org.apache.cayenne.query.ObjectIdQuery;
@@ -143,14 +143,14 @@
.getEntityResolver()
.getCallbackRegistry();
- if (!callbackRegistry.isEmpty(LifecycleListener.POST_LOAD)) {
+ if (!callbackRegistry.isEmpty(LifecycleEvent.POST_LOAD)) {
List list = response.firstList();
if (list != null
&& !list.isEmpty()
&& !(query.getMetaData(domain.getEntityResolver()))
.isFetchingDataRows()) {
- callbackRegistry.performCallbacks(LifecycleListener.POST_LOAD, list);
+ callbackRegistry.performCallbacks(LifecycleEvent.POST_LOAD, list);
}
}
}
@@ -170,8 +170,7 @@
ObjectIdQuery oidQuery = (ObjectIdQuery) query;
DataRow row = null;
- if (cache != null
- && !oidQuery.isFetchMandatory()) {
+ if (cache != null && !oidQuery.isFetchMandatory()) {
row = cache.getCachedSnapshot(oidQuery.getObjectId());
}
@@ -214,10 +213,10 @@
return !DONE;
}
- if(cache == null) {
+ if (cache == null) {
return !DONE;
}
-
+
DataRow sourceRow = cache.getCachedSnapshot(relationshipQuery.getObjectId());
if (sourceRow == null) {
return !DONE;
@@ -492,10 +491,8 @@
.getEntityResolver()
.getCallbackRegistry();
- if (!callbackRegistry.isEmpty(LifecycleListener.POST_LOAD)) {
- callbackRegistry.performCallbacks(
- LifecycleListener.POST_LOAD,
- objects);
+ if (!callbackRegistry.isEmpty(LifecycleEvent.POST_LOAD)) {
+ callbackRegistry.performCallbacks(LifecycleEvent.POST_LOAD, objects);
}
}
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/AshwoodEntitySorter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/AshwoodEntitySorter.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/AshwoodEntitySorter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/AshwoodEntitySorter.java Wed Nov 21 00:37:26 2007
@@ -57,8 +57,8 @@
*/
public class AshwoodEntitySorter implements EntitySorter {
- protected Collection dataMaps;
- protected Map dbEntityToTableMap;
+ protected Collection<DataMap> dataMaps;
+ protected Map<DbEntity, Table> dbEntityToTableMap;
protected Digraph referentialDigraph;
protected Digraph contractedReferentialDigraph;
protected Map components;
@@ -71,7 +71,7 @@
// used for lazy initialization
protected boolean dirty;
- public AshwoodEntitySorter(Collection dataMaps) {
+ public AshwoodEntitySorter(Collection<DataMap> dataMaps) {
tableComparator = new TableComparator();
dbEntityComparator = new DbEntityComparator();
objEntityComparator = new ObjEntityComparator();
@@ -87,14 +87,12 @@
return;
}
- Collection tables = new ArrayList(64);
- dbEntityToTableMap = new HashMap(64);
+ Collection<Table> tables = new ArrayList<Table>(64);
+ dbEntityToTableMap = new HashMap<DbEntity, Table>(64);
reflexiveDbEntities = new HashMap(32);
- for (Iterator i = dataMaps.iterator(); i.hasNext();) {
- DataMap map = (DataMap) i.next();
- Iterator entitiesToConvert = map.getDbEntities().iterator();
- while (entitiesToConvert.hasNext()) {
- DbEntity entity = (DbEntity) entitiesToConvert.next();
+
+ for (DataMap map : dataMaps) {
+ for (DbEntity entity : map.getDbEntities()) {
Table table = new Table(entity.getCatalog(), entity.getSchema(), entity
.getName());
fillInMetadata(table, entity);
@@ -130,17 +128,17 @@
/**
* @since 1.1
*/
- public synchronized void setDataMaps(Collection dataMaps) {
+ public synchronized void setDataMaps(Collection<DataMap> dataMaps) {
this.dirty = true;
this.dataMaps = dataMaps != null ? dataMaps : Collections.EMPTY_LIST;
}
- public void sortDbEntities(List dbEntities, boolean deleteOrder) {
+ public void sortDbEntities(List<DbEntity> dbEntities, boolean deleteOrder) {
_indexSorter();
Collections.sort(dbEntities, getDbEntityComparator(deleteOrder));
}
- public void sortObjEntities(List objEntities, boolean deleteOrder) {
+ public void sortObjEntities(List<ObjEntity> objEntities, boolean deleteOrder) {
_indexSorter();
Collections.sort(objEntities, getObjEntityComparator(deleteOrder));
}
@@ -194,7 +192,8 @@
continue;
}
- masters[k] = descriptor.getProperty(reflexiveRelName).readProperty(current);
+ masters[k] = descriptor.getProperty(reflexiveRelName).readProperty(
+ current);
if (masters[k] == null) {
masters[k] = findReflexiveMaster(current, (ObjRelationship) objEntity
@@ -331,8 +330,8 @@
return c;
}
- protected Comparator getObjEntityComparator(boolean dependantFirst) {
- Comparator c = objEntityComparator;
+ protected Comparator<ObjEntity> getObjEntityComparator(boolean dependantFirst) {
+ Comparator<ObjEntity> c = objEntityComparator;
if (dependantFirst) {
c = new ReverseComparator(c);
}
@@ -351,34 +350,33 @@
return reflexiveDbEntities.containsKey(metadata);
}
- private final class DbEntityComparator implements Comparator {
+ private final class DbEntityComparator implements Comparator<DbEntity> {
- public int compare(Object o1, Object o2) {
+ public int compare(DbEntity o1, DbEntity o2) {
if (o1 == o2)
return 0;
- Table t1 = getTable((DbEntity) o1);
- Table t2 = getTable((DbEntity) o2);
+ Table t1 = getTable(o1);
+ Table t2 = getTable(o2);
return tableComparator.compare(t1, t2);
}
}
- private final class ObjEntityComparator implements Comparator {
+ private final class ObjEntityComparator implements Comparator<ObjEntity> {
- public int compare(Object o1, Object o2) {
+ public int compare(ObjEntity o1, ObjEntity o2) {
if (o1 == o2)
return 0;
- Table t1 = getTable((ObjEntity) o1);
- Table t2 = getTable((ObjEntity) o2);
+ Table t1 = getTable(o1);
+ Table t2 = getTable(o2);
return tableComparator.compare(t1, t2);
}
}
- private final class TableComparator implements Comparator {
+ private final class TableComparator implements Comparator<Table> {
- public int compare(Object o1, Object o2) {
+ public int compare(Table t1, Table t2) {
int result = 0;
- Table t1 = (Table) o1;
- Table t2 = (Table) o2;
+
if (t1 == t2)
return 0;
if (t1 == null)
@@ -400,13 +398,13 @@
private final static class ComponentRecord {
- ComponentRecord(int index, Collection component) {
+ ComponentRecord(int index, Collection<?> component) {
this.index = index;
this.component = component;
}
int index;
- Collection component;
+ Collection<?> component;
}
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/CallbackDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/CallbackDescriptor.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/CallbackDescriptor.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/CallbackDescriptor.java Wed Nov 21 00:37:26 2007
@@ -20,7 +20,6 @@
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
@@ -35,10 +34,10 @@
*/
public class CallbackDescriptor implements Serializable {
- protected int callbackType;
+ protected LifecycleEvent callbackType;
protected Set<String> callbackMethods;
- public CallbackDescriptor(int callbackType) {
+ public CallbackDescriptor(LifecycleEvent callbackType) {
setCallbackType(callbackType);
this.callbackMethods = new LinkedHashSet<String>(3);
}
@@ -67,15 +66,11 @@
callbackMethods.remove(methodName);
}
- public int getCallbackType() {
+ public LifecycleEvent getCallbackType() {
return callbackType;
}
- void setCallbackType(int callbackType) {
- if (Arrays.binarySearch(CallbackMap.CALLBACKS, callbackType) != callbackType) {
- throw new IllegalArgumentException("Invalid callback: " + callbackType);
- }
-
+ void setCallbackType(LifecycleEvent callbackType) {
this.callbackType = callbackType;
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/CallbackMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/CallbackMap.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/CallbackMap.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/CallbackMap.java Wed Nov 21 00:37:26 2007
@@ -19,11 +19,7 @@
package org.apache.cayenne.map;
import java.io.Serializable;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.HashMap;
-import org.apache.cayenne.LifecycleListener;
import org.apache.cayenne.util.XMLEncoder;
/**
@@ -34,114 +30,82 @@
*/
public class CallbackMap implements Serializable {
- // these int constants correspond to indexes in array in LifecycleCallbackRegistry, so
- // they must start with 0 and increment by 1.
+ protected CallbackDescriptor[] callbacks = new CallbackDescriptor[LifecycleEvent
+ .values().length];
- /**
- * An array containing all valid callbacks with each callback int value corresponding
- * to its index in the array.
- */
- public static final int[] CALLBACKS = new int[] {
- LifecycleListener.PRE_PERSIST, LifecycleListener.PRE_REMOVE,
- LifecycleListener.PRE_UPDATE, LifecycleListener.POST_PERSIST,
- LifecycleListener.POST_REMOVE, LifecycleListener.POST_UPDATE,
- LifecycleListener.POST_LOAD
- };
-
- protected CallbackDescriptor prePersist;
- protected CallbackDescriptor postPersist;
- protected CallbackDescriptor preUpdate;
- protected CallbackDescriptor postUpdate;
- protected CallbackDescriptor preRemove;
- protected CallbackDescriptor postRemove;
- protected CallbackDescriptor postLoad;
+ public CallbackMap() {
- /**
- * map for quick access to a callback descriptor by type
- */
- private Map callbacksMap = new HashMap();
+ LifecycleEvent[] events = LifecycleEvent.values();
+ callbacks = new CallbackDescriptor[events.length];
- public CallbackMap() {
- this.prePersist = new CallbackDescriptor(LifecycleListener.PRE_PERSIST);
- this.postPersist = new CallbackDescriptor(LifecycleListener.POST_PERSIST);
- this.preUpdate = new CallbackDescriptor(LifecycleListener.PRE_UPDATE);
- this.postUpdate = new CallbackDescriptor(LifecycleListener.POST_UPDATE);
- this.preRemove = new CallbackDescriptor(LifecycleListener.PRE_REMOVE);
- this.postRemove = new CallbackDescriptor(LifecycleListener.POST_REMOVE);
- this.postLoad = new CallbackDescriptor(LifecycleListener.POST_LOAD);
-
- callbacksMap.put(new Integer(LifecycleListener.PRE_PERSIST), prePersist);
- callbacksMap.put(new Integer(LifecycleListener.POST_PERSIST), postPersist);
- callbacksMap.put(new Integer(LifecycleListener.PRE_UPDATE), preUpdate);
- callbacksMap.put(new Integer(LifecycleListener.POST_UPDATE), postUpdate);
- callbacksMap.put(new Integer(LifecycleListener.PRE_REMOVE), preRemove);
- callbacksMap.put(new Integer(LifecycleListener.POST_REMOVE), postRemove);
- callbacksMap.put(new Integer(LifecycleListener.POST_LOAD), postLoad);
+ for (int i = 0; i < events.length; i++) {
+ callbacks[i] = new CallbackDescriptor(events[i]);
+ }
}
/**
- * @return all event callbacks in a single array ordered by event type, following the
- * order in {@link CallbackMap#CALLBACKS} array.
+ * Returns all event callbacks as an array ordered by event type.
*/
public CallbackDescriptor[] getCallbacks() {
- return new CallbackDescriptor[] {
- prePersist, preRemove, preUpdate, postPersist, postRemove, postUpdate,
- postLoad
- };
+ return callbacks;
}
/**
* @param callbackType callback type id
* @return CallbackDescriptor for the specified callback type id
*/
- public CallbackDescriptor getCallbackDescriptor(int callbackType) {
- return (CallbackDescriptor)callbacksMap.get(new Integer(callbackType));
+ public CallbackDescriptor getCallbackDescriptor(LifecycleEvent callbackType) {
+ return callbacks[callbackType.ordinal()];
}
public CallbackDescriptor getPostLoad() {
- return postLoad;
+ return callbacks[LifecycleEvent.POST_LOAD.ordinal()];
}
public CallbackDescriptor getPostPersist() {
- return postPersist;
+ return callbacks[LifecycleEvent.POST_PERSIST.ordinal()];
}
public CallbackDescriptor getPostRemove() {
- return postRemove;
+ return callbacks[LifecycleEvent.POST_REMOVE.ordinal()];
}
public CallbackDescriptor getPostUpdate() {
- return postUpdate;
+ return callbacks[LifecycleEvent.POST_UPDATE.ordinal()];
}
public CallbackDescriptor getPrePersist() {
- return prePersist;
+ return callbacks[LifecycleEvent.PRE_PERSIST.ordinal()];
}
public CallbackDescriptor getPreRemove() {
- return preRemove;
+ return callbacks[LifecycleEvent.PRE_REMOVE.ordinal()];
}
public CallbackDescriptor getPreUpdate() {
- return preUpdate;
+ return callbacks[LifecycleEvent.PRE_UPDATE.ordinal()];
}
public void encodeCallbacksAsXML(XMLEncoder encoder) {
- printMethods(prePersist, "pre-persist", encoder);
- printMethods(postPersist, "post-persist", encoder);
- printMethods(preUpdate, "pre-update", encoder);
- printMethods(postUpdate, "post-update", encoder);
- printMethods(preRemove, "pre-remove", encoder);
- printMethods(postRemove, "post-remove", encoder);
- printMethods(postLoad, "post-load", encoder);
+ printMethods(getPrePersist(), "pre-persist", encoder);
+ printMethods(getPostPersist(), "post-persist", encoder);
+ printMethods(getPreUpdate(), "pre-update", encoder);
+ printMethods(getPostUpdate(), "post-update", encoder);
+ printMethods(getPreRemove(), "pre-remove", encoder);
+ printMethods(getPostRemove(), "post-remove", encoder);
+ printMethods(getPostLoad(), "post-load", encoder);
}
- private static void printMethods(CallbackDescriptor descriptor, String stringCallbackName, XMLEncoder encoder) {
- for (Iterator i = descriptor.getCallbackMethods().iterator(); i.hasNext();) {
+ private static void printMethods(
+ CallbackDescriptor descriptor,
+ String stringCallbackName,
+ XMLEncoder encoder) {
+
+ for (String methodName : descriptor.getCallbackMethods()) {
encoder.print("<");
encoder.print(stringCallbackName);
encoder.print(" method-name=\"");
- encoder.print((String)i.next());
+ encoder.print(methodName);
encoder.println("\"/>");
}
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java Wed Nov 21 00:37:26 2007
@@ -124,10 +124,8 @@
for (String method : callbacks[i].getCallbackMethods()) {
// note that callbacks[i].getCallbackType() == i
- callbackRegistry.addDefaultListener(
- i,
- listenerInstance,
- method);
+ callbackRegistry.addDefaultListener(callbacks[i]
+ .getCallbackType(), listenerInstance, method);
}
}
}
@@ -149,7 +147,7 @@
for (String method : callbacks[i].getCallbackMethods()) {
// note that callbacks[i].getCallbackType() == i
callbackRegistry.addListener(
- i,
+ callbacks[i].getCallbackType(),
entityClass,
listenerInstance,
method);
@@ -161,7 +159,10 @@
for (int i = 0; i < callbacks.length; i++) {
for (String method : callbacks[i].getCallbackMethods()) {
// note that callbacks[i].getCallbackType() == i
- callbackRegistry.addListener(i, entityClass, method);
+ callbackRegistry.addListener(
+ callbacks[i].getCallbackType(),
+ entityClass,
+ method);
}
}
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntitySorter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntitySorter.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntitySorter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntitySorter.java Wed Nov 21 00:37:26 2007
@@ -33,20 +33,20 @@
/**
* Initializes a list of DataMaps used by the sorter.
*/
- void setDataMaps(Collection dataMaps);
+ void setDataMaps(Collection<DataMap> dataMaps);
/**
* Sorts a list of DbEntities.
*/
- void sortDbEntities(List dbEntities, boolean deleteOrder);
+ void sortDbEntities(List<DbEntity> dbEntities, boolean deleteOrder);
/**
* Sorts a list of ObjEntities.
*/
- void sortObjEntities(List objEntities, boolean deleteOrder);
+ void sortObjEntities(List<ObjEntity> objEntities, boolean deleteOrder);
/**
* Sorts a list of objects belonging to the ObjEntity.
*/
- void sortObjectsForEntity(ObjEntity entity, List objects, boolean deleteOrder);
+ void sortObjectsForEntity(ObjEntity entity, List<?> objects, boolean deleteOrder);
}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/LifecycleEvent.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/LifecycleEvent.java?rev=596986&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/LifecycleEvent.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/LifecycleEvent.java Wed Nov 21 00:37:26 2007
@@ -0,0 +1,29 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+package org.apache.cayenne.map;
+
+/**
+ * Defines possible object lifecycle events for which callbacks are supported.
+ *
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+public enum LifecycleEvent {
+ PRE_PERSIST, PRE_REMOVE, PRE_UPDATE, POST_PERSIST, POST_REMOVE, POST_UPDATE, POST_LOAD;
+}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java Wed Nov 21 00:37:26 2007
@@ -183,13 +183,13 @@
Entity src = this.getSourceEntity();
- Iterator it = target.getRelationships().iterator();
+ Iterator<?> it = target.getRelationships().iterator();
while (it.hasNext()) {
ObjRelationship rel = (ObjRelationship) it.next();
if (rel.getTargetEntity() != src)
continue;
- List otherRels = rel.getDbRelationships();
+ List<?> otherRels = rel.getDbRelationships();
if (reversed.size() != otherRels.size())
continue;
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/Procedure.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/Procedure.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/Procedure.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/Procedure.java Wed Nov 21 00:37:26 2007
@@ -22,7 +22,6 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import org.apache.cayenne.util.CayenneMapEntry;
@@ -43,7 +42,7 @@
protected String catalog;
protected String schema;
protected boolean returningValue;
- protected List callParameters = new ArrayList();
+ protected List<ProcedureParameter> callParameters = new ArrayList<ProcedureParameter>();
/**
* Creates an unnamed procedure object.
@@ -134,7 +133,7 @@
this.dataMap = dataMap;
}
- public void setCallParameters(List parameters) {
+ public void setCallParameters(List<ProcedureParameter> parameters) {
clearCallParameters();
callParameters.addAll(parameters);
}
@@ -160,7 +159,7 @@
/** Removes a named call parameter. */
public void removeCallParameter(String name) {
for (int i = 0; i < callParameters.size(); i++) {
- ProcedureParameter nextParam = (ProcedureParameter) callParameters.get(i);
+ ProcedureParameter nextParam = callParameters.get(i);
if (name.equals(nextParam.getName())) {
callParameters.remove(i);
break;
@@ -175,7 +174,7 @@
/**
* Returns an unmodifiable list of call parameters.
*/
- public List getCallParameters() {
+ public List<ProcedureParameter> getCallParameters() {
return Collections.unmodifiableList(callParameters);
}
@@ -183,11 +182,10 @@
* Returns a list of OUT and INOUT call parameters. If procedure has a return value,
* it will also be included as a call parameter.
*/
- public List getCallOutParameters() {
- List outParams = new ArrayList(callParameters.size());
- Iterator it = callParameters.iterator();
- while (it.hasNext()) {
- ProcedureParameter param = (ProcedureParameter) it.next();
+ public List<ProcedureParameter> getCallOutParameters() {
+ List<ProcedureParameter> outParams = new ArrayList<ProcedureParameter>(
+ callParameters.size());
+ for (ProcedureParameter param : callParameters) {
if (param.isOutParam()) {
outParams.add(param);
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/QueryBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/QueryBuilder.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/QueryBuilder.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/QueryBuilder.java Wed Nov 21 00:37:26 2007
@@ -46,13 +46,12 @@
public static final String JAVA_CLASS_ROOT = "java-class";
protected String name;
- protected Map properties;
- protected List resultColumns;
+ protected Map<String, String> properties;
protected String sql;
- protected Map adapterSql;
+ protected Map<String, String> adapterSql;
protected Expression qualifier;
- protected List orderings;
- protected List prefetches;
+ protected List<Ordering> orderings;
+ protected List<String> prefetches;
protected DataMap dataMap;
protected String rootType;
protected String rootName;
@@ -121,7 +120,7 @@
}
else {
if (adapterSql == null) {
- adapterSql = new HashMap();
+ adapterSql = new HashMap<String, String>();
}
adapterSql.put(adapterClass, sql);
@@ -139,7 +138,7 @@
public void addProperty(String name, String value) {
if (properties == null) {
- properties = new HashMap();
+ properties = new HashMap<String, String>();
}
properties.put(name, value);
@@ -147,7 +146,7 @@
public void addOrdering(String path, String descending, String ignoreCase) {
if (orderings == null) {
- orderings = new ArrayList();
+ orderings = new ArrayList<Ordering>();
}
if (path != null && path.trim().length() == 0) {
@@ -165,7 +164,7 @@
}
if (prefetches == null) {
- prefetches = new ArrayList();
+ prefetches = new ArrayList<String>();
}
prefetches.add(path.trim());
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/LifecycleCallbackRegistry.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/LifecycleCallbackRegistry.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/LifecycleCallbackRegistry.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/LifecycleCallbackRegistry.java Wed Nov 21 00:37:26 2007
@@ -22,15 +22,12 @@
import org.apache.cayenne.LifecycleListener;
import org.apache.cayenne.Persistent;
-import org.apache.cayenne.map.CallbackMap;
import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.map.LifecycleEvent;
/**
* A registry of lifecycle callbacks for all callback event types. Valid event types are
- * {@link LifecycleListener#PRE_PERSIST}, {@link LifecycleListener#POST_PERSIST},
- * {@link LifecycleListener#PRE_UPDATE}, {@link LifecycleListener#POST_UPDATE},
- * {@link LifecycleListener#PRE_REMOVE}, {@link LifecycleListener#POST_REMOVE},
- * {@link LifecycleListener#POST_LOAD}.
+ * defined in {@link LifecycleEvent} enum.
*
* @since 3.0
* @author Andrus Adamchik
@@ -43,7 +40,7 @@
* Creates an empty callback registry.
*/
public LifecycleCallbackRegistry(EntityResolver resolver) {
- eventCallbacks = new LifecycleCallbackEventHandler[CallbackMap.CALLBACKS.length];
+ eventCallbacks = new LifecycleCallbackEventHandler[LifecycleEvent.values().length];
for (int i = 0; i < eventCallbacks.length; i++) {
eventCallbacks[i] = new LifecycleCallbackEventHandler(resolver);
}
@@ -68,8 +65,8 @@
/**
* Returns true if there are no listeners for a specific event type.
*/
- public boolean isEmpty(int type) {
- return eventCallbacks[type].isEmpty();
+ public boolean isEmpty(LifecycleEvent type) {
+ return eventCallbacks[type.ordinal()].isEmpty();
}
/**
@@ -78,21 +75,21 @@
* methods in this class can be used to register arbitrary listeners.
*/
public void addDefaultListener(LifecycleListener listener) {
- addDefaultListener(LifecycleListener.PRE_PERSIST, listener, "prePersist");
- addDefaultListener(LifecycleListener.POST_PERSIST, listener, "postPersist");
- addDefaultListener(LifecycleListener.PRE_REMOVE, listener, "preRemove");
- addDefaultListener(LifecycleListener.POST_REMOVE, listener, "postRemove");
- addDefaultListener(LifecycleListener.PRE_UPDATE, listener, "preUpdate");
- addDefaultListener(LifecycleListener.POST_UPDATE, listener, "postUpdate");
- addDefaultListener(LifecycleListener.POST_LOAD, listener, "postLoad");
+ addDefaultListener(LifecycleEvent.PRE_PERSIST, listener, "prePersist");
+ addDefaultListener(LifecycleEvent.POST_PERSIST, listener, "postPersist");
+ addDefaultListener(LifecycleEvent.PRE_REMOVE, listener, "preRemove");
+ addDefaultListener(LifecycleEvent.POST_REMOVE, listener, "postRemove");
+ addDefaultListener(LifecycleEvent.PRE_UPDATE, listener, "preUpdate");
+ addDefaultListener(LifecycleEvent.POST_UPDATE, listener, "postUpdate");
+ addDefaultListener(LifecycleEvent.POST_LOAD, listener, "postLoad");
}
/**
* Registers a callback method to be invoked on a provided non-entity object when a
* lifecycle event occurs on any entity that does not suppress default callbacks.
*/
- public void addDefaultListener(int type, Object listener, String methodName) {
- eventCallbacks[type].addDefaultListener(listener, methodName);
+ public void addDefaultListener(LifecycleEvent type, Object listener, String methodName) {
+ eventCallbacks[type.ordinal()].addDefaultListener(listener, methodName);
}
/**
@@ -100,14 +97,14 @@
* listeners are not required to implement {@link LifecycleListener} interface. Other
* methods in this class can be used to register arbitrary listeners.
*/
- public void addListener(Class entityClass, LifecycleListener listener) {
- addListener(LifecycleListener.PRE_PERSIST, entityClass, listener, "prePersist");
- addListener(LifecycleListener.POST_PERSIST, entityClass, listener, "postPersist");
- addListener(LifecycleListener.PRE_REMOVE, entityClass, listener, "preRemove");
- addListener(LifecycleListener.POST_REMOVE, entityClass, listener, "postRemove");
- addListener(LifecycleListener.PRE_UPDATE, entityClass, listener, "preUpdate");
- addListener(LifecycleListener.POST_UPDATE, entityClass, listener, "postUpdate");
- addListener(LifecycleListener.POST_LOAD, entityClass, listener, "postLoad");
+ public void addListener(Class<?> entityClass, LifecycleListener listener) {
+ addListener(LifecycleEvent.PRE_PERSIST, entityClass, listener, "prePersist");
+ addListener(LifecycleEvent.POST_PERSIST, entityClass, listener, "postPersist");
+ addListener(LifecycleEvent.PRE_REMOVE, entityClass, listener, "preRemove");
+ addListener(LifecycleEvent.POST_REMOVE, entityClass, listener, "postRemove");
+ addListener(LifecycleEvent.PRE_UPDATE, entityClass, listener, "preUpdate");
+ addListener(LifecycleEvent.POST_UPDATE, entityClass, listener, "postUpdate");
+ addListener(LifecycleEvent.POST_LOAD, entityClass, listener, "postLoad");
}
/**
@@ -115,32 +112,32 @@
* lifecycle event occurs for a specific entity.
*/
public void addListener(
- int type,
- Class entityClass,
+ LifecycleEvent type,
+ Class<?> entityClass,
Object listener,
String methodName) {
- eventCallbacks[type].addListener(entityClass, listener, methodName);
+ eventCallbacks[type.ordinal()].addListener(entityClass, listener, methodName);
}
/**
* Registers a callback method to be invoked on an entity class instances when a
* lifecycle event occurs.
*/
- public void addListener(int type, Class entityClass, String methodName) {
- eventCallbacks[type].addListener(entityClass, methodName);
+ public void addListener(LifecycleEvent type, Class<?> entityClass, String methodName) {
+ eventCallbacks[type.ordinal()].addListener(entityClass, methodName);
}
/**
* Invokes callbacks of a specific type for a given entity object.
*/
- public void performCallbacks(int type, Persistent object) {
- eventCallbacks[type].performCallbacks(object);
+ public void performCallbacks(LifecycleEvent type, Persistent object) {
+ eventCallbacks[type.ordinal()].performCallbacks(object);
}
/**
* Invokes callbacks of a specific type for a collection of entity objects.
*/
- public void performCallbacks(int type, Collection objects) {
- eventCallbacks[type].performCallbacks(objects);
+ public void performCallbacks(LifecycleEvent type, Collection<?> objects) {
+ eventCallbacks[type.ordinal()].performCallbacks(objects);
}
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextWithDataContextTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextWithDataContextTest.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextWithDataContextTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextWithDataContextTest.java Wed Nov 21 00:37:26 2007
@@ -24,6 +24,7 @@
import org.apache.cayenne.access.ClientServerChannel;
import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.map.LifecycleEvent;
import org.apache.cayenne.query.ObjectIdQuery;
import org.apache.cayenne.query.SelectQuery;
import org.apache.cayenne.reflect.LifecycleCallbackRegistry;
@@ -122,7 +123,7 @@
try {
callbackRegistry.addListener(
- LifecycleListener.PRE_PERSIST,
+ LifecycleEvent.PRE_PERSIST,
MtTable1.class,
"prePersistMethod");
@@ -136,8 +137,10 @@
context.commitChanges();
// find peer
- MtTable1 peer = (MtTable1) csChannel.getServerContext().getGraphManager().getNode(
- clientObject.getObjectId());
+ MtTable1 peer = (MtTable1) csChannel
+ .getServerContext()
+ .getGraphManager()
+ .getNode(clientObject.getObjectId());
assertTrue(peer.isPrePersisted());
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextCallbacksTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextCallbacksTest.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextCallbacksTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextCallbacksTest.java Wed Nov 21 00:37:26 2007
@@ -20,8 +20,8 @@
import org.apache.art.Artist;
import org.apache.art.Painting;
-import org.apache.cayenne.LifecycleListener;
import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.map.LifecycleEvent;
import org.apache.cayenne.reflect.LifecycleCallbackRegistry;
import org.apache.cayenne.unit.CayenneCase;
@@ -49,7 +49,7 @@
assertFalse(a1.isPrePersisted());
registry.addListener(
- LifecycleListener.PRE_PERSIST,
+ LifecycleEvent.PRE_PERSIST,
Artist.class,
"prePersistCallback");
@@ -59,7 +59,7 @@
MockCallingBackListener listener2 = new MockCallingBackListener();
registry.addListener(
- LifecycleListener.PRE_PERSIST,
+ LifecycleEvent.PRE_PERSIST,
Artist.class,
listener2,
"publicCallback");
@@ -91,10 +91,8 @@
assertFalse(a1.isPrePersisted());
assertFalse(a1.isPreRemoved());
- registry.addListener(
- LifecycleListener.PRE_REMOVE,
- Artist.class,
- "preRemoveCallback");
+ registry
+ .addListener(LifecycleEvent.PRE_REMOVE, Artist.class, "preRemoveCallback");
Artist a2 = (Artist) context.newObject(Artist.class);
a2.setArtistName("XX");
@@ -105,7 +103,7 @@
MockCallingBackListener listener2 = new MockCallingBackListener();
registry.addListener(
- LifecycleListener.PRE_REMOVE,
+ LifecycleEvent.PRE_REMOVE,
Artist.class,
listener2,
"publicCallback");
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLQueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLQueryTest.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLQueryTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLQueryTest.java Wed Nov 21 00:37:26 2007
@@ -31,9 +31,9 @@
import org.apache.art.CompoundPkTestEntity;
import org.apache.art.Painting;
import org.apache.cayenne.DataObjectUtils;
-import org.apache.cayenne.LifecycleListener;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.PersistenceState;
+import org.apache.cayenne.map.LifecycleEvent;
import org.apache.cayenne.query.EJBQLQuery;
import org.apache.cayenne.reflect.LifecycleCallbackRegistry;
import org.apache.cayenne.unit.CayenneCase;
@@ -60,7 +60,7 @@
DataContextEJBQLQueryCallback listener = new DataContextEJBQLQueryCallback();
testCallbacks.addDefaultListener(
- LifecycleListener.POST_LOAD,
+ LifecycleEvent.POST_LOAD,
listener,
"postLoad");
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainCallbacksTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainCallbacksTest.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainCallbacksTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainCallbacksTest.java Wed Nov 21 00:37:26 2007
@@ -19,10 +19,10 @@
package org.apache.cayenne.access;
import org.apache.art.Artist;
-import org.apache.cayenne.LifecycleListener;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.Persistent;
import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.map.LifecycleEvent;
import org.apache.cayenne.query.RefreshQuery;
import org.apache.cayenne.query.SelectQuery;
import org.apache.cayenne.reflect.LifecycleCallbackRegistry;
@@ -46,13 +46,10 @@
ObjectContext context = createDataContext();
- registry.addListener(
- LifecycleListener.POST_LOAD,
- Artist.class,
- "postLoadCallback");
+ registry.addListener(LifecycleEvent.POST_LOAD, Artist.class, "postLoadCallback");
MockCallingBackListener listener = new MockCallingBackListener();
registry.addListener(
- LifecycleListener.POST_LOAD,
+ LifecycleEvent.POST_LOAD,
Artist.class,
listener,
"publicCallback");
@@ -126,10 +123,8 @@
context.commitChanges();
assertFalse(a1.isPreUpdated());
- registry.addListener(
- LifecycleListener.PRE_UPDATE,
- Artist.class,
- "preUpdateCallback");
+ registry
+ .addListener(LifecycleEvent.PRE_UPDATE, Artist.class, "preUpdateCallback");
a1.setArtistName("ZZ");
context.commitChanges();
assertTrue(a1.isPreUpdated());
@@ -139,7 +134,7 @@
MockCallingBackListener listener2 = new MockCallingBackListener();
registry.addListener(
- LifecycleListener.PRE_UPDATE,
+ LifecycleEvent.PRE_UPDATE,
Artist.class,
listener2,
"publicCallback");
@@ -169,7 +164,7 @@
assertFalse(a1.isPostUpdated());
registry.addListener(
- LifecycleListener.POST_UPDATE,
+ LifecycleEvent.POST_UPDATE,
Artist.class,
"postUpdateCallback");
a1.setArtistName("ZZ");
@@ -181,7 +176,7 @@
MockCallingBackListener listener2 = new MockCallingBackListener();
registry.addListener(
- LifecycleListener.POST_UPDATE,
+ LifecycleEvent.POST_UPDATE,
Artist.class,
listener2,
"publicCallback");
@@ -206,12 +201,12 @@
context.commitChanges();
registry.addListener(
- LifecycleListener.POST_REMOVE,
+ LifecycleEvent.POST_REMOVE,
Artist.class,
"postRemoveCallback");
MockCallingBackListener listener2 = new MockCallingBackListener();
registry.addListener(
- LifecycleListener.POST_REMOVE,
+ LifecycleEvent.POST_REMOVE,
Artist.class,
listener2,
"publicCallback");
@@ -228,7 +223,7 @@
LifecycleCallbackRegistry registry = getDomain()
.getEntityResolver()
.getCallbackRegistry();
-
+
ObjectContext context = createDataContext();
Artist a1 = (Artist) context.newObject(Artist.class);
a1.setArtistName("XX");
@@ -236,7 +231,7 @@
assertFalse(a1.isPostPersisted());
registry.addListener(
- LifecycleListener.POST_PERSIST,
+ LifecycleEvent.POST_PERSIST,
Artist.class,
"postPersistCallback");
MockCallingBackListener listener2 = new MockCallingBackListener() {
@@ -247,7 +242,7 @@
}
};
registry.addListener(
- LifecycleListener.POST_PERSIST,
+ LifecycleEvent.POST_PERSIST,
Artist.class,
listener2,
"publicCallback");
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/CallbackDescriptorTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/CallbackDescriptorTest.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/CallbackDescriptorTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/CallbackDescriptorTest.java Wed Nov 21 00:37:26 2007
@@ -18,27 +18,17 @@
****************************************************************/
package org.apache.cayenne.map;
-import org.apache.cayenne.LifecycleListener;
-
import junit.framework.TestCase;
public class CallbackDescriptorTest extends TestCase {
public void testConstructor() {
- CallbackDescriptor m = new CallbackDescriptor(LifecycleListener.POST_LOAD);
- assertEquals(LifecycleListener.POST_LOAD, m.getCallbackType());
-
- try {
- new CallbackDescriptor(10000);
- fail("Must have thrown");
- }
- catch (IllegalArgumentException e) {
- // expected
- }
+ CallbackDescriptor m = new CallbackDescriptor(LifecycleEvent.POST_LOAD);
+ assertEquals(LifecycleEvent.POST_LOAD, m.getCallbackType());
}
public void testAddCallbackMethod() {
- CallbackDescriptor m = new CallbackDescriptor(LifecycleListener.PRE_PERSIST);
+ CallbackDescriptor m = new CallbackDescriptor(LifecycleEvent.PRE_PERSIST);
assertEquals(0, m.getCallbackMethods().size());
m.addCallbackMethod("a");
assertEquals(1, m.getCallbackMethods().size());
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/CallbackMapTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/CallbackMapTest.java?rev=596986&r1=596985&r2=596986&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/CallbackMapTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/CallbackMapTest.java Wed Nov 21 00:37:26 2007
@@ -22,20 +22,13 @@
public class CallbackMapTest extends TestCase {
- public void testCallbacks() {
- // assert correct callback ordering
- for (int i = 0; i < CallbackMap.CALLBACKS.length; i++) {
- assertEquals(i, CallbackMap.CALLBACKS[i]);
- }
- }
-
public void testGetCallbacks() {
CallbackDescriptor[] callbacks = new CallbackMap().getCallbacks();
- assertEquals(CallbackMap.CALLBACKS.length, callbacks.length);
-
+ assertEquals(LifecycleEvent.values().length, callbacks.length);
+
// assert correct callback ordering
for (int i = 0; i < callbacks.length; i++) {
- assertEquals(CallbackMap.CALLBACKS[i], callbacks[i].getCallbackType());
+ assertEquals(LifecycleEvent.values()[i], callbacks[i].getCallbackType());
}
}
}