You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2008/10/29 09:45:18 UTC

svn commit: r708830 - in /portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade: components/jetspeed-registry/src/main/java/JETSPEED-INF/ojb/ components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/ jetspeed-...

Author: taylor
Date: Wed Oct 29 01:45:17 2008
New Revision: 708830

URL: http://svn.apache.org/viewvc?rev=708830&view=rev
Log:
https://issues.apache.org/jira/browse/JS2-871
rewrite of Preferences service. (not completed, tested, or integrated). Ate, please review, and feel free to start removing old dependencies if satisfied (or change this impl as required)
There are a number of "TODO: 2.2" comments that need reviewing and resolution
Still outstanding:
* tests 
* preload - port from 2.1.3
* validator - needs hooking in from jetspeed registry
* row reader / discriminator - might not need this, since the solution opted for better memory and a simpler cached preference, the database records are not kept around
* delete old implementations - when satisfied with this, will clear up tons of syntax errors for JS2-871 (i moved the previous OJB mapping to "fast_preferences.xml")

Added:
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/JETSPEED-INF/ojb/fast_preferences.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/DatabasePreference.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/DatabasePreferenceValue.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/JetspeedPreferenceImpl.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/JetspeedPreferencesMap.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesServiceImpl.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PreferencesRowReader.java
Modified:
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/JETSPEED-INF/ojb/registry_repository.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PersistenceBrokerPortletPreferencesProvider.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesProvider.java
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/ddl-schema/registry-schema.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/pluto-services.xml
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/registry.xml

Added: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/JETSPEED-INF/ojb/fast_preferences.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/JETSPEED-INF/ojb/fast_preferences.xml?rev=708830&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/JETSPEED-INF/ojb/fast_preferences.xml (added)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/JETSPEED-INF/ojb/fast_preferences.xml Wed Oct 29 01:45:17 2008
@@ -0,0 +1,166 @@
+   <!--
+   - P O R T L E T   P R E F E R E N C E S
+   -->       
+   
+  <class-descriptor
+      class="org.apache.jetspeed.om.preference.impl.PreferenceImpl"
+      table="PORTLET_PREFERENCE"
+  >
+      <documentation>Represents a Portlet Preference definition.</documentation>
+      <field-descriptor
+          name="id"
+          column="ID"
+          jdbc-type="BIGINT"
+          primarykey="true"
+          autoincrement="true"
+      >
+      </field-descriptor>
+      <field-descriptor
+          name="applicationName"
+          column="APPLICATION_NAME"
+          jdbc-type="VARCHAR"
+          nullable="false"
+          length="80"
+      >
+      </field-descriptor>
+      <field-descriptor
+          name="portletName"
+          column="PORTLET_NAME"
+          jdbc-type="VARCHAR"
+          nullable="false"
+          length="80"
+      >
+      </field-descriptor>
+      <field-descriptor
+          name="name"
+          column="NAME"
+          jdbc-type="VARCHAR"
+          nullable="false"
+          length="254"
+      >
+      </field-descriptor>
+  </class-descriptor>
+
+  <class-descriptor
+      class="org.apache.jetspeed.om.preference.impl.PreferenceValueImpl"
+      table="PORTLET_PREFERENCE_VALUE"
+  >
+      <documentation>Represents a Portlet Preference value.</documentation>
+      <field-descriptor
+          name="prefId"
+          column="PREF_ID"
+          jdbc-type="BIGINT"
+          primarykey="true"
+      >
+      </field-descriptor>
+      <reference-descriptor
+          name="preference"
+          class-ref="org.apache.jetspeed.om.preference.impl.PreferenceImpl"
+          auto-retrieve="false"
+          auto-update="none"
+          auto-delete="none"
+      >
+          <foreignkey field-ref="prefId"/>
+      </reference-descriptor>
+      
+      <field-descriptor
+          name="index"
+          column="IDX"
+          jdbc-type="SMALLINT"
+          nullable="false"
+          primarykey="true"
+      >
+      </field-descriptor>
+      <field-descriptor
+          name="entityOid"
+          column="ENTITY_OID"
+          jdbc-type="BIGINT"
+          nullable="false"
+          primarykey="true"
+      >
+      </field-descriptor>
+      <field-descriptor
+          name="userName"
+          column="USER_NAME"
+          jdbc-type="VARCHAR"
+          nullable="false"
+          primarykey="true"
+          length="80"
+      >
+      </field-descriptor>
+      <field-descriptor
+          name="entityId"
+          column="ENTITY_ID"
+          jdbc-type="VARCHAR"
+          nullable="true"
+          length="80"
+      >
+      </field-descriptor>
+      <field-descriptor
+          name="readOnly"
+          column="READONLY"
+          jdbc-type="INTEGER"
+          conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldConversion"
+          nullable="false"
+      >
+      </field-descriptor>      
+      <field-descriptor
+          name="nullValue"
+          column="NULL_VALUE"
+          jdbc-type="INTEGER"
+          conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldConversion"
+          nullable="false"
+      >
+      </field-descriptor>      
+      <field-descriptor
+          name="value"
+          column="PREF_VALUE"
+          jdbc-type="VARCHAR"
+          nullable="true"
+          length="4000"
+      >
+      </field-descriptor>      
+
+  </class-descriptor>
+
+  
+      <table name="PORTLET_PREFERENCE">
+        <column name="ID" primaryKey="true" required="true" type="INTEGER"/>
+        <column name="APPLICATION_NAME" required="true" size="80" type="VARCHAR"/>
+        <column name="PORTLET_NAME" required="true" size="80" type="VARCHAR"/>
+        <column name="NAME" required="true" size="254" type="VARCHAR"/>
+        
+      <!-- non-unique index on APPLICATION_NAME,PORTLET_NAME shouldn't be needed as its already
+           "covered" by unique index on APPLICATION_NAME,PORTLET_NAME,NAME
+        <index name="IX_PORTLET_PREFERENCE">
+            <index-column name="APPLICATION_NAME"/>
+            <index-column name="PORTLET_NAME"/>
+        </index>        
+      -->
+        <unique name="UIX_PORTLET_PREFERENCE">
+          <unique-column name="APPLICATION_NAME"/>
+          <unique-column name="PORTLET_NAME"/>
+          <unique-column name="NAME"/>
+        </unique>        
+
+    </table>
+
+    <table name="PORTLET_PREFERENCE_VALUE">
+        <column name="PREF_ID" primaryKey="true" required="true" type="INTEGER"/>
+        <column name="IDX" primaryKey="true" required="true" type="SMALLINT"/>
+        <column name="ENTITY_OID" primaryKey="true" required="true" type="INTEGER"/>
+        <column name="USER_NAME" primaryKey="true" required="true" size="80" type="VARCHAR"/>
+        <column name="ENTITY_ID" type="VARCHAR" size="80"/>
+        <column name="READONLY" required="true" type="BOOLEANINT"/>
+        <column name="NULL_VALUE" required="true" type="BOOLEANINT"/>
+        <column name="PREF_VALUE" size="4000" type="VARCHAR"/>
+
+        <index name="IX_PREFS_PREF_ID">
+            <index-column name="PREF_ID"/>
+        </index>        
+        
+        <foreign-key foreignTable="PORTLET_PREFERENCE" name="FK_PORTLET_PREFERENCE" onDelete="cascade">
+            <reference foreign="ID" local="PREF_ID"/>
+        </foreign-key>             
+    </table>
+  
\ No newline at end of file

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/JETSPEED-INF/ojb/registry_repository.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/JETSPEED-INF/ojb/registry_repository.xml?rev=708830&r1=708829&r2=708830&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/JETSPEED-INF/ojb/registry_repository.xml (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/JETSPEED-INF/ojb/registry_repository.xml Wed Oct 29 01:45:17 2008
@@ -1153,9 +1153,26 @@
 
    <!--
    - P O R T L E T   P R E F E R E N C E S
-   -->
+  CREATE TABLE PORTLET_PREFERENCE
+(
+	ID INTEGER NOT NULL,
+    DTYPE VARCHAR(20) NOT NULL,
+    APP_NAME VARCHAR(80) NOT NULL,
+	PORTLET_NAME VARCHAR(80) NOT NULL,
+	NAME VARCHAR(128) NOT NULL,
+	USER_NAME VARCHAR(80),
+	ENTITY_ID VARCHAR(80),
+	PRIMARY KEY (ID)
+);
+CREATE UNIQUE INDEX UIX_PORTLET_PREFERENCE ON PORTLET_PREFERENCE (APP_NAME, PORTLET_NAME, NAME, USER_NAME, ENTITY_ID);
+CREATE INDEX IX_PORTLET_PREF_ENTITY ON PORTLET_PREFERENCE (ENTITY_ID, USER_NAME);
+
+        row-reader="org.apache.jetspeed.components.portletpreferences.PreferencesRowReader" 
+  
+   -->       
+
   <class-descriptor
-      class="org.apache.jetspeed.om.preference.impl.PreferenceImpl"
+      class="org.apache.jetspeed.components.portletpreferences.DatabasePreference"
       table="PORTLET_PREFERENCE"
   >
       <documentation>Represents a Portlet Preference definition.</documentation>
@@ -1167,6 +1184,14 @@
           autoincrement="true"
       >
       </field-descriptor>
+     <field-descriptor
+          name="dtype"
+          column="DTYPE"
+          jdbc-type="VARCHAR"
+          nullable="false"
+          length="10"
+      >
+      </field-descriptor>      
       <field-descriptor
           name="applicationName"
           column="APPLICATION_NAME"
@@ -1191,46 +1216,6 @@
           length="254"
       >
       </field-descriptor>
-  </class-descriptor>
-
-  <class-descriptor
-      class="org.apache.jetspeed.om.preference.impl.PreferenceValueImpl"
-      table="PORTLET_PREFERENCE_VALUE"
-  >
-      <documentation>Represents a Portlet Preference value.</documentation>
-      <field-descriptor
-          name="prefId"
-          column="PREF_ID"
-          jdbc-type="BIGINT"
-          primarykey="true"
-      >
-      </field-descriptor>
-      <reference-descriptor
-          name="preference"
-          class-ref="org.apache.jetspeed.om.preference.impl.PreferenceImpl"
-          auto-retrieve="false"
-          auto-update="none"
-          auto-delete="none"
-      >
-          <foreignkey field-ref="prefId"/>
-      </reference-descriptor>
-      
-      <field-descriptor
-          name="index"
-          column="IDX"
-          jdbc-type="SMALLINT"
-          nullable="false"
-          primarykey="true"
-      >
-      </field-descriptor>
-      <field-descriptor
-          name="entityOid"
-          column="ENTITY_OID"
-          jdbc-type="BIGINT"
-          nullable="false"
-          primarykey="true"
-      >
-      </field-descriptor>
       <field-descriptor
           name="userName"
           column="USER_NAME"
@@ -1255,15 +1240,49 @@
           conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldConversion"
           nullable="false"
       >
+      </field-descriptor>
+      
+      <collection-descriptor
+          name="values"
+          element-class-ref="org.apache.jetspeed.components.portletpreferences.DatabasePreferenceValue"
+          auto-retrieve="true"
+          auto-update="object"
+          auto-delete="object"
+      >
+          <inverse-foreignkey field-ref="prefId"/>
+      </collection-descriptor>
+                  
+  </class-descriptor>
+    
+   <class-descriptor
+      class="org.apache.jetspeed.components.portletpreferences.DatabasePreferenceValue"
+      table="PORTLET_PREFERENCE_VALUE"
+  >
+      <documentation>Represents a Portlet Preference value.</documentation>
+      <field-descriptor
+          name="id"
+          column="ID"
+          jdbc-type="BIGINT"
+          primarykey="true"
+          autoincrement="true"
+      >
+      </field-descriptor>
+      <field-descriptor
+          name="prefId"
+          column="PREF_ID"
+          jdbc-type="BIGINT"
+          primarykey="true"
+      >
       </field-descriptor>      
+      
       <field-descriptor
-          name="nullValue"
-          column="NULL_VALUE"
-          jdbc-type="INTEGER"
-          conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldConversion"
+          name="index"
+          column="IDX"
+          jdbc-type="SMALLINT"
           nullable="false"
+          primarykey="true"
       >
-      </field-descriptor>      
+      </field-descriptor>
       <field-descriptor
           name="value"
           column="PREF_VALUE"
@@ -1271,11 +1290,11 @@
           nullable="true"
           length="4000"
       >
-      </field-descriptor>      
-
+      </field-descriptor>
+                  
+                  
   </class-descriptor>
 
-
   <!--
    - S E C U R T I T Y   R O L E   R E F
   -->

Added: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/DatabasePreference.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/DatabasePreference.java?rev=708830&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/DatabasePreference.java (added)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/DatabasePreference.java Wed Oct 29 01:45:17 2008
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.jetspeed.components.portletpreferences;
+
+import java.util.Collection;
+
+import org.apache.jetspeed.om.preference.impl.PreferenceImpl;
+
+/**
+ * <p>
+ * The database representation of a preference object
+ * </p>
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class DatabasePreference
+{
+    private long id;
+    private String dtype;
+    private String applicationName;
+    private String portletName;
+    private String name;
+    private String userName;
+    private String entityId;
+    private boolean readOnly;
+    private Collection<DatabasePreferenceValue> values;
+    
+    public DatabasePreference()
+    {}
+        
+    public String getDtype()
+    {
+        return dtype;
+    }
+    
+    public void setDtype(String dtype)
+    {
+        this.dtype = dtype;
+    }
+    
+    public String getApplicationName()
+    {
+        return applicationName;
+    }
+    
+    public void setApplicationName(String applicationName)
+    {
+        this.applicationName = applicationName;
+    }
+    
+    public String getPortletName()
+    {
+        return portletName;
+    }
+    
+    public void setPortletName(String portletName)
+    {
+        this.portletName = portletName;
+    }
+    
+    public String getName()
+    {
+        return name;
+    }
+    
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+    
+    public String getUserName()
+    {
+        return userName;
+    }
+    
+    public void setUserName(String userName)
+    {
+        this.userName = userName;
+    }
+    
+    public String getEntityId()
+    {
+        return entityId;
+    }
+    
+    public void setEntityId(String entityId)
+    {
+        this.entityId = entityId;
+    }
+    
+    public boolean isReadOnly()
+    {
+        return readOnly;
+    }
+    
+    public void setReadOnly(boolean readOnly)
+    {
+        this.readOnly = readOnly;
+    }
+    
+    public long getId()
+    {
+        return id;
+    }
+
+    public Collection<DatabasePreferenceValue> getPreferenceValues()
+    {
+        return values;
+    }
+
+    public String[] getValues()
+    {
+        String[] result = new String[values.size()];
+        int index = 0;
+        for (DatabasePreferenceValue value : this.getPreferenceValues())
+        {
+            result[index] = value.getValue();
+            index++;
+        }
+        return result; 
+    }
+    
+    public int hashCode()
+    {
+        return applicationName.hashCode()+portletName.hashCode()+name.hashCode();
+    }
+
+    // TODO: 2.2 going to probably want to break these up into a base class and two subclasses if we need the equals
+    public boolean equals(Object object)
+    {
+        if (this == object)
+        {
+            return true;
+        }
+        if ((object instanceof DatabasePreference))
+        {
+            DatabasePreference other = (DatabasePreference)object;            
+            return applicationName.equals(other.applicationName) && portletName.equals(other.applicationName) && name.equals(other.name);
+        }
+        return false;
+    }
+    
+}

Added: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/DatabasePreferenceValue.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/DatabasePreferenceValue.java?rev=708830&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/DatabasePreferenceValue.java (added)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/DatabasePreferenceValue.java Wed Oct 29 01:45:17 2008
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.jetspeed.components.portletpreferences;
+
+/**
+ * <p>
+ * The database representation of a preference value object
+ * </p>
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ *  
+ */
+public class DatabasePreferenceValue
+{
+    private long id;
+    private long prefId;
+    private short index;
+    private String value;
+
+    public DatabasePreferenceValue()
+    {}
+    
+    public long getId()
+    {
+        return id;
+    }
+    
+    public short getIndex()
+    {
+        return index;
+    }
+    
+    public void setIndex(short index)
+    {
+        this.index = index;
+    }
+    
+    public String getValue()
+    {
+        return value;
+    }
+    
+    public void setValue(String value)
+    {
+        this.value = value;
+    }
+    
+    public long getPrefId()
+    {
+        return prefId;
+    }
+
+}

Added: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/JetspeedPreferenceImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/JetspeedPreferenceImpl.java?rev=708830&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/JetspeedPreferenceImpl.java (added)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/JetspeedPreferenceImpl.java Wed Oct 29 01:45:17 2008
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.jetspeed.components.portletpreferences;
+
+import org.apache.pluto.internal.InternalPortletPreference;
+import org.apache.pluto.internal.impl.PortletPreferenceImpl;
+
+/**
+ * <p>
+ * Jetspeed Portlet Preference object, internal representation
+ * </p>
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class JetspeedPreferenceImpl extends PortletPreferenceImpl implements InternalPortletPreference
+{
+    public JetspeedPreferenceImpl(String name, String[] values)
+    {
+        super(name, values);
+    }
+}

Added: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/JetspeedPreferencesMap.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/JetspeedPreferencesMap.java?rev=708830&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/JetspeedPreferencesMap.java (added)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/JetspeedPreferencesMap.java Wed Oct 29 01:45:17 2008
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.jetspeed.components.portletpreferences;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.jetspeed.cache.DistributedCacheObject;
+import org.apache.pluto.internal.InternalPortletPreference;
+
+/**
+ * <p>
+ * Jetspeed Portlet Preference Map, return these to Pluto
+ * </p>
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class JetspeedPreferencesMap implements Map<String, InternalPortletPreference>, DistributedCacheObject
+{
+    private static final long serialVersionUID = 1L;
+    
+    private Map<String, InternalPortletPreference> map = new HashMap<String, InternalPortletPreference>();
+    
+    public JetspeedPreferencesMap()
+    {
+    }
+    
+    public void clear()
+    {
+        map.clear(); 
+    }
+
+    public boolean containsKey(Object key)
+    {
+        return map.containsKey(key);
+    }
+
+    public boolean containsValue(Object value)
+    {
+        return map.containsValue(value);
+    }
+
+    public Set<java.util.Map.Entry<String, InternalPortletPreference>> entrySet()
+    {
+        return map.entrySet();
+    }
+
+    public InternalPortletPreference get(Object key)
+    {
+        return map.get(key);
+    }
+
+    public boolean isEmpty()
+    {
+        return map.isEmpty();
+    }
+
+    public Set<String> keySet()
+    {
+        return map.keySet();
+    }
+
+    public InternalPortletPreference put(String key,
+            InternalPortletPreference value)
+    {
+        return map.put(key, value);
+    }
+
+    public void putAll(
+            Map<? extends String, ? extends InternalPortletPreference> other)
+    {
+        map.putAll(other);
+    }
+
+    public InternalPortletPreference remove(Object key)
+    {
+        return map.remove(key);
+    }
+
+    public int size()
+    {
+        return map.size();
+    }
+
+    public Collection<InternalPortletPreference> values()
+    {
+        return map.values();
+    }
+
+    public void notifyChange(int action)
+    {
+        // TODO: 2.2        
+    }
+
+}

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PersistenceBrokerPortletPreferencesProvider.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PersistenceBrokerPortletPreferencesProvider.java?rev=708830&r1=708829&r2=708830&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PersistenceBrokerPortletPreferencesProvider.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PersistenceBrokerPortletPreferencesProvider.java Wed Oct 29 01:45:17 2008
@@ -23,6 +23,8 @@
 import java.util.LinkedList;
 import java.util.Map;
 
+import javax.portlet.PortletRequest;
+
 import org.apache.jetspeed.cache.CacheElement;
 import org.apache.jetspeed.cache.JetspeedCache;
 import org.apache.jetspeed.container.PortletEntity;
@@ -36,6 +38,9 @@
 import org.apache.ojb.broker.query.QueryByCriteria;
 import org.apache.ojb.broker.query.QueryFactory;
 import org.apache.ojb.broker.query.ReportQueryByCriteria;
+import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.PortletWindow;
+import org.apache.pluto.internal.InternalPortletPreference;
 import org.springframework.orm.ojb.support.PersistenceBrokerDaoSupport;
 
 /**
@@ -86,7 +91,7 @@
     {
         return applicationName + ":" + portletName + ":" + entityOid.toString() + ":" + userName;        
     }
-
+    
     public PreferenceSetComposite getPreferenceSet(PortletDefinition pd)
     {
         return getPreferenceSet(pd.getApplication().getName(), pd.getPortletName(), null, null, false);
@@ -103,6 +108,27 @@
         return getPreferenceSet(pd.getApplication().getName(), pd.getPortletName(), pe.getOid(), userName, false);
     }
 
+    public Map<String, InternalPortletPreference> getDefaultPreferences(
+            PortletWindow portletWindow,
+            PortletRequest request)
+    throws PortletContainerException
+    {
+        String applicationName = portletWindow.getPortletEntity().getPortletDefinition().getApplication().getName();        
+        String portletName = portletWindow.getPortletEntity().getPortletDefinition().getPortletName();
+        this.getPreferenceSetKey(applicationName, portletName, portletWindow.getPortletEntity(), null);
+    }
+     
+    public Map<String, InternalPortletPreference> getStoredPreferences(
+            PortletWindow portletWindow,
+            PortletRequest request)
+    throws PortletContainerException
+    {
+        String applicationName = portletWindow.getPortletEntity().getPortletDefinition().getApplication().getName();        
+        String portletName = portletWindow.getPortletEntity().getPortletDefinition().getPortletName();
+        this.getPreferenceSetKey(applicationName, portletName, , null);
+        
+    }
+    
     private PreferenceSetImpl getPreferenceSet(String applicationName, String portletName, Long entityOid, String userName, boolean forUpdate)
     {
         if (entityOid == null)
@@ -181,6 +207,7 @@
             }
             else
             {
+                // FIXME: i know we are not using this but it seems we are putting a NULL cacheKey
                 preferenceCache.put(preferenceCache.createElement(cacheKey, prefs));
             }
         }
@@ -346,4 +373,20 @@
     public void preloadAllEntities()
     {
     }
+    
+    /**
+     * Stores the portlet references to the persistent storage.
+     * @param portletWindow  the portlet window.
+     * @param request  the portlet request.
+     * @param preferences  the portlet preferences to store.
+     * @throws PortletContainerException  if fail to store preferences.
+     */
+    public void store(PortletWindow portletWindow,
+                      PortletRequest request,
+                      Map<String, InternalPortletPreference> preferences)
+    throws PortletContainerException
+    {
+        // TODO: 2.2 implement
+    }
+   
 }
\ No newline at end of file

Added: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesServiceImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesServiceImpl.java?rev=708830&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesServiceImpl.java (added)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesServiceImpl.java Wed Oct 29 01:45:17 2008
@@ -0,0 +1,311 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.jetspeed.components.portletpreferences;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.PortletRequest;
+import javax.portlet.PreferencesValidator;
+import javax.portlet.ValidatorException;
+
+import org.apache.jetspeed.cache.CacheElement;
+import org.apache.jetspeed.cache.JetspeedCache;
+import org.apache.ojb.broker.query.Criteria;
+import org.apache.ojb.broker.query.QueryByCriteria;
+import org.apache.ojb.broker.query.QueryFactory;
+import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.PortletWindow;
+import org.apache.pluto.internal.InternalPortletPreference;
+import org.apache.pluto.om.portlet.PortletDefinition;
+import org.apache.pluto.spi.optional.PortletPreferencesService;
+import org.springframework.orm.ojb.support.PersistenceBrokerDaoSupport;
+
+/**
+ * <p>
+ * Pluto Preferences Service. This service is designed to work with an existing
+ * JPA service, in anticipation of deprecating OJB for JPA
+ * </p>
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class PortletPreferencesServiceImpl extends PersistenceBrokerDaoSupport
+        implements PortletPreferencesProvider // TODO: 2.2 extend this interface
+{
+    protected static final String DISCRIMINATOR_PORTLET = "portlet";
+    protected static final String DISCRIMINATOR_ENTITY = "entity";
+    protected static final String DISCRIMINATOR_USER = "user";
+    protected static final String KEY_SEPARATOR = ":";
+    
+    /**
+     * Cache elements are stored as element type JetspeedPreferencesMap
+     */
+    private JetspeedCache preferenceCache;
+    private List<String> preloadedApplications = null;
+    private boolean preloadEntities = false;    
+
+    public PortletPreferencesServiceImpl(JetspeedCache preferenceCache)
+            throws ClassNotFoundException
+    {
+        this.preferenceCache = preferenceCache;
+    }
+    
+    public PortletPreferencesServiceImpl(JetspeedCache preferenceCache, List<String> apps, boolean preloadEntities)
+    throws ClassNotFoundException
+    {
+        this(preferenceCache);
+        this.preloadedApplications = apps;
+        this.preloadEntities = preloadEntities;
+    }
+    
+    public void destroy()
+    {
+        preferenceCache = null;
+        preloadedApplications = null;
+        preloadEntities = false;
+    }
+    
+    public Map<String, InternalPortletPreference> getDefaultPreferences(
+            PortletWindow window, PortletRequest request)
+            throws PortletContainerException
+    {
+        String appName = window.getPortletEntity().getPortletDefinition().getApplication().getName();
+        String portletName = window.getPortletEntity().getPortletDefinition().getPortletName();
+        
+        // // TODO: 2.2 - Ate, is this your intention, to always go to the DB and avoid cache in a process action?
+        // I am removing this check as I don't think default preferences can ever be "for Update"
+        // boolean forUpdate = (request instanceof ActionRequest); 
+        String cacheKey = getPorletPreferenceKey(appName, portletName);
+        // first search in cache, but only if we are not in update mode        
+        CacheElement cachedElement = preferenceCache.get(cacheKey);        
+        if (cachedElement != null)
+        {
+            JetspeedPreferencesMap map = (JetspeedPreferencesMap)cachedElement.getContent();
+            return map;
+        }            
+        // TODO: 2.2 this api also supports getting default preferences via "entity" preferences
+        // if we were to look up first with a dtype of "entity" and add the entityId to the query,
+        // then if not found, fallback to dtype of "portlet"
+        // c.addEqualTo("entityId", window.getId()); // TODO: 2.2 need an API to get the entity id from the entity object
+        
+        // not found in cache, lookup in database
+        // TODO: 2.2 I want to avoid storing all this on the map to conserve memory (DISCRIMATOR_PORTLET, appName, portletName), 
+        // maybe we can get fields from cache key or from calling params
+        JetspeedPreferencesMap map = new JetspeedPreferencesMap(); 
+        Criteria c = new Criteria();
+        c.addEqualTo("dtype", DISCRIMINATOR_PORTLET);
+        c.addEqualTo("applicationName", appName);
+        c.addEqualTo("portletName", portletName);                
+        QueryByCriteria query = QueryFactory.newQuery(DatabasePreference.class, c);
+        Iterator<DatabasePreference> preferences = getPersistenceBrokerTemplate().getIteratorByQuery(query);
+        while (preferences.hasNext())
+        {
+            DatabasePreference preference = preferences.next();            
+            JetspeedPreferenceImpl value = new JetspeedPreferenceImpl(preference.getName(), preference.getValues());
+            map.put(preference.getName(), value);
+        }
+        preferenceCache.put(preferenceCache.createElement(cacheKey, map));
+        return map;
+    }
+
+    public Map<String, InternalPortletPreference> getStoredPreferences(
+            PortletWindow window, PortletRequest request)
+            throws PortletContainerException
+    {
+        String appName = window.getPortletEntity().getPortletDefinition().getApplication().getName();
+        String portletName = window.getPortletEntity().getPortletDefinition().getPortletName();
+        String entityId = window.getId().getStringId(); // TODO: 2.2 - FIXME: think we need to add entity.getId()
+        String userName = request.getRemoteUser();
+        if (userName == null)
+        {
+            userName = "guest"; // TODO: 2.2 might not wanna do this, might wanna throw exception
+        }
+        boolean forUpdate = (request instanceof ActionRequest); // TODO: 2.2 - Ate, is this your intention, to always go to the DB and avoid cache in a process action?
+        String cacheKey = getUserPreferenceKey(appName, portletName, entityId, userName);
+        // first search in cache, but only if we are not in update mode        
+        if (!forUpdate)
+        {
+            CacheElement cachedElement = preferenceCache.get(cacheKey);        
+            if (cachedElement != null)
+            {
+                JetspeedPreferencesMap map = (JetspeedPreferencesMap)cachedElement.getContent();
+                return map;
+            }            
+        }
+        // not found in cache, lookup in database
+        JetspeedPreferencesMap map = new JetspeedPreferencesMap(); 
+        Criteria c = new Criteria();
+        c.addEqualTo("dtype", DISCRIMINATOR_USER);
+        c.addEqualTo("applicationName", appName);
+        c.addEqualTo("portletName", portletName);
+        c.addEqualTo("entityId", entityId);
+        c.addEqualTo("userName", userName);
+        QueryByCriteria query = QueryFactory.newQuery(DatabasePreference.class, c);
+        Iterator<DatabasePreference> preferences = getPersistenceBrokerTemplate().getIteratorByQuery(query);
+        while (preferences.hasNext())
+        {
+            DatabasePreference preference = preferences.next();            
+            JetspeedPreferenceImpl value = new JetspeedPreferenceImpl(preference.getName(), preference.getValues());
+            map.put(preference.getName(), value);
+        }
+        preferenceCache.put(preferenceCache.createElement(cacheKey, map));
+        return map;        
+    }
+
+    public void store(PortletWindow window, PortletRequest request,
+            Map<String, InternalPortletPreference> map)
+            throws PortletContainerException
+    {
+        String appName = window.getPortletEntity().getPortletDefinition().getApplication().getName();
+        String portletName = window.getPortletEntity().getPortletDefinition().getPortletName();
+        String entityId = window.getId().getStringId(); // TODO: 2.2 - FIXME: think we need to add entity.getId()
+        String userName = request.getRemoteUser();
+        if (userName == null)
+        {
+            userName = "guest"; // TODO: 2.2 might not wanna do this, might wanna throw exception
+        }
+        // Merge: going through all this to keep down prefs memory footprint
+        // always read in to get a fresh copy for merge
+        Criteria c = new Criteria();
+        c.addEqualTo("dtype", DISCRIMINATOR_USER);
+        c.addEqualTo("applicationName", appName);
+        c.addEqualTo("portletName", portletName);
+        c.addEqualTo("entityId", entityId);
+        c.addEqualTo("userName", userName);
+        QueryByCriteria query = QueryFactory.newQuery(DatabasePreference.class, c);
+        Map<String, DatabasePreference> mergeMap = new HashMap<String, DatabasePreference>();
+        List<DatabasePreference> deletes = new LinkedList<DatabasePreference>();
+        List<DatabasePreference> updates = new LinkedList<DatabasePreference>();
+        List<InternalPortletPreference> inserts = new LinkedList<InternalPortletPreference>();        
+        Iterator<DatabasePreference> preferences = getPersistenceBrokerTemplate().getIteratorByQuery(query);
+        while (preferences.hasNext())
+        {
+            DatabasePreference preference = preferences.next();
+            InternalPortletPreference found = map.get(preference.getName());
+            if (found == null)
+            {
+                deletes.add(preference);
+            }
+            else
+            {
+                updates.add(preference);
+            }
+            mergeMap.put(preference.getName(), preference); 
+            
+        }
+        for (InternalPortletPreference preference : map.values())
+        {
+            DatabasePreference dbPref = mergeMap.get(preference.getName());
+            if (dbPref == null)
+            {
+                inserts.add(preference);
+            }                
+        }
+        // perform database manipulations
+        for (DatabasePreference dbPref : deletes)
+        {
+            getPersistenceBrokerTemplate().delete(dbPref);
+        }
+        for (InternalPortletPreference preference : inserts)
+        {
+            DatabasePreference dbPref = new DatabasePreference();
+            dbPref.setDtype(DISCRIMINATOR_USER);
+            dbPref.setApplicationName(appName);
+            dbPref.setPortletName(portletName);
+            dbPref.setEntityId(entityId);
+            dbPref.setUserName(userName);
+            dbPref.setName(preference.getName());
+            dbPref.setReadOnly(preference.isReadOnly());
+            short index = 0;
+            for (String value : preference.getValues())
+            {
+                DatabasePreferenceValue dbValue = new DatabasePreferenceValue();
+                dbValue.setIndex(index);
+                dbValue.setValue(value);
+                index++;
+            }
+            getPersistenceBrokerTemplate().store(dbPref);
+        }
+        for (DatabasePreference dbPref : updates)
+        {
+            dbPref.getPreferenceValues().clear();
+            InternalPortletPreference preference = map.get(dbPref.getName());
+            short index = 0;
+            for (String value : preference.getValues())
+            {
+                DatabasePreferenceValue dbValue = new DatabasePreferenceValue();
+                dbValue.setIndex(index);
+                dbValue.setValue(value);
+                index++;
+            }            
+            getPersistenceBrokerTemplate().store(dbPref);            
+        }        
+        // remove from cache to send distributed notification
+        String cacheKey = getUserPreferenceKey(appName, portletName, entityId, userName);
+        preferenceCache.remove(cacheKey);        
+    }
+
+    public PreferencesValidator getPreferencesValidator(PortletDefinition pd)
+            throws ValidatorException
+    {
+        // TODO: 2.2 go get the preferences validator
+        return null;
+    }
+
+    private String getPorletPreferenceKey(String applicationName, String portletName)
+    {
+        return DISCRIMINATOR_PORTLET + KEY_SEPARATOR + applicationName + KEY_SEPARATOR + portletName;        
+    }
+
+    private String getUserPreferenceKey(String applicationName, String portletName, String entityId, String userName)
+    {
+        return DISCRIMINATOR_USER + KEY_SEPARATOR + applicationName + KEY_SEPARATOR + portletName + KEY_SEPARATOR + entityId + KEY_SEPARATOR + userName;        
+    }
+    
+    public void preloadApplicationPreferences(String portletApplicationName)
+    {
+        // TODO: 2.2 implement
+    }
+    
+    public void preloadAllEntities()
+    {
+        // TODO: 2.2 implement        
+    }
+
+    public void init() throws Exception
+    {
+        if (preloadedApplications != null)
+        {
+            Iterator<String> apps = this.preloadedApplications.iterator();
+            while (apps.hasNext())
+            {
+                String appName = (String)apps.next();
+                preloadApplicationPreferences(appName);
+            }
+        }
+        if (preloadEntities)
+        {
+            preloadAllEntities();
+        }
+    }    
+    
+}

Added: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PreferencesRowReader.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PreferencesRowReader.java?rev=708830&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PreferencesRowReader.java (added)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PreferencesRowReader.java Wed Oct 29 01:45:17 2008
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.jetspeed.components.portletpreferences;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Map;
+
+import org.apache.jetspeed.security.JetspeedPrincipalManagerProvider;
+import org.apache.ojb.broker.PersistenceBrokerException;
+import org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl;
+import org.apache.ojb.broker.metadata.ClassDescriptor;
+import org.apache.ojb.broker.metadata.FieldDescriptor;
+
+/**
+ * OJB RowReader for PersistentJetspeedPrincipal to derive the concrete principal className *and* instance dynamically
+ * as OJB itself makes a mess of it...
+ * @version $Id: JetspeedPrincipalConcreteClassRowReader.java 695798 2008-09-16 09:48:31Z ate $
+ */
+public class PreferencesRowReader extends RowReaderDefaultImpl
+{
+    private static final long serialVersionUID = 1L;
+
+    private ClassDescriptor m_cld;
+    
+    
+    public static void setJetspeedPrincipalManagerProvider()
+    {
+    }
+    
+    private static final String OJB_CONCRETE_CLASS_KEY = "ojbTemporaryNoneColumnKey";
+    
+    /**
+     * @param cld
+     */
+    public PreferencesRowReader(ClassDescriptor cld)
+    {
+        super(cld);
+        this.m_cld = cld;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl#extractOjbConcreteClass(org.apache.ojb.broker.metadata.ClassDescriptor, java.sql.ResultSet)
+     */
+    @Override
+    protected String extractOjbConcreteClass(ClassDescriptor cld, ResultSet rs)
+    {
+        FieldDescriptor fld = m_cld.getFieldDescriptorByName("type");
+        if (fld == null)
+        {
+            return null;
+        }
+        try
+        {
+            Object tmp = fld.getJdbcType().getObjectFromColumn(rs, fld.getColumnName());
+            String result = jpmp.getPrincipalType((String)tmp).getClassName();
+            result = result != null ? result.trim() : null;
+            if (result == null || result.length() == 0)
+            {
+                throw new PersistenceBrokerException(
+                        "ojbConcreteClass field for class " + cld.getClassNameOfObject()
+                        + " returned null or 0-length string");
+            }
+            else
+            {
+                return result;
+            }
+        }
+        catch(SQLException e)
+        {
+            throw new PersistenceBrokerException("Unexpected error while try to read 'ojbConcretClass'" +
+                    " field from result set using column name " + fld.getColumnName() + " main class" +
+                    " was " + m_cld.getClassNameOfObject(), e);
+        }
+    }
+
+    protected Object buildOrRefreshObject(Map row, ClassDescriptor targetClassDescriptor, Object targetObject)
+    {
+        Object result = targetObject;
+        FieldDescriptor fmd = null;
+
+        if(targetObject == null)
+        {
+            // 1. create new object instance if needed
+//            result = ClassHelper.buildNewObjectInstance(targetClassDescriptor);
+            try
+            {
+                result = Class.forName((String) row.get(OJB_CONCRETE_CLASS_KEY)).newInstance();
+            }
+            catch (Exception e)
+            {
+                throw new PersistenceBrokerException("Unexpected error while try to instantiate concrete PersistentJetspeedPrincipal instance of class: [" +row.get(OJB_CONCRETE_CLASS_KEY), e);
+            }
+        }
+
+        // 2. fill all scalar attributes of the new object
+        FieldDescriptor[] fields = targetClassDescriptor.getFieldDescriptions();
+        for (int i = 0; i < fields.length; i++)
+        {
+            fmd = fields[i];
+            fmd.getPersistentField().set(result, row.get(fmd.getColumnName()));
+        }
+
+        return result;
+    }
+    
+    protected ClassDescriptor selectClassDescriptor(Map row) throws PersistenceBrokerException
+    {
+        ClassDescriptor result = m_cld;
+        String ojbConcreteClass = (String) row.get(OJB_CONCRETE_CLASS_KEY);
+        if(ojbConcreteClass != null)
+        {
+            result = m_cld.getRepository().getDescriptorFor(ojbConcreteClass);
+            // if we can't find class-descriptor for concrete class, something wrong with mapping
+            if (result == null)
+            {
+                throw new PersistenceBrokerException("Can't find class-descriptor for ojbConcreteClass '"
+                        + ojbConcreteClass + "', the main class was " + m_cld.getClassNameOfObject());
+            }
+        }
+        return result;
+    }
+
+}

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesProvider.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesProvider.java?rev=708830&r1=708829&r2=708830&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesProvider.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesProvider.java Wed Oct 29 01:45:17 2008
@@ -23,5 +23,6 @@
  */
 public interface PortletPreferencesProvider extends org.apache.pluto.spi.optional.PortletPreferencesService
 {
-    void init() throws Exception;
+    public void preloadApplicationPreferences(String portletApplicationName);
+    public void preloadAllEntities();    
 }

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/ddl-schema/registry-schema.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/ddl-schema/registry-schema.xml?rev=708830&r1=708829&r2=708830&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/ddl-schema/registry-schema.xml (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/ddl-schema/registry-schema.xml Wed Oct 29 01:45:17 2008
@@ -150,35 +150,33 @@
         </unique>
     </table>
     
+   <!-- 
+      Preferences
+    -->    
     <table name="PORTLET_PREFERENCE">
         <column name="ID" primaryKey="true" required="true" type="INTEGER"/>
+        <column name="DTYPE" required="true" size="10" type="VARCHAR"/>
         <column name="APPLICATION_NAME" required="true" size="80" type="VARCHAR"/>
         <column name="PORTLET_NAME" required="true" size="80" type="VARCHAR"/>
+        <column name="ENTITY_ID" type="VARCHAR" size="80"/>
+        <column name="USER_NAME"  size="80" type="VARCHAR"/>
         <column name="NAME" required="true" size="254" type="VARCHAR"/>
-        
-      <!-- non-unique index on APPLICATION_NAME,PORTLET_NAME shouldn't be needed as its already
-           "covered" by unique index on APPLICATION_NAME,PORTLET_NAME,NAME
-        <index name="IX_PORTLET_PREFERENCE">
-            <index-column name="APPLICATION_NAME"/>
-            <index-column name="PORTLET_NAME"/>
-        </index>        
-      -->
+        <column name="READONLY" required="true" type="BOOLEANINT"/>        
         <unique name="UIX_PORTLET_PREFERENCE">
+          <unique-column name="DTYPE"/>
           <unique-column name="APPLICATION_NAME"/>
           <unique-column name="PORTLET_NAME"/>
+          <unique-column name="ENTITY_ID"/>
+          <unique-column name="USER_NAME"/>
           <unique-column name="NAME"/>
         </unique>        
 
     </table>
 
     <table name="PORTLET_PREFERENCE_VALUE">
+        <column name="ID" primaryKey="true" required="true" type="INTEGER"/>
         <column name="PREF_ID" primaryKey="true" required="true" type="INTEGER"/>
         <column name="IDX" primaryKey="true" required="true" type="SMALLINT"/>
-        <column name="ENTITY_OID" primaryKey="true" required="true" type="INTEGER"/>
-        <column name="USER_NAME" primaryKey="true" required="true" size="80" type="VARCHAR"/>
-        <column name="ENTITY_ID" type="VARCHAR" size="80"/>
-        <column name="READONLY" required="true" type="BOOLEANINT"/>
-        <column name="NULL_VALUE" required="true" type="BOOLEANINT"/>
         <column name="PREF_VALUE" size="4000" type="VARCHAR"/>
 
         <index name="IX_PREFS_PREF_ID">

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/pluto-services.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/pluto-services.xml?rev=708830&r1=708829&r2=708830&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/pluto-services.xml (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/pluto-services.xml Wed Oct 29 01:45:17 2008
@@ -120,7 +120,7 @@
       <constructor-arg><ref bean="org.apache.pluto.services.PortletInvokerService"/></constructor-arg>            
       <constructor-arg><ref bean="org.apache.pluto.services.PlutoRegistryServiceAdaptor"/></constructor-arg>            
       <constructor-arg><ref bean="org.apache.pluto.services.DescriptorService"/></constructor-arg>
-	<!--  TODO: preferences -->
+      <constructor-arg><ref bean="org.apache.pluto.services.PreferencesService"/></constructor-arg>
     </bean>
     
     <bean id="org.apache.pluto.services.NamespaceMapper"

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/registry.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/registry.xml?rev=708830&r1=708829&r2=708830&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/registry.xml (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/registry.xml Wed Oct 29 01:45:17 2008
@@ -87,15 +87,15 @@
     </property>
   </bean>
 
-  <!-- Portlet Preferences Implementation -->
-  <bean id="PortletPreferencesProviderImpl"
-    class="org.apache.jetspeed.components.portletpreferences.PersistenceBrokerPortletPreferencesProvider"
-    init-method="init" destroy-method="destroy">
-    <meta key="j2:cat" value="default,registry" />
+    <bean id="org.apache.pluto.services.PreferencesService" name="PortletPreferencesProviderImpl"
+          class="org.apache.jetspeed.components.portletpreferences.PortletPreferencesServiceImpl"
+	    init-method="init" destroy-method="destroy">
+          
+      <meta key="j2:cat" value="default,registry" />          
     <constructor-arg index="0">
       <ref bean="preferencesCache" />
     </constructor-arg>
-  </bean>
+    </bean>
 
   <bean id="org.apache.jetspeed.components.portletpreferences.PortletPreferencesProvider" parent="baseTransactionProxy"
     name="portletPreferencesProvider" destroy-method="destroy">
@@ -109,8 +109,7 @@
     </property>
     <property name="transactionAttributes">
       <props>
-        <prop key="save*">PROPAGATION_REQUIRED</prop>
-        <prop key="delete*">PROPAGATION_REQUIRED</prop>
+        <prop key="store*">PROPAGATION_REQUIRED</prop>
         <prop key="*">PROPAGATION_SUPPORTS</prop>
       </props>
     </property>



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org