Modified: 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/server/Start.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/server/Start.java?rev=955236&r1=955235&r2=955236&view=diff
==============================================================================
--- 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/server/Start.java
 (original)
+++ 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/server/Start.java
 Wed Jun 16 14:16:36 2010
@@ -15,30 +15,58 @@
 package org.apache.wookie.server;
 
 import java.io.BufferedReader;
-import java.io.IOException;
+import java.io.File;
 import java.io.InputStreamReader;
 import java.net.InetAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
-import java.util.StringTokenizer;
 
-import org.apache.commons.io.IOUtils;
+import javax.jcr.Repository;
+
+import org.apache.jackrabbit.core.TransientRepository;
 import org.apache.log4j.Logger;
-import org.apache.wookie.util.hibernate.DBManagerFactory;
-import org.apache.wookie.util.hibernate.IDBManager;
+import org.apache.wookie.beans.jcr.JCRPersistenceManager;
+import org.apache.wookie.beans.jpa.JPAPersistenceManager;
+import org.apache.wookie.beans.util.PersistenceManagerFactory;
 import org.mortbay.jetty.Server;
+import org.mortbay.jetty.plus.naming.Resource;
 import org.mortbay.jetty.security.HashUserRealm;
 import org.mortbay.jetty.security.UserRealm;
 import org.mortbay.jetty.webapp.WebAppContext;
 
+import com.mchange.v2.c3p0.ComboPooledDataSource;
+
 public class Start {
        static final private Logger logger = Logger.getLogger(Start.class);
        private static int port = 8080;
-
+       
+    public static final String DB_USER_PROPERTY_NAME = "wookie.db.user";
+    public static final String DB_PASSWORD_PROPERTY_NAME = 
"wookie.db.password";
+    public static final String DB_DRIVER_CLASS_PROPERTY_NAME = 
"wookie.db.driver";
+    public static final String DB_URI_PROPERTY_NAME = "wookie.db.uri";
+    public static final String DB_TYPE_PROPERTY_NAME = "wookie.db.type";
+    public static final String REPOSITORY_USER_PROPERTY_NAME = 
"wookie.repository.user";
+    public static final String REPOSITORY_PASSWORD_PROPERTY_NAME = 
"wookie.repository.password";
+    public static final String REPOSITORY_ROOT_PATH_PROPERTY_NAME = 
"wookie.repository.rootpath";
+    public static final String REPOSITORY_WORKSPACE_PROPERTY_NAME = 
"wookie.repository.workspace";
+    public static final String PERSISTENCE_MANAGER_TYPE_PROPERTY_NAME = 
"wookie.persistence.manager.type";
+    public static final String PERSISTENCE_MANAGER_TYPE_JPA = "jpa";
+    public static final String PERSISTENCE_MANAGER_TYPE_JCR = "jcr";
+
+    private static String persistenceManagerType;
+    private static String dbUser;
+    private static String dbPassword;
+    private static String dbDriver;
+    private static String dbUri;
+    private static String dbType;
+    private static String repositoryUser;
+    private static String repositoryPassword;
+    private static String repositoryRootPath;
+    private static String repositoryWorkspace;
        private static Server server;
 
        public static void main(String[] args) throws Exception {
-         boolean initDB = true;
+           boolean initDB = true;
                for (int i = 0; i < args.length; i++) {
                        String arg = args[i];
                        System.out.println("Runtime argmuent: " + arg);
@@ -50,45 +78,39 @@ public class Start {
                          System.out.println("argument UNRECOGNISED - 
ignoring");
                        }
                }
-               
+
+               // load configuration from environment
+        persistenceManagerType = 
getSystemProperty(PERSISTENCE_MANAGER_TYPE_PROPERTY_NAME, 
PERSISTENCE_MANAGER_TYPE_JPA);
+        dbUser = getSystemProperty(DB_USER_PROPERTY_NAME, "java");
+        dbPassword = getSystemProperty(DB_PASSWORD_PROPERTY_NAME, "java");
+        dbDriver = getSystemProperty(DB_DRIVER_CLASS_PROPERTY_NAME, 
"org.apache.derby.jdbc.EmbeddedDriver");
+        dbUri = getSystemProperty(DB_URI_PROPERTY_NAME, 
"jdbc:derby:widgetDatabase/widgetDB;create=true");
+        dbType = getSystemProperty(DB_TYPE_PROPERTY_NAME, "derby");
+        repositoryUser = getSystemProperty(REPOSITORY_USER_PROPERTY_NAME, 
"java");
+        repositoryPassword = 
getSystemProperty(REPOSITORY_PASSWORD_PROPERTY_NAME, "java");
+        repositoryRootPath = 
getSystemProperty(REPOSITORY_ROOT_PATH_PROPERTY_NAME, "/wookie");
+        repositoryWorkspace = 
getSystemProperty(REPOSITORY_WORKSPACE_PROPERTY_NAME, "default");
+
+        // set configuration properties
+        if (persistenceManagerType.equals(PERSISTENCE_MANAGER_TYPE_JPA)) {
+            
System.setProperty(PersistenceManagerFactory.PERSISTENCE_MANAGER_CLASS_NAME_PROPERTY_NAME,
 JPAPersistenceManager.class.getName());
+        } else if 
(persistenceManagerType.equals(PERSISTENCE_MANAGER_TYPE_JCR)) {
+            
System.setProperty(PersistenceManagerFactory.PERSISTENCE_MANAGER_CLASS_NAME_PROPERTY_NAME,
 JCRPersistenceManager.class.getName());
+        }
                if (initDB) {
-               try {
-                       configureDatabase();
-               } catch (Exception e) {
-                       if (e.getCause().getMessage().contains("duplicate key 
value")){
-                         StringBuilder sb = new StringBuilder("There was a 
problem setting up the database.\n");
-                         sb.append("If this is not the first time you are 
running Wookie in");
-                         sb.append(" standalone mode, then you should run 
\"ant clean-db\" before \"ant run\"");
-                         sb.append(" to clear the database.\n");
-                         sb.append("To run without re-configuring the database 
set \"initDB=false\" in the command line");
-                               throw new IOException(sb.toString());
-                       } else {
-                               throw e;
-                       }
-               }
+                   
System.setProperty(PersistenceManagerFactory.PERSISTENCE_MANAGER_INITIALIZE_STORE_PROPERTY_NAME,
 "true");
                }
-               
+               
System.setProperty(JPAPersistenceManager.PERSISTENCE_MANAGER_DB_TYPE_PROPERTY_NAME,
 dbType);
+        
System.setProperty(JCRPersistenceManager.PERSISTENCE_MANAGER_USER_PROPERTY_NAME,
 repositoryUser);
+        
System.setProperty(JCRPersistenceManager.PERSISTENCE_MANAGER_PASSWORD_PROPERTY_NAME,
 repositoryPassword);
+        
System.setProperty(JCRPersistenceManager.PERSISTENCE_MANAGER_ROOT_PATH_PROPERTY_NAME,
 repositoryRootPath);
+        
System.setProperty(JCRPersistenceManager.PERSISTENCE_MANAGER_WORKSPACE_PROPERTY_NAME,
 repositoryWorkspace);
+
+               // configure and start server
                configureServer();
                startServer();
        }
 
-       /**
-        * Create the database by reading in the file widgetdb_derby.sql and 
executing all SQL found within.
-        * 
-        * @throws IOException  if the file is not found or is unreadable
-        */
-       private static void configureDatabase() throws Exception {
-               logger.debug("Configuring Derby Database");
-               String sqlScript = 
IOUtils.toString(Start.class.getClassLoader().getResourceAsStream("widgetdb.sql"));
-               final IDBManager dbManager = DBManagerFactory.getDBManager();
-               StringTokenizer st = new StringTokenizer(sqlScript, ";"); 
-               while (st.hasMoreTokens()) { 
-                       dbManager.beginTransaction(); 
-                       
dbManager.createSQLQuery(st.nextToken()).executeUpdate(); 
-                       dbManager.commitTransaction(); 
-               } 
-       }
-
        private static void startServer() throws Exception, 
InterruptedException {
                logger.info("Starting Wookie Server");
                logger.info("point your browser at http://localhost:"; + port + 
"/wookie");
@@ -102,16 +124,85 @@ public class Start {
        }
 
        private static void configureServer() throws Exception {
+           // create embedded jetty instance
                logger.info("Configuring Jetty server");
                server = new Server(port);
+
+               // configure embedded jetty to handle wookie web application
                WebAppContext context = new WebAppContext();
                context.setServer(server);
                context.setContextPath("/wookie");
                context.setWar("build/webapp/wookie");
+               
+               // enable and configure JNDI container resources
+        context.setConfigurationClasses(new 
String[]{"org.mortbay.jetty.webapp.WebInfConfiguration",
+                                                     
"org.mortbay.jetty.plus.webapp.EnvConfiguration",
+                                                     
"org.mortbay.jetty.plus.webapp.Configuration",
+                                                     
"org.mortbay.jetty.webapp.JettyWebXmlConfiguration",
+                                                     
"org.mortbay.jetty.webapp.TagLibConfiguration"});
+        if (persistenceManagerType.equals(PERSISTENCE_MANAGER_TYPE_JPA)) {
+            logger.info("Configuring JPA persistence manager");
+
+            // setup derby database directory and logging properties
+            if (dbType.equals("derby") && dbUri.startsWith("jdbc:derby:")) {
+                int dbUriArgsIndex = dbUri.indexOf(";", 11);
+                if (dbUriArgsIndex == -1) {
+                    dbUriArgsIndex = dbUri.length();
+                }
+                String databasePath = dbUri.substring(11, dbUriArgsIndex);
+                int databaseDirIndex = 
databasePath.lastIndexOf(File.separatorChar);
+                if ((databaseDirIndex == -1) && (File.separatorChar != '/')) {
+                    databaseDirIndex = databasePath.lastIndexOf('/');          
          
+                }
+                if (databaseDirIndex != -1) {
+                    String databaseDir = databasePath.substring(0, 
databaseDirIndex);
+                    File databaseDirFile = new File(databaseDir);
+                    if (!databaseDirFile.exists()) {
+                        databaseDirFile.mkdirs();
+                    }
+                    String derbyLog = 
databaseDirFile.getAbsolutePath()+File.separator+"derby.log";
+                    System.setProperty("derby.stream.error.file", derbyLog);
+                }
+            }
+
+            // setup C3P0 JPA database connection pool JNDI resource
+            ComboPooledDataSource dataSource = new ComboPooledDataSource();
+            dataSource.setJdbcUrl(dbUri);
+            dataSource.setDriverClass(dbDriver);
+            dataSource.setUser(dbUser);
+            dataSource.setPassword(dbPassword);
+            dataSource.setAcquireIncrement(1);
+            dataSource.setIdleConnectionTestPeriod(200);
+            dataSource.setMaxPoolSize(80);
+            dataSource.setMaxStatements(0);
+            dataSource.setMinPoolSize(5);
+            dataSource.setMaxIdleTime(80);
+            new 
Resource(JPAPersistenceManager.WIDGET_DATABASE_JNDI_DATASOURCE_NAME, 
dataSource);
+        } else if 
(persistenceManagerType.equals(PERSISTENCE_MANAGER_TYPE_JCR)) {
+            logger.info("Configuring JCR persistence manager");
+
+            // setup repository directory and derby logging properties
+            File repositoryDirFile = new File("widgetRepository");
+            if (!repositoryDirFile.exists()) {
+                repositoryDirFile.mkdirs();
+            }
+            String derbyLog = 
repositoryDirFile.getAbsolutePath()+File.separator+"derby.log";
+            System.setProperty("derby.stream.error.file", derbyLog);
+
+            // setup Jackrabbit JCR repository JNDI resource
+            String repositoryConfig = 
repositoryDirFile.getAbsolutePath()+File.separator+"repository.xml";
+            Repository repository = new TransientRepository(repositoryConfig, 
repositoryDirFile.getAbsolutePath());
+            new 
Resource(JCRPersistenceManager.WIDGET_REPOSITORY_JNDI_REPOSITORY_NAME, 
repository);
+        }
+
+        // configure embedded jetty web application handler
                server.addHandler(context);
                
+        // configure embedded jetty authentication realm
                HashUserRealm authedRealm = new HashUserRealm("Authentication 
Required","etc/jetty-realm.properties");
                server.setUserRealms(new UserRealm[]{authedRealm});
+
+               logger.info("Configured Jetty server");
        }
        
        private static class MonitorThread extends Thread {
@@ -145,4 +236,17 @@ public class Start {
                        }
                }
        }
+
+       /**
+     * Get configuration system property.
+     * 
+     * @param name property name
+     * @param defaultValue default property value
+     * @return property value
+     */
+    private static String getSystemProperty(String name, String defaultValue)
+    {
+        String value = System.getProperty(name);
+        return (((value != null) && (value.length() > 0) && 
!value.startsWith("$")) ? value : defaultValue);
+    }
 }

Modified: 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/SiblingPageNormalizer.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/SiblingPageNormalizer.java?rev=955236&r1=955235&r2=955236&view=diff
==============================================================================
--- 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/SiblingPageNormalizer.java
 (original)
+++ 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/SiblingPageNormalizer.java
 Wed Jun 16 14:16:36 2010
@@ -15,7 +15,9 @@ package org.apache.wookie.util;
 
 import java.util.HashMap;
 
-import org.apache.wookie.beans.WidgetInstance;
+import org.apache.wookie.beans.IWidgetInstance;
+import org.apache.wookie.beans.util.IPersistenceManager;
+import org.apache.wookie.beans.util.PersistenceManagerFactory;
 import org.directwebremoting.impl.DefaultPageNormalizer;
 
 /**
@@ -40,7 +42,7 @@ org.directwebremoting.extend.PageNormali
         * @param instance the instance
         * @return the normalized URI of the widget instance
         */
-       public String getNormalizedPage(WidgetInstance instance){
+       public String getNormalizedPage(IWidgetInstance instance){
                return 
super.normalizePage(instance.getWidget().getUrl())+"?"+instance.getApiKey()+"="+instance.getSharedDataKey();
        }
 
@@ -63,7 +65,8 @@ org.directwebremoting.extend.PageNormali
                // API key and Shared Data Key: in combination with
                // the Widget URL it uniquely identifies sibling instances
                
-               WidgetInstance widgetInstance = 
WidgetInstance.findByIdKey((String)parmsMap.get("idkey"));
+        IPersistenceManager persistenceManager = 
PersistenceManagerFactory.getPersistenceManager();
+        IWidgetInstance widgetInstance = 
persistenceManager.findWidgetInstanceByIdKey((String)parmsMap.get("idkey"));
                // Invalid instance
                if(widgetInstance==null) return super.normalizePage(page);
 

Modified: 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/html/StartPageProcessor.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/html/StartPageProcessor.java?rev=955236&r1=955235&r2=955236&view=diff
==============================================================================
--- 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/html/StartPageProcessor.java
 (original)
+++ 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/html/StartPageProcessor.java
 Wed Jun 16 14:16:36 2010
@@ -17,7 +17,9 @@ import java.io.File;
 import java.io.FileReader;
 import java.io.FileWriter;
 
-import org.apache.wookie.beans.ServerFeature;
+import org.apache.wookie.beans.IServerFeature;
+import org.apache.wookie.beans.util.IPersistenceManager;
+import org.apache.wookie.beans.util.PersistenceManagerFactory;
 import org.apache.wookie.feature.IFeature;
 import org.apache.wookie.w3c.IFeatureEntity;
 import org.apache.wookie.w3c.W3CWidget;
@@ -69,7 +71,8 @@ public class StartPageProcessor implemen
         */
        private void addFeatures(IHtmlProcessor engine,W3CWidget model) throws 
Exception{
                for (IFeatureEntity feature: model.getFeatures()){
-                       ServerFeature sf = 
ServerFeature.findByName(feature.getName());
+                   IPersistenceManager persistenceManager = 
PersistenceManagerFactory.getPersistenceManager();
+                       IServerFeature sf = 
persistenceManager.findServerFeatureByName(feature.getName());
                        IFeature theFeature = 
getFeatureInstanceForName(sf.getClassName());
                        addScripts(engine, theFeature);
                        addStylesheets(engine, theFeature);
@@ -82,7 +85,8 @@ public class StartPageProcessor implemen
         * @return an IFeature instance
         * @throws Exception if the feature cannot be instantiated
         */
-       private IFeature getFeatureInstanceForName(String featureName) throws 
Exception{
+       @SuppressWarnings("unchecked")
+    private IFeature getFeatureInstanceForName(String featureName) throws 
Exception{
                Class<? extends IFeature> klass = (Class<? extends IFeature>) 
Class.forName(featureName);
                IFeature theFeature = (IFeature) klass.newInstance();
                return theFeature;

Modified: 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/opensocial/OpenSocialUtils.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/opensocial/OpenSocialUtils.java?rev=955236&r1=955235&r2=955236&view=diff
==============================================================================
--- 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/opensocial/OpenSocialUtils.java
 (original)
+++ 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/opensocial/OpenSocialUtils.java
 Wed Jun 16 14:16:36 2010
@@ -15,14 +15,16 @@
 package org.apache.wookie.util.opensocial;
 
 import java.net.URLEncoder;
+import java.util.Collection;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.apache.shindig.auth.BlobCrypterSecurityToken;
 import org.apache.shindig.common.crypto.BasicBlobCrypter;
 import org.apache.wookie.Messages;
-import org.apache.wookie.beans.StartFile;
-import org.apache.wookie.beans.WidgetInstance;
+import org.apache.wookie.beans.IStartFile;
+import org.apache.wookie.beans.IWidgetInstance;
+import org.apache.wookie.w3c.ILocalizedElement;
 import org.apache.wookie.w3c.util.LocalizationUtils;
 
 /**
@@ -57,7 +59,7 @@ public class OpenSocialUtils {
         * @return the plain text token for the widget instance
         * @throws Exception
         */
-       public static String createPlainToken(WidgetInstance instance, Messages 
localizedMessages) throws Exception{
+       public static String createPlainToken(IWidgetInstance instance, 
Messages localizedMessages) throws Exception{
                
                if (instance == null) throw new 
Exception(localizedMessages.getString("OpenSocialUtils.0")); //$NON-NLS-1$
                // check we have the required information:
@@ -87,7 +89,7 @@ public class OpenSocialUtils {
         * @return the encrypted token for the widget instance
         * @throws Exception
         */
-       public static String createEncryptedToken(WidgetInstance instance, 
String key, Messages localizedMessages) throws Exception{
+       public static String createEncryptedToken(IWidgetInstance instance, 
String key, Messages localizedMessages) throws Exception{
                
                if (instance == null) throw new 
Exception(localizedMessages.getString("OpenSocialUtils.0")); //$NON-NLS-1$
                // check we have the required information:
@@ -113,20 +115,20 @@ public class OpenSocialUtils {
                return encryptedToken;
        }
        
-       private static String getOwnerId(WidgetInstance instance){
+       private static String getOwnerId(IWidgetInstance instance){
                //TODO FIXME
                return getUserId(instance);
        }
        
-       private static String getUserId(WidgetInstance instance){
+       private static String getUserId(IWidgetInstance instance){
                String userid = "@anon"; //$NON-NLS-1$
                if (instance.getUserId()!=null) 
if(!instance.getUserId().equals("")) userid = instance.getUserId(); 
//$NON-NLS-1$
                return userid;
        }
        
-       private static String getUrl(WidgetInstance instance){
-               StartFile[] files = StartFile.findByValue("widget", 
instance.getWidget());
-               StartFile start = (StartFile) 
LocalizationUtils.getLocalizedElement(files, new String[]{"en"});
+       private static String getUrl(IWidgetInstance instance){
+           Collection<IStartFile> files = instance.getWidget().getStartFiles();
+               IStartFile start = (IStartFile) 
LocalizationUtils.getLocalizedElement(files, new String[]{"en"});
                return start.getUrl();
        }
 

Modified: 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/widgets/forum/IForumManager.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/widgets/forum/IForumManager.java?rev=955236&r1=955235&r2=955236&view=diff
==============================================================================
--- 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/widgets/forum/IForumManager.java
 (original)
+++ 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/widgets/forum/IForumManager.java
 Wed Jun 16 14:16:36 2010
@@ -36,7 +36,7 @@ public interface IForumManager {
         * @param postId
         * @return - the correct postnode
         */
-       PostNode getPost(String sharedKey, int postId);
+       PostNode getPost(String sharedKey, String postId);
 
        /**
         * Add a new post to the given parent post

Modified: 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/widgets/forum/PostNode.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/widgets/forum/PostNode.java?rev=955236&r1=955235&r2=955236&view=diff
==============================================================================
--- 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/widgets/forum/PostNode.java
 (original)
+++ 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/widgets/forum/PostNode.java
 Wed Jun 16 14:16:36 2010
@@ -18,6 +18,8 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
+import org.apache.wookie.beans.IPost;
+
 /**
  * A bean to model a post (with optional children)
  * @author Paul Sharples
@@ -26,38 +28,53 @@ import java.util.List;
  */
 public class PostNode {
        
-       private int id; 
+       private Object id;      
        private String userId;
-       private int parentId;
        private String content;
        private String title;
        private Date publishDate;       
        private Date updateDate;
        private String sharedDataKey;
 
-       private List<PostNode> posts;
-       
-       
-       public PostNode(int id, String userId, int parentId, String content,
-                       String title, Date publishDate, Date updateDate) {
+       private List<PostNode> posts = new ArrayList<PostNode>();
+               
+    /**
+     * Construct transient post node to post message.
+     * 
+     * @param message message to post
+     */
+    public PostNode(String message) {
+        super();
+        this.content = message;
+        this.title = message;
+        this.publishDate = new Date();
+        this.updateDate = this.publishDate;
+    }
+
+       /**
+        * Construct transient from persistent post node.
+        * 
+        * @param post persistent post node
+        */
+       public PostNode(IPost post) {
                super();
-               this.id = id;
-               this.userId = userId;
-               this.parentId = parentId;
-               this.content = content;
-               this.title = title;
-               this.publishDate = publishDate;
-               this.updateDate = updateDate;
+               this.id = post.getId();
+               this.userId = post.getUserId();
+               this.content = post.getContent();
+               this.title = post.getTitle();
+               this.publishDate = post.getPublishDate();
+               this.updateDate = post.getUpdateDate();
+               for (IPost childPost : post.getPosts())
+               {
+                   posts.add(new PostNode(childPost));
+               }
        }
 
        public List<PostNode> getPosts() {
-               if(posts == null) {
-                       posts = new ArrayList<PostNode>();
-               }
                return posts;
        }
 
-       public int getId() {
+       public Object getId() {
                return id;
        }
 
@@ -65,10 +82,6 @@ public class PostNode {
                return userId;
        }
 
-       public int getParentId() {
-               return parentId;
-       }
-
        public String getContent() {
                return content;
        }
@@ -92,9 +105,4 @@ public class PostNode {
        public String getSharedDataKey() {
                return sharedDataKey;
        }
-
-       public void setSharedDataKey(String sharedDataKey) {
-               this.sharedDataKey = sharedDataKey;
-       }
-
 }

Modified: 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/widgets/forum/impl/DefaultForumServiceImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/widgets/forum/impl/DefaultForumServiceImpl.java?rev=955236&r1=955235&r2=955236&view=diff
==============================================================================
--- 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/widgets/forum/impl/DefaultForumServiceImpl.java
 (original)
+++ 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/widgets/forum/impl/DefaultForumServiceImpl.java
 Wed Jun 16 14:16:36 2010
@@ -15,17 +15,17 @@
 package org.apache.wookie.widgets.forum.impl;
 
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 import java.util.Locale;
-import java.util.ResourceBundle;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
 import org.apache.log4j.Logger;
 import org.apache.wookie.Messages;
-import org.apache.wookie.beans.WidgetInstance;
+import org.apache.wookie.beans.IWidgetInstance;
+import org.apache.wookie.beans.util.IPersistenceManager;
+import org.apache.wookie.beans.util.PersistenceManagerFactory;
 import org.apache.wookie.server.LocaleHandler;
 import org.apache.wookie.widgets.forum.IForumManager;
 import org.apache.wookie.widgets.forum.IForumService;
@@ -76,7 +76,8 @@ public class DefaultForumServiceImpl imp
                
                try {
                        // check if instance is valid
-                       WidgetInstance widgetInstance = 
WidgetInstance.findByIdKey(id_key);
+                   IPersistenceManager persistenceManager = 
PersistenceManagerFactory.getPersistenceManager();
+                       IWidgetInstance widgetInstance = 
persistenceManager.findWidgetInstanceByIdKey(id_key);
                        if(widgetInstance!=null){
                                IForumManager fManager = new ForumManager();
                                String sharedDataKey = 
widgetInstance.getSharedDataKey();       
@@ -111,11 +112,12 @@ public class DefaultForumServiceImpl imp
                }                                       
                try {
                        // check if instance is valid
-                       WidgetInstance widgetInstance = 
WidgetInstance.findByIdKey(id_key);
+            IPersistenceManager persistenceManager = 
PersistenceManagerFactory.getPersistenceManager();
+                       IWidgetInstance widgetInstance = 
persistenceManager.findWidgetInstanceByIdKey(id_key);
                        if(widgetInstance!=null){
                                IForumManager fManager = new ForumManager();
                                String sharedDataKey = 
widgetInstance.getSharedDataKey();       
-                               return fManager.getPost(sharedDataKey, 
Integer.parseInt(postId));       
+                               return fManager.getPost(sharedDataKey, postId); 
                        }
                        else{
                                return 
getErrorPost(localizedMessages.getString("DefaultForumServiceImpl.1"));         
 
@@ -146,7 +148,8 @@ public class DefaultForumServiceImpl imp
                }               
                try {
                        // check if instance is valid
-                       WidgetInstance widgetInstance = 
WidgetInstance.findByIdKey(id_key);
+            IPersistenceManager persistenceManager = 
PersistenceManagerFactory.getPersistenceManager();
+                       IWidgetInstance widgetInstance = 
persistenceManager.findWidgetInstanceByIdKey(id_key);
                        if(widgetInstance!=null){
                                IForumManager fManager = new ForumManager();
                                String sharedDataKey = 
widgetInstance.getSharedDataKey();
@@ -185,8 +188,7 @@ public class DefaultForumServiceImpl imp
         * @return
         */
        private PostNode getErrorPost(String reason){
-               Date date = new Date();
-               return new PostNode(-1, reason, -1, reason, reason, date, date);
+               return new PostNode(reason);
        }
 
 

Modified: 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/widgets/forum/impl/ForumManager.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/widgets/forum/impl/ForumManager.java?rev=955236&r1=955235&r2=955236&view=diff
==============================================================================
--- 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/widgets/forum/impl/ForumManager.java
 (original)
+++ 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/widgets/forum/impl/ForumManager.java
 Wed Jun 16 14:16:36 2010
@@ -16,19 +16,16 @@ package org.apache.wookie.widgets.forum.
 
 import java.util.ArrayList;
 import java.util.Date;
-import java.util.LinkedHashMap;
+import java.util.HashMap;
 import java.util.List;
-import java.util.Map.Entry;
+import java.util.Map;
 
 import org.apache.log4j.Logger;
-import org.apache.wookie.beans.Post;
-import org.apache.wookie.util.hibernate.DBManagerFactory;
-import org.apache.wookie.util.hibernate.IDBManager;
+import org.apache.wookie.beans.IPost;
+import org.apache.wookie.beans.util.IPersistenceManager;
+import org.apache.wookie.beans.util.PersistenceManagerFactory;
 import org.apache.wookie.widgets.forum.IForumManager;
 import org.apache.wookie.widgets.forum.PostNode;
-import org.hibernate.Criteria;
-import org.hibernate.criterion.Order;
-import org.hibernate.criterion.Restrictions;
 
 /**
  * The forum manager class.  Methods needed by the forum widget
@@ -46,68 +43,32 @@ public class ForumManager implements IFo
         * @see 
org.apache.wookie.widgets.forum.IForumManager#getNodeTree(java.lang.String)
         */
        public List<PostNode> getNodeTree(String sharedKey) {                   
        
-               IDBManager dbManager = null;
-               try {
-                       List<PostNode> list = new ArrayList<PostNode>();
-                       LinkedHashMap<Integer, PostNode> postLookupTable = new 
LinkedHashMap<Integer, PostNode>();
-                       dbManager = DBManagerFactory.getDBManager();
-                       final Criteria crit = 
dbManager.createCriteria(Post.class);
-                       crit.add(Restrictions.eq("sharedDataKey", sharedKey));
-                       crit.addOrder( Order.desc("publishDate"));
-                       final List<Post> sqlReturnList =  
dbManager.getObjects(Post.class, crit);
-                       Post[] posts = sqlReturnList.toArray(new 
Post[sqlReturnList.size()]);
-                       for(Post post : posts){                                 
                                
-                               postLookupTable.put(post.getId(),new 
PostNode(post.getId(),
-                                               
post.getUserId(),post.getParentId(),post.getContent(),post.getTitle(),
-                                               
post.getPublishDate(),post.getUpdateDate()));
-                       }
-                       // Iterate thru the posts constructing a tree hierarchy
-                       for(Entry<Integer, PostNode> entry : 
postLookupTable.entrySet()) {
-                               PostNode post = entry.getValue();
-                               // Has a Post as a Parent
-                               if(post.getParentId()!=-1) {
-                                       PostNode parentPost = 
postLookupTable.get(post.getParentId());
-                                       parentPost.getPosts().add(post);        
               
-                               }
-                               // No Parent Post so it's a top-level post with 
the topic as parent
-                               else {
-                                       list.add(post);                
-                               }
-                       }
-                       return list;            
-               } 
-               catch (Exception ex) {
-                       dbManager.rollbackTransaction();
-                       _logger.error(ex.getMessage());
-                       return null;
-               }
+           // query for root posts in most to least recent published order
+           IPersistenceManager persistenceManager = 
PersistenceManagerFactory.getPersistenceManager();
+           Map<String,Object> values = new HashMap<String,Object>();
+        values.put("sharedDataKey", sharedKey);
+        values.put("parent", null);
+           IPost [] posts = persistenceManager.findByValues(IPost.class, 
values, "publishDate", false);
+           // return PostNode hierarchies to mirror IPost hierarchies
+        List<PostNode> list = new ArrayList<PostNode>();
+           for(IPost post : posts){
+               list.add(new PostNode(post));
+           }
+           return list;                
        }
        
        /* (non-Javadoc)
-        * @see 
org.apache.wookie.widgets.forum.IForumManager#getPost(java.lang.String, int)
+        * @see 
org.apache.wookie.widgets.forum.IForumManager#getPost(java.lang.String, 
java.lang.String)
         */
-       public PostNode getPost(String sharedKey, int postId){
-               IDBManager dbManager = null;
-               try {
-                       dbManager = DBManagerFactory.getDBManager();
-                       final Criteria crit = 
dbManager.createCriteria(Post.class);
-                       crit.add(Restrictions.eq("sharedDataKey", sharedKey));
-                       crit.add(Restrictions.eq("id", postId));
-                       final List<Post> sqlReturnList =  
dbManager.getObjects(Post.class, crit);
-                       if (sqlReturnList.size() != 1) {
-                               return null;
-                       } 
-                       else {
-                               Post post = (Post) sqlReturnList.get(0);
-                               return new PostNode(post.getId(),
-                                               
post.getUserId(),post.getParentId(),post.getContent(),post.getTitle(),
-                                               
post.getPublishDate(),post.getUpdateDate());
-                       }                       
-               } 
-               catch (Exception e) {
-                       dbManager.rollbackTransaction();
-                       _logger.error(e.getMessage());
-               }
+       public PostNode getPost(String sharedKey, String postId){
+        // query for post by id
+        IPersistenceManager persistenceManager = 
PersistenceManagerFactory.getPersistenceManager();
+        IPost post = persistenceManager.findById(IPost.class, postId);
+        if ((post != null) && post.getSharedDataKey().equals(sharedKey))
+        {
+            // return PostNode hierarchy to mirror IPost hierarchy
+            return new PostNode(post);
+        }
                return null;
        }
 
@@ -115,26 +76,27 @@ public class ForumManager implements IFo
         * @see 
org.apache.wookie.widgets.forum.IForumManager#newPost(java.lang.String, 
java.lang.String, java.lang.String, java.lang.String, java.lang.String)
         */
        public boolean newPost(String sharedDataKey, String parent, String 
username, String title, String content){
-               final IDBManager dbManager = DBManagerFactory.getDBManager();
-               Post post = new Post();
-               try {
-                       post.setParentId(Integer.parseInt(parent));
-                       post.setTitle(title);
-                       post.setContent(content);
-                       post.setUserId(username);
-                       post.setPublishDate(new Date());
-                       post.setSharedDataKey(sharedDataKey);
-                       dbManager.saveObject(post);
-                       return true;
-               } 
-               catch (NumberFormatException e) {
-                       dbManager.rollbackTransaction();
-                       _logger.error(e.getMessage());
-               } 
-               catch (Exception e) {
-                       dbManager.rollbackTransaction();
-                       _logger.error(e.getMessage());
-               }       
-               return false;
+        // create and save new post
+        IPersistenceManager persistenceManager = 
PersistenceManagerFactory.getPersistenceManager();
+        IPost post = persistenceManager.newInstance(IPost.class);
+        post.setTitle(title);
+        post.setContent(content);
+        post.setUserId(username);
+        post.setPublishDate(new Date());
+        post.setSharedDataKey(sharedDataKey);
+        boolean saved = persistenceManager.save(post);
+        // add as child to parent post and save
+           if (parent != null)
+           {
+               // query for parent post by id
+               IPost parentPost = persistenceManager.findById(IPost.class, 
parent);
+               if (parentPost != null)
+               {
+                   // add as child post to parent post
+                   parentPost.getPosts().add(post);
+                saved = persistenceManager.save(parentPost);
+               }
+           }
+               return saved;
        }
 }

Modified: 
incubator/wookie/branches/pluggablepersistence/src/widgetserver.properties
URL: 
http://svn.apache.org/viewvc/incubator/wookie/branches/pluggablepersistence/src/widgetserver.properties?rev=955236&r1=955235&r2=955236&view=diff
==============================================================================
--- incubator/wookie/branches/pluggablepersistence/src/widgetserver.properties 
(original)
+++ incubator/wookie/branches/pluggablepersistence/src/widgetserver.properties 
Wed Jun 16 14:16:36 2010
@@ -37,5 +37,6 @@ widget.proxy.username=
 widget.proxy.password=
 widget.proxy.usentlmauthentication=false
 ## language settings
-widget.locales=en, nl, fr
+## NB "en-gb-yorks" is for testing localization
+widget.locales=en, nl, fr, en-gb-yorks
 widget.default.locale=en
\ No newline at end of file


Reply via email to