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 15:19:51 UTC

svn commit: r349119 - in /portals/pluto/trunk: ./ pluto-optional-services/src/main/java/org/apache/pluto/optional/db/ pluto-portal-driver/src/main/java/org/apache/pluto/driver/ pluto-portal/src/main/webapp/WEB-INF/

Author: ddewolf
Date: Sat Nov 26 06:19:43 2005
New Revision: 349119

URL: http://svn.apache.org/viewcvs?rev=349119&view=rev
Log:
Reconfiguring services to utilize db services; Adding comments to config; Adding test to prefernce dao to ensure preferences aren't created more than once

Removed:
    portals/pluto/trunk/TODO
Modified:
    portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/DBPortletPreferencesService.java
    portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/PreferencesDao.java
    portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalStartupListener.java
    portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-config.xml
    portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-services-config.xml
    portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/web.xml

Modified: portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/DBPortletPreferencesService.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/DBPortletPreferencesService.java?rev=349119&r1=349118&r2=349119&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/DBPortletPreferencesService.java (original)
+++ portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/DBPortletPreferencesService.java Sat Nov 26 06:19:43 2005
@@ -43,10 +43,6 @@
 
     private DataSourceManager dataSourceManager;
 
-    public DBPortletPreferencesService() {
-
-    }
-
     private PreferencesDao dao;
 
     public DBPortletPreferencesService(DataSourceManager dataSourceManager)

Modified: portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/PreferencesDao.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/PreferencesDao.java?rev=349119&r1=349118&r2=349119&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/PreferencesDao.java (original)
+++ portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/PreferencesDao.java Sat Nov 26 06:19:43 2005
@@ -69,6 +69,16 @@
         return container.createPreferences();
     }
 
+    private static final String TEST_PR_SQL =
+       "SELECT count(*)" +
+       "  FROM preference pr, portlet p, portlet_app pa" +
+       " WHERE pa.app_context = ? "+
+       "   AND p.portlet_app_id = pa.portlet_app_id "+
+       "   AND p.portlet_name = ? "+
+       "   AND pr.portlet_id = p.portlet_id "+
+       "   AND pr.preference_name = ?";
+
+
     private String createPreferenceSql(String context, String portletName) {
         StringBuffer sb = new StringBuffer();
         sb.append("INSERT INTO preference (portlet_id, preference_name, auth_user, read_only) ")
@@ -85,7 +95,15 @@
     private String createPreferenceValueSql() {
         StringBuffer sb = new StringBuffer();
         sb.append("INSERT INTO preference_value (preference_id, preference_value) ")
-                .append("     VALUES ( (SELECT IDENTITY_VAL_LOCAL() FROM preference), ?)");
+          .append("     VALUES ( " )
+          .append("             (SELECT preference_id " )
+          .append("                FROM preference pr, portlet plt, portlet_app pa ")
+          .append("               WHERE pa.app_context = ? ")
+          .append("                 AND plt.portlet_app_id = pa.portlet_app_id ")
+          .append("                 AND plt.portlet_name = ? ")
+          .append("                 AND pr.portlet_id = plt.portlet_id ")
+          .append("                 AND pr.preference_name = ?")
+          .append(        "), ?)");
         return sb.toString();
     }
 
@@ -98,34 +116,55 @@
        boolean autoCommit = false;
 
        Connection conn = null;
+
+       PreparedStatement testStmt = null;
+
        PreparedStatement stmt = null;
        PreparedStatement valueStmt = null;
 
+       ResultSet rs = null;
+
        try {
            conn = getConnection();
            autoCommit = conn.getAutoCommit();
            conn.setAutoCommit(false);
 
+           testStmt = conn.prepareStatement(TEST_PR_SQL);
            stmt = conn.prepareStatement(createPreferenceSql(context, portletName));
            valueStmt = conn.prepareStatement(createPreferenceValueSql());
 
 
            for(int i=0;i<preferences.length;i++) {
 
-               stmt.setString(1, preferences[i].getName());
-               stmt.setString(2, authUser);
-               stmt.setString(3, preferences[i].isReadOnly()?"Y":"N");
-               stmt.addBatch();
-
-               // Now, we add the values
-               String[] values = preferences[i].getValues();
-               for(int j=0;j<values.length;j++) {
-                   valueStmt.setString(1, values[j]);
-                   valueStmt.addBatch();
+               testStmt.setString(1, context);
+               testStmt.setString(2, portletName);
+               testStmt.setString(3, preferences[i].getName());
+
+               rs = testStmt.executeQuery();
+               if(rs.next() && rs.getInt(1) < 1) {
+                   if(LOG.isDebugEnabled()) {
+                       LOG.debug("Creating preference for user '"+authUser+"': "+context+"/"+portletName+"/"+preferences[i].getName());
+                   }
+                   stmt.setString(1, preferences[i].getName());
+                   stmt.setString(2, authUser);
+                   stmt.setString(3, preferences[i].isReadOnly()?"Y":"N");
+                   stmt.addBatch();
+
+                   // Now, we add the values
+                   String[] values = preferences[i].getValues();
+                   for(int j=0;j<values.length;j++) {
+                       valueStmt.setString(1, context);
+                       valueStmt.setString(2, portletName);
+                       valueStmt.setString(3, preferences[i].getName());
+                       valueStmt.setString(4, values[j]);
+                       valueStmt.addBatch();
+                   }
+
+                   stmt.executeBatch();
+                   valueStmt.executeBatch();
                }
 
-               stmt.executeBatch();
-               valueStmt.executeBatch();
+               rs.close();
            }
 
            conn.commit();

Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalStartupListener.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalStartupListener.java?rev=349119&r1=349118&r2=349119&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalStartupListener.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalStartupListener.java Sat Nov 26 06:19:43 2005
@@ -106,15 +106,8 @@
 
             PortletContainer container = factory.createContainer(
                     config.getContainerName(),
-                    containerServices);
-
-            /*
-              Support Optional!  Not yet!
-            PortletContainer container = factory.createContainer(
-                    config.getContainerName(),
                     containerServices,
                     containerServices);
-            */
 
             if (LOG.isDebugEnabled()) {
                 LOG.debug(" * Initializing portlet container...");

Modified: portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-config.xml
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-config.xml?rev=349119&r1=349118&r2=349119&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-config.xml (original)
+++ portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-config.xml Sat Nov 26 06:19:43 2005
@@ -7,6 +7,23 @@
                       http://portals.apache.org/pluto/xsd/pluto-portal-driver-config.xsd"
   version="1.1">
 
+<!--
+Copyright 2004 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.
+-->
+
     <portal-name>pluto-portal-driver</portal-name>
     <portal-version>1.1.0-ALPHA</portal-version>
     <container-name>Pluto Portal Driver</container-name>

Modified: portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-services-config.xml
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-services-config.xml?rev=349119&r1=349118&r2=349119&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-services-config.xml (original)
+++ portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-services-config.xml Sat Nov 26 06:19:43 2005
@@ -2,37 +2,65 @@
 <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
         "http://www.springframework.org/dtd/spring-beans.dtd">
 
+<!--
+
+  ************************************************************
+
+  NOTE:
+
+  The following configuration file contains the spring bean
+  configuration needed to run the pluto-portal with all the
+  bells and whistles.  This includes, but is not limited to,
+  database backed preferences and user-attributes.  Additionally
+  it supports advanced administration utilities (such as
+  portlet application publishing) to ease getting started
+  with pluto.
+
+  While these bells and whistles are nice, all of these functions
+  are not required.  A *very* lightweight implementation is provided
+  in comments below. This configuration provides memory based
+  services (instead of db ones).
+
+  In order to ease getting started, by default, the database
+  used is embedded within the portal and will be automatically
+  be created the FIRST TIME you startup pluto.  Once created,
+  your startup time should decreate significantly.
+
+  ************************************************************
+
+  -->
+
 <beans>
-    <!-- The DriverConfiguration Bean.  This is the only bean required -->
+
+    <!-- ================================================ -->
+    <!-- The single top element of the configuration tree -->
+    <!-- ================================================ -->
     <bean id="DriverConfiguration"
           class="org.apache.pluto.driver.config.impl.DriverConfigurationImpl">
+      <!-- ===== Portal Services ===== -->
       <constructor-arg><ref local="PropertyConfigService"/></constructor-arg>
       <constructor-arg><ref local="PortletRegistryConfig"/></constructor-arg>
       <constructor-arg><ref local="RenderConfigService"/></constructor-arg>
 
-      <!-- Container Services -->
+      <!-- === Container Services === -->
       <constructor-arg><ref local="PortalCallbackService"/></constructor-arg>
 
-      <!-- Optional Services which can be injected via properties -->
-      <!-- <property name="PortletPreferencesService"/> -->
+      <!--  Optional Container Services -->
+      <property name="portletPreferencesService"><ref local="PortletPreferencesService"/></property>
     </bean>
 
+    <!-- ================================================ -->
+    <!-- Portal Services injected into the Configuration  -->
+    <!-- ================================================ -->
     <bean id="PropertyConfigService"
           class="org.apache.pluto.driver.services.impl.resource.PropertyConfigServiceImpl"
           singleton="true">
     </bean>
 
-    <!--
-    <bean name="PortletRegistryService"
-          class="org.apache.pluto.driver.services.impl.resource.PortletRegistryServiceImpl
-          singleton="true">
-    </bean>
-    -->
-
     <bean id="PortletRegistryConfig"
           class="org.apache.pluto.driver.services.impl.db.DBPortletRegistryService"
           singleton="true">
-        <constructor-arg><ref bean="DataSourceManager"/></constructor-arg>
+        <constructor-arg><ref local="DataSourceManager"/></constructor-arg>
     </bean>
 
     <bean id="RenderConfigService"
@@ -41,30 +69,28 @@
     </bean>
 
 
-    <!-- ================== -->
-    <!-- Container Services -->
-    <!-- ================== -->
+    <!-- ================================================ -->
+    <!-- Container Services injected into  Configuration  -->
+    <!-- ================================================ -->
     <bean id="PortalCallbackService"
           class="org.apache.pluto.driver.services.container.PortalCallbackServiceImpl"
           singleton="true">
     </bean>
 
 
-    <!-- =========================== -->
-    <!-- Optional Container Services -->
-    <!-- =========================== -->
-    <!--
-    <bean id="PortletPreferencesService"
+    <!-- ================================================ -->
+    <!-- = Optional Services injected into Configuration  -->
+    <!-- ================================================ -->
+   <bean id="PortletPreferencesService"
           class="org.apache.pluto.optional.db.DBPortletPreferencesService"
           singleton="true">
-        <constructor-arg><ref bean="DataSourceManager"/></constructor-arg>
-    </bean>
-   -->
+        <constructor-arg><ref local="DataSourceManager"/></constructor-arg>
+   </bean>
+
+    <!-- ================================================ -->
+    <!-- = Nested Services needed for Portal and Container Services -->
+    <!-- ================================================ -->
 
-    <!-- =========================== -->
-    <!-- DataSourceManager:
-           used for DataSource Lookup in all db services
-    -->
     <bean id="DataSourceManager"
           class="org.apache.pluto.optional.db.support.EmbeddedDataSourceManager"
           singleton="true">
@@ -83,4 +109,44 @@
     </bean>
     -->
 
+
+
+
+
+
+
+
+
+
+
+    <!-- =========================================== -->
+    <!-- ====== LIGTHWEIGHT CONFIGURATION  ========= -->
+    <!-- =========================================== -->
+
+    <!--
+
+      To utilize the lightweight configuration, comment out
+      all services defined above and uncomment the following.
+
+      NOTE: make sure that you don't comment out the DriverConfiguration
+      (top element);
+
+     -->
+
+    <!--
+    <bean id="PropertyConfigService"
+          class="org.apache.pluto.driver.services.impl.resource.PropertyConfigServiceImpl"
+          singleton="true">
+    </bean>
+
+    <bean name="PortletRegistryService"
+          class="org.apache.pluto.driver.services.impl.resource.PortletRegistryServiceImpl
+          singleton="true">
+    </bean>
+
+     <bean id="RenderConfigService"
+          class="org.apache.pluto.driver.services.impl.resource.RenderConfigServiceImpl"
+          singleton="true">
+    </bean>
+   -->
 </beans>

Modified: portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/web.xml?rev=349119&r1=349118&r2=349119&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/web.xml (original)
+++ portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/web.xml Sat Nov 26 06:19:43 2005
@@ -3,6 +3,7 @@
 <!DOCTYPE web-app
     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
            "http://java.sun.com/dtd/web-app_2_3.dtd">
+
 <!-- 
 Copyright 2004 The Apache Software Foundation.
 Licensed  under the  Apache License,  Version 2.0  (the "License");
@@ -19,6 +20,7 @@
 See the License for the specific language governing permissions and
 limitations under the License.
 -->
+
 <web-app>
 
     <display-name>Pluto Reference Implementation</display-name>