From df0639c02f062e190bfa8bd2b2ca79ea6de6c4d8 Mon Sep 17 00:00:00 2001 From: hns Date: Fri, 6 Sep 2002 19:42:32 +0000 Subject: [PATCH] Big patch to clean up checking type.properties files. Changes in type.properties are now reflected on existing collection objects (aka virtual subnodes). DbMappings are no longer managed by the application. Instead they're now held by the prototype they belong to. --- src/helma/framework/core/Application.java | 50 ++-------- src/helma/framework/core/Prototype.java | 17 +++- src/helma/framework/core/TypeManager.java | 103 ++++++++++++-------- src/helma/framework/core/ZippedAppFile.java | 2 +- src/helma/objectmodel/db/DbMapping.java | 31 ++---- src/helma/objectmodel/db/NodeManager.java | 4 +- src/helma/objectmodel/db/Relation.java | 13 ++- 7 files changed, 103 insertions(+), 117 deletions(-) diff --git a/src/helma/framework/core/Application.java b/src/helma/framework/core/Application.java index aaadc145..f61bf1c3 100644 --- a/src/helma/framework/core/Application.java +++ b/src/helma/framework/core/Application.java @@ -74,7 +74,6 @@ public final class Application long starttime; Hashtable sessions; - Hashtable dbMappings; Hashtable dbSources; // internal worker thread for scheduler, session cleanup etc. @@ -224,7 +223,6 @@ public final class Application } sessions = new Hashtable (); - dbMappings = new Hashtable (); dbSources = new Hashtable (); cachenode = new TransientNode ("app"); @@ -281,8 +279,7 @@ public final class Application p.put ("_children", "collection(user)"); p.put ("_children.accessname", usernameField); userRootMapping = new DbMapping (this, "__userroot__", p); - - rewireDbMappings (); + userRootMapping.update (); nmgr = new NodeManager (this, dbDir.getAbsolutePath (), props); @@ -1144,39 +1141,6 @@ public final class Application logEvent ("Scheduler for "+name+" exiting"); } - /** - * This method is called after the type.properties files are read on all prototypes, or after one - * or more of the type properties have been re-read after an update, to let the DbMappings reestablish - * the relations among them according to their mappings. - */ - public void rewireDbMappings () { - for (Enumeration e=dbMappings.elements(); e.hasMoreElements(); ) { - try { - DbMapping m = (DbMapping) e.nextElement (); - m.rewire (); - String typename = m.getTypeName (); - // set prototype hierarchy - if (!"hopobject".equalsIgnoreCase (typename) && !"global".equalsIgnoreCase (typename)) { - Prototype proto = (Prototype) typemgr.prototypes.get (typename); - if (proto != null) { - String protoname = m.getExtends (); - // only use hopobject prototype if we're scripting HopObjects, not - // java objects. - boolean isjava = isJavaPrototype (typename); - if (protoname == null && !isjava) - protoname = "hopobject"; - Prototype parentProto = (Prototype) typemgr.prototypes.get (protoname); - if (parentProto == null && !isjava) - parentProto = (Prototype) typemgr.prototypes.get ("hopobject"); - if (parentProto != null) - proto.setParentPrototype (parentProto); - } - } - } catch (Exception x) { - logEvent ("Error rewiring DbMappings: "+x); - } - } - } /** * Check whether a prototype is for scripting a java class, i.e. if there's an entry @@ -1230,15 +1194,13 @@ public final class Application * Get the DbMapping associated with a prototype name in this application */ public DbMapping getDbMapping (String typename) { - return typename == null ? null : (DbMapping) dbMappings.get (typename); + Prototype proto = typemgr.getPrototype (typename); + if (proto == null) + return null; + return proto.getDbMapping (); } - /** - * Associate a DbMapping object with a prototype name for this application. - */ - public void putDbMapping (String typename, DbMapping dbmap) { - dbMappings.put (typename, dbmap); - } + /** * Proxy method to get a property from the applications properties. */ diff --git a/src/helma/framework/core/Prototype.java b/src/helma/framework/core/Prototype.java index ec5f259a..b26b112d 100644 --- a/src/helma/framework/core/Prototype.java +++ b/src/helma/framework/core/Prototype.java @@ -10,13 +10,14 @@ import java.io.*; import helma.framework.*; import helma.scripting.*; import helma.objectmodel.*; +import helma.objectmodel.db.DbMapping; import helma.util.Updatable; /** * The Prototype class represents Script prototypes/type defined in a Helma - * application. This class manages a prototypes templates, functions and actions - * as well as optional information about the mapping of this type to a + * application. This class manages a prototypes templates, functions and actions + * as well as optional information about the mapping of this type to a * relational database table. */ @@ -32,6 +33,8 @@ public final class Prototype { final HashMap skins; final HashMap updatables; + DbMapping dbmap; + // lastCheck is the time the prototype's files were last checked private long lastCheck; // lastUpdate is the time at which any of the prototype's files were @@ -68,7 +71,7 @@ public final class Prototype { /** - * Set the parent prototype of this prototype, i.e. the prototype this + * Set the parent prototype of this prototype, i.e. the prototype this * prototype inherits from. */ public void setParentPrototype (Prototype parent) { @@ -86,6 +89,14 @@ public final class Prototype { return parent; } + public void setDbMapping (DbMapping dbmap) { + this.dbmap = dbmap; + } + + public DbMapping getDbMapping () { + return dbmap; + } + /** * Get a template defined for this prototype. Templates * are files that mix layout and code and were used diff --git a/src/helma/framework/core/TypeManager.java b/src/helma/framework/core/TypeManager.java index de2faa6e..d7021ef5 100644 --- a/src/helma/framework/core/TypeManager.java +++ b/src/helma/framework/core/TypeManager.java @@ -23,7 +23,7 @@ public final class TypeManager { HashMap prototypes; HashMap zipfiles; long lastCheck = 0; - boolean rewire; + // boolean rewire; final static String[] standardTypes = {"user", "global", "root", "hopobject"}; final static String templateExtension = ".hsp"; @@ -54,6 +54,7 @@ public final class TypeManager { * compile or evaluate any scripts. */ public void createPrototypes () { + // loop through directories and create prototypes checkFiles (); // check if standard prototypes have been created // if not, create them. @@ -62,9 +63,22 @@ public final class TypeManager { if (prototypes.get (pname) == null) { Prototype proto = new Prototype (pname, app); registerPrototype (pname, new File (appDir, pname), proto); - prototypes.put (pname, proto); } } + Prototype hobjectProto = getPrototype ("hopobject"); + // loop through freshly created prototypes and rewire them, + // i.e. establish connections between them (inherit, collection etc.) + for (Iterator i = prototypes.values().iterator(); i.hasNext(); ) { + Prototype proto = (Prototype) i.next(); + DbMapping dbm = proto.getDbMapping (); + dbm.update (); + // set parent prototype + String parentName = dbm.getExtends (); + if (parentName == null) + proto.setParentPrototype (hobjectProto); + else + proto.setParentPrototype (getPrototype (parentName)); + } } @@ -82,34 +96,44 @@ public final class TypeManager { } /** - * Run through application's prototype directories and check if anything has been updated. + * Run through application's prototype directories and check if + * there are any prototypes to be created. */ public void checkFiles () { // long now = System.currentTimeMillis (); - // System.out.print ("checking "+Thread.currentThread ()); + // System.out.print ("checking prototypes for "+app); File[] list = appDir.listFiles (); if (list == null) throw new RuntimeException ("Can't read app directory "+appDir+" - check permissions"); for (int i=0; i