ObjectStore cache is working with StorableObjectEntities
authorrk <rk>
Mon, 18 Mar 2002 23:04:23 +0000 (23:04 +0000)
committerrk <rk>
Mon, 18 Mar 2002 23:04:23 +0000 (23:04 +0000)
source/mir/entity/EntityList.java
source/mir/misc/MirConfig.java
source/mir/servlet/ServletModule.java
source/mir/storage/Database.java
source/mir/storage/store/ObjectStore.java
source/mir/storage/store/StoreIdentifier.java
source/mir/storage/store/StoreUtil.java

index 9aca5c7..d82de97 100755 (executable)
@@ -13,9 +13,11 @@ import  java.util.*;
 import  freemarker.template.*;
 
 import  mir.misc.*;
+import  mir.storage.*;
 import  mir.storage.store.*;
 
 
+
 /**
  *
  * Container class for lists of Entities.
@@ -32,7 +34,7 @@ public class EntityList implements TemplateListModel, StorableObject {
   private static Logfile      theLog;
   private ArrayList           theEntityArrayList = new ArrayList();
   private String              whereClause, orderClause;
-  private Class               theEntityClass;
+  private StorageObject       theStorage;
   private int                 count, offset, limit;
   private int                 offsetnext = -1, offsetprev = -1;
   private int                 freemarkerListPointer=-1;
@@ -48,8 +50,8 @@ public class EntityList implements TemplateListModel, StorableObject {
   public EntityList(){         }
 
   /* get/set EntityClass of Objects stored in EntityList */
-  public void setEntityClass(Class theEntityClass) { this.theEntityClass=theEntityClass; }
-  public Class getEntityClass() { return theEntityClass; }
+  public void setStorage(StorageObject storage) { this.theStorage=storage; }
+  public StorageObject getStorage() { return theStorage; }
 
   public void setLimit(int limit) { this.limit = limit; }
 
@@ -261,10 +263,11 @@ public class EntityList implements TemplateListModel, StorableObject {
   public Set getNotifyOnReleaseSet() { return null; }
 
   public StoreIdentifier getStoreIdentifier() {
-    if ( theEntityClass!=null ) {
+    if ( theStorage!=null ) {
       return
         new StoreIdentifier( this, StoreContainerType.STOC_TYPE_ENTITYLIST,
-            StoreUtil.getEntityListUniqueIdentifierFor( whereClause, orderClause, offset, limit ));
+            StoreUtil.getEntityListUniqueIdentifierFor( theStorage.getTableName(),
+                       whereClause, orderClause, offset, limit ));
     }
     theLog.printWarning("EntityList could not return StoreIdentifier");
     return null;
index 88fa0aa..bfd51d7 100755 (executable)
@@ -40,7 +40,7 @@ public class MirConfig extends Configuration {
    * @param name, The name of the servlet (usually "Mir")
    * @param confName, the name of the config file to load.
    */
-  public static synchronized void initConfig(String home, String uri, 
+  public static synchronized void initConfig(String home, String uri,
                                             String name, String confName) {
     initConfResource(confName);
     configHash = new HashMap();
index 2355920..7d076bf 100755 (executable)
@@ -129,10 +129,10 @@ public abstract class ServletModule {
     throws ServletModuleException, ServletModuleUserException {
     try {
       HashMap withValues = getIntersectingValues(req, mainModule.getStorageObject());
+      theLog.printDebugInfo("--trying to add...");
       String id = mainModule.add(withValues);
-      // theLog.printDebugInfo("--trying to deliver..."+id);
+      theLog.printDebugInfo("--trying to deliver..."+id);
       list(req,res);
-      //deliver(req, res, mainModule.getById(id), templateObjektString);
     } catch (Exception e) {
       throw new ServletModuleException(e.toString());
     }
index 1ed463c..43dcad9 100755 (executable)
@@ -57,7 +57,7 @@ public class Database implements StorageObject {
                // always same object saves a little space
                POPUP_EMTYLINE.put("key", ""); POPUP_EMTYLINE.put("value", "--");
     try {
-      GENERIC_ENTITY_CLASS = Class.forName("mir.entity.GenericEntity");
+      GENERIC_ENTITY_CLASS = Class.forName("mir.entity.StorableObjectEntity");
       STORABLE_OBJECT_ENTITY_CLASS = Class.forName("mir.entity.StorableObjectEntity");
     }
     catch (Exception e) {
@@ -433,7 +433,7 @@ public class Database implements StorageObject {
       StoreIdentifier search_sid =
         new StoreIdentifier( theEntityClass,
                              StoreContainerType.STOC_TYPE_ENTITYLIST,
-                             StoreUtil.getEntityListUniqueIdentifierFor(wc,ob,offset,limit) );
+                             StoreUtil.getEntityListUniqueIdentifierFor(theTable,wc,ob,offset,limit) );
       EntityList hit = (EntityList)o_store.use(search_sid);
       if ( hit!=null ) {
         theLog.printDebugInfo("CACHE (hit): " + search_sid.toString());
@@ -518,7 +518,7 @@ public class Database implements StorageObject {
                                theReturnList.setOffset(offset);
                                theReturnList.setWhere(wc);
                                theReturnList.setOrder(ob);
-        theReturnList.setEntityClass(theEntityClass);
+        theReturnList.setStorage(this);
         theReturnList.setLimit(limit);
                                if ( offset >= limit )
                                        theReturnList.setPrevBatch(offset - limit);
@@ -613,14 +613,21 @@ public class Database implements StorageObject {
         * @return der Wert des Primary-keys der eingefügten Entity
         */
        public String insert (Entity theEntity) throws StorageObjectException {
-               String returnId = null;
-               Connection con = null;
-               PreparedStatement pstmt = null;
                //cache
                invalidatePopupCache();
-               /** @todo OS: if Entity is StorableObject, invalidate in ObjectStore
-                *  careful: Entity has no id yet! */
-               try {
+
+    // invalidating all EntityLists corresponding with theEntityClass
+    if ( StoreUtil.implementsStorableObject(theEntityClass) ) {
+      StoreContainerType stoc_type =
+        StoreContainerType.valueOf( theEntityClass,
+                                    StoreContainerType.STOC_TYPE_ENTITYLIST);
+      o_store.invalidate(stoc_type);
+    }
+
+               String returnId = null;
+               Connection con = null; PreparedStatement pstmt = null;
+
+    try {
                        ArrayList streamedInput = theEntity.streamedInput();
                        StringBuffer f = new StringBuffer();
                        StringBuffer v = new StringBuffer();
@@ -693,6 +700,7 @@ public class Database implements StorageObject {
                        }
                        freeConnection(con, pstmt);
                }
+    /** @todo store entity in o_store */
                return  returnId;
        }
 
@@ -712,8 +720,16 @@ public class Database implements StorageObject {
                 *  have a primary key in the entity. i don't know if we
                 *  still need the streamed input fields. // rk  */
 
-               /** @todo extension: check if Entity did change, otherwise we don't need */
-               /** @todo OS: invalidate in Ostore if Entity is StorableObject */
+               /** @todo extension: check if Entity did change, otherwise we don't need
+     *  the roundtrip to the database */
+
+               /** invalidating corresponding entitylists in o_store*/
+    if ( StoreUtil.implementsStorableObject(theEntityClass) ) {
+      StoreContainerType stoc_type =
+        StoreContainerType.valueOf( theEntityClass,
+                                    StoreContainerType.STOC_TYPE_ENTITYLIST);
+      o_store.invalidate(stoc_type);
+    }
 
                ArrayList streamedInput = theEntity.streamedInput();
                String id = theEntity.getId();
@@ -784,10 +800,13 @@ public class Database implements StorageObject {
 
                invalidatePopupCache();
     // ostore send notification
-    if (StoreUtil.implementsStorableObject(theEntityClass) ) {
+    if ( StoreUtil.implementsStorableObject(theEntityClass) ) {
+      String uniqueId = id;
+      if ( theEntityClass.equals(StorableObjectEntity.class) )
+        uniqueId+="@"+theTable;
                        theLog.printInfo("CACHE: (del) " + id);
                        StoreIdentifier search_sid =
-        new StoreIdentifier(theEntityClass, StoreContainerType.STOC_TYPE_ENTITY, id);
+        new StoreIdentifier(theEntityClass, StoreContainerType.STOC_TYPE_ENTITY, uniqueId);
       o_store.invalidate(search_sid);
                }
 
index 311c3a9..4d00c6d 100755 (executable)
@@ -115,6 +115,10 @@ public class ObjectStore {
    */
   public void invalidate(StoreContainerType stoc_type) {
     if ( stoc_type != null ) {
+      /** @todo invalidates too much:
+       *  improvement: if instanceof StoreContainerEntity && EntityList
+       *  then invalidate only StoreIdentifier matching the right table
+       */
       StoreContainer stoc = getStoreContainerForStocType(stoc_type);
       if ( stoc!=null )
         stoc.invalidate();
index 6c8969b..c9d5094 100755 (executable)
@@ -37,7 +37,7 @@ public class StoreIdentifier {
        public StoreIdentifier(StorableObject reference, int storeType, String uniqueIdentifier) {
     Class theClass;
     if (reference instanceof EntityList)
-      theClass=((EntityList)reference).getEntityClass();
+      theClass=((EntityList)reference).getStorage().getEntityClass();
     else
       theClass=reference.getClass();
     this.uniqueIdentifier=uniqueIdentifier;
index fdebb89..80037da 100755 (executable)
@@ -25,10 +25,11 @@ public final class StoreUtil {
     return null;
   }
 
-  public static final String getEntityListUniqueIdentifierFor(String where, String order,
-    int offset, int limit)
+  public static final String getEntityListUniqueIdentifierFor( String table,
+    String where, String order, int offset, int limit)
   {
-    StringBuffer sb = new StringBuffer("@");
+    StringBuffer sb = new StringBuffer(table);
+    sb.append("@");
     if ( where!=null ) sb.append(where);
     sb.append("@");
     if ( order!=null ) sb.append(order);