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 21:25:46 UTC
svn commit: r349020 - in /portals/pluto/trunk: ./
pluto-container/src/main/java/org/apache/pluto/core/impl/
pluto-optional-services/ pluto-optional-services/src/
pluto-optional-services/src/main/ pluto-optional-services/src/main/java/
pluto-optional-se...
Author: ddewolf
Date: Fri Nov 25 12:25:31 2005
New Revision: 349020
URL: http://svn.apache.org/viewcvs?rev=349020&view=rev
Log:
Refactoring optional container services into seperate subproject
Added:
portals/pluto/trunk/pluto-optional-services/
portals/pluto/trunk/pluto-optional-services/pluto-optional-services.iml
portals/pluto/trunk/pluto-optional-services/pom.xml
portals/pluto/trunk/pluto-optional-services/src/
portals/pluto/trunk/pluto-optional-services/src/main/
portals/pluto/trunk/pluto-optional-services/src/main/java/
portals/pluto/trunk/pluto-optional-services/src/main/java/org/
portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/
portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/
portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/
portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/
portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/DBPortletPreferencesService.java
portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/PortletPreferenceContainer.java
portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/PreferencesDao.java
portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/
portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/AbstractDao.java
portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/AbstractPreparedDao.java
portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/DataSourceManager.java
portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/EmbeddedDataSourceManager.java
portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/JNDIDataSourceManager.java
portals/pluto/trunk/pluto-optional-services/src/test/
portals/pluto/trunk/pluto-optional-services/src/test/java/
portals/pluto/trunk/pluto-optional-services/src/test/java/org/
portals/pluto/trunk/pluto-optional-services/src/test/java/org/apache/
portals/pluto/trunk/pluto-optional-services/src/test/java/org/apache/pluto/
portals/pluto/trunk/pluto-optional-services/src/test/java/org/apache/pluto/optional/
portals/pluto/trunk/pluto-optional-services/src/test/java/org/apache/pluto/optional/db/
portals/pluto/trunk/pluto-optional-services/src/test/java/org/apache/pluto/optional/db/PortletPreferenceContainerTest.java
Removed:
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/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/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/DataSourceManager.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/EmbeddedDataSourceManager.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/JNDIDataSourceManager.java
portals/pluto/trunk/pluto-portal-driver/src/test/java/org/apache/pluto/driver/services/container/db/PortletPreferenceContainerTest.java
Modified:
portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletPreferenceImpl.java
portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletPreferencesImpl.java
portals/pluto/trunk/pluto-portal-driver/pom.xml
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/PortletRegistryDao.java
portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-services-config.xml
portals/pluto/trunk/pom.xml
Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletPreferenceImpl.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletPreferenceImpl.java?rev=349020&r1=349019&r2=349020&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletPreferenceImpl.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletPreferenceImpl.java Fri Nov 25 12:25:31 2005
@@ -38,6 +38,12 @@
this.values = values;
}
+ public PortletPreferenceImpl(String name, String[] values, boolean readOnly) {
+ this.name = name;
+ this.values = values;
+ this.readOnly = readOnly;
+ }
+
public String getName() {
return name;
}
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=349020&r1=349019&r2=349020&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 12:25:31 2005
@@ -203,9 +203,8 @@
);
}
- PortletPreference pref = (PortletPreference)preferences.get(key);
-
+ preferences.clear();
for(int i=0;i<defaultPreferences.length;i++) {
if(key.equals(defaultPreferences[i].getName())) {
preferences.put(key, defaultPreferences[i]);
Added: portals/pluto/trunk/pluto-optional-services/pluto-optional-services.iml
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-optional-services/pluto-optional-services.iml?rev=349020&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-optional-services/pluto-optional-services.iml (added)
+++ portals/pluto/trunk/pluto-optional-services/pluto-optional-services.iml Fri Nov 25 12:25:31 2005
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module version="4" relativePaths="false" type="JAVA_MODULE">
+ <component name="ModuleRootManager" />
+ <component name="NewModuleRootManager">
+ <output url="file://$MODULE_DIR$/target/classes" />
+ <exclude-output />
+ <output-test url="file://$MODULE_DIR$/target/test-classes" />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="module" module-name="pluto-container" />
+ <orderEntry type="module-library">
+ <library name="avalon-framework">
+ <CLASSES>
+ <root url="jar://C:/Documents and Settings/dxd0/.m2/repository/avalon-framework/avalon-framework/4.1.3/avalon-framework-4.1.3.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library name="derby">
+ <CLASSES>
+ <root url="jar://C:/Documents and Settings/dxd0/.m2/repository/org/apache/derby/derby/10.1.1.0/derby-10.1.1.0.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library name="junit">
+ <CLASSES>
+ <root url="jar://C:/Documents and Settings/dxd0/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library name="servlet-api">
+ <CLASSES>
+ <root url="jar://C:/Documents and Settings/dxd0/.m2/repository/javax/servlet/servlet-api/2.3/servlet-api-2.3.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library name="commons-logging">
+ <CLASSES>
+ <root url="jar://C:/Documents and Settings/dxd0/.m2/repository/commons-logging/commons-logging/1.0.4/commons-logging-1.0.4.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library name="log4j">
+ <CLASSES>
+ <root url="jar://C:/Documents and Settings/dxd0/.m2/repository/log4j/log4j/1.2.6/log4j-1.2.6.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library name="commons-logging-api">
+ <CLASSES>
+ <root url="jar://C:/Documents and Settings/dxd0/.m2/repository/commons-logging/commons-logging-api/1.0.4/commons-logging-api-1.0.4.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library name="portlet-api">
+ <CLASSES>
+ <root url="jar://C:/Documents and Settings/dxd0/.m2/repository/javax/portlet/portlet-api/1.0/portlet-api-1.0.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module" module-name="pluto-descriptor-api" />
+ <orderEntry type="module-library">
+ <library name="logkit">
+ <CLASSES>
+ <root url="jar://C:/Documents and Settings/dxd0/.m2/repository/logkit/logkit/1.0.1/logkit-1.0.1.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntryProperties />
+ </component>
+</module>
+
Added: portals/pluto/trunk/pluto-optional-services/pom.xml
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-optional-services/pom.xml?rev=349020&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-optional-services/pom.xml (added)
+++ portals/pluto/trunk/pluto-optional-services/pom.xml Fri Nov 25 12:25:31 2005
@@ -0,0 +1,80 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.pluto</groupId>
+ <artifactId>pluto-optional-services</artifactId>
+ <packaging>jar</packaging>
+ <name>Pluto Portal Optional Services</name>
+ <url>http://portals.apache.org/pluto</url>
+ <parent>
+ <groupId>org.apache.pluto</groupId>
+ <artifactId>pluto</artifactId>
+ <version>1.1-SNAPSHOT</version>
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.pluto</groupId>
+ <artifactId>pluto-container</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <version>10.1.1.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.portlet</groupId>
+ <artifactId>portlet-api</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.3</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging-api</artifactId>
+ <version>1.0.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.0.4</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/resources</directory>
+ <includes name="**/*.sql"/>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptor>src/assemble/bin.xml</descriptor>
+ <finalName>pluto-portal-${pom.version}</finalName>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/DBPortletPreferencesService.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/DBPortletPreferencesService.java?rev=349020&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/DBPortletPreferencesService.java (added)
+++ portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/DBPortletPreferencesService.java Fri Nov 25 12:25:31 2005
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.optional.db;
+
+//import java.sql.Connection;
+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.optional.db.support.DataSourceManager;
+import org.apache.pluto.services.optional.PortletPreferencesService;
+
+import javax.portlet.PortletRequest;
+import java.sql.SQLException;
+
+/**
+ * The Portal Driver's PortletPreferencesService implementation. This
+ * implementation makes use of the embeded derby db for writing portlet preferences.
+ * @author <a href="ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="cdoremus@apache.org">Craig Doremus</a>
+ * @version 1.0
+ * @since Sep 22, 2004
+ */
+public class DBPortletPreferencesService
+ implements PortletPreferencesService {
+
+ private static final Log LOG =
+ LogFactory.getLog(DBPortletPreferencesService.class);
+
+ private DataSourceManager dataSourceManager;
+
+ public DBPortletPreferencesService() {
+
+ }
+
+ private PreferencesDao dao;
+
+ public DBPortletPreferencesService(DataSourceManager dataSourceManager)
+ throws InstantiationException {
+ this.dataSourceManager = dataSourceManager;
+ if(!dataSourceManager.isRunning()) {
+ try {
+ dataSourceManager.startup();
+ }
+ catch(PortletContainerException pce) {
+ String msg =
+ "Unable to startup portlet preferences service due to dataSourceManager error."+
+ pce.getMessage();
+ LOG.error(msg, pce);
+ throw new InstantiationException(msg);
+ }
+ }
+ dao = new PreferencesDao(dataSourceManager.getPortalDataSource());
+ }
+
+ public PortletPreference[] getStoredPreferences(PortletWindow window,
+ PortletRequest req)
+ throws PortletContainerException {
+ PortletPreference[] prefs = null;
+ try {
+
+ if (window == null) {
+ throw new PortletContainerException("Null PortletWindow");
+ }
+
+ String user = req.getRemoteUser();
+ if (user == null) {
+ user = "ANONYMOUS";
+ }
+
+ String context = window.getContextPath();
+ String portlet = window.getPortletName();
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Retrieving preferences for user '" + user +
+ "' at context '" + context +
+ "' for portlet '" + portlet + "'");
+ }
+ prefs = dao.getPreferences(context, portlet, user);
+ }
+ catch(SQLException e) {
+ LOG.error(e);
+ throw new PortletContainerException(e);
+ }
+
+ return prefs;
+ }
+
+ public void store(PortletWindow window,
+ PortletRequest request,
+ PortletPreference[] preferences)
+ throws PortletContainerException {
+ try {
+ if (window == null) {
+
+ throw new PortletContainerException("Null PortletWindow");
+ }
+ if (preferences == null) {
+ throw new PortletContainerException("Null PortletPreference array");
+ }
+ if (preferences.length == 0) {
+ LOG.warn("No preferences to store!");
+ }
+ String user = request.getRemoteUser();
+ if (user == null) {
+ user = "ANONYMOUS";
+ }
+ String context = window.getContextPath();
+ String portlet = window.getPortletName();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Retrieving preferences for user '" + user +
+ "' at context '" + context +
+ "' for portlet '" + portlet + "'");
+ }
+ dao.storePreferences(context, portlet, user, preferences);
+ }
+ catch(SQLException e) {
+ LOG.error(e);
+ throw new PortletContainerException(e);
+ }
+ }
+}
+
Added: portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/PortletPreferenceContainer.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/PortletPreferenceContainer.java?rev=349020&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/PortletPreferenceContainer.java (added)
+++ portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/PortletPreferenceContainer.java Fri Nov 25 12:25:31 2005
@@ -0,0 +1,79 @@
+/*
+ * 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.optional.db;
+
+import org.apache.pluto.core.PortletPreference;
+import org.apache.pluto.core.impl.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 String[] { name });
+ }
+ else {
+ String[] values = (String[])preferences.get(name);
+ String[] nw = new String[values.length+1];
+ System.arraycopy(values, 0, nw, 0, values.length);
+ nw[values.length] = value;
+ preferences.put(name, nw);
+ }
+ }
+
+ 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(),
+ (String[])entry.getValue()
+ );
+ }
+ return prefs;
+ }
+}
Added: portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/PreferencesDao.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/PreferencesDao.java?rev=349020&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/PreferencesDao.java (added)
+++ portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/PreferencesDao.java Fri Nov 25 12:25:31 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.optional.db;
+
+import org.apache.pluto.core.PortletPreference;
+import org.apache.pluto.core.impl.PortletPreferenceImpl;
+import org.apache.pluto.optional.db.support.AbstractPreparedDao;
+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, new String[] { value }, readOnly);
+ }
+
+}
Added: portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/AbstractDao.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/AbstractDao.java?rev=349020&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/AbstractDao.java (added)
+++ portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/AbstractDao.java Fri Nov 25 12:25:31 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.optional.db.support;
+
+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-optional-services/src/main/java/org/apache/pluto/optional/db/support/AbstractPreparedDao.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/AbstractPreparedDao.java?rev=349020&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/AbstractPreparedDao.java (added)
+++ portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/AbstractPreparedDao.java Fri Nov 25 12:25:31 2005
@@ -0,0 +1,221 @@
+package org.apache.pluto.optional.db.support;
+
+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 org.apache.pluto.optional.db.support.AbstractDao;
+
+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-optional-services/src/main/java/org/apache/pluto/optional/db/support/DataSourceManager.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/DataSourceManager.java?rev=349020&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/DataSourceManager.java (added)
+++ portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/DataSourceManager.java Fri Nov 25 12:25:31 2005
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.optional.db.support;
+
+import org.apache.pluto.PortletContainerException;
+
+import javax.sql.DataSource;
+
+/**
+ *
+ */
+public interface DataSourceManager {
+
+ void startup() throws PortletContainerException;
+
+ void shutdown() throws PortletContainerException;
+
+ boolean isRunning();
+
+ DataSource getPortalDataSource();
+}
Added: portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/EmbeddedDataSourceManager.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/EmbeddedDataSourceManager.java?rev=349020&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/EmbeddedDataSourceManager.java (added)
+++ portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/EmbeddedDataSourceManager.java Fri Nov 25 12:25:31 2005
@@ -0,0 +1,298 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.optional.db.support;
+
+import org.apache.derby.jdbc.EmbeddedDataSource;
+import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.optional.db.support.DataSourceManager;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+
+import javax.sql.DataSource;
+import java.sql.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.BufferedReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Iterator;
+
+
+/**
+ * Provides access to the DataSource used for Derby.
+ * Provided so that advanced configuration may be
+ * provided in the future.
+ *
+ */
+public class EmbeddedDataSourceManager implements DataSourceManager {
+
+ private static final Log LOG =
+ LogFactory.getLog(EmbeddedDataSourceManager.class);
+
+ private String connectionString;
+
+ private String shutdown = "shutdownDatabase=true";
+
+ private EmbeddedDataSource embeddedDataSource;
+
+ public EmbeddedDataSourceManager() {
+ connectionString =
+ "databaseName=PLUTO_PORTAL_DRIVER;name=pluto_portal_driver;password=apachep0rtals;create=true";
+
+ System.setProperty(
+ "derby.system.home",
+ System.getProperty("user.home") + "/.pluto/portal-driver/data"
+ );
+ }
+
+ public EmbeddedDataSourceManager(String connectionString, String systemDirectory) {
+ this.connectionString = connectionString;
+ System.setProperty("derby.system.home", systemDirectory);
+ }
+
+ public void startup() throws PortletContainerException {
+ if(embeddedDataSource == null) {
+ embeddedDataSource = new EmbeddedDataSource();
+ embeddedDataSource.setConnectionAttributes(connectionString);
+ embeddedDataSource.setDatabaseName("PLUTO_PORTAL_DRIVER");
+ embeddedDataSource.setCreateDatabase("true");
+ initDatabase();
+ }
+ }
+
+ public void shutdown() throws PortletContainerException {
+ if(embeddedDataSource != null)
+ embeddedDataSource.setConnectionAttributes(connectionString+shutdown);
+ embeddedDataSource = null;
+ }
+
+ public boolean isRunning() {
+ return embeddedDataSource != null;
+ }
+
+
+ public DataSource getPortalDataSource() {
+ return embeddedDataSource;
+ }
+
+ /**
+ * Eventually we should ensure pooling.
+ */
+ private void initDatabase() throws PortletContainerException {
+ if(!isDatabaseInitialized()) {
+ if(LOG.isInfoEnabled()) {
+ LOG.info("Pluto Database does not exist. Creating database now.");
+ }
+
+ boolean autoCommit = false;
+ Connection conn = null;
+ Statement stmt = null;
+ try {
+ List script = readScript();
+ conn = embeddedDataSource.getConnection();
+ autoCommit = conn.getAutoCommit();
+ conn.setAutoCommit(false);
+
+ stmt = conn.createStatement();
+ Iterator it = script.iterator();
+ int results = 0;
+ while(it.hasNext()) {
+ String sql = it.next().toString();
+ if(sql.trim().length() > 0) {
+ results = stmt.executeUpdate(sql);
+ }
+ }
+ conn.commit();
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Created "+results+ " database objects");
+ }
+ }
+ catch(IOException io) {
+ if(LOG.isErrorEnabled()) {
+ LOG.error("Error reading script file", io);
+ }
+
+ throw new PortletContainerException(io);
+ }
+ catch(SQLException sql) {
+ try {
+ if(conn != null)
+ conn.rollback();
+ } catch(SQLException sqle) {
+ if(LOG.isErrorEnabled()) {
+ LOG.error("SQLException rolling back connection", sqle);
+ }
+ }
+
+
+ if(LOG.isErrorEnabled()) {
+ LOG.error("Error creating database schema", sql);
+ }
+ throw new PortletContainerException(sql);
+ }
+ finally {
+ try {
+ conn.setAutoCommit(autoCommit);
+ }
+ catch(SQLException sql) {
+ if(LOG.isErrorEnabled()) {
+ LOG.error("Error resetting autocommit.",sql);
+ }
+ }
+ cleanup(conn, stmt, null);
+ }
+ }
+
+ if(LOG.isDebugEnabled()) {
+ try {
+ displaySchema();
+ }
+ catch(SQLException sql) {
+ LOG.error("Error debugging schema: ", sql);
+ }
+ }
+
+ }
+
+ /**
+ * @return true if the database is valid
+ */
+ private boolean isDatabaseInitialized() throws PortletContainerException {
+ boolean found = false;
+ Connection conn = null;
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ conn = embeddedDataSource.getConnection();
+ stmt = conn.createStatement();
+ rs = stmt.executeQuery("SELECT count(*) FROM SYS.SYSTABLES WHERE TABLENAME = 'VERSION'");
+ if(rs.next()) {
+ found = rs.getInt(1) == 1;
+ }
+ else throw new SQLException("No results returned. Should never happen for count(*)");
+ }
+ catch(SQLException sql) {
+ if(LOG.isErrorEnabled()) {
+ LOG.error("Error testing database validity", sql);
+ }
+ throw new PortletContainerException(sql);
+ }
+ finally {
+ cleanup(conn, stmt, rs);
+ }
+ return found;
+ }
+
+ private ArrayList readScript() throws IOException {
+ InputStream in = getClass().getResourceAsStream("/create_schema.sql");
+ if(in == null) {
+ throw new IOException("Unable to find schemal data definition");
+ }
+
+ BufferedReader input = new BufferedReader(new InputStreamReader(in));
+
+ ArrayList commands = new ArrayList();
+ StringBuffer sb = new StringBuffer();
+ String read;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Adding SQL Commands for schema creation");
+ }
+
+ while( (read = input.readLine()) != null) {
+ read = read.trim();
+ if(read.startsWith("--"))
+ continue;
+
+ if(read.indexOf(';') > -0) {
+ read = read.replace(';', ' ');
+ if(LOG.isDebugEnabled()) {
+ LOG.debug(sb.toString());
+ }
+ commands.add(sb.append(read).toString());
+ sb = new StringBuffer();
+ continue;
+ }
+
+ if(read.length() > 0) {
+ sb.append(read).append(" ");
+ }
+ }
+
+ input.close();
+ return commands;
+ }
+
+ private void cleanup(Connection conn, Statement stmt, ResultSet rs) {
+ if(rs != null)
+ try { rs.close(); } catch(SQLException sql) {
+ LOG.error("Unable to close result set.", sql);
+ }
+
+ if(stmt != null)
+ try { stmt.close(); } catch(SQLException sql) {
+ LOG.error("Unable to close result set.", sql);
+ }
+
+ if(conn != null)
+ 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());
+ }
+ }
+
+
+}
Added: portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/JNDIDataSourceManager.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/JNDIDataSourceManager.java?rev=349020&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/JNDIDataSourceManager.java (added)
+++ portals/pluto/trunk/pluto-optional-services/src/main/java/org/apache/pluto/optional/db/support/JNDIDataSourceManager.java Fri Nov 25 12:25:31 2005
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.optional.db.support;
+
+import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.optional.db.support.DataSourceManager;
+
+import javax.sql.DataSource;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+
+/**
+ * Provides access to the DataSource used for Derby.
+ * Provided so that advanced configuration may be
+ * provided in the future.
+ *
+ */
+public class JNDIDataSourceManager implements DataSourceManager {
+
+ private String jndiName;
+
+ private DataSource dataSource;
+
+ public JNDIDataSourceManager(String jndiName) {
+ this.jndiName = jndiName;
+ }
+
+
+ public void startup() throws PortletContainerException {
+ try {
+ Context ctx = new InitialContext();
+ ctx = (Context)ctx.lookup("java:comp/env");
+ dataSource = (DataSource)ctx.lookup(jndiName);
+ }
+ catch(NamingException ne) {
+ throw new PortletContainerException(ne);
+ }
+ }
+
+ public void shutdown() throws PortletContainerException {
+ if(dataSource != null)
+ dataSource = null;
+ }
+
+ public boolean isRunning() {
+ return dataSource != null;
+ }
+
+
+ public DataSource getPortalDataSource() {
+ return dataSource;
+ }
+}
Added: portals/pluto/trunk/pluto-optional-services/src/test/java/org/apache/pluto/optional/db/PortletPreferenceContainerTest.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-optional-services/src/test/java/org/apache/pluto/optional/db/PortletPreferenceContainerTest.java?rev=349020&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-optional-services/src/test/java/org/apache/pluto/optional/db/PortletPreferenceContainerTest.java (added)
+++ portals/pluto/trunk/pluto-optional-services/src/test/java/org/apache/pluto/optional/db/PortletPreferenceContainerTest.java Fri Nov 25 12:25:31 2005
@@ -0,0 +1,40 @@
+/*
+ * 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.optional.db;
+
+import junit.framework.TestCase;
+
+/**
+ * TODO JavaDoc
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>:
+ * @version 1.0
+ * @since Nov 23, 2005
+ */
+public class PortletPreferenceContainerTest extends TestCase {
+
+ public void testAddPreference() {
+
+ PortletPreferenceContainer container = new PortletPreferenceContainer();
+ container.add("test", "one");
+ assertEquals(1, container.createPreferences().length);
+ container.add("test", "two");
+ assertEquals(1, container.createPreferences().length);
+ container.add("test2", "two");
+ assertEquals(2, container.createPreferences().length);
+ }
+
+}
Modified: portals/pluto/trunk/pluto-portal-driver/pom.xml
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/pom.xml?rev=349020&r1=349019&r2=349020&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/pom.xml (original)
+++ portals/pluto/trunk/pluto-portal-driver/pom.xml Fri Nov 25 12:25:31 2005
@@ -21,6 +21,13 @@
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.pluto</groupId>
+ <artifactId>pluto-optional-services</artifactId>
+ <version>${pom.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java?rev=349020&r1=349019&r2=349020&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java Fri Nov 25 12:25:31 2005
@@ -22,6 +22,7 @@
import org.apache.pluto.driver.services.impl.resource.ResourceConfigReader;
import org.apache.pluto.driver.config.DriverConfigurationException;
import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.optional.db.support.DataSourceManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/PortletRegistryDao.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/PortletRegistryDao.java?rev=349020&r1=349019&r2=349020&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/PortletRegistryDao.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/PortletRegistryDao.java Fri Nov 25 12:25:31 2005
@@ -17,6 +17,7 @@
import org.apache.pluto.driver.services.portal.PortletApplicationConfig;
import org.apache.pluto.driver.services.portal.PortletWindowConfig;
+import org.apache.pluto.optional.db.support.AbstractDao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Modified: portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-services-config.xml
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-services-config.xml?rev=349020&r1=349019&r2=349020&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-services-config.xml (original)
+++ portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-services-config.xml Fri Nov 25 12:25:31 2005
@@ -54,13 +54,13 @@
<!-- Uncomment for Embedded Derby Service Implementations -->
<bean id="PortletPreferencesService"
- class="org.apache.pluto.driver.services.container.db.DBPortletPreferencesService"
+ class="org.apache.pluto.optional.db.DBPortletPreferencesService"
singleton="true">
<constructor-arg><ref bean="DataSourceManager"/></constructor-arg>
</bean>
<bean id="DataSourceManager"
- class="org.apache.pluto.driver.services.impl.db.EmbeddedDataSourceManager"
+ class="org.apache.pluto.optional.db.support.EmbeddedDataSourceManager"
singleton="true">
</bean>
@@ -71,7 +71,7 @@
-->
<!--
<bean name="DataSourceManager"
- class="org.apache.pluto.driver.services.impl.db.JNDIDataSourceManager"
+ class="org.apache.pluto.optional.db.support.JNDIDataSourceManager"
singleton="true">
<constructor-arg><value>plutoDB</value></constructor-arg>
</bean>
Modified: portals/pluto/trunk/pom.xml
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pom.xml?rev=349020&r1=349019&r2=349020&view=diff
==============================================================================
--- portals/pluto/trunk/pom.xml (original)
+++ portals/pluto/trunk/pom.xml Fri Nov 25 12:25:31 2005
@@ -194,6 +194,7 @@
<module>pluto-ant-tasks</module>
<!-- ==== Misc ==== -->
<module>pluto-site</module>
+ <module>pluto-optional-services</module>
</modules>
<distributionManagement>