diff options
Diffstat (limited to 'projects/net.wotonomy.persistence/src/main/java/net')
13 files changed, 243 insertions, 150 deletions
diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOAdaptor.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOAdaptor.java index 17d6454..8624458 100644 --- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOAdaptor.java +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOAdaptor.java @@ -35,10 +35,11 @@ import net.wotonomy.foundation.NSTimestamp; public abstract class EOAdaptor { protected String _name; - protected NSDictionary _connectionDictionary = NSDictionary.EmptyDictionary; - protected NSMutableArray _contexts = new NSMutableArray(); - protected Class _expressionClass; - private static NSMutableDictionary _expressionClassesByName = new NSMutableDictionary(); + @SuppressWarnings("unchecked") + protected NSDictionary<String, Object> _connectionDictionary = (NSDictionary<String, Object>) NSDictionary.EmptyDictionary; + protected NSMutableArray<Object> _contexts = new NSMutableArray<>(); + protected Class<? extends EOSQLExpression> _expressionClass; + private static NSMutableDictionary<String, String> _expressionClassesByName = new NSMutableDictionary<>(); public EOAdaptor(String name) { super(); @@ -75,8 +76,9 @@ public abstract class EOAdaptor { * @param name The name of the adaptor, or a fully qualified class name. * @return */ + @SuppressWarnings("unchecked") public static EOAdaptor adaptorWithName(String name) { - Class adaptorClass = null; + Class<? extends EOAdaptor> adaptorClass = null; String cname = null; if (name.endsWith("Adaptor") && name.indexOf('.') > 0) { cname = name; @@ -88,15 +90,15 @@ public abstract class EOAdaptor { cname = "net.wotonomy." + name.toLowerCase() + "adaptor." + name + "Adaptor"; } try { - adaptorClass = Class.forName(cname); + adaptorClass = (Class<? extends EOAdaptor>) Class.forName(cname); } catch (ClassNotFoundException ex) { throw new IllegalArgumentException("Cannot find class named " + name); } EOAdaptor adaptor = null; - java.lang.reflect.Constructor callme = null; + java.lang.reflect.Constructor<? extends EOAdaptor> callme = null; try { callme = adaptorClass.getConstructor(new Class[] { String.class }); - adaptor = (EOAdaptor) callme.newInstance((Object[]) new String[] { name }); + adaptor = callme.newInstance((Object[]) new String[] { name }); } catch (ClassCastException ex) { throw new IllegalArgumentException( "Class " + adaptorClass.getName() + " must inherit from net.wotonomy.access.EOAdaptor"); @@ -130,13 +132,13 @@ public abstract class EOAdaptor { } public void assignExternalInfoForEntireModel(EOModel model) { - NSArray ents = model.entities(); + NSArray<EOEntity> ents = model.entities(); for (int i = 0; i < ents.count(); i++) { - EOEntity e = (EOEntity) ents.objectAtIndex(i); + EOEntity e = ents.objectAtIndex(i); // TODO: check that entity is not a prototypes entity - NSArray atts = e.attributes(); + NSArray<EOAttribute> atts = e.attributes(); for (int j = 0; j < atts.count(); j++) { - EOAttribute a = (EOAttribute) atts.objectAtIndex(i); + EOAttribute a = atts.objectAtIndex(i); assignExternalInfoForAttribute(a); } assignExternalInfoForEntity(e); @@ -144,7 +146,7 @@ public abstract class EOAdaptor { } public boolean canServiceModel(EOModel model) { - NSDictionary mcd = model.connectionDictionary(); + NSDictionary<String, Object> mcd = model.connectionDictionary(); if (mcd == null && _connectionDictionary == null) return true; if (mcd == null || _connectionDictionary == null) @@ -152,35 +154,36 @@ public abstract class EOAdaptor { return mcd.equals(_connectionDictionary); } - public void setConnectionDictionary(NSDictionary connection) { + public void setConnectionDictionary(NSDictionary<String, Object> connection) { _connectionDictionary = connection; } - public NSDictionary connectionDictionary() { + public NSDictionary<String, Object> connectionDictionary() { return _connectionDictionary; } - public NSArray contexts() { - return new NSArray(_contexts); + public NSArray<Object> contexts() { + return new NSArray<>(_contexts); } public abstract void assertConnectionDictionaryIsValid(); public abstract EOAdaptorContext createAdaptorContext(); - public abstract Class defaultExpressionClass(); + public abstract Class<? extends EOSQLExpression> defaultExpressionClass(); public abstract EOSQLExpressionFactory expressionFactory(); public abstract boolean isValidQualifierType(String typeName, EOModel model); - public Class expressionClass() { + @SuppressWarnings("unchecked") + public Class<? extends EOSQLExpression> expressionClass() { if (_expressionClass != null) return _expressionClass; String cname = expressionClassName(name()); if (cname != null) { try { - _expressionClass = Class.forName(cname); + _expressionClass = (Class<? extends EOSQLExpression>) Class.forName(cname); } catch (ClassNotFoundException ex) { throw new IllegalStateException("Cannot find expression class named " + cname); } @@ -188,7 +191,7 @@ public abstract class EOAdaptor { return defaultExpressionClass(); } - public NSArray externalTypesWithModel(EOModel model) { + public NSArray<?> externalTypesWithModel(EOModel model) { return NSArray.EmptyArray; } @@ -252,7 +255,7 @@ public abstract class EOAdaptor { return _name; } - public NSArray prototypeAttributes() { + public NSArray<?> prototypeAttributes() { return NSArray.EmptyArray; } diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOAdaptorChannel.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOAdaptorChannel.java index 44b3401..13c914c 100644 --- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOAdaptorChannel.java +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOAdaptorChannel.java @@ -42,7 +42,7 @@ public abstract class EOAdaptorChannel { return _context; } - public void addStoredProceduresNamed(NSArray names, EOModel model) { + public void addStoredProceduresNamed(NSArray<String> names, EOModel model) { } public abstract NSArray attributesToFetch(); diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EODatabase.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EODatabase.java index a995290..b98b148 100644 --- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EODatabase.java +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EODatabase.java @@ -28,7 +28,7 @@ import net.wotonomy.foundation.NSMutableDictionary; import net.wotonomy.foundation.NSTimestamp; /** - * + * * @author ezamudio@nasoft.com * @author $Author: cgruber $ * @version $Revision: 894 $ diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EODatabaseContext.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EODatabaseContext.java index 6ee58a5..9cf6721 100644 --- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EODatabaseContext.java +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EODatabaseContext.java @@ -42,40 +42,57 @@ import net.wotonomy.foundation.NSMutableArray; import net.wotonomy.foundation.NSMutableDictionary; /** - * + * Represents an EOObjectStore that connects to an EODatabase * @author ezamudio@nasoft.com * @author $Author: cgruber $ * @version $Revision: 894 $ */ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLocking { - private static Class _contextClass; + private static Class<? extends EODatabaseContext> _contextClass; protected EODatabase _database; protected EOAdaptorContext _context; protected NSMutableArray _channels = new NSMutableArray(); protected NSMutableArray _lockedObjects = new NSMutableArray(); - protected NSMutableDictionary _simpleSnaps; + protected NSMutableDictionary<EOGlobalID, NSDictionary> _simpleSnaps; protected NSMutableDictionary _manySnaps; protected EOObjectStoreCoordinator _coordinator; protected EOEditingContext _currEC; protected int _updateStrategy; + /** + * Create an EODatabaseContext backed by the given EODatabase + * + * @param database The database + */ public EODatabaseContext(EODatabase database) { super(); _database = database; _context = _database.adaptor().createAdaptorContext(); } + /** + * Retrieve the EOAdaptorContext for this context + * @return The EOAdaptorContext + */ public EOAdaptorContext adaptorContext() { return _context; } + /** + * Retrieve the EODatabase for this context + * @return The EODatabase for this context + */ public EODatabase database() { return _database; } + /** + * Retrieve an available EODatabaseChannel for this context + * @return An available EODatabaseChannel + */ public EODatabaseChannel availableChannel() { for (int i = 0; i < _channels.count(); i++) { EODatabaseChannel c = (EODatabaseChannel) _channels.objectAtIndex(i); @@ -88,13 +105,22 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc } public void batchFetchRelationship(EORelationship rel, NSArray arr, EOEditingContext ec) { + // TODO should this do something? } - public static void setContextClassToRegister(Class contextClass) { + /** + * Set the context class + * @param contextClass The context class + */ + public static void setContextClassToRegister(Class<? extends EODatabaseContext> contextClass) { _contextClass = contextClass; } - public static Class contextClassToRegister() { + /** + * Retrieve the context class + * @return + */ + public static Class<? extends EODatabaseContext> contextClassToRegister() { if (_contextClass == null) _contextClass = EODatabaseContext.class; return _contextClass; @@ -104,12 +130,14 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc return _coordinator; } + @Override public void editingContextDidForgetObjectWithGlobalID(EOEditingContext ec, EOGlobalID gid) { database().decrementSnapshotCountForGlobalID(gid); } public void handleDroppedConnection() { // TODO: unregister channels + adaptorContext().handleDroppedConnection(); } @@ -119,6 +147,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * @see net.wotonomy.control.EOCooperatingObjectStore#ownsGlobalID(net.wotonomy. * control.EOGlobalID) */ + @Override public boolean ownsGlobalID(EOGlobalID gid) { if (!(gid instanceof EOKeyGlobalID)) return false; @@ -132,6 +161,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * net.wotonomy.control.EOCooperatingObjectStore#ownsObject(net.wotonomy.control * .EOEnterpriseObject) */ + @Override public boolean ownsObject(EOEnterpriseObject eo) { if (eo.entityName() == null) return false; @@ -145,6 +175,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * net.wotonomy.control.EOCooperatingObjectStore#handlesFetchSpecification(net. * wotonomy.control.EOFetchSpecification) */ + @Override public boolean handlesFetchSpecification(EOFetchSpecification fspec) { String ename = fspec.entityName(); return (database().entityNamed(ename) != null); @@ -162,6 +193,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * net.wotonomy.control.EOObjectStoreCoordinator, * net.wotonomy.control.EOEditingContext) */ + @Override public void prepareForSaveWithCoordinator(EOObjectStoreCoordinator coord, EOEditingContext ec) { // TODO Auto-generated method stub _coordinator = coord; @@ -174,6 +206,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * @see * net.wotonomy.control.EOCooperatingObjectStore#recordChangesInEditingContext() */ + @Override public void recordChangesInEditingContext() { // TODO insert, delete, update } @@ -184,6 +217,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * @see net.wotonomy.control.EOCooperatingObjectStore#recordUpdateForObject(net. * wotonomy.control.EOEnterpriseObject, net.wotonomy.foundation.NSDictionary) */ + @Override public void recordUpdateForObject(EOEnterpriseObject eo, NSDictionary changes) { // TODO Auto-generated method stub } @@ -205,7 +239,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc d.setObjectForKey(gids, relationName); } - public void recordSnapshots(NSDictionary snaps) { + public void recordSnapshots(NSDictionary<EOGlobalID, NSDictionary> snaps) { if (_simpleSnaps == null) throw new IllegalArgumentException("Attempt to record snapshots without a transaction in progress."); _simpleSnaps.addEntriesFromDictionary(snaps); @@ -220,7 +254,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc public void recordToManySnapshots(NSDictionary snaps) { if (_manySnaps == null) throw new IllegalArgumentException("Attempt to record snapshots without a transaction in progress."); - Enumeration enumeration = snaps.keyEnumerator(); + Enumeration<Object> enumeration = snaps.keyEnumerator(); while (enumeration.hasMoreElements()) { Object key = enumeration.nextElement(); NSDictionary d = (NSDictionary) snaps.objectForKey(key); @@ -239,9 +273,9 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * * @see net.wotonomy.control.EOCooperatingObjectStore#performChanges() */ + @Override public void performChanges() { // TODO Auto-generated method stub - } /* @@ -249,6 +283,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * * @see net.wotonomy.control.EOCooperatingObjectStore#commitChanges() */ + @Override public void commitChanges() { adaptorContext().commitTransaction(); } @@ -258,6 +293,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * * @see net.wotonomy.control.EOCooperatingObjectStore#rollbackChanges() */ + @Override public void rollbackChanges() { adaptorContext().rollbackTransaction(); } @@ -269,6 +305,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * net.wotonomy.control.EOCooperatingObjectStore#valuesForKeys(net.wotonomy. * foundation.NSArray, net.wotonomy.control.EOEnterpriseObject) */ + @Override public NSDictionary valuesForKeys(NSArray keys, EOEnterpriseObject eo) { // TODO check snapshots; eo could be a fault return eo.valuesForKeys(keys); @@ -279,6 +316,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * * @see net.wotonomy.foundation.NSLocking#lock() */ + @Override public void lock() { EOAccessLock.lock(); } @@ -288,6 +326,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * * @see net.wotonomy.foundation.NSLocking#unlock() */ + @Override public void unlock() { EOAccessLock.unlock(); } @@ -299,6 +338,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * net.wotonomy.control.EOObjectStore#arrayFaultWithSourceGlobalID(net.wotonomy. * control.EOGlobalID, java.lang.String, net.wotonomy.control.EOEditingContext) */ + @Override public NSArray arrayFaultWithSourceGlobalID(EOGlobalID gid, String relName, EOEditingContext ec) { if (!(gid instanceof EOKeyGlobalID)) throw new IllegalArgumentException("an EOKeyGlobalID is needed."); @@ -313,6 +353,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * net.wotonomy.control.EOObjectStore#faultForGlobalID(net.wotonomy.control. * EOGlobalID, net.wotonomy.control.EOEditingContext) */ + @Override public /* EOEnterpriseObject */Object faultForGlobalID(EOGlobalID gid, EOEditingContext ec) { if (!(gid instanceof EOKeyGlobalID)) throw new IllegalArgumentException("Cannot fault an object that doesn't have a key global ID."); @@ -329,6 +370,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * @see net.wotonomy.control.EOObjectStore#faultForRawRow(java.util.Map, * java.lang.String, net.wotonomy.control.EOEditingContext) */ + @Override public /* EOEnterpriseObject */ Object faultForRawRow(Map row, String entityName, EOEditingContext ec) { EOEntity e = database().entityNamed(entityName); EOGlobalID gid = e.globalIDForRow(row); @@ -342,9 +384,9 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc _manySnaps.removeObjectForKey(gid); } - public void forgetSnapshotsForGlobalIDs(List gids) { + public void forgetSnapshotsForGlobalIDs(List<EOGlobalID> gids) { for (int i = 0; i < gids.size(); i++) { - EOGlobalID g = (EOGlobalID) gids.get(i); + EOGlobalID g = gids.get(i); forgetSnapshotForGlobalID(g); database().forgetSnapshotForGlobalID(g); } @@ -356,6 +398,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * @see net.wotonomy.control.EOObjectStore#initializeObject(java.lang.Object, * net.wotonomy.control.EOGlobalID, net.wotonomy.control.EOEditingContext) */ + @Override public void initializeObject(/* EOEnterpriseObject */Object eo, EOGlobalID gid, EOEditingContext ec) { if (gid.isTemporary()) return; @@ -398,6 +441,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * * @see net.wotonomy.control.EOObjectStore#invalidateAllObjects() */ + @Override public void invalidateAllObjects() { invalidateObjectsWithGlobalIDs(database().snapshots().allKeys()); } @@ -409,6 +453,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * net.wotonomy.control.EOObjectStore#invalidateObjectsWithGlobalIDs(java.util. * List) */ + @Override public void invalidateObjectsWithGlobalIDs(List aList) { forgetSnapshotsForGlobalIDs(aList); } @@ -420,6 +465,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * net.wotonomy.control.EOObjectStore#isObjectLockedWithGlobalID(net.wotonomy. * control.EOGlobalID, net.wotonomy.control.EOEditingContext) */ + @Override public boolean isObjectLockedWithGlobalID(EOGlobalID gid, EOEditingContext ec) { return isObjectLockedWithGlobalID(gid); } @@ -434,6 +480,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * @see net.wotonomy.control.EOObjectStore#lockObjectWithGlobalID(net.wotonomy. * control.EOGlobalID, net.wotonomy.control.EOEditingContext) */ + @Override public void lockObjectWithGlobalID(EOGlobalID gid, EOEditingContext ec) { NSDictionary snap = snapshotForGlobalID(gid); if (snap == null) @@ -456,6 +503,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * net.wotonomy.control.EOObjectStore#objectsForSourceGlobalID(net.wotonomy. * control.EOGlobalID, java.lang.String, net.wotonomy.control.EOEditingContext) */ + @Override public NSArray objectsForSourceGlobalID(EOGlobalID gid, String relationName, EOEditingContext ec) { EOEnterpriseObject eo = (EOEnterpriseObject) ec.objectForGlobalID(gid); if (eo == null) @@ -515,6 +563,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * net.wotonomy.control.EOObjectStore#objectsWithFetchSpecification(net.wotonomy * .control.EOFetchSpecification, net.wotonomy.control.EOEditingContext) */ + @Override public NSArray objectsWithFetchSpecification(EOFetchSpecification fspec, EOEditingContext ec) { EODatabaseChannel channel = availableChannel(); channel.selectObjectsWithFetchSpecification(fspec, ec); @@ -534,6 +583,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * @see net.wotonomy.control.EOObjectStore#refaultObject(java.lang.Object, * net.wotonomy.control.EOGlobalID, net.wotonomy.control.EOEditingContext) */ + @Override public void refaultObject(Object obj, EOGlobalID gid, EOEditingContext ec) { if (!(gid instanceof EOKeyGlobalID)) throw new IllegalArgumentException("GlobalID must be an EOKeyGlobalID"); @@ -551,6 +601,7 @@ public class EODatabaseContext extends EOCooperatingObjectStore implements NSLoc * net.wotonomy.control.EOObjectStore#saveChangesInEditingContext(net.wotonomy. * control.EOEditingContext) */ + @Override public void saveChangesInEditingContext(EOEditingContext ec) { prepareForSaveWithCoordinator(null, ec); recordChangesInEditingContext(); diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/AbstractObjectStore.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/AbstractObjectStore.java index 1989582..d47d86b 100644 --- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/AbstractObjectStore.java +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/AbstractObjectStore.java @@ -70,18 +70,19 @@ public abstract class AbstractObjectStore extends EOObjectStore { /** * This implementation returns an appropriately configured array fault. */ - public NSArray arrayFaultWithSourceGlobalID(EOGlobalID aGlobalID, String aRelationship, EOEditingContext aContext) { // System.out.println( - // "arrayFaultWithSourceGlobalID: - // " - // + - // aGlobalID - // + - // " - // : - // " - // + - // aRelationship - // ); + public NSArray arrayFaultWithSourceGlobalID(EOGlobalID aGlobalID, String aRelationship, EOEditingContext aContext) { + // System.out.println( + // "arrayFaultWithSourceGlobalID: + // " + // + + // aGlobalID + // + + // " + // : + // " + // + + // aRelationship + // ); return new ArrayFault(aGlobalID, aRelationship, aContext); } diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOClassDescription.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOClassDescription.java index 79019de..c4425cb 100644 --- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOClassDescription.java +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOClassDescription.java @@ -36,7 +36,7 @@ import net.wotonomy.foundation.internal.WotonomyException; * The default implementation works for most well-formed java beans, but you * will want to create your own subclass most typically to customize the toOne * and toMany relationships for your class to ensure that an entire graph of - * objects is not persisted in order to perist a single object. <br> + * objects is not persisted in order to persist a single object. <br> * <br> * * The easiest way to register your subclass is to create it in the same package @@ -53,7 +53,7 @@ import net.wotonomy.foundation.internal.WotonomyException; * @author $Author: cgruber $ * @version $Revision: 900 $ */ -public class EOClassDescription { +public class EOClassDescription<C> { /** * A delete rule specifying that object(s) that reference this object should * have those references set to null when this object is deleted. @@ -67,7 +67,7 @@ public class EOClassDescription { public static final int DeleteRuleCascade = 1; /** - * A delete rule specicying that this object should not be allowed to be deleted + * A delete rule specifying that this object should not be allowed to be deleted * if it references any object(s). */ public static final int DeleteRuleDeny = 2; @@ -110,24 +110,25 @@ public class EOClassDescription { * still not found, a class description is returned that uses java bean * introspection to provide reasonable values. */ - public static EOClassDescription classDescriptionForClass(Class aClass) { + @SuppressWarnings("unchecked") + public static <C> EOClassDescription<C> classDescriptionForClass(Class<C> aClass) { if (classMap == null) - classMap = new HashMap(); - EOClassDescription result = (EOClassDescription) classMap.get(aClass); + classMap = new HashMap<>(); + EOClassDescription<C> result = (EOClassDescription<C>) classMap.get(aClass); if (result == null) { // if not found, post notification NSNotificationCenter.defaultCenter().postNotification(ClassDescriptionNeededForClassNotification, aClass, null); - result = (EOClassDescription) classMap.get(aClass); + result = (EOClassDescription<C>) classMap.get(aClass); } if (result == null) { // if not found, look for similarly named class String className = aClass.getName() + ClassNameSuffix; - Class classDesc; + Class<EOClassDescription<C>> classDesc; try { - classDesc = aClass.getClassLoader().loadClass(className); + classDesc = (Class<EOClassDescription<C>>) aClass.getClassLoader().loadClass(className); if (classDesc != null) { - result = (EOClassDescription) classDesc.newInstance(); + result = classDesc.getDeclaredConstructor().newInstance(); registerClassDescription(result, aClass); } } catch (Exception exc) { @@ -136,7 +137,7 @@ public class EOClassDescription { } if (result == null) { // if not found, default to this class - result = new EOClassDescription(aClass); + result = new EOClassDescription<>(aClass); registerClassDescription(result, aClass); } return result; @@ -148,15 +149,16 @@ public class EOClassDescription { * ClassDescriptionNeededForEntityNameNotification is posted. Returns null if no * class description can be found for the entity name. */ - public static EOClassDescription classDescriptionForEntityName(String aName) { + @SuppressWarnings("unchecked") + public static <C> EOClassDescription<C> classDescriptionForEntityName(String aName) { if (entityMap == null) - entityMap = new HashMap(); - EOClassDescription result = (EOClassDescription) entityMap.get(aName); + entityMap = new HashMap<>(); + EOClassDescription<C> result = (EOClassDescription<C>) entityMap.get(aName); if (result == null) { // if not found, post notification NSNotificationCenter.defaultCenter().postNotification(ClassDescriptionNeededForEntityNameNotification, aName, null); - result = (EOClassDescription) entityMap.get(aName); + result = (EOClassDescription<C>) entityMap.get(aName); } return result; } @@ -171,14 +173,14 @@ public class EOClassDescription { } /** - * Registers the specified class descriptiong for the specified class. Nulls are + * Registers the specified class description for the specified class. Nulls are * not allowed - to clear the cache call invalidateClassDescriptionCache(). */ - public static void registerClassDescription(EOClassDescription description, Class aClass) { + public static <C> void registerClassDescription(EOClassDescription<C> description, Class<C> aClass) { if (classMap == null) - classMap = new HashMap(); + classMap = new HashMap<>(); if (entityMap == null) - entityMap = new HashMap(); + entityMap = new HashMap<>(); description.theClass = aClass; classMap.put(aClass, description); entityMap.put(description.entityName(), description); @@ -198,16 +200,16 @@ public class EOClassDescription { */ private final static String ClassNameSuffix = "ClassDesc"; - private static Map classMap; - private static Map entityMap; + private static Map<Class<?>, EOClassDescription<?>> classMap; + private static Map<String, EOClassDescription<?>> entityMap; - protected Class theClass; + protected Class<?> theClass; private NSMutableArray attributes; /** * Constructor may only be called by subclasses. */ - protected EOClassDescription(Class aClass) { + protected EOClassDescription(Class<?> aClass) { theClass = aClass; } @@ -265,7 +267,7 @@ public class EOClassDescription { * relationship key, or null if the class description cannot be determined for * that key. This implementation returns null. */ - public EOClassDescription classDescriptionForDestinationKey(String detailKey) { + public EOClassDescription<?> classDescriptionForDestinationKey(String detailKey) { return null; } @@ -280,11 +282,12 @@ public class EOClassDescription { * editing context is specified, the global id is ignored and the new instance * of the class is returned. */ - public Object createInstanceWithEditingContext(EOEditingContext anEditingContext, EOGlobalID globalID) { + @SuppressWarnings("unchecked") + public C createInstanceWithEditingContext(EOEditingContext anEditingContext, EOGlobalID globalID) { //System.out.println( "createInstanceWithEditingContext: " + this + " : " + theClass ); Object result = null; try { - result = theClass.newInstance(); + result = theClass.getDeclaredConstructor().newInstance(); if (anEditingContext != null) { if (globalID != null) { if (result instanceof EOEnterpriseObject) { @@ -305,7 +308,7 @@ public class EOClassDescription { // error instantiating throw new WotonomyException(exc); } - return result; + return (C) result; } /* diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOCooperatingObjectStore.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOCooperatingObjectStore.java index 98a8a60..552e6b8 100644 --- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOCooperatingObjectStore.java +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOCooperatingObjectStore.java @@ -59,8 +59,10 @@ public abstract class EOCooperatingObjectStore extends EOObjectStore implements public abstract NSDictionary valuesForKeys(NSArray nsarray, EOEnterpriseObject eoenterpriseobject); + @Override public abstract void lock(); + @Override public abstract void unlock(); } diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOEditingContext.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOEditingContext.java index 3a39035..8342722 100644 --- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOEditingContext.java +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOEditingContext.java @@ -89,23 +89,24 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { private EOObjectStore parentStore; private WeakReference delegate; private WeakReference messageHandler; - private List editorSet; + private List<WeakReference<EOEditingContext.Editor>> editorSet; private double fetchTimestamp; private boolean lockBeforeModify; private boolean propagateDeletesAfterEvent; private boolean stopValidationAfterError; - private NSMutableArray insertedObjects; - private NSMutableArray insertedObjectsBuffer; - private NSArray insertedObjectsProxy; - private NSMutableArray updatedObjects; - private NSMutableArray updatedObjectsBuffer; - private NSArray updatedObjectsProxy; - private NSMutableArray deletedObjects; - private NSMutableArray deletedObjectsBuffer; - private NSArray deletedObjectsProxy; - private NSMutableArray deletedIDsBuffer; - private NSMutableArray invalidatedObjectsBuffer; - private NSMutableArray invalidatedIDsBuffer; + private NSMutableArray<Object> insertedObjects; + private NSMutableArray<Object> insertedObjectsBuffer; + private NSArray<Object> insertedObjectsProxy; + private NSMutableArray<Object> updatedObjects; + private NSMutableArray<Object> updatedObjectsBuffer; + private NSArray<Object> updatedObjectsProxy; + private NSMutableArray<Object> deletedObjects; + private NSMutableArray<Object> deletedObjectsBuffer; + private NSArray<Object> deletedObjectsProxy; + // TODO I think this is EOGlobalID but not certain + private NSMutableArray<Object> deletedIDsBuffer; + private NSMutableArray<Object> invalidatedObjectsBuffer; + private NSMutableArray<EOGlobalID> invalidatedIDsBuffer; private Registrar registrar; // private UndoManager undoManager; @@ -143,7 +144,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { parentStore = anObjectStore; delegate = null; messageHandler = null; - editorSet = new LinkedList(); + editorSet = new LinkedList<>(); fetchTimestamp = 0; lockBeforeModify = false; propagateDeletesAfterEvent = true; @@ -189,10 +190,10 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * Registers the specified object as an editor for this context. The object is * expected to implement EOEditingContext.Editor. */ - public void addEditor(Object anEditor) { + public void addEditor(EOEditingContext.Editor anEditor) { if (anEditor == null) return; - editorSet.add(new WeakReference(anEditor)); + editorSet.add(new WeakReference<>(anEditor)); } /** @@ -205,6 +206,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * specified relationship key must produce a result of type Collection for the * source object or an exception is thrown. */ + @Override public NSArray arrayFaultWithSourceGlobalID(EOGlobalID aGlobalID, String aRelationshipKey, EOEditingContext aContext) { NSArray result = null; @@ -337,6 +339,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * Called by child editing contexts when they no longer need to track the * specified id. This implementation forwards the call to the parent store. */ + @Override public void editingContextDidForgetObjectWithGlobalID(EOEditingContext aContext, EOGlobalID aGlobalID) { parentStore.editingContextDidForgetObjectWithGlobalID(aContext, aGlobalID); } @@ -347,9 +350,9 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { public NSArray editors() { NSMutableArray result = new NSMutableArray(); Object o; - Iterator i = editorSet.iterator(); + Iterator<WeakReference<Editor>> i = editorSet.iterator(); while (i.hasNext()) { - o = ((WeakReference) i.next()).get(); + o = i.next().get(); if (o != null) { result.addObject(o); } else { @@ -370,6 +373,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * create a copy of the object and register it in the specified context. * Otherwise it will forward the call to the parent object store. */ + @Override public /* EOEnterpriseObject */ Object faultForGlobalID(EOGlobalID aGlobalID, EOEditingContext aContext) { Object result = registrar.objectForGlobalID(aGlobalID); @@ -402,6 +406,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * specified editing context. This implementation forwards the call to the * parent store. */ + @Override public /* EOEnterpriseObject */ Object faultForRawRow(Map aDictionary, String anEntityName, EOEditingContext aContext) { return parentStore.faultForRawRow(aDictionary, anEntityName, aContext); @@ -461,11 +466,10 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { /** * Returns an array of ids for an array of objects. */ - private NSArray globalIDsForObjects(List anObjectList) { + private NSArray globalIDsForObjects(List<Object> anObjectList) { NSMutableArray result = new NSMutableArray(); - Iterator it = anObjectList.iterator(); - while (it.hasNext()) { - result.add(globalIDForObject(it.next())); + for (Object obj : anObjectList) { + result.add(globalIDForObject(obj)); } return result; } @@ -492,6 +496,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * in this editing context if possible, calling to the parent object store only * if such an object is not found. */ + @Override public void initializeObject(/* EOEnterpriseObject */ Object anObject, EOGlobalID aGlobalID, EOEditingContext aContext) { Object existingObject = registrar.objectForGlobalID(aGlobalID); @@ -539,6 +544,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { deletedObjects.removeObjectAtIndex(index); // if in the deleted ids buffer + // TODO is this index = deletedIDsBuffer.indexOfIdenticalObject(anObject); if (index != NSArray.NotFound) { // remove from deleted ids buffer @@ -587,6 +593,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * fetched the next time they are accessed, and calls * invalidateObjectsWithGlobalIDs on the parent object store. */ + @Override public void invalidateAllObjects() { // register change so processRecentChanges is called willChange(); @@ -613,9 +620,9 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { // refault all objects EOGlobalID id; Object o; - Enumeration e = ids.objectEnumerator(); + Enumeration<EOGlobalID> e = ids.objectEnumerator(); while (e.hasMoreElements()) { - id = (EOGlobalID) e.nextElement(); + id = e.nextElement(); o = objectForGlobalID(id); // some objects may have been manually discarded @@ -645,6 +652,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * fetched the next time they are accessed, and forwards the call to the parent * object store. */ + @Override public void invalidateObjectsWithGlobalIDs(List anArray) { // register change so processRecentChanges is called willChange(); @@ -654,9 +662,9 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { Object o; EOGlobalID id; - Iterator it = anArray.iterator(); + Iterator<EOGlobalID> it = anArray.iterator(); while (it.hasNext()) { - id = (EOGlobalID) it.next(); + id = it.next(); if (id != null) { o = objectForGlobalID(id); if (o != null) { @@ -688,6 +696,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * Returns whether the object referenced by the specified id is locked. This * implementation simply forwards the call to the parent object store. */ + @Override public boolean isObjectLockedWithGlobalID(EOGlobalID aGlobalID, EOEditingContext aContext) { return parentStore.isObjectLockedWithGlobalID(aGlobalID, aContext); } @@ -709,6 +718,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * context. This implementation simply forwards the call to the parent object * store. */ + @Override public void lockObjectWithGlobalID(EOGlobalID aGlobalID, EOEditingContext aContext) { parentStore.lockObjectWithGlobalID(aGlobalID, aContext); } @@ -747,6 +757,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * specified relationship key must produce a result of type Collection for the * source object or an exception is thrown. */ + @Override public NSArray objectsForSourceGlobalID(EOGlobalID aGlobalID, String aRelationshipKey, EOEditingContext aContext) { //System.out.println( "EOEditingContext.objectsForSourceGlobalID: " //+ aGlobalID + " : " + aRelationshipKey ); @@ -793,7 +804,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { } else // not NSArray if (value instanceof Collection) { // convert to NSArray - result = new NSArray((Collection) value); + result = new NSArray((Collection<?>) value); } else { throw new WotonomyException( "Relationship key did not return a collection: " + aGlobalID + " : " + aRelationshipKey); @@ -825,6 +836,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * parent object store, which will register each object in the specified editing * context only if it does not already exist. */ + @Override public NSArray objectsWithFetchSpecification(EOFetchSpecification aFetchSpec, EOEditingContext aContext) { if (aContext == this) { Object result = notifyDelegate("editingContextShouldFetchObjects", @@ -869,7 +881,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { boolean postStoreInfo = (insertedObjectsBuffer.size() + updatedObjectsBuffer.size() + deletedIDsBuffer.size() + invalidatedIDsBuffer.size() > 0); - NSMutableDictionary storeInfo = new NSMutableDictionary(); + NSMutableDictionary<String, NSArray> storeInfo = new NSMutableDictionary<>(); if (postStoreInfo) { storeInfo.setObjectForKey(globalIDsForObjects(insertedObjectsBuffer), // globalIDsForObjects( insertedObjects ), @@ -877,10 +889,10 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { storeInfo.setObjectForKey(globalIDsForObjects(updatedObjectsBuffer), // globalIDsForObjects( updatedObjects ), EOObjectStore.UpdatedKey); - storeInfo.setObjectForKey(new NSArray((Collection) deletedIDsBuffer), + storeInfo.setObjectForKey(new NSArray((Collection<?>) deletedIDsBuffer), // globalIDsForObjects( deletedObjects ), EOObjectStore.DeletedKey); - storeInfo.setObjectForKey(new NSArray((Collection) invalidatedIDsBuffer), EOObjectStore.InvalidatedKey); + storeInfo.setObjectForKey(new NSArray((Collection<?>) invalidatedIDsBuffer), EOObjectStore.InvalidatedKey); } // broadcast ObjectsChangedInEditingContextNotification @@ -889,27 +901,27 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { boolean postContextInfo = (insertedObjectsBuffer.size() + updatedObjectsBuffer.size() + deletedObjectsBuffer.size() + invalidatedObjectsBuffer.size() > 0); - NSMutableDictionary contextInfo = new NSMutableDictionary(); + NSMutableDictionary<String, NSArray> contextInfo = new NSMutableDictionary<>(); if (postContextInfo) { - contextInfo.setObjectForKey(new NSArray((Collection) insertedObjectsBuffer), + contextInfo.setObjectForKey(new NSArray((Collection<?>) insertedObjectsBuffer), // new NSArray( (Collection) insertedObjects ), EOObjectStore.InsertedKey); - contextInfo.setObjectForKey(new NSArray((Collection) updatedObjectsBuffer), + contextInfo.setObjectForKey(new NSArray((Collection<?>) updatedObjectsBuffer), // new NSArray( (Collection) updatedObjects ), EOObjectStore.UpdatedKey); - contextInfo.setObjectForKey(new NSArray((Collection) deletedObjectsBuffer), + contextInfo.setObjectForKey(new NSArray((Collection<?>) deletedObjectsBuffer), // new NSArray( (Collection) deletedObjects ), EOObjectStore.DeletedKey); - contextInfo.setObjectForKey(new NSArray((Collection) invalidatedObjectsBuffer), + contextInfo.setObjectForKey(new NSArray((Collection<?>) invalidatedObjectsBuffer), EOObjectStore.InvalidatedKey); } // update the current snapshots Object o; - Iterator it; + Iterator<Object> it; it = insertedObjectsBuffer.iterator(); while (it.hasNext()) { o = it.next(); @@ -1024,6 +1036,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * Refaults the specified object, turning it into a fault for the specified * global id in the specified context. */ + @Override public void refaultObject(Object anObject, EOGlobalID aGlobalID, EOEditingContext aContext) { aContext.registrar.setCurrentSnapshot(anObject, null); @@ -1052,7 +1065,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { Object o; EOGlobalID id; - Iterator it = registeredObjects().iterator(); + Iterator<Object> it = registeredObjects().iterator(); while (it.hasNext()) { o = it.next(); if ((updatedObjects.indexOfIdenticalObject(o) == NSArray.NotFound) @@ -1088,9 +1101,9 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { return; Object o; - Iterator i = editorSet.iterator(); + Iterator<WeakReference<Editor>> i = editorSet.iterator(); while (i.hasNext()) { - o = ((WeakReference) i.next()).get(); + o = i.next().get(); if ((o == null) || (o == anObject)) { i.remove(); } @@ -1102,7 +1115,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * timestamp. */ public void reset() { - Iterator it = registeredObjects().iterator(); + Iterator<Object> it = registeredObjects().iterator(); while (it.hasNext()) { forgetObject(it.next()); } @@ -1119,7 +1132,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { willChange(); fireWillSaveChanges(); - Iterator it; + Iterator<Object> it; // forget inserted objects it = new NSArray(insertedObjects).iterator(); @@ -1127,7 +1140,6 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { forgetObject(it.next()); } - EOGlobalID id; Object o; byte[] snapshot; @@ -1190,10 +1202,10 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { processRecentChanges(); // set up user info for notification to be posted. - NSMutableDictionary userInfo = new NSMutableDictionary(); - userInfo.setObjectForKey(new NSArray((Collection) insertedObjects), EOObjectStore.InsertedKey); - userInfo.setObjectForKey(new NSArray((Collection) updatedObjects), EOObjectStore.UpdatedKey); - userInfo.setObjectForKey(new NSArray((Collection) deletedObjects), EOObjectStore.DeletedKey); + NSMutableDictionary<String, NSArray> userInfo = new NSMutableDictionary<>(); + userInfo.setObjectForKey(new NSArray((Collection<?>) insertedObjects), EOObjectStore.InsertedKey); + userInfo.setObjectForKey(new NSArray((Collection<?>) updatedObjects), EOObjectStore.UpdatedKey); + userInfo.setObjectForKey(new NSArray((Collection<?>) deletedObjects), EOObjectStore.DeletedKey); // notify the editors fireWillSaveChanges(); @@ -1215,8 +1227,8 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { // no exceptions: proceed! - Object o, key; - Iterator it; + Object o; + Iterator<Object> it; // update the committed snapshots it = insertedObjects.iterator(); @@ -1249,12 +1261,13 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * Commits all changes in the specified editing context to this one. Called by * child editing contexts in their saveChanges() method. */ + @Override public void saveChangesInEditingContext(EOEditingContext aContext) { Object o; - Iterator it; + Iterator<Object> it; // process deletes - List deletes = new NSArray(aContext.deletedObjects()); + List<Object> deletes = new NSArray(aContext.deletedObjects()); it = deletes.iterator(); while (it.hasNext()) { o = it.next(); @@ -1276,7 +1289,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { } // process inserts - all inserts are new objects - List inserts = new NSArray(aContext.insertedObjects()); + List<Object> inserts = new NSArray(aContext.insertedObjects()); it = inserts.iterator(); while (it.hasNext()) { o = it.next(); @@ -1293,7 +1306,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { } // process updates - List updates = new NSArray(aContext.updatedObjects()); + List<Object> updates = new NSArray(aContext.updatedObjects()); it = updates.iterator(); while (it.hasNext()) { willChange(); // need to mark editing context as changed @@ -1335,7 +1348,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { public void setDelegate(Object anObject) { if (anObject == null) delegate = null; - delegate = new WeakReference(anObject); + delegate = new WeakReference<>(anObject); } /** @@ -1442,7 +1455,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { */ private void fireWillSaveChanges() { Object o = null; - Iterator i = editors().iterator(); + Iterator<WeakReference<EOEditingContext.Editor>> i = editors().iterator(); while (i.hasNext()) { try { o = i.next(); @@ -1477,16 +1490,16 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { NSNotificationCenter.defaultCenter() .postNotification(new NSNotification(InvalidatedAllObjectsInStoreNotification, this)); } else if (EOGlobalID.GlobalIDChangedNotification.equals(aNotification.name())) { - NSDictionary userInfo = aNotification.userInfo(); + NSDictionary<EOGlobalID, ?> userInfo = aNotification.userInfo(); // if any keys in userInfo are registered ids, // re-register with new permanent values. Object o; EOGlobalID id; - Enumeration e = userInfo.keyEnumerator(); + Enumeration<EOGlobalID> e = userInfo.keyEnumerator(); while (e.hasMoreElements()) { - id = (EOGlobalID) e.nextElement(); + id = e.nextElement(); o = objectForGlobalID(id); if (o != null) { // record object is assumed to handle key updates @@ -1501,16 +1514,16 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { Object o; EOGlobalID id; - Enumeration e; - NSDictionary userInfo = aNotification.userInfo(); + Enumeration<EOGlobalID> e; + NSDictionary<String, NSArray<EOGlobalID>> userInfo = (NSDictionary<String, NSArray<EOGlobalID>>) aNotification.userInfo(); // inserted objects are ignored // existing deleted objects are removed - NSArray deletes = (NSArray) userInfo.objectForKey(EOObjectStore.DeletedKey); + NSArray<EOGlobalID> deletes = userInfo.objectForKey(EOObjectStore.DeletedKey); e = deletes.objectEnumerator(); while (e.hasMoreElements()) { - id = (EOGlobalID) e.nextElement(); + id = e.nextElement(); o = objectForGlobalID(id); if (o != null) { // System.out.println( "EOEditingContext: deleted: " + id ); @@ -1521,10 +1534,10 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { } // existing updated objects are merged - NSArray updates = (NSArray) userInfo.objectForKey(EOObjectStore.UpdatedKey); + NSArray<EOGlobalID> updates = userInfo.objectForKey(EOObjectStore.UpdatedKey); e = updates.objectEnumerator(); while (e.hasMoreElements()) { - id = (EOGlobalID) e.nextElement(); + id = e.nextElement(); o = objectForGlobalID(id); if (o != null) { // System.out.println( "EOEditingContext: updated: " + id ); @@ -1540,10 +1553,10 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { } // existing invalidated objects are refaulted - NSArray invalidates = (NSArray) userInfo.objectForKey(EOObjectStore.InvalidatedKey); + NSArray<EOGlobalID> invalidates = userInfo.objectForKey(EOObjectStore.InvalidatedKey); e = invalidates.objectEnumerator(); while (e.hasMoreElements()) { - id = (EOGlobalID) e.nextElement(); + id = e.nextElement(); o = objectForGlobalID(id); if (o != null) { if (updatedObjects // only invalidate if unchanged @@ -1719,6 +1732,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * Implementation of the EOObserving interface. Called before objects are * modified. */ + @Override public void objectWillChange(Object anObject) { if (ignoreChanges) return; @@ -1812,6 +1826,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { * net.wotonomy.util.WotonomyException("Not implemented yet."); } */ + @Override public String toString() { return "[EOEditingContext@" + Integer.toHexString(System.identityHashCode(this)) + ":" + " inserted=" + idsForObjects(insertedObjects) + " updated=" + idsForObjects(updatedObjects) + " deleted=" @@ -2054,6 +2069,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { weakComparisonKey = new WeakReferenceKey(); } + @Override public NSArray registeredObjects() { Object object; WeakReferenceKey weakKey; @@ -2072,6 +2088,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { return result; } + @Override public Object objectForGlobalID(EOGlobalID aGlobalID) { WeakReference ref = (WeakReference) super.objectForGlobalID(aGlobalID); if (ref == null) @@ -2089,11 +2106,13 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { return result; } + @Override public byte[] getCommitSnapshot(Object anObject) { weakComparisonKey.set(anObject); return (byte[]) objectsToCommitSnapshots.objectForKey(weakComparisonKey); } + @Override public void setCommitSnapshot(Object anObject, byte[] aSnapshot) { if (aSnapshot == null) { weakComparisonKey.set(anObject); @@ -2103,11 +2122,13 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { } } + @Override public byte[] getCurrentSnapshot(Object anObject) { weakComparisonKey.set(anObject); return (byte[]) objectsToCurrentSnapshots.objectForKey(weakComparisonKey); } + @Override public void setCurrentSnapshot(Object anObject, byte[] aSnapshot) { if (aSnapshot == null) { weakComparisonKey.set(anObject); @@ -2117,6 +2138,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { } } + @Override public void registerObject(Object anObject, EOGlobalID aGlobalID) { // new // net.wotonomy.ui.swing.ReferenceInspector( // anObject ); @@ -2125,6 +2147,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { EOObserverCenter.addObserver(context, anObject); } + @Override public void forgetObject(Object anObject) { disposeObject(anObject, null); } @@ -2173,6 +2196,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { /** * Returns the actual key's hash code. */ + @Override public int hashCode() { return hashCode; } @@ -2180,6 +2204,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { /** * Compares by reference. */ + @Override public boolean equals(Object anObject) { if (anObject == this) return true; @@ -2203,10 +2228,12 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { super(anObject); } + @Override public Object get() { return ((WeakReference) referent).get(); } + @Override public void set(Object anObject) { referent = new WeakReference(anObject); hashCode = anObject.hashCode(); @@ -2215,6 +2242,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { /** * Compares by reference. */ + @Override public boolean equals(Object anObject) { if (anObject == this) return true; @@ -2242,10 +2270,12 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { hashCode = object.hashCode() + string.hashCode(); } + @Override public int hashCode() { return hashCode; } + @Override public boolean equals(Object anObject) { if (anObject instanceof CompoundKey) { CompoundKey key = (CompoundKey) anObject; @@ -2254,6 +2284,7 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { return false; } + @Override public String toString() { return "[CompoundKey:" + object + ":" + string + "]"; } diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOFaultHandler.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOFaultHandler.java index e407492..c9c9de4 100644 --- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOFaultHandler.java +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOFaultHandler.java @@ -28,7 +28,7 @@ package net.wotonomy.control; */ public abstract class EOFaultHandler { - protected Class _targetClass; + protected Class<?> _targetClass; public EOFaultHandler() { super(); @@ -61,7 +61,7 @@ public abstract class EOFaultHandler { ((EOFaulting) obj).clearFault(); } - public Class targetClass() { + public Class<?> targetClass() { return _targetClass; } diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOKeyValueCodingAdditions.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOKeyValueCodingAdditions.java index d1bb2c0..f0fdba1 100644 --- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOKeyValueCodingAdditions.java +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOKeyValueCodingAdditions.java @@ -47,7 +47,7 @@ public interface EOKeyValueCodingAdditions extends EOKeyValueCoding, NSKeyValueC * NSKeyValueCodingAdditions, otherwise calls the method on * DefaultImplementation. */ - public static void takeValuesFromDictionary(Object object, Map dictionary) { + public static void takeValuesFromDictionary(Object object, Map<String, Object> dictionary) { if (object instanceof NSKeyValueCodingAdditions) { ((NSKeyValueCodingAdditions) object).takeValuesFromDictionary(dictionary); } else { @@ -75,7 +75,7 @@ public interface EOKeyValueCodingAdditions extends EOKeyValueCoding, NSKeyValueC * NSKeyValueCodingAdditions, otherwise calls the method on * DefaultImplementation. */ - public static NSDictionary valuesForKeys(Object object, List keys) { + public static NSDictionary<String, Object> valuesForKeys(Object object, List<String> keys) { if (object instanceof NSKeyValueCodingAdditions) { return ((NSKeyValueCodingAdditions) object).valuesForKeys(keys); } else { @@ -102,20 +102,20 @@ public interface EOKeyValueCodingAdditions extends EOKeyValueCoding, NSKeyValueC * NSKeyValueCodingAdditions. */ public class DefaultImplementation extends NSKeyValueCodingAdditions.DefaultImplementation { - public static void takeValuesFromDictionary(Object object, NSDictionary dictionary) { + public static void takeValuesFromDictionary(Object object, NSDictionary<String, Object> dictionary) { throw new RuntimeException("Not implemented yet."); } - public static void takeValuesFromDictionaryWithMapping(Object object, NSDictionary dictionary, - NSDictionary mapping) { + public static void takeValuesFromDictionaryWithMapping(Object object, NSDictionary<String, Object> dictionary, + NSDictionary<?, ?> mapping) { throw new RuntimeException("Not implemented yet."); } - public static NSDictionary valuesForKeys(Object object, List keys) { + public static NSDictionary<String, Object> valuesForKeys(Object object, List<String> keys) { throw new RuntimeException("Not implemented yet."); } - public static NSDictionary valuesForKeysWithMapping(Object object, Map mapping) { + public static NSDictionary<String, Object> valuesForKeysWithMapping(Object object, Map<String, Object> mapping) { throw new RuntimeException("Not implemented yet."); } } diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOObjectStore.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOObjectStore.java index 4f60045..8998bab 100644 --- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOObjectStore.java +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOObjectStore.java @@ -103,7 +103,7 @@ public abstract class EOObjectStore { * must produce a result of type Collection for the source object or an * exception is thrown. */ - public abstract NSArray arrayFaultWithSourceGlobalID(EOGlobalID aGlobalID, String aRelationship, + public abstract NSArray<?> arrayFaultWithSourceGlobalID(EOGlobalID aGlobalID, String aRelationship, EOEditingContext aContext); /** @@ -187,7 +187,7 @@ public abstract class EOObjectStore { public abstract void refaultObject(Object anObject, EOGlobalID aGlobalID, EOEditingContext aContext); /** - * Writes all changes in the specified editing context to the respository. The + * Writes all changes in the specified editing context to the repository. The * object store is expected to post a notification that should be named with the * string constant ObjectsChangedInStoreNotification with this object store as * the object and user info containing keys named UpdatedKey, InsertedKey, and diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOObjectStoreCoordinator.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOObjectStoreCoordinator.java index c2ad03d..6fa0486 100644 --- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOObjectStoreCoordinator.java +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOObjectStoreCoordinator.java @@ -20,7 +20,7 @@ $Id: EOObjectStoreCoordinator.java 894 2006-02-16 16:47:14Z cgruber $ */ package net.wotonomy.control; - + import java.util.List; import java.util.Map; diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOTemporaryGlobalID.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOTemporaryGlobalID.java index 31351a9..b5c60b7 100644 --- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOTemporaryGlobalID.java +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOTemporaryGlobalID.java @@ -37,6 +37,8 @@ import java.net.InetAddress; * @version $Revision: 893 $ */ public class EOTemporaryGlobalID extends EOGlobalID { + private static final long serialVersionUID = 7652533198394290800L; + /** * Holds the length in bytes of the key that is generated. */ |
