You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrp4j-dev@portals.apache.org by dl...@apache.org on 2006/12/23 23:52:20 UTC
svn commit: r489939 - in /portals/wsrp4j/trunk/persistence-db: ./ src/
src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/wsrp4j/
src/java/org/apache/wsrp4j/persistence/
src/java/org/apache/wsrp4j/persistence/db/ src/java/org/apache/wsrp4...
Author: dlouzan
Date: Sat Dec 23 14:52:19 2006
New Revision: 489939
URL: http://svn.apache.org/viewvc?view=rev&rev=489939
Log:
Initial version of persistence-db module
Added:
portals/wsrp4j/trunk/persistence-db/ (with props)
portals/wsrp4j/trunk/persistence-db/pom.xml
portals/wsrp4j/trunk/persistence-db/src/
portals/wsrp4j/trunk/persistence-db/src/java/
portals/wsrp4j/trunk/persistence-db/src/java/org/
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/PersistentDataObjectDB.java
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ConsumerConfiguredPortletList.java
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ConsumerPortletRegistrationList.java
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PersistentDataObjectImpl.java
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PersistentHandlerImpl.java
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PersistentInformationProviderImpl.java
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PortletDescriptionList.java
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ProducerPersistentFactoryImpl.java
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/RegistrationList.java
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ServiceDescriptionList.java
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/util/
portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/util/HibernateUtil.java
portals/wsrp4j/trunk/persistence-db/src/resources/
Propchange: portals/wsrp4j/trunk/persistence-db/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 23 14:52:19 2006
@@ -0,0 +1,2 @@
+catalog.xml
+target
Added: portals/wsrp4j/trunk/persistence-db/pom.xml
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/persistence-db/pom.xml?view=auto&rev=489939
==============================================================================
--- portals/wsrp4j/trunk/persistence-db/pom.xml (added)
+++ portals/wsrp4j/trunk/persistence-db/pom.xml Sat Dec 23 14:52:19 2006
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright 2003-2006 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.
+-->
+<!--+
+ | This is the main Maven file for wsrp4j-persistence-db
+ | @version $Id$
+ +-->
+<project>
+ <parent>
+ <artifactId>wsrp4j</artifactId>
+ <groupId>org.apache.wsrp4j</groupId>
+ <version>0.4-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>wsrp4j-persistence-db</artifactId>
+ <packaging>jar</packaging>
+ <name>WSRP4J Persistence-DB</name>
+ <description>
+ WSRP4J Persistence-DB provides a database persistence mechanism for
+ producers and consumers.
+ </description>
+ <build>
+ <sourceDirectory>src/java</sourceDirectory>
+ <resources>
+ <resource>
+ <filtering>false</filtering>
+ <directory>${basedir}/src/resources</directory>
+ </resource>
+ </resources>
+ </build>
+ <dependencies>
+ <dependency>
+ <artifactId>wsrp4j-commons-consumer</artifactId>
+ <groupId>org.apache.wsrp4j</groupId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <artifactId>wsrp4j-commons-producer</artifactId>
+ <groupId>org.apache.wsrp4j</groupId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <artifactId>hibernate</artifactId>
+ <groupId>org.hibernate</groupId>
+ <version>${hibernate.version}</version>
+ </dependency>
+ </dependencies>
+</project>
Added: portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/PersistentDataObjectDB.java
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/PersistentDataObjectDB.java?view=auto&rev=489939
==============================================================================
--- portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/PersistentDataObjectDB.java (added)
+++ portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/PersistentDataObjectDB.java Sat Dec 23 14:52:19 2006
@@ -0,0 +1,79 @@
+/**
+ * Copyright 2003-2006 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.wsrp4j.persistence.db;
+
+import org.hibernate.Session;
+
+import org.apache.wsrp4j.commons.exception.WSRPException;
+import org.apache.wsrp4j.commons.persistence.PersistentDataObject;
+
+
+/**
+ * This class is the basic persistence support for the PersistentDataObject
+ * implementations with DB support.
+ *
+ * @version $Id$
+ */
+public interface PersistentDataObjectDB extends PersistentDataObject {
+
+ /**
+ * Generic operation for loading an object state from DB
+ *
+ * @param pdo PersistentDataObject containing the object referencing
+ * the object to load
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void load(PersistentDataObject pdo, Session session)
+ throws WSRPException;
+
+ /**
+ * Generic operation for loading all available objects state from DB
+ *
+ * @param pdo PersistentDataObject used as a container for all the
+ * objects to load
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void loadAll(PersistentDataObject pdo, Session session)
+ throws WSRPException;
+
+ /**
+ * Generic operation for storing an object state to DB
+ *
+ * @param pdo PersistentDataObject containing the object to save
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void save(PersistentDataObject pdo, Session session)
+ throws WSRPException;
+
+ /**
+ * Generic operation for deleting an object state from DB
+ *
+ * @param pdo PersistentDataObject containing an object referencing
+ * to the object to delete
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void delete(PersistentDataObject pdo, Session session)
+ throws WSRPException;
+
+}
Added: portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ConsumerConfiguredPortletList.java
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ConsumerConfiguredPortletList.java?view=auto&rev=489939
==============================================================================
--- portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ConsumerConfiguredPortletList.java (added)
+++ portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ConsumerConfiguredPortletList.java Sat Dec 23 14:52:19 2006
@@ -0,0 +1,133 @@
+/**
+ * Copyright 2003-2006 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.wsrp4j.persistence.db.driver;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.hibernate.Session;
+
+import org.apache.wsrp4j.commons.producer.provider.driver.ConsumerConfiguredPortletImpl;
+
+import org.apache.wsrp4j.commons.exception.WSRPException;
+
+import org.apache.wsrp4j.commons.persistence.PersistentDataObject;
+
+
+/**
+ * This class collects
+ * org.apache.wsrp4j.commons.producer.provider.driver.ConsumerConfiguredPortletImpl
+ * objects and uses Hibernate for persistence support.
+ *
+ * @version $Id$
+ */
+public class ConsumerConfiguredPortletList extends PersistentDataObjectImpl {
+
+ /**
+ * Loads a concrete ConsumerConfiguredPortletImpl object from the db
+ *
+ * @param pdo PersistentDataObject containing the object referencing
+ * the object to load
+ * @param session Hibernate Session
+ *
+ * @throws WSRPException
+ */
+ public void load(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Cast the pdo last element to the expected type and get the key */
+ ConsumerConfiguredPortletImpl ccp =
+ (ConsumerConfiguredPortletImpl) pdo.getLastElement();
+ String key = ccp.getPortletHandle();
+
+ /* Load the object */
+ ConsumerConfiguredPortletImpl loadedCcp =
+ (ConsumerConfiguredPortletImpl) session.load(
+ ConsumerConfiguredPortletImpl.class, key);
+
+ /* Store the object on the pdo */
+ pdo.clear();
+ pdo.addObject(loadedCcp);
+
+ }
+
+ /**
+ * Loads all ConsumerConfiguredPortletImpl objects from the db
+ *
+ * @param pdo PersistentDataObject used as a container for all the
+ * objects to load
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void loadAll(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Load all objects from db */
+ List result = session.createQuery("from ConsumerConfiguredPortletImpl").list();
+
+ /* Clear the pdo, iterate over results and add them to the pdo */
+ pdo.clear();
+ for (Iterator iter=result.iterator(); iter.hasNext(); ) {
+ ConsumerConfiguredPortletImpl ccp =
+ (ConsumerConfiguredPortletImpl) iter.next();
+ pdo.addObject(ccp);
+ }
+
+ }
+
+ /**
+ * Stores a concrete ConsumerConfiguredPortletImpl object to the db
+ *
+ * @param pdo PersistentDataObject containing the object to save
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void save(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Cast the pdo to the expected type */
+ ConsumerConfiguredPortletImpl ccp =
+ (ConsumerConfiguredPortletImpl) pdo.getLastElement();
+
+ /* Save the object to the db */
+ session.save(ccp);
+
+ }
+
+ /**
+ * Deletes a concrete ConsumerConfiguredPortletImpl object from the db
+ *
+ * @param pdo PersistentDataObject containing an object referencing
+ * to the object to delete
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void delete(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Cast the pdo to the expected type */
+ ConsumerConfiguredPortletImpl ccp =
+ (ConsumerConfiguredPortletImpl) pdo.getLastElement();
+
+ /* Delete the object from the db */
+ session.delete(ccp);
+
+ }
+
+}
\ No newline at end of file
Added: portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ConsumerPortletRegistrationList.java
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ConsumerPortletRegistrationList.java?view=auto&rev=489939
==============================================================================
--- portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ConsumerPortletRegistrationList.java (added)
+++ portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ConsumerPortletRegistrationList.java Sat Dec 23 14:52:19 2006
@@ -0,0 +1,133 @@
+/**
+ * Copyright 2003-2006 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.wsrp4j.persistence.db.driver;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.hibernate.Session;
+
+import org.apache.wsrp4j.commons.producer.provider.driver.ConsumerPortletRegistrationImpl;
+
+import org.apache.wsrp4j.commons.exception.WSRPException;
+
+import org.apache.wsrp4j.commons.persistence.PersistentDataObject;
+
+
+/**
+ * This class collects
+ * org.apache.wsrp4j.commons.producer.driver.ConsumerPortletRegistrationImpl
+ * objects and uses Hibernate for persistence support.
+ *
+ * @version $Id$
+ */
+public class ConsumerPortletRegistrationList extends PersistentDataObjectImpl {
+
+ /**
+ * Loads a concrete ConsumerPortletRegistrationImpl object from the db
+ *
+ * @param pdo PersistentDataObject containing the object referencing
+ * the object to load
+ * @param session Hibernate Session
+ *
+ * @throws WSRPException
+ */
+ public void load(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Cast the pdo last element to the expected type and get the key */
+ ConsumerPortletRegistrationImpl cpr =
+ (ConsumerPortletRegistrationImpl) pdo.getLastElement();
+ String key = cpr.getRegistrationHandle();
+
+ /* Load the object */
+ ConsumerPortletRegistrationImpl loadedCpr =
+ (ConsumerPortletRegistrationImpl) session.load(
+ ConsumerPortletRegistrationImpl.class, key);
+
+ /* Store the object on the pdo */
+ pdo.clear();
+ pdo.addObject(loadedCpr);
+
+ }
+
+ /**
+ * Loads all ConsumerPortletRegistrationImpl objects from the db
+ *
+ * @param pdo PersistentDataObject used as a container for all the
+ * objects to load
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void loadAll(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Load all objects from db */
+ List result = session.createQuery("from ConsumerPortletRegistrationImpl").list();
+
+ /* Clear the pdo, iterate over results and add them to the pdo */
+ pdo.clear();
+ for (Iterator iter=result.iterator(); iter.hasNext(); ) {
+ ConsumerPortletRegistrationImpl cpr =
+ (ConsumerPortletRegistrationImpl) iter.next();
+ pdo.addObject(cpr);
+ }
+
+ }
+
+ /**
+ * Stores a concrete ConsumerPortletRegistrationImpl object to the db
+ *
+ * @param pdo PersistentDataObject containing the object to save
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void save(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Cast the pdo to the expected type */
+ ConsumerPortletRegistrationImpl cpr =
+ (ConsumerPortletRegistrationImpl) pdo.getLastElement();
+
+ /* Save the object to the db */
+ session.save(cpr);
+
+ }
+
+ /**
+ * Deletes a concrete ConsumerPortletRegistrationImpl object from the db
+ *
+ * @param pdo PersistentDataObject containing an object referencing
+ * to the object to delete
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void delete(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Cast the pdo to the expected type */
+ ConsumerPortletRegistrationImpl cpr =
+ (ConsumerPortletRegistrationImpl) pdo.getLastElement();
+
+ /* Delete the object from the db */
+ session.delete(cpr);
+
+ }
+
+}
Added: portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PersistentDataObjectImpl.java
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PersistentDataObjectImpl.java?view=auto&rev=489939
==============================================================================
--- portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PersistentDataObjectImpl.java (added)
+++ portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PersistentDataObjectImpl.java Sat Dec 23 14:52:19 2006
@@ -0,0 +1,153 @@
+/**
+ * Copyright 2003-2006 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.wsrp4j.persistence.db.driver;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.hibernate.Session;
+
+import org.apache.wsrp4j.commons.exception.WSRPException;
+
+import org.apache.wsrp4j.commons.persistence.PersistentDataObject;
+import org.apache.wsrp4j.commons.persistence.PersistentInformation;
+
+import org.apache.wsrp4j.persistence.db.PersistentDataObjectDB;
+
+
+/**
+ * Abstract class that implements the basic functionality needed for a
+ * PersistentDataObjectDB.
+ *
+ * @version $Id$
+ */
+public abstract class PersistentDataObjectImpl
+ implements PersistentDataObjectDB {
+
+ /* The persistent information object */
+ private PersistentInformation _persistentInfo;
+
+ /* List of objects stored in the data object */
+ protected ArrayList _objects = new ArrayList();
+
+ /* The last element added to the list */
+ protected Object _lastElement = null;
+
+ /**
+ * Return the persistent information for this data object.
+ *
+ * @return PersistentInformation
+ */
+ public PersistentInformation getPersistentInformation() {
+ return _persistentInfo;
+ }
+
+ /**
+ * Set the persistent information for this data object.
+ *
+ * @param persistentInfo The persistent information for this data
+ * object
+ */
+ public void setPersistentInformation(PersistentInformation persistentInfo) {
+ this._persistentInfo = persistentInfo;
+ }
+
+ /**
+ * Clear the object list stored by this data object.
+ */
+ public void clear() {
+ _objects.clear();
+ _lastElement = null;
+ }
+
+ /**
+ * Returns an iterator over the objects stored by this data object
+ *
+ * @return Iterator An iterator over the objects stored
+ */
+ public Iterator getObjects() {
+ return _objects.iterator();
+ }
+
+ /**
+ * Adds and object to the objects stored by this data object
+ *
+ * @param object An Object to store
+ */
+ public void addObject(Object object) {
+ _objects.add(object);
+ _lastElement = object;
+ }
+
+ /**
+ * Returns the last element stored by this data object, or null
+ * if there's not such element.
+ *
+ * @return Object The last object stored by this data object
+ */
+ public Object getLastElement() {
+ return _lastElement;
+ }
+
+ /**
+ * Generic load method to be implemented by concrete classes.
+ *
+ * @param pdo PersistentDataObject containing the object referencing
+ * the object to load
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public abstract void load(PersistentDataObject pdo, Session session)
+ throws WSRPException;
+
+ /**
+ * Generic load all available method to be implemented by concrete
+ * classes.
+ *
+ * @param pdo PersistentDataObject used as a container for all the
+ * objects to load
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public abstract void loadAll(PersistentDataObject pdo, Session session)
+ throws WSRPException;
+
+ /**
+ * Generic store method to be implemented by concrete classes.
+ *
+ * @param pdo PersistentDataObject containing the object to save
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public abstract void save(PersistentDataObject pdo, Session session)
+ throws WSRPException;
+
+ /**
+ * Generic delete method to be implemented by concrete classes.
+ *
+ * @param pdo PersistentDataObject containing an object referencing
+ * to the object to delete
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public abstract void delete(PersistentDataObject pdo, Session session)
+ throws WSRPException;
+
+}
Added: portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PersistentHandlerImpl.java
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PersistentHandlerImpl.java?view=auto&rev=489939
==============================================================================
--- portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PersistentHandlerImpl.java (added)
+++ portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PersistentHandlerImpl.java Sat Dec 23 14:52:19 2006
@@ -0,0 +1,259 @@
+/**
+ * Copyright 2003-2006 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.wsrp4j.persistence.db.driver;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.hibernate.Session;
+
+import org.apache.wsrp4j.commons.exception.ErrorCodes;
+import org.apache.wsrp4j.commons.exception.WSRPException;
+import org.apache.wsrp4j.commons.exception.WSRPXHelper;
+
+import org.apache.wsrp4j.commons.persistence.PersistentDataObject;
+import org.apache.wsrp4j.commons.persistence.PersistentHandler;
+
+import org.apache.wsrp4j.commons.util.Utility;
+
+import org.apache.wsrp4j.persistence.db.PersistentDataObjectDB;
+import org.apache.wsrp4j.persistence.db.driver.util.HibernateUtil;
+
+
+/**
+ * This class serves the store, restore and delete functionality for
+ * PersistentDataObjectDB objects.
+ *
+ * @version $Id$
+ */
+public class PersistentHandlerImpl implements PersistentHandler {
+
+ /* The log instance */
+ private static final Log log = LogFactory.getLog(PersistentHandlerImpl.class);
+
+ /* The instance of this class for Singleton pattern */
+ private static PersistentHandler _instance = null;
+
+ /**
+ * Private constructor for Singleton pattern.
+ */
+ private PersistentHandlerImpl() {}
+
+ /**
+ * Gets the Singleton instance of this class.
+ *
+ * @return PersistentHandler The Singleton instance
+ */
+ public static PersistentHandler getInstance() {
+ if (_instance == null) {
+ _instance = new PersistentHandlerImpl();
+ }
+ return _instance;
+ }
+
+ /**
+ * Takes a PersistentDataObjectDB and restores an object from the DB
+ * persistent store. It is expected that the last element in the pdo
+ * is an object that is used to obtain the key of the object to restorate.
+ *
+ * @param persistentDataObject The PersistentDataObject used for restoring
+ *
+ * @throws WSRPException
+ */
+ public PersistentDataObject restore(
+ PersistentDataObject persistentDataObject)
+ throws WSRPException {
+
+ String MN = "restore";
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strEnter(MN));
+ }
+
+ /* Get the current session */
+ Session session = HibernateUtil.getSessionFactory().getCurrentSession();
+
+ try {
+
+ /* Start the transaction */
+ session.beginTransaction();
+
+ /* Load object from the DB */
+ PersistentDataObjectDB pdoDB =
+ (PersistentDataObjectDB) persistentDataObject;
+ pdoDB.load(pdoDB, session);
+
+ /* Commit the transaction */
+ session.getTransaction().commit();
+
+ } catch (Exception e) {
+ /* Rollback the operation */
+ session.getTransaction().rollback();
+ /* Throw the exception */
+ WSRPXHelper.throwX(log, ErrorCodes.RESTORE_OBJECT_ERROR, e);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strExit(MN));
+ }
+
+ return persistentDataObject;
+
+ }
+
+ /**
+ * Takes a PersistentDataObjectDB and restores multiple objects from
+ * the DB persistent store. The pdo is used as a container for all the
+ * restored objects.
+ *
+ * @param persistentDataObject The PersistentDataObject used for restoring
+ *
+ * @throws WSRPException
+ */
+ public PersistentDataObject restoreMultiple(
+ PersistentDataObject persistentDataObject)
+ throws WSRPException {
+
+ String MN = "restoreMultiple";
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strEnter(MN));
+ }
+
+ /* Get the current session */
+ Session session = HibernateUtil.getSessionFactory().getCurrentSession();
+
+ try {
+
+ /* Start the transaction */
+ session.beginTransaction();
+
+ /* Load all objects from the DB */
+ PersistentDataObjectDB pdoDB =
+ (PersistentDataObjectDB) persistentDataObject;
+ pdoDB.loadAll(pdoDB, session);
+
+ /* Commit the transaction */
+ session.getTransaction().commit();
+
+ } catch (Exception e) {
+ /* Rollback the operation */
+ session.getTransaction().rollback();
+ /* Throw the exception */
+ WSRPXHelper.throwX(log, ErrorCodes.RESTORE_OBJECT_ERROR, e);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strExit(MN));
+ }
+
+ return persistentDataObject;
+
+ }
+
+ /**
+ * Takes a PersistentDataObjectDB and stores its state to the DB
+ * persistent store. It is expected that the object to store is the last
+ * element of the pdo.
+ *
+ * @param persistentDataObject The PersistentDataObject used for storing
+ *
+ * @throws WSRPException
+ */
+ public void store(PersistentDataObject persistentDataObject)
+ throws WSRPException {
+
+ String MN = "store";
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strEnter(MN));
+ }
+
+ /* Get the current session */
+ Session session = HibernateUtil.getSessionFactory().getCurrentSession();
+
+ try {
+
+ /* Start the transaction */
+ session = HibernateUtil.getSessionFactory().getCurrentSession();
+ session.beginTransaction();
+
+ /* Store object to the DB */
+ PersistentDataObjectDB pdoDB =
+ (PersistentDataObjectDB) persistentDataObject;
+ pdoDB.save(pdoDB, session);
+
+ /* Commit the transaction */
+ session.getTransaction().commit();
+
+ } catch (Exception e) {
+ /* Rollback the operation */
+ session.getTransaction().rollback();
+ /* Throw the exception */
+ WSRPXHelper.throwX(log, ErrorCodes.RESTORE_OBJECT_ERROR, e);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strExit(MN));
+ }
+
+ }
+
+ /**
+ * Takes a PersistentDataObjectDB and deletes its state from the DB
+ * persistent store. It is expected that the object to delete is the last
+ * object contained in the pdo.
+ *
+ * @param persistentDataObject The PersistentDataObject used for deleting
+ *
+ * @throws WSRPException
+ */
+ public void delete(PersistentDataObject persistentDataObject)
+ throws WSRPException {
+
+ String MN = "delete";
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strEnter(MN));
+ }
+
+ /* Get the current session */
+ Session session = HibernateUtil.getSessionFactory().getCurrentSession();
+
+ try {
+
+ /* Start the transaction */
+ session = HibernateUtil.getSessionFactory().getCurrentSession();
+ session.beginTransaction();
+
+ /* Delete object from the DB */
+ PersistentDataObjectDB pdoDB =
+ (PersistentDataObjectDB) persistentDataObject;
+ pdoDB.delete(pdoDB, session);
+
+ /* Commit the transaction */
+ session.getTransaction().commit();
+
+ } catch (Exception e) {
+ /* Rollback the operation */
+ session.getTransaction().rollback();
+ /* Throw the exception */
+ WSRPXHelper.throwX(log, ErrorCodes.RESTORE_OBJECT_ERROR, e);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strExit(MN));
+ }
+
+ }
+
+}
Added: portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PersistentInformationProviderImpl.java
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PersistentInformationProviderImpl.java?view=auto&rev=489939
==============================================================================
--- portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PersistentInformationProviderImpl.java (added)
+++ portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PersistentInformationProviderImpl.java Sat Dec 23 14:52:19 2006
@@ -0,0 +1,41 @@
+/**
+ * Copyright 2003-2006 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.wsrp4j.persistence.db.driver;
+
+import org.apache.wsrp4j.commons.persistence.PersistentInformationProvider;
+
+
+/**
+ * This class is provided for completeness as it is not used in
+ * Hibernate DB implementation.
+ *
+ * @version $Id$
+ */
+public class PersistentInformationProviderImpl
+ implements PersistentInformationProvider {
+
+ /* The singleton instance */
+ private static PersistentInformationProviderImpl _instance;
+
+ /* Returns the singleton instance */
+ public static PersistentInformationProvider getInstance() {
+ if (_instance == null) {
+ _instance = new PersistentInformationProviderImpl();
+ }
+ return _instance;
+ }
+
+}
Added: portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PortletDescriptionList.java
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PortletDescriptionList.java?view=auto&rev=489939
==============================================================================
--- portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PortletDescriptionList.java (added)
+++ portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/PortletDescriptionList.java Sat Dec 23 14:52:19 2006
@@ -0,0 +1,131 @@
+/**
+ * Copyright 2003-2006 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.wsrp4j.persistence.db.driver;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.hibernate.Session;
+
+import oasis.names.tc.wsrp.v1.types.PortletDescription;
+
+import org.apache.wsrp4j.commons.exception.WSRPException;
+
+import org.apache.wsrp4j.commons.persistence.PersistentDataObject;
+
+
+/**
+ * This class collects
+ * oasis.names.tc.wsrp.v1.types.PortletDescription objects and
+ * uses Hibernate for persistence support.
+ *
+ * @version $Id$
+ */
+public class PortletDescriptionList extends PersistentDataObjectImpl {
+
+ /**
+ * Loads a concrete PortletDescription object from the db
+ *
+ * @param pdo PersistentDataObject containing the object referencing
+ * the object to load
+ * @param session Hibernate Session
+ *
+ * @throws WSRPException
+ */
+ public void load(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Cast the pdo last element to the expected type and get the key */
+ PortletDescription description =
+ (PortletDescription) pdo.getLastElement();
+ String key = description.getPortletHandle();
+
+ /* Load the object */
+ PortletDescription loadedDescription =
+ (PortletDescription) session.load(PortletDescription.class, key);
+
+ /* Store the object on the pdo */
+ pdo.clear();
+ pdo.addObject(loadedDescription);
+
+ }
+
+ /**
+ * Loads all PortletDescription objects from the db
+ *
+ * @param pdo PersistentDataObject used as a container for all the
+ * objects to load
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void loadAll(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Load all objects from db */
+ List result = session.createQuery("from PortletDescription").list();
+
+ /* Clear the pdo, iterate over results and add them to the pdo */
+ pdo.clear();
+ for (Iterator iter=result.iterator(); iter.hasNext(); ) {
+ PortletDescription description = (PortletDescription) iter.next();
+ pdo.addObject(description);
+ }
+
+ }
+
+ /**
+ * Stores a concrete PortletDescription object to the db
+ *
+ * @param pdo PersistentDataObject containing the object to save
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void save(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Cast the pdo to the expected type */
+ PortletDescription description =
+ (PortletDescription) pdo.getLastElement();
+
+ /* Save the object to the db */
+ session.save(description);
+
+ }
+
+ /**
+ * Deletes a concrete PortletDescription object from the db
+ *
+ * @param pdo PersistentDataObject containing an object referencing
+ * to the object to delete
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void delete(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Cast the pdo to the expected type */
+ PortletDescription description =
+ (PortletDescription) pdo.getLastElement();
+
+ /* Delete the object from the db */
+ session.delete(description);
+
+ }
+
+}
Added: portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ProducerPersistentFactoryImpl.java
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ProducerPersistentFactoryImpl.java?view=auto&rev=489939
==============================================================================
--- portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ProducerPersistentFactoryImpl.java (added)
+++ portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ProducerPersistentFactoryImpl.java Sat Dec 23 14:52:19 2006
@@ -0,0 +1,207 @@
+/**
+ * Copyright 2003-2006 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.wsrp4j.persistence.db.driver;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.wsrp4j.commons.exception.ErrorCodes;
+import org.apache.wsrp4j.commons.exception.WSRPException;
+import org.apache.wsrp4j.commons.exception.WSRPXHelper;
+
+import org.apache.wsrp4j.commons.persistence.PersistentDataObject;
+import org.apache.wsrp4j.commons.persistence.PersistentHandler;
+import org.apache.wsrp4j.commons.persistence.PersistentInformationProvider;
+import org.apache.wsrp4j.commons.persistence.ProducerPersistentFactory;
+
+import org.apache.wsrp4j.commons.util.Utility;
+
+
+/**
+ * Server factory implementation for the persistence support.
+ *
+ * @version $Id$
+ */
+public class ProducerPersistentFactoryImpl implements ProducerPersistentFactory {
+
+ /* The log instance */
+ private static final Log log =
+ LogFactory.getLog(ProducerPersistentFactoryImpl.class);
+
+ /**
+ * Returns the PersistentHandler for this factory
+ *
+ * @return PersistentHandler The persistent handler for this producer factory
+ */
+ public PersistentHandler getPersistentHandler() {
+ return PersistentHandlerImpl.getInstance();
+ }
+
+ /**
+ * Returns the PersistentInformationProvider for this factory
+ *
+ * @return PersistentInformationProvider The provider for this producer factory
+ */
+ public PersistentInformationProvider getPersistentInformationProvider() {
+ return PersistentInformationProviderImpl.getInstance();
+ }
+
+ /**
+ * Returns a PersistentDataObject for a list of Registration objects
+ */
+ public PersistentDataObject getRegistrationList() throws WSRPException {
+
+ String MN = "getRegistrationList";
+
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strEnter(MN));
+ }
+
+ RegistrationList pdo = null;
+
+ try {
+
+ pdo = new RegistrationList();
+
+ } catch (Exception e) {
+ /* Error while accesing DB */
+ WSRPXHelper.throwX(log, ErrorCodes.DB_ERROR, e);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strExit(MN));
+ }
+
+ return pdo;
+ }
+
+ /**
+ * Returns a PersistentDataObject for a list of ConsumerConfiguredPortlet objects
+ */
+ public PersistentDataObject getConsumerConfiguredPortletList() throws WSRPException {
+
+ String MN = "getConsumerConfiguredPortletList";
+
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strEnter(MN));
+ }
+
+ ConsumerConfiguredPortletList pdo = null;
+
+ try {
+
+ pdo = new ConsumerConfiguredPortletList();
+
+ } catch (Exception e) {
+ /* Error while accesing DB */
+ WSRPXHelper.throwX(log, ErrorCodes.DB_ERROR, e);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strExit(MN));
+ }
+
+ return pdo;
+ }
+
+ /**
+ * Returns a PersistentDataObject for a list of PortletDescription objects
+ */
+ public PersistentDataObject getPortletDescriptionList() throws WSRPException {
+
+ String MN = "getPortletDescriptionList";
+
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strEnter(MN));
+ }
+
+ PortletDescriptionList pdo = null;
+
+ try {
+
+ pdo = new PortletDescriptionList();
+
+ } catch (Exception e) {
+ /* Error while accesing DB */
+ WSRPXHelper.throwX(log, ErrorCodes.DB_ERROR, e);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strExit(MN));
+ }
+
+ return pdo;
+ }
+
+ /**
+ * Returns a PersistentDataObject for a list of ServiceDescription objects
+ */
+ public PersistentDataObject getServiceDescriptionList() throws WSRPException {
+
+ String MN = "getServiceDescriptionList";
+
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strEnter(MN));
+ }
+
+ ServiceDescriptionList pdo = null;
+
+ try {
+
+ pdo = new ServiceDescriptionList();
+
+ } catch (Exception e) {
+ /* Error while accesing DB */
+ WSRPXHelper.throwX(log, ErrorCodes.DB_ERROR, e);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strExit(MN));
+ }
+
+ return pdo;
+ }
+
+ /**
+ * Returns a PersistentDataObject for a list of ConsumerPortletRegistration objects
+ */
+ public PersistentDataObject getConsumerPortletRegistrationList() throws WSRPException {
+
+ String MN = "getConsumerPortletRegistrationList";
+
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strEnter(MN));
+ }
+
+ ConsumerPortletRegistrationList pdo = null;
+
+ try {
+
+ pdo = new ConsumerPortletRegistrationList();
+
+ } catch (Exception e) {
+ /* Error while accesing DB */
+ WSRPXHelper.throwX(log, ErrorCodes.DB_ERROR, e);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug(Utility.strExit(MN));
+ }
+
+ return pdo;
+ }
+
+}
Added: portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/RegistrationList.java
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/RegistrationList.java?view=auto&rev=489939
==============================================================================
--- portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/RegistrationList.java (added)
+++ portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/RegistrationList.java Sat Dec 23 14:52:19 2006
@@ -0,0 +1,130 @@
+/**
+ * Copyright 2003-2006 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.wsrp4j.persistence.db.driver;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.hibernate.Session;
+
+import oasis.names.tc.wsrp.v1.types.RegistrationContext;
+
+import org.apache.wsrp4j.commons.producer.driver.RegistrationImpl;
+
+import org.apache.wsrp4j.commons.exception.WSRPException;
+
+import org.apache.wsrp4j.commons.persistence.PersistentDataObject;
+
+
+/**
+ * This class collects
+ * org.apache.wsrp4j.commons.producer.driver.RegistrationImpl objects and
+ * uses Hibernate for persistence support.
+ *
+ * @version $Id$
+ */
+public class RegistrationList extends PersistentDataObjectImpl {
+
+ /**
+ * Loads a concrete RegistrationImpl object from the db
+ *
+ * @param pdo PersistentDataObject containing the object referencing
+ * the object to load
+ * @param session Hibernate Session
+ *
+ * @throws WSRPException
+ */
+ public void load(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Cast the pdo last element to the expected type and get the key */
+ RegistrationImpl registration = (RegistrationImpl) pdo.getLastElement();
+ RegistrationContext key = registration.getRegistrationContext();
+
+ /* Load the object */
+ RegistrationImpl loadedRegistration =
+ (RegistrationImpl) session.load(RegistrationImpl.class, key);
+
+ /* Store the object on the pdo */
+ pdo.clear();
+ pdo.addObject(loadedRegistration);
+
+ }
+
+ /**
+ * Loads all RegistrationImpl objects from the db
+ *
+ * @param pdo PersistentDataObject used as a container for all the
+ * objects to load
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void loadAll(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Load all objects from db */
+ List result = session.createQuery("from RegistrationImpl").list();
+
+ /* Clear the pdo, iterate over results and add them to the pdo */
+ pdo.clear();
+ for (Iterator iter=result.iterator(); iter.hasNext(); ) {
+ RegistrationImpl registration = (RegistrationImpl) iter.next();
+ pdo.addObject(registration);
+ }
+
+ }
+
+ /**
+ * Stores a concrete RegistrationImpl object to the db
+ *
+ * @param pdo PersistentDataObject containing the object to save
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void save(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Cast the pdo to the expected type */
+ RegistrationImpl registration = (RegistrationImpl) pdo.getLastElement();
+
+ /* Save the object to the db */
+ session.save(registration);
+
+ }
+
+ /**
+ * Deletes a concrete RegistrationImpl object from the db
+ *
+ * @param pdo PersistentDataObject containing an object referencing
+ * to the object to delete
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void delete(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Cast the pdo to the expected type */
+ RegistrationImpl registration = (RegistrationImpl) pdo.getLastElement();
+
+ /* Delete the object from the db */
+ session.delete(registration);
+
+ }
+
+}
Added: portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ServiceDescriptionList.java
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ServiceDescriptionList.java?view=auto&rev=489939
==============================================================================
--- portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ServiceDescriptionList.java (added)
+++ portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/ServiceDescriptionList.java Sat Dec 23 14:52:19 2006
@@ -0,0 +1,133 @@
+/**
+ * Copyright 2003-2006 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.wsrp4j.persistence.db.driver;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.hibernate.Session;
+
+import org.apache.wsrp4j.commons.persistence.driver.WSRPServiceDescription;
+
+import org.apache.wsrp4j.commons.exception.WSRPException;
+
+import org.apache.wsrp4j.commons.persistence.PersistentDataObject;
+
+
+/**
+ * This class collects
+ * org.apache.wsrp4j.commons.persistence.driver.WSRPServiceDescription
+ * objects and uses Hibernate for persistence support.
+ *
+ * @version $Id$
+ */
+public class ServiceDescriptionList extends PersistentDataObjectImpl {
+
+ /**
+ * Loads a concrete WSRPServiceDescription object from the db
+ *
+ * @param pdo PersistentDataObject containing the object referencing
+ * the object to load
+ * @param session Hibernate Session
+ *
+ * @throws WSRPException
+ */
+ public void load(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Cast the pdo last element to the expected type and get the key */
+ WSRPServiceDescription description =
+ (WSRPServiceDescription) pdo.getLastElement();
+ String key = description.getId();
+
+ /* Load the object */
+ WSRPServiceDescription loadedDescription =
+ (WSRPServiceDescription) session.load(
+ WSRPServiceDescription.class, key);
+
+ /* Store the object on the pdo */
+ pdo.clear();
+ pdo.addObject(loadedDescription);
+
+ }
+
+ /**
+ * Loads all WSRPServiceDescription objects from the db
+ *
+ * @param pdo PersistentDataObject used as a container for all the
+ * objects to load
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void loadAll(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Load all objects from db */
+ List result = session.createQuery("from WSRPServiceDescription").list();
+
+ /* Clear the pdo, iterate over results and add them to the pdo */
+ pdo.clear();
+ for (Iterator iter=result.iterator(); iter.hasNext(); ) {
+ WSRPServiceDescription description =
+ (WSRPServiceDescription) iter.next();
+ pdo.addObject(description);
+ }
+
+ }
+
+ /**
+ * Stores a concrete WSRPServiceDescription object to the db
+ *
+ * @param pdo PersistentDataObject containing the object to save
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void save(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Cast the pdo to the expected type */
+ WSRPServiceDescription description =
+ (WSRPServiceDescription) pdo.getLastElement();
+
+ /* Save the object to the db */
+ session.save(description);
+
+ }
+
+ /**
+ * Deletes a concrete ServiceDescription object from the db
+ *
+ * @param pdo PersistentDataObject containing an object referencing
+ * to the object to delete
+ * @param session Hibernate Session used for db access
+ *
+ * @throws WSRPException
+ */
+ public void delete(PersistentDataObject pdo, Session session)
+ throws WSRPException {
+
+ /* Cast the pdo to the expected type */
+ WSRPServiceDescription description =
+ (WSRPServiceDescription) pdo.getLastElement();
+
+ /* Delete the object from the db */
+ session.delete(description);
+
+ }
+
+}
Added: portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/util/HibernateUtil.java
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/util/HibernateUtil.java?view=auto&rev=489939
==============================================================================
--- portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/util/HibernateUtil.java (added)
+++ portals/wsrp4j/trunk/persistence-db/src/java/org/apache/wsrp4j/persistence/db/driver/util/HibernateUtil.java Sat Dec 23 14:52:19 2006
@@ -0,0 +1,65 @@
+/**
+ * Copyright 2003-2006 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.wsrp4j.persistence.db.driver.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+
+
+/**
+ * Utils class used for getting the Hibernate SessionFactory
+ */
+public class HibernateUtil {
+
+ /* Log instance */
+ private static final Log log = LogFactory.getLog(HibernateUtil.class);
+
+ /* The SessionFactory instance */
+ private static final SessionFactory _sessionFactory;
+
+ /* This static block initializes the SessionFactory */
+ static {
+ try {
+ if (log.isInfoEnabled()) {
+ log.info("Trying to create the Hibernate SessionFactory...");
+ }
+
+ _sessionFactory = new Configuration().configure().buildSessionFactory();
+
+ if (log.isInfoEnabled()) {
+ log.info("SessionFactory successfully created");
+ }
+ } catch (Throwable t) {
+ if (log.isErrorEnabled()) {
+ log.error("Initial SessionFactory creation failed", t);
+ }
+ throw new ExceptionInInitializerError(t);
+ }
+ }
+
+ /**
+ * Utility method for getting the Hibernate SessionFactory
+ *
+ * @return SessionFactory The configured Hibernate SessionFactory
+ */
+ public static SessionFactory getSessionFactory() {
+ return _sessionFactory;
+ }
+
+}