Good day, xwiki community.

I want to discuss path, with allows to set in configuration name of main wiki
database schema and prefixes for databases schemes of virtual wiki-s.

This allows to use few wiki-based applications on one computer.

Proposed path itself is attached.
The work of this path is
1. add configuration variables:
xwiki.db  --  database schema name of main wiki instance.
xwiki.virtual.db.prefix  -- prefix for  database scheme-s of virtual wiki-s.

So, questions:
a)  where I must write documentation for this parameters ?
b)  can I submit JIRA issue now or exists some other things which i forgott.


--
Ruslan Shevchenko
GradSoft. http://www.gradsoft.ua

Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/render/DefaultXWikiRenderingEngine.java
===================================================================
--- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/render/DefaultXWikiRenderingEngine.java	(revision 6741)
+++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/render/DefaultXWikiRenderingEngine.java	(working copy)
@@ -5,7 +5,7 @@
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
+ * the Liense, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/XWikiContext.java
===================================================================
--- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/XWikiContext.java	(revision 6741)
+++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/XWikiContext.java	(working copy)
@@ -42,8 +42,13 @@
 import com.xpn.xwiki.web.XWikiResponse;
 import com.xpn.xwiki.web.XWikiURLFactory;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 public class XWikiContext extends Hashtable {
 
+   protected static final Log LOG = LogFactory.getLog(XWikiContext.class);
+
    public static final int MODE_SERVLET = 0;
    public static final int MODE_PORTLET = 1;
    public static final int MODE_XMLRPC = 2;
@@ -151,6 +156,7 @@
     public void setOriginalDatabase(String database) {
         this.orig_database = database;
     }
+      
 
     public boolean isVirtual() {
         return virtual;
Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/store/XWikiHibernateBaseStore.java
===================================================================
--- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/store/XWikiHibernateBaseStore.java	(revision 6741)
+++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/store/XWikiHibernateBaseStore.java	(working copy)
@@ -255,6 +255,7 @@
      */
     public void updateSchema(XWikiContext context) throws HibernateException
     {
+        log.debug("updateSchema: context.database is:"+context.getDatabase());
         updateSchema(context, false);
     }
 
@@ -323,22 +324,44 @@
      * @return the database/schema name.
      * @since XWiki Core 1.1.2, XWiki Core 1.2M2
      */
-    protected String getSchemaFromWikiName(String wikiName, XWikiContext context)
+    protected String getSchemaFromWikiName(String wikiName, XWikiContext context) throws XWikiException
     {
         if (wikiName == null) {
             return null;
         }
 
+
         DatabaseProduct databaseProduct = getDatabaseProductName(context);
 
-        if (databaseProduct == DatabaseProduct.DERBY) {
-            return wikiName.equalsIgnoreCase(context.getMainXWiki()) ? "APP" : wikiName.replace(
-                '-', '_');
-        } else if (databaseProduct == DatabaseProduct.HSQLDB) {
-            return wikiName.equalsIgnoreCase(context.getMainXWiki()) ? "PUBLIC" : wikiName
-                .replace('-', '_');
-        } else
-            return wikiName.replace('-', '_');
+        String retval  = wikiName.replace('-','_');
+        boolean isMain = wikiName.equalsIgnoreCase(context.getMainXWiki());
+               
+        
+        if (isMain) {
+            String configuredMainDatabaseSchemaName = XWiki.staticGetMainDatabaseSchemaName();
+            if (configuredMainDatabaseSchemaName.length()!=0) {
+                retval=configuredMainDatabaseSchemaName;
+            }else{
+                if (databaseProduct == DatabaseProduct.DERBY) {
+                   retval="APP";    
+                }else if (databaseProduct == DatabaseProduct.HSQLDB) {
+                   retval = "PUBLIC";                   
+                }
+            }
+        }else{
+            // virtual
+            String configurableVirtualDabaseSchemaPrefix = XWiki.staticGetVirtualDatabaseSchemaPrefix();
+            if (configurableVirtualDabaseSchemaPrefix.length()!=0) {
+                retval = configurableVirtualDabaseSchemaPrefix + retval;
+            }
+        }
+
+        if (log.isDebugEnabled()) {
+            log.debug("schema for wiki " + context.getDatabase()+" is "+retval);
+        }
+
+        return retval;
+                
     }
 
     /**
@@ -348,7 +371,7 @@
      * @return the database/schema name.
      * @since XWiki Core 1.1.2, XWiki Core 1.2M2
      */
-    protected String getSchemaFromWikiName(XWikiContext context)
+    protected String getSchemaFromWikiName(XWikiContext context) throws XWikiException
     {
         return getSchemaFromWikiName(context.getDatabase(), context);
     }
Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/XWikiInterface.java
===================================================================
--- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/XWikiInterface.java	(revision 6741)
+++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/XWikiInterface.java	(working copy)
@@ -222,8 +222,8 @@
 
     String getDatabase();
 
-    void setDatabase(String database);
-
+    void setDatabase(String databaseName);    
+    
     void gc();
 
     long freeMemory();
Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java	(revision 6741)
+++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java	(working copy)
@@ -207,6 +207,16 @@
     private String database;
 
     private String fullNameSQL;
+    
+    /**
+     * schema name for main database (cached from configuration)
+     */
+    private static String mainDatabaseSchema = null;
+    
+    /**
+     * database prefix for virtual wiki-s (cached from configuration)
+     */    
+    private static String virtualDatabaseSchemaPrefix = null;
 
     private URLPatternMatcher urlPatternMatcher = new URLPatternMatcher();
 
@@ -249,7 +259,7 @@
      */
     private static File tempDir = null;
 
-    private static String getConfigPath() throws NamingException
+    private static String getConfigPath() 
     {
         if (configPath == null) {
             try {
@@ -548,7 +558,7 @@
                     wikiOwner = xwiki.getDatabase() + ":" + wikiOwner;
                 context.setWikiOwner(wikiOwner);
                 context.setWikiServer(doc);
-                context.setVirtual(true);
+                context.setVirtual(true);               
                 context.setDatabase(appname);
                 context.setOriginalDatabase(appname);
 
@@ -958,6 +968,24 @@
         return getConfig().getProperty(key);
     }
 
+    private static String  staticParam(String key) throws XWikiException
+    {        
+     String cfgpath = getConfigPath();   
+     try {    
+       FileInputStream fis = new FileInputStream(cfgpath);   
+       XWikiConfig tmpConfig = new XWikiConfig(fis);
+       return tmpConfig.getProperty(key);
+     }catch(FileNotFoundException ex){
+            Object[] args = {cfgpath};
+            throw new XWikiException(XWikiException.MODULE_XWIKI_CONFIG,
+                XWikiException.ERROR_XWIKI_CONFIG_FILENOTFOUND,
+                "Configuration file {0} not found",
+                ex,
+                args);         
+     }
+    }
+    
+    
     public String ParamAsRealPath(String key)
     {
         String param = Param(key);
@@ -1054,13 +1082,12 @@
     public void saveDocument(XWikiDocument doc, String comment, boolean isMinorEdit,
         XWikiContext context) throws XWikiException
     {
-        String server = null, database = null;
+        String serverDatabase = null, database = null;
         try {
-            server = doc.getDatabase();
-
-            if (server != null) {
+            serverDatabase = doc.getDatabase();
+            if (serverDatabase != null) {
                 database = context.getDatabase();
-                context.setDatabase(server);
+                context.setDatabase(serverDatabase);
             }
 
             // Setting comment & minoredit before saving
@@ -1081,7 +1108,7 @@
             getNotificationManager().verify(doc, originalDocument,
                 XWikiDocChangeNotificationInterface.EVENT_CHANGE, context);
         } finally {
-            if ((server != null) && (database != null)) {
+            if ((serverDatabase != null) && (database != null)) {
                 context.setDatabase(database);
             }
         }
@@ -1090,18 +1117,18 @@
     private XWikiDocument getDocument(XWikiDocument doc, XWikiContext context)
         throws XWikiException
     {
-        String server = null, database = null;
+        String serverDatabase = null, database = null;
         try {
-            server = doc.getDatabase();
+            serverDatabase = doc.getDatabase();
 
-            if (server != null) {
+            if (serverDatabase != null) {
                 database = context.getDatabase();
-                context.setDatabase(server);
+                context.setDatabase(serverDatabase);
             }
 
             return getStore().loadXWikiDoc(doc, context);
         } finally {
-            if ((server != null) && (database != null)) {
+            if ((serverDatabase != null) && (database != null)) {
                 context.setDatabase(database);
             }
         }
@@ -2250,7 +2277,10 @@
 
     public void setConfig(XWikiConfig config)
     {
-        this.config = config;
+        this.config = config;        
+        //lazy initialize configurable static variables.
+        getMainDatabaseSchemaName();
+        getVirtualDatabaseSchemaPrefix();
     }
 
     public void setStore(XWikiStoreInterface store)
@@ -3242,7 +3272,7 @@
                 LOG.debug("Including Topic " + topic);
 
                 int i0 = topic.indexOf(":");
-                if (i0 != -1) {
+                if (i0 != -1) {                 
                     incdatabase = topic.substring(0, i0);
                     topic = topic.substring(i0 + 1);
                     database = context.getDatabase();
@@ -3362,7 +3392,48 @@
     {
         this.database = database;
     }
+    
+        
+    public String getMainDatabaseSchemaName() 
+    {
+        if (mainDatabaseSchema == null) {
+            mainDatabaseSchema = Param("xwiki.db","");
+        }
+        return mainDatabaseSchema;
+    }
 
+    public static String staticGetMainDatabaseSchemaName() throws XWikiException
+    {
+        if (mainDatabaseSchema == null) {
+            mainDatabaseSchema = XWiki.staticParam("xwiki.db");
+            if (mainDatabaseSchema == null) {
+                mainDatabaseSchema = "";
+            }
+        }
+        return mainDatabaseSchema;
+    }
+
+    
+    public String getVirtualDatabaseSchemaPrefix()
+    {
+        if (virtualDatabaseSchemaPrefix == null){
+            virtualDatabaseSchemaPrefix = Param("xwiki.virtual.db.prefix","");
+        }
+        return virtualDatabaseSchemaPrefix;            
+    }
+
+    public static String staticGetVirtualDatabaseSchemaPrefix() throws XWikiException
+    {
+        if (virtualDatabaseSchemaPrefix == null){
+            virtualDatabaseSchemaPrefix = XWiki.staticParam("xwiki.virtual.db.prefix");
+            if (virtualDatabaseSchemaPrefix==null) {
+                virtualDatabaseSchemaPrefix = "";
+            }
+        }
+        return virtualDatabaseSchemaPrefix;            
+    }
+    
+    
     public void gc()
     {
         System.gc();
@@ -3485,8 +3556,9 @@
             sourceWiki = db;
 
         try {
-            if (sourceWiki != null)
+            if (sourceWiki != null) {
                 context.setDatabase(sourceWiki);
+            }
             XWikiDocument sdoc = getDocument(docname, context);
             if (!sdoc.isNew()) {
                 if (LOG.isInfoEnabled())
@@ -3494,8 +3566,9 @@
                         + " on wiki " + targetWiki);
 
                 // Let's switch to the other database to verify if the document already exists
-                if (targetWiki != null)
+                if (targetWiki != null) {
                     context.setDatabase(targetWiki);
+                }
                 XWikiDocument tdoc = getDocument(targetdocname, context);
                 // There is already an existing document
                 if (!tdoc.isNew()) {
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to