From: rk Date: Mon, 25 Feb 2002 17:46:32 +0000 (+0000) Subject: basic test run working, next step incorporating into db-layer X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=de8b3b1c19d80b592a490cf63078f48645f13e50;p=mir.git basic test run working, next step incorporating into db-layer --- diff --git a/source/mir/storage/Database.java b/source/mir/storage/Database.java index 06afdf1b..257c1c72 100755 --- a/source/mir/storage/Database.java +++ b/source/mir/storage/Database.java @@ -207,6 +207,8 @@ public class Database implements StorageObject { outValue = new Integer(out).toString(); break; case java.sql.Types.NUMERIC: + /** @todo Numeric can be float or double depending upon + * metadata.getScale() / especially with oracle */ long outl = rs.getLong(valueIndex); if (!rs.wasNull()) outValue = new Long(outl).toString(); diff --git a/source/mir/storage/store/ObjectStore.java b/source/mir/storage/store/ObjectStore.java index 5c554828..0bf8dbd2 100755 --- a/source/mir/storage/store/ObjectStore.java +++ b/source/mir/storage/store/ObjectStore.java @@ -55,12 +55,16 @@ public class ObjectStore { * StoreIdentifier sid is found. */ public StorableObject use(StoreIdentifier sid) { - StorableObject storeObject=null; - StoreContainer stoc = getStoreContainerForSid( sid ); - if (stoc!=null) storeObject=stoc.use(sid); - else System.out.println("Warning: container not found for: " + sid.toString()); - if (storeObject==null) storeMiss++; else storeHit++; - return storeObject; + if (sid!=null ) { + StorableObject storeObject=null; + StoreContainer stoc = getStoreContainerForSid( sid ); + if (stoc!=null) storeObject=stoc.use(sid); + else System.out.println("Warning: container not found for: " + sid.toString()); + if (storeObject!=null) storeHit++; + return storeObject; + } + storeMiss++; return null; + } /** @@ -119,17 +123,29 @@ public class ObjectStore { * sto and invalidates all relevant cache entries. */ - public void invalidate(StorableObject sto) { + public void invalidate(StoreIdentifier sid) { // propagate invalidation to StoreContainer - if (sto!=null) { - StoreIdentifier sid = sto.getStoreIdentifier(); - if (sto!=null) { - StoreContainer stoc = getStoreContainerForSid(sid); - stoc.invalidate(sto); - } + if (sid!=null) { + StoreContainer stoc = getStoreContainerForSid(sid); + stoc.invalidate(sid); } } + /** + * Method: invalidate(StoreContainerType) + * Description: serves to invalidate a whole StoreContainer + * + * @return + */ + public void invalidate(StoreContainerType stoc_type) { + if ( stoc_type != null ) { + StoreContainer stoc = getStoreContainerForStocType(stoc_type); + if ( stoc!=null ) + stoc.invalidate(); + } + + } + // internal methods for StoreContainer managment /** @@ -143,12 +159,17 @@ public class ObjectStore { // find apropriate container for a specific sid if (sid!=null) { StoreContainerType stoc_type = sid.getStoreContainerType(); - if ( containerMap.containsKey(stoc_type) ) - return (StoreContainer)containerMap.get(stoc_type); + return getStoreContainerForStocType(stoc_type); } return null; } + private StoreContainer getStoreContainerForStocType(StoreContainerType stoc_type) { + if ( stoc_type!=null && containerMap.containsKey(stoc_type) ) + return (StoreContainer)containerMap.get(stoc_type); + return null; + } + /** * Method: implementsStorableObject * Description: internall helper method to find out if a class implements @@ -181,5 +202,5 @@ public class ObjectStore { * * @return String */ - private String version() { return "00.d4";} + private String version() { return "00.d5";} } \ No newline at end of file diff --git a/source/mir/storage/store/StoreContainer.java b/source/mir/storage/store/StoreContainer.java index 397179f8..53256d7c 100755 --- a/source/mir/storage/store/StoreContainer.java +++ b/source/mir/storage/store/StoreContainer.java @@ -44,7 +44,7 @@ public class StoreContainer { this.maxSize=maxSize; } - public StorableObject use(StoreIdentifier sid) { + public synchronized StorableObject use(StoreIdentifier sid) { int hit = container.indexOf(sid); if (hit>0) { StoreIdentifier hitSid = (StoreIdentifier)container.get(hit); @@ -82,19 +82,27 @@ public class StoreContainer { * @see StoreIdentifier and removes StoreIdentifier from * list. */ - public void invalidate(StorableObject sto) { - if (sto!=null) { - StoreIdentifier sid = sto.getStoreIdentifier(); - if (sid!=null) { - if ( container.contains(sid) ) { - sid.invalidate(); - container.remove(sid); - removeCount++; - } - } - } + public synchronized void invalidate(StoreIdentifier search_sid) { + if (search_sid!=null) { + int hit = container.indexOf(search_sid); + if (hit >0 ) { + StoreIdentifier sid = (StoreIdentifier)container.get(hit); + container.remove(sid); + sid.invalidate(); + removeCount++; + } + } } + public synchronized void invalidate() { + StoreIdentifier sid; + while (container.size() > 0) { + sid=(StoreIdentifier)container.getLast(); + container.removeLast(); + sid.invalidate(); + } + } + /** * Method: setSize * Description: readjusts StoreContainer size to value. diff --git a/source/mir/storage/store/StoreContainerType.java b/source/mir/storage/store/StoreContainerType.java index f1535bc3..3cb33835 100755 --- a/source/mir/storage/store/StoreContainerType.java +++ b/source/mir/storage/store/StoreContainerType.java @@ -45,7 +45,7 @@ public class StoreContainerType { public static StoreContainerType valueOf(Class stoc_class, int stoc_type) { StoreContainerType returnStocType=null; - if (stoc_type>=0 && stoc_type < STOC_TYPE_MAX) { + if (stoc_type>=0 && stoc_type <= STOC_TYPE_MAX) { HashMap current = uniqueTypes[stoc_type]; if ( current.containsKey(stoc_class) ) returnStocType=(StoreContainerType)current.get(stoc_class); @@ -57,6 +57,9 @@ public class StoreContainerType { return returnStocType; } + public int getStocType() { return stocType; } + public Class getStocClass() { return stocClass; } + public String toString() { StringBuffer sb = new StringBuffer(this.stocClass.toString()); sb.append("@").append(stringForStoreType(stocType)); diff --git a/source/mir/storage/store/StoreIdentifier.java b/source/mir/storage/store/StoreIdentifier.java index 4b7000fc..92ae95ca 100755 --- a/source/mir/storage/store/StoreIdentifier.java +++ b/source/mir/storage/store/StoreIdentifier.java @@ -21,6 +21,7 @@ public class StoreIdentifier { * what about concurrency? */ private static Logfile storeLog; + private static ObjectStore o_store = ObjectStore.getInstance(); private StoreContainerType stocType=null; private StorableObject reference=null; @@ -52,12 +53,38 @@ public class StoreIdentifier { * @return */ public void invalidate() { + System.out.println("Invalidating: " + toString()); // avoid deadlock due to propagation. if (!invalidating) { invalidating=true; + if ( stocType!=null && + stocType.getStocType()==StoreContainerType.STOC_TYPE_ENTITY ) + { + System.out.println("Propagating invalidation to EntityList for " + toString()); + // we should invalidate related ENTITY_LIST + StoreContainerType entityListStocType = + StoreContainerType.valueOf( stocType.getStocClass(), + StoreContainerType.STOC_TYPE_ENTITYLIST ); + o_store.invalidate(entityListStocType); + } + + // propagate invalidation to Set Set set = reference.getNotifyOnReleaseSet(); - /** @todo here we should propagate the invalidation all members of Set - * @see StoreContainer. The set may contain objects of different type.*/ + if (set!=null) { + for (Iterator it = set.iterator(); it.hasNext(); ) { + Object o = it.next(); + if ( o instanceof StoreIdentifier ) { + System.out.println("Propagating invalidation to StoreIdentifier: " + o.toString()); + // propagate invalidation to a specific StoreIdentifier in cache + o_store.invalidate((StoreIdentifier)o); + } else if ( o instanceof StoreContainerType ) { + System.out.println("Propagating invalidation to StoreContainer: " + o.toString()); + // propagate invalidation to a whole StoreContainer + o_store.invalidate((StoreContainerType)o); + } + + } + } release(); } } diff --git a/source/mir/storage/store/test/EntityC1.java b/source/mir/storage/store/test/EntityC1.java index 4f5d89d7..1d2209c3 100755 --- a/source/mir/storage/store/test/EntityC1.java +++ b/source/mir/storage/store/test/EntityC1.java @@ -25,6 +25,13 @@ public class EntityC1 implements StorableObject { } public Set getNotifyOnReleaseSet() { - return null; + HashSet notifiees = new HashSet(); + // simulating a relation from EntityC1 to EntityC2/Entitylist + notifiees.add(StoreContainerType.valueOf( EntityC2.class, + StoreContainerType.STOC_TYPE_ENTITYLIST)); + // simulates a relation to EntityC2 with uniqueIdentifier "1" + notifiees.add(new StoreIdentifier(EntityC2.class,"1")); + notifiees.add(new StoreIdentifier(EntityC2.class,"18")); + return (Set)notifiees; } } \ No newline at end of file diff --git a/source/mir/storage/store/test/TestStore.java b/source/mir/storage/store/test/TestStore.java index 29c15e5e..d549a779 100755 --- a/source/mir/storage/store/test/TestStore.java +++ b/source/mir/storage/store/test/TestStore.java @@ -62,13 +62,15 @@ public class TestStore { if (reference!=null) System.out.println("--- should not have found" + search_sid.toString()); + // test cycle: invalidation */ + search_sid=new StoreIdentifier(EntityC1.class,"1"); + o_store.invalidate(search_sid); System.out.println(o_store.toString()); /** @todo compare values of store and state failed if values are not * right*/ - /** @todo test cycle: search in store */ - /** @todo test cycle: invalidation */ + } } \ No newline at end of file