From: rk Date: Mon, 18 Mar 2002 23:04:23 +0000 (+0000) Subject: ObjectStore cache is working with StorableObjectEntities X-Git-Tag: prexmlproducerconfig~266 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=aa6c03501a1cca8714ce094d566769540045c1ab;p=mir.git ObjectStore cache is working with StorableObjectEntities --- diff --git a/source/mir/entity/EntityList.java b/source/mir/entity/EntityList.java index 9aca5c78..d82de973 100755 --- a/source/mir/entity/EntityList.java +++ b/source/mir/entity/EntityList.java @@ -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; diff --git a/source/mir/misc/MirConfig.java b/source/mir/misc/MirConfig.java index 88fa0aa9..bfd51d72 100755 --- a/source/mir/misc/MirConfig.java +++ b/source/mir/misc/MirConfig.java @@ -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(); diff --git a/source/mir/servlet/ServletModule.java b/source/mir/servlet/ServletModule.java index 2355920a..7d076bf9 100755 --- a/source/mir/servlet/ServletModule.java +++ b/source/mir/servlet/ServletModule.java @@ -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()); } diff --git a/source/mir/storage/Database.java b/source/mir/storage/Database.java index 1ed463cf..43dcad90 100755 --- a/source/mir/storage/Database.java +++ b/source/mir/storage/Database.java @@ -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); } diff --git a/source/mir/storage/store/ObjectStore.java b/source/mir/storage/store/ObjectStore.java index 311c3a9c..4d00c6dd 100755 --- a/source/mir/storage/store/ObjectStore.java +++ b/source/mir/storage/store/ObjectStore.java @@ -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(); diff --git a/source/mir/storage/store/StoreIdentifier.java b/source/mir/storage/store/StoreIdentifier.java index 6c8969bd..c9d50940 100755 --- a/source/mir/storage/store/StoreIdentifier.java +++ b/source/mir/storage/store/StoreIdentifier.java @@ -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; diff --git a/source/mir/storage/store/StoreUtil.java b/source/mir/storage/store/StoreUtil.java index fdebb895..80037dab 100755 --- a/source/mir/storage/store/StoreUtil.java +++ b/source/mir/storage/store/StoreUtil.java @@ -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);