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();
* 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;
+
}
/**
* 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
/**
// 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
*
* @return String
*/
- private String version() { return "00.d4";}
+ private String version() { return "00.d5";}
}
\ No newline at end of file
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);
* @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.
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);
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));
* what about concurrency? */
private static Logfile storeLog;
+ private static ObjectStore o_store = ObjectStore.getInstance();
private StoreContainerType stocType=null;
private StorableObject reference=null;
* @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();
}
}
}
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
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