You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by dd...@apache.org on 2005/11/26 04:02:46 UTC

svn commit: r349065 - in /portals/pluto/trunk: pluto-optional-services/src/resources/ pluto-portal-driver/src/main/java/org/apache/pluto/driver/ pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/admin/ pluto-portal-driver/src/main/java...

Author: ddewolf
Date: Fri Nov 25 19:02:38 2005
New Revision: 349065

URL: http://svn.apache.org/viewcvs?rev=349065&view=rev
Log:
moving dll to optional-services; refactor auto-publishing at startup

Added:
    portals/pluto/trunk/pluto-optional-services/src/resources/
    portals/pluto/trunk/pluto-optional-services/src/resources/create_schema.sql
    portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/
      - copied from r349061, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/admin/
Removed:
    portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/admin/
    portals/pluto/trunk/pluto-portal-driver/src/resources/create_schema.sql
Modified:
    portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PublishServlet.java
    portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java
    portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/PortletRegistryDao.java
    portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/AdminException.java
    portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/PublishService.java

Added: portals/pluto/trunk/pluto-optional-services/src/resources/create_schema.sql
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-optional-services/src/resources/create_schema.sql?rev=349065&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-optional-services/src/resources/create_schema.sql (added)
+++ portals/pluto/trunk/pluto-optional-services/src/resources/create_schema.sql Fri Nov 25 19:02:38 2005
@@ -0,0 +1,112 @@
+--
+-- Copyright 2004,2005 The Apache Software Foundation
+-- Licensed  under the  Apache License,  Version 2.0  (the "License");
+-- you may not use  this file  except in  compliance with the License.
+-- You may obtain a copy of the License at
+--
+--   http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed  under the  License is distributed on an "AS IS" BASIS,
+-- WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+-- implied.
+--
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
+--
+-- SQL Script for the Pluto Portal Driver Schema
+--
+
+CREATE SCHEMA pluto_portal_driver;
+
+-- SET SCHEMA pluto_portal_driver;
+
+--
+-- Global Portal Tables
+--
+
+CREATE TABLE version (
+  major_version INTEGER NOT NULL,
+  minor_version INTEGER NOT NULL,
+  release       INTEGER NOT NULL,
+  constraint version_pk primary key (major_version, minor_version, release)
+);
+
+CREATE TABLE portlet_app (
+  portlet_app_id INTEGER      NOT NULL generated always as identity (start with 1, increment by 1),
+  app_context    VARCHAR(250) NOT NULL,
+  deploy_date    TIMESTAMP             DEFAULT CURRENT_TIMESTAMP,
+  constraint portlet_app_pk primary key (portlet_app_id),
+  constraint app_context_unique unique (app_context)
+);
+
+CREATE TABLE portlet (
+	portlet_id     INTEGER NOT NULL generated always as identity (start with 1, increment by 1),
+	portlet_app_id INTEGER NOT NULL,
+	portlet_name   VARCHAR(75) NOT NULL,
+	mod_date       TIMESTAMP default CURRENT_TIMESTAMP,
+	constraint portlet_pk primary key (portlet_id),
+	constraint portlet_fk foreign key (portlet_app_id) references portlet_app(portlet_app_id)
+);
+
+--
+-- Portlet Preferences
+--
+CREATE TABLE preference (
+	preference_id    INTEGER     NOT NULL generated always as identity  (start with 1, increment by 1),
+	portlet_id       INTEGER     NOT NULL,
+	preference_name  VARCHAR(75) NOT NULL,
+	description      VARCHAR(250),
+	read_only        CHAR(1)              DEFAULT 'N',
+	auth_user        VARCHAR(75),
+	mod_date         TIMESTAMP            DEFAULT current_timestamp,
+	constraint preference_pk primary key (preference_id),
+	constraint preference_fk foreign key (portlet_id) references portlet(portlet_id)
+);
+
+CREATE INDEX preference_auth_user_ndx on preference(auth_user);
+
+CREATE TABLE preference_value (
+	preference_id    INTEGER NOT NULL,
+	preference_value VARCHAR(250),
+	mod_date         TIMESTAMP default CURRENT_TIMESTAMP,
+	constraint preference_value_pk primary key  (preference_id, preference_value),
+	constraint preference_value_fk foreign key (preference_id) references preference(preference_id)
+);
+
+-- User information attribute names as defined in PLT.D of the JSR-168 spec
+CREATE TABLE user_info_attribute (
+	user_info_attribute_id INTEGER      NOT NULL generated always as identity (start with 1, increment by 1),
+	attribute_name         VARCHAR(75),
+	mod_date               TIMESTAMP    default CURRENT_TIMESTAMP,
+	constraint user_info_attribute_pk primary key (user_info_attribute_id)
+);
+
+-- Holds user information attribute values as defined in PLT.17 of the JSR-168 spec
+CREATE TABLE user_info_attribute_value (
+	user_info_attribute_id INTEGER NOT NULL,
+	auth_user              VARCHAR(75),
+	attribute_value        VARCHAR(250),
+	mod_date               TIMESTAMP default CURRENT_TIMESTAMP,
+	constraint user_info_attribute_value_pk primary key (user_info_attribute_id, auth_user),
+	constraint user_info_attribute_value_fk foreign key (user_info_attribute_id) references user_info_attribute(user_info_attribute_id)
+);
+
+CREATE INDEX user_info_attribute_auth_user_ndx on user_info_attribute_value(auth_user);
+
+--View that holds all the portlet app data.
+--Use this with a where clause to get data for a
+--particular portlet app or portlet.
+CREATE VIEW portlet_app_view
+	   (portlet_app_id, app_context, portlet_id,
+	    portlet_name,  preference_name, preference_value,
+		read_only) as
+       SELECT pa.portlet_app_id, pa.app_context, p.portlet_id,
+              p.portlet_name, pr.preference_name, pv.preference_value,
+              pr.read_only
+	     FROM preference pr, preference_value pv,
+	          portlet p, portlet_app pa
+	    WHERE pr.preference_id=pv.preference_id
+	      AND pr.portlet_id=p.portlet_id
+	      AND p.portlet_app_id=pa.portlet_app_id;

Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PublishServlet.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PublishServlet.java?rev=349065&r1=349064&r2=349065&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PublishServlet.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PublishServlet.java Fri Nov 25 19:02:38 2005
@@ -15,7 +15,7 @@
  */
 package org.apache.pluto.driver;
 
-import org.apache.pluto.driver.services.admin.AdminException;
+import org.apache.pluto.driver.services.portal.admin.AdminException;
 
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;

Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java?rev=349065&r1=349064&r2=349065&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java Fri Nov 25 19:02:38 2005
@@ -28,7 +28,6 @@
 
 import javax.servlet.ServletContext;
 import java.util.Set;
-import java.sql.SQLException;
 import java.io.InputStream;
 
 /**
@@ -78,7 +77,7 @@
             InputStream in = ctx.getResourceAsStream(ResourceConfigReader.CONFIG_FILE);
             config = ResourceConfigReader.getFactory().parse(in);
 
-            dao.createPortletApplications(config.getPortletApplications());
+            dao.seedPortletApplications(config.getPortletApplications());
         }
         catch(Exception sql) {
             if(LOG.isErrorEnabled()) {

Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/PortletRegistryDao.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/PortletRegistryDao.java?rev=349065&r1=349064&r2=349065&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/PortletRegistryDao.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/PortletRegistryDao.java Fri Nov 25 19:02:38 2005
@@ -41,13 +41,14 @@
         super(dataSource);
     }
 
-    public void createPortletApplications(Collection portletApplications)
+    public void seedPortletApplications(Collection portletApplications)
     throws SQLException {
 
         boolean autoCommit = false;
         Connection conn = null;
 
-        PreparedStatement testStmt = null;
+        PreparedStatement appTestStmt = null;
+        PreparedStatement portletTestStmt = null;
         PreparedStatement appStmt = null;
         PreparedStatement pStmt = null;
 
@@ -57,7 +58,9 @@
             autoCommit = conn.getAutoCommit();
             conn.setAutoCommit(false);
 
-            testStmt = conn.prepareStatement(TEST_APP_SQL);
+            appTestStmt = conn.prepareStatement(TEST_APP_SQL);
+            portletTestStmt = conn.prepareStatement(TEST_PORTLET_SQL);
+
             appStmt = conn.prepareStatement(CREATE_APP_SQL);
             pStmt = conn.prepareStatement(CREATE_PORTLET_SQL);
 
@@ -65,21 +68,36 @@
             while(it.hasNext()) {
                 PortletApplicationConfig app = (PortletApplicationConfig)it.next();
 
-                testStmt.setString(1, app.getContextPath());
-                ResultSet rs = testStmt.executeQuery();
-                if(rs.next() && rs.getInt(1) > 0) {
-                    continue;
+                appTestStmt.setString(1, app.getContextPath());
+                ResultSet rs = appTestStmt.executeQuery();
+
+                if(!rs.next() || rs.getInt(1) < 1) {
+                    if(LOG.isDebugEnabled()) {
+                        LOG.debug("Auto-Publishing Portlet Application: "+app.getContextPath());
+                    }
+                    appStmt.setString(1, app.getContextPath());
+                    appStmt.addBatch();
                 }
 
-                appStmt.setString(1, app.getContextPath());
-                appStmt.addBatch();
+                rs.close();
 
                 Iterator portlets = app.getPortlets().iterator();
                 while(portlets.hasNext()) {
                     PortletWindowConfig window = (PortletWindowConfig)portlets.next();
-                    pStmt.setString(1, window.getPortletName());
-                    pStmt.addBatch();
-                }
+                    portletTestStmt.setString(1, app.getContextPath());
+                    portletTestStmt.setString(2, window.getPortletName());
+                    rs = portletTestStmt.executeQuery();
+
+                    if(!rs.next() || rs.getInt(1) < 1) {
+                        if(LOG.isDebugEnabled()) {
+                            LOG.debug("Auto-Publishing Portlet: "+app.getContextPath() + " --> " + window.getPortletName());
+                        }
+
+                        pStmt.setString(1, app.getContextPath());
+                        pStmt.setString(2, window.getPortletName());
+                        pStmt.addBatch();
+                    }
+               }
 
                 appStmt.executeBatch();
                 pStmt.executeBatch();
@@ -95,7 +113,7 @@
         finally {
             if(conn != null)
                 conn.setAutoCommit(autoCommit);
-            cleanup(null, testStmt, null);
+            cleanup(null, appTestStmt, null);
             cleanup(null, pStmt, null);
             cleanup(conn, appStmt, null);
         }
@@ -106,12 +124,20 @@
     }
 
     private static final String TEST_APP_SQL =
-            "SELECT count(*) FROM portlet_app WHERE app_context = ?";
+        "SELECT count(*) FROM portlet_app WHERE app_context = ?";
 
+    private static final String TEST_PORTLET_SQL =
+        "SELECT count(*) " +
+        "  FROM portlet p, portlet_app pa " +
+        " WHERE pa.app_context = ? " +
+        "   AND p.portlet_app_id = pa.portlet_app_id " +
+        "   AND p.portlet_name = ? ";
 
     private static final String CREATE_APP_SQL =
         "INSERT INTO portlet_app (app_context) VALUES (?)";
 
     public static final String CREATE_PORTLET_SQL =
-        "INSERT INTO portlet (portlet_app_id, portlet_name) VALUES ((SELECT IDENTITY_VAL_LOCAL() FROM portlet_app), ?)";
+        "INSERT INTO portlet (portlet_app_id, portlet_name) VALUES (" +
+        "       (SELECT portlet_app_id FROM portlet_app WHERE app_context = ?), ?" +
+        ")";
 }

Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/AdminException.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/AdminException.java?rev=349065&r1=349061&r2=349065&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/AdminException.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/AdminException.java Fri Nov 25 19:02:38 2005
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.pluto.driver.services.admin;
+package org.apache.pluto.driver.services.portal.admin;
 
 import javax.servlet.ServletException;
 

Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/PublishService.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/PublishService.java?rev=349065&r1=349061&r2=349065&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/PublishService.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/PublishService.java Fri Nov 25 19:02:38 2005
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.pluto.driver.services.admin;
+package org.apache.pluto.driver.services.portal.admin;
 
 /**
  *