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/25 20:49:06 UTC
svn commit: r349006 [1/2] - in /portals/pluto/trunk:
pluto-container/src/main/java/org/apache/pluto/core/
pluto-container/src/main/java/org/apache/pluto/core/impl/
pluto-container/src/resources/properties/org/apache/pluto/core/impl/
pluto-container/src...
Author: ddewolf
Date: Fri Nov 25 11:48:33 2005
New Revision: 349006
URL: http://svn.apache.org/viewcvs?rev=349006&view=rev
Log:
Implementing database services for Portlet Registry; Refactoring to promote reuse amoung preferences dao and registry dao; Reenabling schema creation on startup; Preparing to refactor things into an optional services module
Added:
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/config/package.html
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/admin/
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/admin/AdminException.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/admin/PublishService.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/PortletPreferenceContainer.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/PreferencesDao.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/memory/
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/memory/MemoryPreferencesService.java
- copied, changed from r348374, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/MemoryPreferencesService.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/memory/PortletPreferenceImpl.java
- copied, changed from r348374, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/PortletPreferenceImpl.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/AbstractDao.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/AbstractPreparedDao.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/DataSourceManager.java
- copied, changed from r348374, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/DataSourceManager.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/EmbeddedDataSourceManager.java
- copied, changed from r348374, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/EmbeddedDataSourceManager.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/JNDIDataSourceManager.java
- copied, changed from r348374, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/JNDIDataSourceManager.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/impl/memory/
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/PortletRegistryServiceImpl.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/PropertyConfigServiceImpl.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/RenderConfigServiceImpl.java
- copied, changed from r348518, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/ResourceServicesImpl.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/ResourceConfig.java
- copied, changed from r348374, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/Configuration.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/ResourceConfigReader.java
- copied, changed from r348374, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/ConfigurationFactory.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/package.html
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/DriverConfigurationService.java
- copied, changed from r348374, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationService.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PageConfig.java
- copied, changed from r348518, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/PageConfig.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PortletApplicationConfig.java
- copied, changed from r348518, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/PortletApplicationConfig.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PortletRegistryService.java
- copied, changed from r348374, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/PortletRegistryService.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PortletWindowConfig.java
- copied, changed from r348518, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/PortletWindowConfig.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PropertyConfigService.java
- copied, changed from r348374, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/PropertyConfigService.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/RenderConfig.java
- copied, changed from r348518, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/RenderConfig.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/RenderConfigService.java
- copied, changed from r348374, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/RenderConfigService.java
portals/pluto/trunk/pluto-portal-driver/src/test/
portals/pluto/trunk/pluto-portal-driver/src/test/java/
portals/pluto/trunk/pluto-portal-driver/src/test/java/org/
portals/pluto/trunk/pluto-portal-driver/src/test/java/org/apache/
portals/pluto/trunk/pluto-portal-driver/src/test/java/org/apache/pluto/
portals/pluto/trunk/pluto-portal-driver/src/test/java/org/apache/pluto/driver/
portals/pluto/trunk/pluto-portal-driver/src/test/java/org/apache/pluto/driver/services/
portals/pluto/trunk/pluto-portal-driver/src/test/java/org/apache/pluto/driver/services/container/
portals/pluto/trunk/pluto-portal-driver/src/test/java/org/apache/pluto/driver/services/container/db/
portals/pluto/trunk/pluto-portal-driver/src/test/java/org/apache/pluto/driver/services/container/db/PortletPreferenceContainerTest.java
Removed:
portals/pluto/trunk/pluto-container/src/site/apt/.getting-started.apt.swp
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationService.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/PortletRegistryService.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/PropertyConfigService.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/RenderConfigService.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/MemoryPreferencesService.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/PortletPreferenceImpl.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/DataSourceManager.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/EmbeddedDataSourceManager.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/JNDIDataSourceManager.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/Configuration.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/ConfigurationFactory.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/PageConfig.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/PortletApplicationConfig.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/PortletWindowConfig.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/RenderConfig.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/resource/ResourceServicesImpl.java
Modified:
portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/DefaultOptionalServices.java
portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletPreferencesImpl.java
portals/pluto/trunk/pluto-container/src/resources/properties/org/apache/pluto/core/impl/LocalStrings.properties
portals/pluto/trunk/pluto-derby/src/main/scripts/env.bat
portals/pluto/trunk/pluto-derby/src/main/scripts/ij.bat
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalStartupListener.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfiguration.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfigurationFactory.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortletWindowImpl.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/DBPortletPreferencesService.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletTag.java
portals/pluto/trunk/pluto-portal-driver/src/resources/create_schema.sql
portals/pluto/trunk/pluto-portal/src/main/resources/server.xml
portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-services-config.xml
Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/DefaultOptionalServices.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/DefaultOptionalServices.java?rev=349006&r1=349005&r2=349006&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/DefaultOptionalServices.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/DefaultOptionalServices.java Fri Nov 25 11:48:33 2005
@@ -26,6 +26,9 @@
import org.apache.pluto.services.optional.PortletEnvironmentService;
import org.apache.pluto.services.optional.PortletInvokerService;
+import java.util.Map;
+import java.util.HashMap;
+
/**
* Default Optional Services implementation.
*
@@ -44,6 +47,12 @@
this.preferenceService = new PortletPreferencesServiceImpl();
}
+ public DefaultOptionalServices(OptionalPortletContainerServices rootServices) {
+ this();
+ if(rootServices.getPortletPreferencesService() != null)
+ this.preferenceService = rootServices.getPortletPreferencesService();
+ }
+
public PortletPreferencesService getPortletPreferencesService() {
return preferenceService;
@@ -51,18 +60,42 @@
public class PortletPreferencesServiceImpl
implements PortletPreferencesService {
+ private Map storage;
- public PortletPreference[] getStoredPreferences(PortletWindow window,
- PortletRequest req)
- throws PortletContainerException {
+ public PortletPreferencesServiceImpl() {
+ storage = new HashMap();
+ }
+
+ public PortletPreference[] getStoredPreferences(PortletWindow window,
+ PortletRequest req)
+ throws PortletContainerException {
+ String key = getFormattedKey(window, req.getRemoteUser());
+ PortletPreference[] prefs = (PortletPreference[])storage.get(key);
+ if(prefs == null) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("No portlet preferences found for: "+key);
+ }
return new PortletPreference[0];
}
+ return prefs;
+ }
- public void store(PortletWindow window,
- PortletRequest req,
- PortletPreference[] preferences) throws PortletContainerException {
-
+ public void store(PortletWindow window,
+ PortletRequest request,
+ PortletPreference[] preferences)
+ throws PortletContainerException {
+ String key = getFormattedKey(window, request.getRemoteUser());
+ storage.put(key, preferences);
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Portlet preferences saved for: "+key);
}
+
+ }
+
+ private String getFormattedKey(PortletWindow window, String user) {
+ return "user="+user+";"+"window="+window;
+ }
+
}
Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletPreferencesImpl.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletPreferencesImpl.java?rev=349006&r1=349005&r2=349006&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletPreferencesImpl.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletPreferencesImpl.java Fri Nov 25 11:48:33 2005
@@ -19,11 +19,7 @@
package org.apache.pluto.core.impl;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Vector;
+import java.util.*;
import javax.portlet.PortletPreferences;
import javax.portlet.PreferencesValidator;
@@ -33,6 +29,7 @@
import org.apache.pluto.Constants;
import org.apache.pluto.PortletContainer;
import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.util.StringManager;
import org.apache.pluto.core.InternalPortletRequest;
import org.apache.pluto.core.InternalPortletWindow;
import org.apache.pluto.core.PortletPreference;
@@ -43,7 +40,12 @@
public class PortletPreferencesImpl implements PortletPreferences {
- private static final Log LOG = LogFactory.getLog(PortletPreferencesImpl.class);
+
+ private static final Log LOG =
+ LogFactory.getLog(PortletPreferencesImpl.class);
+
+ private static final StringManager EXCEPTIONS =
+ StringManager.getManager(PortletPreferencesImpl.class.getPackage().getName());
private PortletPreferencesService factory;
@@ -51,9 +53,9 @@
private InternalPortletRequest request;
+ private PortletPreference[] defaultPreferences;
private Map preferences;
-
// current method used for managing these preferences
private Integer methodId = null;
@@ -63,7 +65,8 @@
InternalPortletRequest request,
Integer methodId) {
this.factory =
- container.getOptionalContainerServices().getPortletPreferencesService();
+ container.getOptionalContainerServices().getPortletPreferencesService();
+
this.window = window;
this.request = request;
this.methodId = methodId;
@@ -71,41 +74,49 @@
this.preferences = new java.util.HashMap();
PortletEntity entity = window.getPortletEntity();
- PortletPreference[] prefs = entity.getDefaultPreferences();
+ defaultPreferences = entity.getDefaultPreferences();
- for (int i = 0; i < prefs.length; i++) {
- preferences.put(prefs[i].getName(), prefs[i]);
+ for (int i = 0; i < defaultPreferences.length; i++) {
+ preferences.put(defaultPreferences[i].getName(), defaultPreferences[i]);
}
PortletPreferencesService factory = container
.getOptionalContainerServices()
.getPortletPreferencesService();
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("PreferencesService: "+factory.getClass().getName());
+ }
+
try {
- prefs = factory.getStoredPreferences(window, request);
+ PortletPreference[] prefs =
+ factory.getStoredPreferences(window, request);
+
+ for (int i = 0; i < prefs.length; i++) {
+ preferences.put(prefs[i].getName(), prefs[i]);
+ }
}
catch(PortletContainerException pe) {
LOG.error("Error retrieving preferences.", pe);
}
-
- for (int i = 0; i < prefs.length; i++) {
- preferences.put(prefs[i].getName(), prefs[i]);
- }
-
}
public boolean isReadOnly(String key) {
if (key == null) {
- throw new IllegalArgumentException("key == null");
+ throw new IllegalArgumentException(
+ EXCEPTIONS.getString("error.null", "Preference key ")
+ );
}
PortletPreference pref = (PortletPreference) preferences.get(key);
- return pref == null || pref.isReadOnly();
+ return pref != null && pref.isReadOnly();
}
public String getValue(String key, String def) {
if (key == null) {
- throw new IllegalArgumentException("key == null");
+ throw new IllegalArgumentException(
+ EXCEPTIONS.getString("error.null", "Preference key ")
+ );
}
String[] value;
@@ -121,7 +132,9 @@
public String[] getValues(String key, String[] def) {
if (key == null) {
- throw new IllegalArgumentException("key == null");
+ throw new IllegalArgumentException(
+ EXCEPTIONS.getString("error.null", "Preference key ")
+ );
}
String[] values;
@@ -136,16 +149,16 @@
}
public void setValue(String key, String value) throws ReadOnlyException {
- if (key == null) {
- throw new IllegalArgumentException("key == null");
+ if(isReadOnly(key)) {
+ throw new ReadOnlyException(EXCEPTIONS.getString("error.preference.readonly", key));
}
+
PortletPreference pref = (PortletPreference) preferences.get(key);
- if (pref != null && pref.isReadOnly()) {
- throw new ReadOnlyException("Preference [" + key + "] is read only");
- } else if (pref != null) {
+ if (pref != null) {
pref.setValues(new String[]{value});
+
} else {
pref = new PortletPreferenceImpl(key, new String[]{value});
preferences.put(key, pref);
@@ -154,15 +167,14 @@
public void setValues(String key, String[] values)
throws ReadOnlyException {
- if (key == null) {
- throw new IllegalArgumentException("key == null");
+
+ if(isReadOnly(key)) {
+ throw new ReadOnlyException(EXCEPTIONS.getString("error.preference.readonly"));
}
PortletPreference pref = (PortletPreference) preferences.get(key);
- if (pref != null && pref.isReadOnly()) {
- throw new ReadOnlyException("Preference [" + key + "] is read only");
- } else if (pref != null) {
+ if (pref != null) {
pref.setValues(values);
} else {
pref = new PortletPreferenceImpl(key, values);
@@ -175,7 +187,7 @@
}
public Map getMap() {
- Map map = new java.util.HashMap();
+ Map map = new HashMap();
Iterator it = preferences.keySet().iterator();
while (it.hasNext()) {
PortletPreference pref = (PortletPreference)preferences.get(it.next());
@@ -185,31 +197,26 @@
}
public void reset(String key) throws ReadOnlyException {
- if (key == null) {
- throw new IllegalArgumentException("key == null");
- }
-
- PortletPreference pref = (PortletPreference) preferences.get(key);
- if (pref.isReadOnly()) {
+ if(isReadOnly(key)) {
throw new ReadOnlyException(
- "preference attribute called " + key + " may not be modified");
+ EXCEPTIONS.getString("error.preference.readonly", "Preference key ")
+ );
}
- // I think we should remove all preferences which are stored --
- // NOT reset them to how they were stored before!
- /*
- PortletPreference[] preferences = factory.getStoredPreferences(window, request);
- for(int i=0;i<preferences.length;i++) {
- preferences.put(preference.getName(), preference);
- }
- */
+ PortletPreference pref = (PortletPreference)preferences.get(key);
+
+ for(int i=0;i<defaultPreferences.length;i++) {
+ if(key.equals(defaultPreferences[i].getName())) {
+ preferences.put(key, defaultPreferences[i]);
+ }
+ }
}
public void store() throws java.io.IOException, ValidatorException {
// not allowed when not called in action
if (!Constants.METHOD_ACTION.equals(methodId)) {
- throw new java.lang.IllegalStateException(
+ throw new IllegalStateException(
"store is only allowed inside a processAction call");
}
@@ -236,8 +243,9 @@
}
PortletPreference[] pref =
- (PortletPreference[]) preferences.values().toArray(
- new PortletPreference[preferences.size()]);
+ (PortletPreference[]) new ArrayList(preferences.values()).toArray(
+ new PortletPreference[preferences.size()]
+ );
try {
factory.store(window, request, pref);
@@ -246,7 +254,5 @@
LOG.error("Error storing preferences.", pe);
}
}
- // --------------------------------------------------------------------------------------------
-
}
Modified: portals/pluto/trunk/pluto-container/src/resources/properties/org/apache/pluto/core/impl/LocalStrings.properties
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-container/src/resources/properties/org/apache/pluto/core/impl/LocalStrings.properties?rev=349006&r1=349005&r2=349006&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/resources/properties/org/apache/pluto/core/impl/LocalStrings.properties (original)
+++ portals/pluto/trunk/pluto-container/src/resources/properties/org/apache/pluto/core/impl/LocalStrings.properties Fri Nov 25 11:48:33 2005
@@ -20,7 +20,8 @@
error.attributeName.null=Attribute Name may not be null.
error.propertyName.null=Property Name may not be null.
-error.session.illegalState=Session may not be retrieved before cross context portlet invocation
+error.session.illegalState=Session may not be retrieved before cross context portlet invocation.
+error.preference.readonly=Preference {0} may not be modified. It is marked as read only.
############################################
# Warning Messages:
Modified: portals/pluto/trunk/pluto-derby/src/main/scripts/env.bat
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-derby/src/main/scripts/env.bat?rev=349006&r1=349005&r2=349006&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-derby/src/main/scripts/env.bat (original)
+++ portals/pluto/trunk/pluto-derby/src/main/scripts/env.bat Fri Nov 25 11:48:33 2005
@@ -1,8 +1,6 @@
-#Sets environmental variables for use to run scripts in this directory
-set MAVEN_REPO="%M2_REPO%"
-#derby.system.home
-set SYSTEM_HOME="%HOME%\.pluto\derby"
+set MAVEN_REPO=%M2_REPO%
+set SYSTEM_HOME=%HOME%\.pluto\derby
set CLASSPATH=%MAVEN_REPO%\org\apache\derby\derby\10.1.1.0\derby-10.1.1.0.jar;%MAVEN_REPO%\org\apache\derby\derbytools\10.1.1.0\derbytools-10.1.1.0.jar
set DB_CONN=PlutoDB;create=true;name=container;password=container
-set PROTOCOL=jdbc:derby:
\ No newline at end of file
+set PROTOCOL=jdbc:derby:
Modified: portals/pluto/trunk/pluto-derby/src/main/scripts/ij.bat
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-derby/src/main/scripts/ij.bat?rev=349006&r1=349005&r2=349006&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-derby/src/main/scripts/ij.bat (original)
+++ portals/pluto/trunk/pluto-derby/src/main/scripts/ij.bat Fri Nov 25 11:48:33 2005
@@ -1,3 +1,3 @@
#Starts ij SQL command-line utility
call env.bat
-java -cp %CLASSPATH% -Dij.protocol=%PROTOCOL% -Dij.connection.connectionName=%DB_CONN% -Dderby.system.home=%SYSTEM_HOME% org.apache.derby.tools.ij
\ No newline at end of file
+java -cp "%CLASSPATH%" -Dij.protocol=%PROTOCOL% -Dij.connection.connectionName=%DB_CONN% -Dderby.system.home=%SYSTEM_HOME% org.apache.derby.tools.ij
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java?rev=349006&r1=349005&r2=349006&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java Fri Nov 25 11:48:33 2005
@@ -23,8 +23,8 @@
import org.apache.pluto.driver.core.PortalEnvironment;
import org.apache.pluto.driver.core.PortalURL;
import org.apache.pluto.driver.core.PortletWindowImpl;
-import org.apache.pluto.driver.services.impl.resource.PageConfig;
-import org.apache.pluto.driver.services.impl.resource.PortletWindowConfig;
+import org.apache.pluto.driver.services.portal.PageConfig;
+import org.apache.pluto.driver.services.portal.PortletWindowConfig;
import javax.portlet.PortletException;
import javax.servlet.RequestDispatcher;
@@ -51,9 +51,6 @@
/** The portlet container to which we will forward all portlet requests. */
protected PortletContainer container = null;
- /** The driver configuration defining our configuraiton. */
- protected DriverConfiguration driverConfig = null;
-
/**
* Initialize the Portal Driver. Initialization completes the following
* tasks:
@@ -62,16 +59,20 @@
* <li>Retrieve and cache the <code>DriverConfigurationImpl</code>.</li>
* </ul>
* @see PortletContainer
- * @see DriverConfigurationImpl
+ * @see DriverConfiguration
*/
public void init() {
ServletContext servletContext = getServletContext();
container = (PortletContainer) servletContext.getAttribute(
AttributeKeys.PORTLET_CONTAINER);
- driverConfig = (DriverConfiguration) servletContext.getAttribute(
- AttributeKeys.DRIVER_CONFIG);
+ }
+
+ private DriverConfiguration getDriverConfiguration() {
+ return (DriverConfiguration) getServletContext()
+ .getAttribute(AttributeKeys.DRIVER_CONFIG);
}
+
/**
* Handle all requests.
* @param request the incoming HttpServletRequest.
@@ -87,7 +88,7 @@
request, response);
PortalURL currentURL = environment.getRequestedPortalURL();
String actionWindowId = currentURL.getActionWindow();
- PortletWindowConfig windowConfig = driverConfig.getPortletWindowConfig(
+ PortletWindowConfig windowConfig = getDriverConfiguration().getPortletWindowConfig(
actionWindowId);
// Window will only exist if there's an action.
@@ -119,7 +120,7 @@
if (LOG.isDebugEnabled()) {
LOG.debug("Rendering Portal: Requested Page: " + currentPage);
}
- return driverConfig.getPageConfig(currentPage);
+ return getDriverConfiguration().getPageConfig(currentPage);
}
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=349006&r1=349005&r2=349006&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 Fri Nov 25 11:48:33 2005
@@ -56,8 +56,8 @@
* Receive the startup notification and subsequently start up the portal
* driver. The following are done in this order:
* <ol>
- * <li>Retrieve the Configuration File</li>
- * <li>Parse the Configuration File into Configuration Objects</li>
+ * <li>Retrieve the ResourceConfig File</li>
+ * <li>Parse the ResourceConfig File into ResourceConfig Objects</li>
* <li>Create a Portal Context</li>
* <li>Create the ContainerServices implementation</li>
* <li>Create the Portlet Container</li>
@@ -103,9 +103,18 @@
}
PortletContainerFactory factory =
PortletContainerFactory.getInstance();
+
+ 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...");
Added: 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=349006&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PublishServlet.java (added)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PublishServlet.java Fri Nov 25 11:48:33 2005
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2003,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.
+ */
+package org.apache.pluto.driver;
+
+import org.apache.pluto.driver.services.admin.AdminException;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import java.io.IOException;
+
+
+/**
+ * Publishing administrative servlet.
+ * Allows external clients to connect and notify the portal
+ * of available portlet applications.
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>:
+ * @version 1.0
+ * @since Nov 23, 2005
+ */
+public class PublishServlet extends HttpServlet {
+
+ protected void doGet(HttpServletRequest req,
+ HttpServletResponse res)
+ throws ServletException, IOException {
+
+ String context = req.getParameter("context");
+ try {
+ doPublish(context);
+ }
+ catch(AdminException admin) {
+ res.getWriter().println("Unable to publish portlet application bound to context '"+context+"'.");
+ }
+ }
+
+ private void doPublish(String context) throws AdminException {
+
+ }
+}
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfiguration.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfiguration.java?rev=349006&r1=349005&r2=349006&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfiguration.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfiguration.java Fri Nov 25 11:48:33 2005
@@ -15,9 +15,9 @@
*/
package org.apache.pluto.driver.config;
-import org.apache.pluto.driver.services.impl.resource.PortletApplicationConfig;
-import org.apache.pluto.driver.services.impl.resource.PortletWindowConfig;
-import org.apache.pluto.driver.services.impl.resource.PageConfig;
+import org.apache.pluto.driver.services.portal.PortletApplicationConfig;
+import org.apache.pluto.driver.services.portal.PortletWindowConfig;
+import org.apache.pluto.driver.services.portal.PageConfig;
import org.apache.pluto.services.PortalCallbackService;
import org.apache.pluto.services.optional.PortletPreferencesService;
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfigurationFactory.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfigurationFactory.java?rev=349006&r1=349005&r2=349006&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfigurationFactory.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfigurationFactory.java Fri Nov 25 11:48:33 2005
@@ -67,7 +67,7 @@
if(LOG.isDebugEnabled()) {
LOG.debug(
- "Driver Configuration of type "+configuration.getClass() +
+ "Driver ResourceConfig of type "+configuration.getClass() +
" Initialized and Ready For Service"
);
}
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java?rev=349006&r1=349005&r2=349006&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java Fri Nov 25 11:48:33 2005
@@ -15,9 +15,12 @@
*/
package org.apache.pluto.driver.config.impl;
-import org.apache.pluto.driver.services.impl.resource.PortletApplicationConfig;
-import org.apache.pluto.driver.services.impl.resource.PortletWindowConfig;
-import org.apache.pluto.driver.services.impl.resource.PageConfig;
+import org.apache.pluto.driver.services.portal.PortletApplicationConfig;
+import org.apache.pluto.driver.services.portal.PortletWindowConfig;
+import org.apache.pluto.driver.services.portal.PageConfig;
+import org.apache.pluto.driver.services.portal.PortletRegistryService;
+import org.apache.pluto.driver.services.portal.PropertyConfigService;
+import org.apache.pluto.driver.services.portal.RenderConfigService;
import org.apache.pluto.driver.config.DriverConfiguration;
import org.apache.pluto.services.PortalCallbackService;
import org.apache.pluto.services.optional.PortletPreferencesService;
@@ -26,7 +29,7 @@
import java.util.Collection;
/**
- * Encapsulation of the Pluto Driver Configuration.
+ * Encapsulation of the Pluto Driver ResourceConfig.
*
* @author <a href="ddewolf@apache.org">David H. DeWolf</a>
* @version 1.0
Added: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/package.html
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/package.html?rev=349006&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/package.html (added)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/package.html Fri Nov 25 11:48:33 2005
@@ -0,0 +1,6 @@
+<html>
+<body>
+ Provides a single interface for retrieving configuration
+ and instantiating services.
+</body>
+</html>
\ No newline at end of file
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortletWindowImpl.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortletWindowImpl.java?rev=349006&r1=349005&r2=349006&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortletWindowImpl.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortletWindowImpl.java Fri Nov 25 11:48:33 2005
@@ -23,7 +23,7 @@
import javax.portlet.WindowState;
import org.apache.pluto.PortletWindow;
-import org.apache.pluto.driver.services.impl.resource.PortletWindowConfig;
+import org.apache.pluto.driver.services.portal.PortletWindowConfig;
import org.apache.pluto.driver.util.ObjectIdImpl;
import org.apache.pluto.om.ObjectID;
Added: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/admin/AdminException.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/admin/AdminException.java?rev=349006&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/admin/AdminException.java (added)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/admin/AdminException.java Fri Nov 25 11:48:33 2005
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2003,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.
+ */
+package org.apache.pluto.driver.services.admin;
+
+import javax.servlet.ServletException;
+
+/**
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>:
+ * @version 1.0
+ * @since Nov 23, 2005
+ */
+public class AdminException extends ServletException {
+
+ public AdminException(Throwable cause) {
+ super(cause);
+ }
+
+
+}
Added: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/admin/PublishService.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/admin/PublishService.java?rev=349006&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/admin/PublishService.java (added)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/admin/PublishService.java Fri Nov 25 11:48:33 2005
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2003,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.
+ */
+package org.apache.pluto.driver.services.admin;
+
+/**
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>:
+ * @version 1.0
+ * @since Nov 23, 2005
+ */
+public class PublishService {
+
+}
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/DBPortletPreferencesService.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/DBPortletPreferencesService.java?rev=349006&r1=349005&r2=349006&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/DBPortletPreferencesService.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/DBPortletPreferencesService.java Fri Nov 25 11:48:33 2005
@@ -16,17 +16,16 @@
package org.apache.pluto.driver.services.container.db;
//import java.sql.Connection;
-import java.sql.SQLException;
-
-import javax.portlet.PortletRequest;
-
-import org.apache.pluto.PortletWindow;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.PortletWindow;
import org.apache.pluto.core.PortletPreference;
-//import org.apache.pluto.derby.DerbyPlutoContainerDAO;
+import org.apache.pluto.driver.services.impl.db.DataSourceManager;
import org.apache.pluto.services.optional.PortletPreferencesService;
-import org.apache.commons.logging.LogFactory;
-import org.apache.commons.logging.Log;
+
+import javax.portlet.PortletRequest;
+import java.sql.SQLException;
/**
* The Portal Driver's PortletPreferencesService implementation. This
@@ -43,11 +42,13 @@
LogFactory.getLog(DBPortletPreferencesService.class);
private DataSourceManager dataSourceManager;
-
+
public DBPortletPreferencesService() {
-
+
}
-
+
+ private PreferencesDao dao;
+
public DBPortletPreferencesService(DataSourceManager dataSourceManager)
throws InstantiationException {
this.dataSourceManager = dataSourceManager;
@@ -63,38 +64,39 @@
throw new InstantiationException(msg);
}
}
+ dao = new PreferencesDao(dataSourceManager.getPortalDataSource());
}
-
+
public PortletPreference[] getStoredPreferences(PortletWindow window,
PortletRequest req)
throws PortletContainerException {
PortletPreference[] prefs = null;
-// try {
+ try {
if (window == null) {
throw new PortletContainerException("Null PortletWindow");
}
- String user = req.getRemoteUser();
+
+ String user = req.getRemoteUser();
if (user == null) {
user = "ANONYMOUS";
}
- String context = window.getContextPath();
+
+ String context = window.getContextPath();
String portlet = window.getPortletName();
- if (LOG.isDebugEnabled()) {
+
+ if (LOG.isDebugEnabled()) {
LOG.debug("Retrieving preferences for user '" + user +
"' at context '" + context +
"' for portlet '" + portlet + "'");
}
-
-// prefs = DerbyPlutoContainerDAO.getStoredPreferences(
-// context,
-// portlet,
-// user);
-// }
-// catch(SQLException e) {
-// LOG.error(e);
-// throw new PortletContainerException(e);
-// }
+ prefs = dao.getPreferences(context, portlet, user);
+ }
+ catch(SQLException e) {
+ LOG.error(e);
+ throw new PortletContainerException(e);
+ }
+
return prefs;
}
@@ -102,9 +104,9 @@
PortletRequest request,
PortletPreference[] preferences)
throws PortletContainerException {
-// try {
+ try {
+ if (window == null) {
- if (window == null) {
throw new PortletContainerException("Null PortletWindow");
}
if (preferences == null) {
@@ -124,21 +126,12 @@
"' at context '" + context +
"' for portlet '" + portlet + "'");
}
-// DerbyPlutoContainerDAO.storePreferences(
-// context,
-// portlet,
-// preferences,
-// user);
-// }
-// catch(SQLException e) {
-// LOG.error(e);
-// throw new PortletContainerException(e);
-// }
+ dao.storePreferences(context, portlet, user, preferences);
+ }
+ catch(SQLException e) {
+ LOG.error(e);
+ throw new PortletContainerException(e);
+ }
}
-
-// private Connection getConnection() throws SQLException {
-// return dataSourceManager.getPortalDataSource().getConnection();
-// }
-
}
Added: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/PortletPreferenceContainer.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/PortletPreferenceContainer.java?rev=349006&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/PortletPreferenceContainer.java (added)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/PortletPreferenceContainer.java Fri Nov 25 11:48:33 2005
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2003,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.
+ */
+package org.apache.pluto.driver.services.container.db;
+
+import org.apache.pluto.core.PortletPreference;
+import org.apache.pluto.driver.services.container.memory.PortletPreferenceImpl;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Iterator;
+
+/**
+ * TODO JavaDoc
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>:
+ * @version 1.0
+ * @since Nov 23, 2005
+ */
+class PortletPreferenceContainer {
+
+ private Map preferences = new HashMap();
+
+ public void add(List preferences) {
+ Iterator it = preferences.iterator();
+ while(it.hasNext()) {
+ PortletPreference p = (PortletPreference)it.next();
+ add(p.getName(), p.getValues());
+ }
+ }
+
+ private void add(String name, String[] values) {
+ for(int i=0;i<values.length;i++) {
+ add(name, values[i]);
+ }
+ }
+
+ public void add(String name, String value) {
+ if(!preferences.containsKey(name)) {
+ preferences.put(name, new ArrayList());
+ }
+
+ List list = (List)preferences.get(name);
+ list.add(value);
+ }
+
+ public PortletPreference[] createPreferences() {
+ PortletPreference[] prefs = new PortletPreference[preferences.size()];
+
+ Iterator it = preferences.entrySet().iterator();
+ int i = 0;
+ while(it.hasNext()) {
+ Map.Entry entry = (Map.Entry)it.next();
+ prefs[i++] = new PortletPreferenceImpl(
+ entry.getKey().toString(),
+ (List)entry.getValue()
+ );
+ }
+ return prefs;
+ }
+}
Added: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/PreferencesDao.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/PreferencesDao.java?rev=349006&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/PreferencesDao.java (added)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/PreferencesDao.java Fri Nov 25 11:48:33 2005
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2003,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.
+ */
+package org.apache.pluto.driver.services.container.db;
+
+import org.apache.pluto.core.PortletPreference;
+import org.apache.pluto.driver.services.impl.db.AbstractPreparedDao;
+import org.apache.pluto.driver.services.container.memory.PortletPreferenceImpl;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.sql.DataSource;
+import java.sql.*;
+import java.util.List;
+
+/**
+ * Dao for preference persistance.
+ *
+ * @author <a href="mailto:cdoremus@apache.org">Craig Doremus</a>:
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>:
+ * @version 1.0
+ * @since Nov 23, 2005
+ */
+class PreferencesDao extends AbstractPreparedDao {
+
+ private static final Log LOG = LogFactory.getLog(PreferencesDao.class);
+
+ PreferencesDao(DataSource dataSource) {
+ super(dataSource);
+ }
+
+ PortletPreference[] getPreferences(String context,
+ String portletName,
+ String authUser)
+ throws SQLException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Retrieving preferences for: "+context+" / "+portletName+" / "+authUser);
+ }
+
+ StringBuffer sb = new StringBuffer();
+ sb.append("SELECT pr.preference_id, pr.preference_name, pr.read_only, pv.preference_value")
+ .append(" FROM preference_value pv, preference pr, portlet plt, portlet_app pa ")
+ .append(" WHERE pa.app_context = ").append(fmt(context))
+ .append(" AND plt.portlet_app_id = pa.portlet_app_id ")
+ .append(" AND plt.portlet_name = ").append(fmt(portletName))
+ .append(" AND pr.portlet_id = plt.portlet_id ")
+ .append(" AND pr.auth_user = ").append(fmt(authUser))
+ .append(" AND pv.preference_id = pr.preference_id");
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Executing SQL to retrieve preferences: \n"+sb.toString());
+ }
+
+ List list = super.doList(sb.toString());
+ PortletPreferenceContainer container = new PortletPreferenceContainer();
+ container.add(list);
+ return container.createPreferences();
+ }
+
+ private String createPreferenceSql(String context, String portletName) {
+ StringBuffer sb = new StringBuffer();
+ sb.append("INSERT INTO preference (portlet_id, preference_name, auth_user, read_only) ")
+ .append(" VALUES (")
+ .append(" (SELECT portlet_id")
+ .append(" FROM portlet plt, portlet_app pa ")
+ .append(" WHERE pa.app_context = ").append(fmt(context))
+ .append(" AND plt.portlet_app_id = pa.portlet_app_id ")
+ .append(" AND plt.portlet_name = ").append(fmt(portletName))
+ .append(" ), ?, ?, ?)");
+ return sb.toString();
+ }
+
+ 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), ?)");
+ return sb.toString();
+ }
+
+ void storePreferences(String context,
+ String portletName,
+ String authUser,
+ PortletPreference[] preferences)
+ throws SQLException {
+
+ boolean autoCommit = false;
+
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ PreparedStatement valueStmt = null;
+
+ try {
+ conn = getConnection();
+ autoCommit = conn.getAutoCommit();
+ conn.setAutoCommit(false);
+
+ 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();
+ }
+
+ stmt.executeBatch();
+ valueStmt.executeBatch();
+ }
+
+ conn.commit();
+ }
+ catch(SQLException sqle) {
+ if(LOG.isErrorEnabled()) {
+ LOG.error("Error saving preferences: ", sqle);
+ }
+ conn.rollback();
+ throw sqle;
+ }
+ finally {
+ conn.setAutoCommit(autoCommit);
+ cleanup(null, stmt, null);
+ cleanup(conn, valueStmt, null);
+ }
+ }
+
+ protected Object instantiate(ResultSet rs) throws SQLException {
+ String name = rs.getString("preference_name");
+ String value = rs.getString("preference_value");
+ boolean readOnly = rs.getString("read_only").equals("Y");
+ return new PortletPreferenceImpl(name, value, readOnly);
+ }
+
+}
Copied: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/memory/MemoryPreferencesService.java (from r348374, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/MemoryPreferencesService.java)
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/memory/MemoryPreferencesService.java?p2=portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/memory/MemoryPreferencesService.java&p1=portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/MemoryPreferencesService.java&r1=348374&r2=349006&rev=349006&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/MemoryPreferencesService.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/memory/MemoryPreferencesService.java Fri Nov 25 11:48:33 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.container;
+package org.apache.pluto.driver.services.container.memory;
import java.util.Map;
import java.util.HashMap;
Copied: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/memory/PortletPreferenceImpl.java (from r348374, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/PortletPreferenceImpl.java)
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/memory/PortletPreferenceImpl.java?p2=portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/memory/PortletPreferenceImpl.java&p1=portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/PortletPreferenceImpl.java&r1=348374&r2=349006&rev=349006&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/PortletPreferenceImpl.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/memory/PortletPreferenceImpl.java Fri Nov 25 11:48:33 2005
@@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.pluto.driver.services.container;
+package org.apache.pluto.driver.services.container.memory;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
+import java.util.Collections;
import org.apache.pluto.core.PortletPreference;
@@ -31,12 +33,27 @@
public class PortletPreferenceImpl implements PortletPreference {
private String name;
- private ArrayList values;
+ private List values;
+ private boolean readOnly;
public PortletPreferenceImpl() {
this.values = new ArrayList();
}
+ public PortletPreferenceImpl(String name, String value) {
+ this(name, Arrays.asList(new String[] { value }));
+ }
+
+ public PortletPreferenceImpl(String name, String value, boolean readOnly) {
+ this(name, Arrays.asList(new String[] { value }));
+ this.readOnly = readOnly;
+ }
+
+ public PortletPreferenceImpl(String name, List values) {
+ this.name = name;
+ this.values = values;
+ }
+
public String getName() {
return name;
}
@@ -52,10 +69,9 @@
/**
* Returns false. Any PortletPreference retrieved by
* the manager can't be read only.
- * @return
*/
public boolean isReadOnly() {
- return false;
+ return readOnly;
}
public void setName(String name) {
Added: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/AbstractDao.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/AbstractDao.java?rev=349006&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/AbstractDao.java (added)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/AbstractDao.java Fri Nov 25 11:48:33 2005
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2003,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.
+ */
+package org.apache.pluto.driver.services.impl.db;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.sql.DataSource;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Connection;
+import java.sql.Statement;
+
+/**
+ * TODO JavaDoc
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>:
+ * @version 1.0
+ * @since Nov 23, 2005
+ */
+public abstract class AbstractDao {
+
+ private static final Log LOG =
+ LogFactory.getLog(AbstractDao.class);
+
+ private DataSource dataSource;
+
+ public AbstractDao(DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ protected abstract Object instantiate(ResultSet rs) throws SQLException;
+
+
+ protected List doList(String sql) throws SQLException {
+ ArrayList list = new ArrayList();
+
+ Connection conn = null;
+ Statement stmt = null;
+ ResultSet rs = null;
+
+ try {
+ conn = getConnection();
+ stmt = conn.createStatement();
+ rs = stmt.executeQuery(sql);
+ while(rs.next()) {
+ list.add(instantiate(rs));
+ }
+ }
+ finally {
+ cleanup(conn, stmt, rs);
+ }
+ return list;
+ }
+
+ protected String fmt(String value) {
+ return "'"+value+"'";
+ }
+
+ private int doExecute(String sql) throws SQLException {
+ Connection conn = null;
+ Statement stmt = null;
+ int number = 0;
+
+ try {
+ conn = getConnection();
+ stmt = conn.createStatement();
+ number = stmt.executeUpdate(sql);
+ }
+ finally {
+ cleanup(conn, stmt, null);
+ }
+ return number;
+ }
+
+ private int[] doBatch(List sqls) throws SQLException {
+ Connection conn = null;
+ Statement stmt = null;
+ int[] number;
+
+ try {
+ conn = getConnection();
+ stmt = conn.createStatement();
+ Iterator it = sqls.iterator();
+ while(it.hasNext()) {
+ stmt.addBatch(it.next().toString());
+ }
+ number = stmt.executeBatch();
+ }
+ finally {
+ cleanup(conn, stmt, null);
+ }
+ return number;
+ }
+
+ protected Connection getConnection() throws SQLException {
+ return dataSource.getConnection();
+ }
+
+ protected void cleanup(Connection conn, Statement stmt, ResultSet rs) {
+ if(rs != null) {
+ try {
+ rs.close();
+ }
+ catch(SQLException sql) {
+ if(LOG.isWarnEnabled()) {
+ LOG.warn("Unable to successfully close connection");
+ }
+ }
+ }
+
+ if(stmt != null) {
+ try {
+ stmt.close();
+ }
+ catch(SQLException sql) {
+ if(LOG.isWarnEnabled()) {
+ LOG.warn("Unable to successfully close stmtection");
+ }
+ }
+ }
+
+ if(conn != null) {
+ try {
+ conn.close();
+ }
+ catch(SQLException sql) {
+ if(LOG.isWarnEnabled()) {
+ LOG.warn("Unable to successfully close connection");
+ }
+ }
+ }
+ }
+}
Added: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/AbstractPreparedDao.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/AbstractPreparedDao.java?rev=349006&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/AbstractPreparedDao.java (added)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/AbstractPreparedDao.java Fri Nov 25 11:48:33 2005
@@ -0,0 +1,220 @@
+package org.apache.pluto.driver.services.impl.db;
+
+import java.math.BigDecimal;
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.sql.DataSource;
+
+/**
+ * Basic CRUD operations using Apache Derby. Autocommit
+ * is set to true by default unless it is set to false using
+ * the single parameter constructor.
+ *
+ * TODO: Add support for other schemas
+ *
+ * @author <a href="mailto:cdoremus@apache.org">Craig Doremus</a>
+ *
+ */
+public abstract class AbstractPreparedDao extends AbstractDao {
+
+ private static final Log LOG =
+ LogFactory.getLog(AbstractPreparedDao.class);
+
+ private boolean autocommit = false;
+
+ public AbstractPreparedDao(DataSource dataSource) {
+ super(dataSource);
+ }
+
+ public AbstractPreparedDao(DataSource dataSource, boolean autocommit) {
+ this(dataSource);
+ this.autocommit = autocommit ;
+ }
+
+
+ /**
+ * Do a standard SQL update using a PreparedStatement.
+ *
+ * @param sql SQL in PreparedStatement format
+ * @param parameters Array of parameters in proper order.
+ * @return The number of rows updated
+ * @throws SQLException
+ */
+ protected int doUpdate(String sql, Object[] parameters) throws SQLException {
+ int rows = 0;
+ Connection conn = null;
+ PreparedStatement ps = null;
+
+ try {
+ conn = getConnection();
+ ps = conn.prepareStatement(sql);
+ bindPreparedStatement(parameters, ps);
+ rows = ps.executeUpdate();
+
+ } finally {
+ cleanup(conn, ps, null);
+ }
+ return rows;
+ }
+
+ public int doUpdate(String sql) throws SQLException {
+ return doUpdate(sql, null);
+ }
+
+ /**
+ * Do a standard SQL insert using a PreparedStatement.
+ *
+ * @param sql SQL in PreparedStatement format
+ * @param parameters Array of parameters in proper order.
+ * @return The new generated primary key
+ * @throws SQLException
+ */
+ public int doInsert(String sql, Object[] parameters ) throws SQLException {
+ return doUpdate(sql, parameters);
+ }
+
+ /**
+ * Do a standard SQL delete using a PreparedStatement.
+ *
+ * @param sql SQL in PreparedStatement format
+ * @param parameters Array of parameters in proper order.
+ * @return The number of rows updated
+ * @throws SQLException
+ */
+ public int doDelete(String sql, Object[] parameters ) throws SQLException {
+ return doUpdate(sql, parameters);
+ }
+
+ /**
+ * Do a standard SQL delete using a PreparedStatement.
+ *
+ * @param sql SQL in PreparedStatement format
+ * @param id Key of the record(s) to be deleted.
+ * @return The number of rows updated
+ * @throws SQLException
+ */
+ public int doDelete(String sql, int id) throws SQLException {
+ return doUpdate(sql, new Object[]{new Integer(id)});
+ }
+
+ /**
+ * Retreives a <code>List</code> of <code>Map</code> objects representing a result set
+ * row based on the sql parameter and the array of parameters sent into this method.
+ *
+ * The sql field is the <code>Map's</code> key. <code>Map.get(key)</code> would be used
+ * to retreive the value of each item in a results set's rows. The Derby database uppercases
+ * the key in the result set, so, for instance, the proper way to retreive the portlet_app_id
+ * from a row, would be:
+ * <pre>
+ * Integer oId = (Integer)row.get("PORTLET_APP_ID");//row is a Map item in the result set List
+ * </pre>
+ *
+ * @param sql The SQL statement to be run as a <code>PreparedStatement</code>
+ * @param parameters An <code>Object</code> array of parameters for the <code>PreparedStatement</code>
+ * in proper order.
+ * @return A <code>List</code> of <code>Map</code> objects.
+ * @throws SQLException
+ */
+ public List doSelect(String sql, Object[] parameters ) throws SQLException {
+ List results = new ArrayList();
+
+ Connection conn = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+
+ try {
+ conn = getConnection();
+ ps = conn.prepareStatement(sql);
+ bindPreparedStatement(parameters, ps);
+ rs = ps.executeQuery();
+ } finally {
+ cleanup(conn, ps, rs);
+ }
+ return results;
+ }
+
+ /**
+ * Do a standard SQL select using a PreparedStatement.
+ *
+ * @param sql SQL in PreparedStatement format
+ * @return A <code>List</code> of <code>Map</code> objects.
+ * @throws SQLException
+ */
+ public List doSelect(String sql) throws SQLException {
+ return doSelect(sql, null);
+ }
+
+ /**
+ * Binds a PreparedStatement using appropraite
+ * setXXX() methods.
+ *
+ * @param parameters Parameters
+ * @param ps
+ * @throws SQLException
+ */
+ private void bindPreparedStatement(Object[] parameters, PreparedStatement ps) throws SQLException {
+ //Loop through each value, determine it's corresponding SQL type,
+ //and stuff that value into the prepared statement.
+ //Skip everything if parameters are null or empty.
+ if (parameters != null && parameters.length > 0) {
+ Object value = null;
+ int len = parameters.length;
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Parameter count: " + parameters.length);
+ }
+ int colno = 0;
+ for (int i = 0; i < len; i++) {
+ colno = i + 1;
+ value = parameters[i];
+ if (value instanceof String) {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("String Parameter [" + i + "] value=" + value);
+ }
+ if(value == null) {
+ ps.setNull(colno, Types.VARCHAR);
+ } else {
+ ps.setString(i + 1, (String) value);
+ }
+ } else if (value instanceof Integer){
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Integer Parameter [" + i + "] value=" + value);
+ }
+ if(value == null) {
+ ps.setNull(colno, Types.INTEGER);
+ } else {
+ int val = ((Integer)value).intValue();
+ ps.setInt(colno, val);
+ }
+ } else if (value instanceof Timestamp){
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Timestamp Parameter [" + i + "] value=" + value);
+ }
+ if(value == null) {
+ ps.setNull(colno, Types.TIMESTAMP);
+ } else {
+ ps.setTimestamp(colno, (Timestamp)value);
+ }
+ } else {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Object Parameter [" + i + "] value=" + value);
+ }
+ if(value == null) {
+ ps.setNull(colno, Types.JAVA_OBJECT);
+ } else {
+ ps.setObject(colno, value);
+ }
+ }
+ }
+ }
+ }
+}
Added: 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=349006&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java (added)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java Fri Nov 25 11:48:33 2005
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2003,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.
+ */
+package org.apache.pluto.driver.services.impl.db;
+
+import org.apache.pluto.driver.services.portal.PortletRegistryService;
+import org.apache.pluto.driver.services.portal.PortletApplicationConfig;
+import org.apache.pluto.driver.services.portal.PortletWindowConfig;
+import org.apache.pluto.driver.services.impl.resource.ResourceConfig;
+import org.apache.pluto.driver.services.impl.resource.ResourceConfigReader;
+import org.apache.pluto.driver.config.DriverConfigurationException;
+import org.apache.pluto.PortletContainerException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.servlet.ServletContext;
+import java.util.Set;
+import java.sql.SQLException;
+import java.io.InputStream;
+
+/**
+ * TODO JavaDoc
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>:
+ * @version 1.0
+ * @since Nov 24, 2005
+ */
+public class DBPortletRegistryService implements PortletRegistryService {
+
+ private static final Log LOG = LogFactory.getLog(DBPortletRegistryService.class);
+
+ private ResourceConfig config;
+
+ private DataSourceManager dataSourceManager;
+
+ private PortletRegistryDao dao;
+
+ public DBPortletRegistryService(DataSourceManager dataSourceManager)
+ throws InstantiationException {
+ this.dataSourceManager = dataSourceManager;
+ if(!dataSourceManager.isRunning()) {
+ try {
+ dataSourceManager.startup();
+ }
+ catch(PortletContainerException pce) {
+ String msg =
+ "Unable to startup portlet registry service due to dataSourceManager error."+
+ pce.getMessage();
+ if(LOG.isErrorEnabled()) {
+ LOG.error(msg, pce);
+ }
+ throw new InstantiationException(msg);
+ }
+ }
+ dao = new PortletRegistryDao(dataSourceManager.getPortalDataSource());
+ }
+
+ public void init(ServletContext ctx) throws DriverConfigurationException {
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Registering portlet applications. . .");
+ }
+
+ try {
+ InputStream in = ctx.getResourceAsStream(ResourceConfigReader.CONFIG_FILE);
+ config = ResourceConfigReader.getFactory().parse(in);
+
+ dao.createPortletApplications(config.getPortletApplications());
+ }
+ catch(Exception sql) {
+ if(LOG.isErrorEnabled()) {
+ LOG.error("Unable to initialize portlet registry services: ", sql);
+ }
+ throw new DriverConfigurationException("Unable to initialize portlet registry service: ", sql);
+ }
+
+ }
+
+ public void destroy() throws DriverConfigurationException {
+
+ }
+
+ public Set getPortletApplications() {
+ return config.getPortletApplications();
+ }
+
+ public PortletApplicationConfig getPortletApplication(String id) {
+ return config.getPortletApp(id);
+ }
+
+ public PortletWindowConfig getPortlet(String id) {
+ return config.getPortletWindowConfig(id);
+ }
+}
Copied: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DataSourceManager.java (from r348374, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/DataSourceManager.java)
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DataSourceManager.java?p2=portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DataSourceManager.java&p1=portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/DataSourceManager.java&r1=348374&r2=349006&rev=349006&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/DataSourceManager.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DataSourceManager.java Fri Nov 25 11:48:33 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.container.db;
+package org.apache.pluto.driver.services.impl.db;
import org.apache.pluto.PortletContainerException;
Copied: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/EmbeddedDataSourceManager.java (from r348374, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/EmbeddedDataSourceManager.java)
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/EmbeddedDataSourceManager.java?p2=portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/EmbeddedDataSourceManager.java&p1=portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/EmbeddedDataSourceManager.java&r1=348374&r2=349006&rev=349006&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/EmbeddedDataSourceManager.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/EmbeddedDataSourceManager.java Fri Nov 25 11:48:33 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.container.db;
+package org.apache.pluto.driver.services.impl.db;
import org.apache.derby.jdbc.EmbeddedDataSource;
import org.apache.pluto.PortletContainerException;
@@ -21,10 +21,7 @@
import org.apache.commons.logging.Log;
import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.ResultSet;
-import java.sql.Statement;
+import java.sql.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -53,7 +50,7 @@
public EmbeddedDataSourceManager() {
connectionString =
- "databaseName=PLUTO_PORTAL_DRIVER;name=pluto;password=apachep0rtals;create=true";
+ "databaseName=PLUTO_PORTAL_DRIVER;name=pluto_portal_driver;password=apachep0rtals;create=true";
System.setProperty(
"derby.system.home",
@@ -67,11 +64,13 @@
}
public void startup() throws PortletContainerException {
- embeddedDataSource = new EmbeddedDataSource();
- embeddedDataSource.setConnectionAttributes(connectionString);
- embeddedDataSource.setDatabaseName("PLUTO_PORTAL_DRIVER");
- embeddedDataSource.setCreateDatabase("true");
- initDatabase();
+ if(embeddedDataSource == null) {
+ embeddedDataSource = new EmbeddedDataSource();
+ embeddedDataSource.setConnectionAttributes(connectionString);
+ embeddedDataSource.setDatabaseName("PLUTO_PORTAL_DRIVER");
+ embeddedDataSource.setCreateDatabase("true");
+ initDatabase();
+ }
}
public void shutdown() throws PortletContainerException {
@@ -113,7 +112,7 @@
while(it.hasNext()) {
String sql = it.next().toString();
if(sql.trim().length() > 0) {
- results += stmt.executeUpdate(sql);
+ results = stmt.executeUpdate(sql);
}
}
conn.commit();
@@ -156,10 +155,16 @@
cleanup(conn, stmt, null);
}
}
- // 1) Read in the PORTABLE CREATE SQL Script
- // 2) Execute the CREATE Script via JDBC
- // 3) Retrieve default data
- // 4) Insert default data via JDBC
+
+ if(LOG.isDebugEnabled()) {
+ try {
+ displaySchema();
+ }
+ catch(SQLException sql) {
+ LOG.error("Error debugging schema: ", sql);
+ }
+ }
+
}
/**
@@ -246,6 +251,46 @@
try { conn.close(); } catch(SQLException sql) {
LOG.error("Unable to close result set.", sql);
}
+ }
+
+ private void displaySchema() throws SQLException {
+
+ Connection conn = null;
+ ResultSet rs = null;
+
+ ArrayList tbls = new ArrayList();
+
+ try {
+ conn = embeddedDataSource.getConnection();
+ DatabaseMetaData data = conn.getMetaData();
+
+ rs = data.getSchemas();
+ while(rs.next()) {
+ String schema = rs.getString("TABLE_SCHEM");
+ if(schema.startsWith("SYS")) {
+ continue;
+ }
+ ResultSet tables = data.getTables(null, rs.getString(1), "%", null);
+ while(tables.next()) {
+ tbls.add(schema + " --> " + tables.getString("TABLE_NAME"));
+ }
+ tables.close();
+ }
+ rs.close();
+ }
+ finally {
+ cleanup(conn, null, rs);
+
+ //Do this here so we spit out what we can. . .
+ Iterator it = tbls.iterator();
+ StringBuffer sb = new StringBuffer("Started up database with table structure: \n ");
+ sb.append("---------------------------------------------------------------\n");
+ while(it.hasNext()) {
+ sb.append(" - "+it.next()+"\n");
+ }
+ sb.append("---------------------------------------------------------------\n");
+ LOG.debug(sb.toString());
+ }
}
Copied: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/JNDIDataSourceManager.java (from r348374, portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/JNDIDataSourceManager.java)
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/JNDIDataSourceManager.java?p2=portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/JNDIDataSourceManager.java&p1=portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/JNDIDataSourceManager.java&r1=348374&r2=349006&rev=349006&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/db/JNDIDataSourceManager.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/JNDIDataSourceManager.java Fri Nov 25 11:48:33 2005
@@ -13,16 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.pluto.driver.services.container.db;
+package org.apache.pluto.driver.services.impl.db;
-import org.apache.derby.jdbc.EmbeddedDataSource;
import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.driver.services.impl.db.DataSourceManager;
import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
-import java.io.File;
/**