Commits

Anonymous committed 6621de3

Moved existing source into new layout.

git-svn-id: http://svn.opensymphony.com/svn/propertyset/branches/maven_build@208bf3cbcdd-1c1a-0410-9a68-d6f521e3fa7b

  • Participants
  • Parent commits 1d9f5a3

Comments (0)

Files changed (18)

providers/hibernate3/src/com/opensymphony/module/propertyset/hibernate3/DefaultHibernateConfigurationProvider.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.module.propertyset.hibernate3;
-
-import org.hibernate.HibernateException;
-import org.hibernate.SessionFactory;
-
-import org.hibernate.cfg.Configuration;
-
-import java.util.Iterator;
-import java.util.Map;
-
-
-/**
- * Created by IntelliJ IDEA.
- * User: Mike
- * Date: Jul 26, 2003
- * Time: 5:05:55 PM
- * To change this template use Options | File Templates.
- */
-public class DefaultHibernateConfigurationProvider implements HibernateConfigurationProvider {
-    //~ Instance fields ////////////////////////////////////////////////////////
-
-    private Configuration configuration;
-    private HibernatePropertySetDAO propertySetDAO;
-    private SessionFactory sessionFactory;
-
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    public void setConfiguration(Configuration configuration) {
-        this.configuration = configuration;
-    }
-
-    public Configuration getConfiguration() {
-        return configuration;
-    }
-
-    public HibernatePropertySetDAO getPropertySetDAO() {
-        if (propertySetDAO == null) {
-            propertySetDAO = new HibernatePropertySetDAOImpl(sessionFactory);
-        }
-
-        return propertySetDAO;
-    }
-
-    public void setSessionFactory(SessionFactory sessionFactory) {
-        this.sessionFactory = sessionFactory;
-    }
-
-    public void setupConfiguration(Map configurationProperties) {
-        // loaded hibernate config
-        try {
-            configuration = new Configuration().addClass(PropertySetItemImpl.class);
-
-            Iterator itr = configurationProperties.keySet().iterator();
-
-            while (itr.hasNext()) {
-                String key = (String) itr.next();
-
-                if (key.startsWith("hibernate3")) {
-                    configuration.setProperty(key, (String) configurationProperties.get(key));
-                }
-            }
-
-            this.sessionFactory = configuration.buildSessionFactory();
-        } catch (HibernateException e) {
-        }
-    }
-}

providers/hibernate3/src/com/opensymphony/module/propertyset/hibernate3/HibernateConfigurationProvider.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.module.propertyset.hibernate3;
-
-import org.hibernate.cfg.Configuration;
-
-import java.util.Map;
-
-
-/**
- * Use this class to provide your own configurations to the PropertySet hibernate providers.
- * <p>
- * Simply implement this interface and return a Hibernate Configuration object.
- * <p>
- * This is setup by using the configuration.provider.class property, with the classname
- * of your implementation.
- */
-public interface HibernateConfigurationProvider {
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    /**
-* Get a Hibernate configuration object
-*/
-    public Configuration getConfiguration();
-
-    HibernatePropertySetDAO getPropertySetDAO();
-
-    /**
-* Setup a Hibernate configuration object with the given properties.
-*
-* This will always be called before getConfiguration().
-*/
-    void setupConfiguration(Map properties);
-}

providers/hibernate3/src/com/opensymphony/module/propertyset/hibernate3/HibernatePropertySet.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.module.propertyset.hibernate3;
-
-import com.opensymphony.module.propertyset.AbstractPropertySet;
-import com.opensymphony.module.propertyset.PropertyException;
-import com.opensymphony.module.propertyset.PropertySet;
-
-import com.opensymphony.util.ClassLoaderUtil;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
-
-
-/**
- * This is the property set implementation for storing properties using Hibernate.
- * <p>
- *
- * <b>Required Args</b>
- * <ul>
- *  <li><b>entityId</b> - Long that holds the ID of this entity.</li>
- *  <li><b>entityName</b> - String that holds the name of this entity type</li>
- * </ul>
- *
- * if "<b>sessionFactory</b> - hibernate sessionFactory" is not passed as an arg then init will use: <br />
- *  <b>hibernate.*</b> - config params needed to create a hibernate sessionFactory in the propertyset config xml.
- * <br />
- * This can be any of the configs avail from hibernate.
- * <p>
- *
- * @author $Author: hani $
- * @version $Revision: 169 $
- */
-public class HibernatePropertySet extends AbstractPropertySet {
-    //~ Static fields/initializers /////////////////////////////////////////////
-
-    protected static Log log = LogFactory.getLog(HibernatePropertySet.class.getName());
-
-    //~ Instance fields ////////////////////////////////////////////////////////
-
-    private HibernateConfigurationProvider configProvider;
-    private Long entityId;
-    private String entityName;
-
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    public Collection getKeys(String prefix, int type) throws PropertyException {
-        return configProvider.getPropertySetDAO().getKeys(entityName, entityId, prefix, type);
-    }
-
-    public int getType(String key) throws PropertyException {
-        return findByKey(key).getType();
-    }
-
-    public boolean exists(String key) throws PropertyException {
-        try {
-            if (findByKey(key) != null) {
-                return true;
-            }
-
-            return false;
-        } catch (PropertyException e) {
-            return false;
-        }
-    }
-
-    public void init(Map config, Map args) {
-        super.init(config, args);
-        this.entityId = (Long) args.get("entityId");
-        this.entityName = (String) args.get("entityName");
-
-        // first let's see if we got given a configuration provider to use already
-        configProvider = (HibernateConfigurationProvider) args.get("configurationProvider");
-
-        if (configProvider == null) // if we did not get given one in the args, we need to set a config provider up
-         {
-            // lets see if we need to use a configurationProvider from a class
-            String configProviderClass = (String) config.get("configuration.provider.class");
-
-            if (configProviderClass != null) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Setting up property set provider of class: " + configProviderClass);
-                }
-
-                try {
-                    configProvider = (HibernateConfigurationProvider) ClassLoaderUtil.loadClass(configProviderClass, this.getClass()).newInstance();
-                } catch (Exception e) {
-                    log.error("Unable to load configuration provider class: " + configProviderClass, e);
-
-                    return;
-                }
-            } else {
-                if (log.isDebugEnabled()) {
-                    log.debug("Setting up property set with DefaultHibernateConfigurationProvider");
-                }
-
-                configProvider = new DefaultHibernateConfigurationProvider();
-            }
-
-            configProvider.setupConfiguration(config);
-        } else {
-            if (log.isDebugEnabled()) {
-                log.debug("Setting up property set with hibernate provider passed in args.");
-            }
-        }
-    }
-
-    public void remove(String key) throws PropertyException {
-        configProvider.getPropertySetDAO().remove(entityName, entityId, key);
-    }
-
-    public void remove() throws PropertyException {
-        configProvider.getPropertySetDAO().remove(entityName, entityId);
-    }
-
-    public boolean supportsType(int type) {
-        switch (type) {
-        case PropertySet.DATA:
-        case PropertySet.OBJECT:
-        case PropertySet.PROPERTIES:
-        case PropertySet.XML:
-            return false;
-        }
-
-        return true;
-    }
-
-    protected void setImpl(int type, String key, Object value) throws PropertyException {
-        PropertySetItem item = null;
-
-        boolean update = true;
-        item = configProvider.getPropertySetDAO().findByKey(entityName, entityId, key);
-
-        if (item == null) {
-            update = false;
-            item = configProvider.getPropertySetDAO().create(entityName, entityId.longValue(), key);
-        } else if (item.getType() != type) {
-            throw new PropertyException("Existing key '" + key + "' does not have matching type of " + type);
-        }
-
-        switch (type) {
-        case BOOLEAN:
-            item.setBooleanVal(((Boolean) value).booleanValue());
-
-            break;
-
-        case DOUBLE:
-            item.setDoubleVal(((Double) value).doubleValue());
-
-            break;
-
-        case STRING:
-        case TEXT:
-            item.setStringVal((String) value);
-
-            break;
-
-        case LONG:
-            item.setLongVal(((Long) value).longValue());
-
-            break;
-
-        case INT:
-            item.setIntVal(((Integer) value).intValue());
-
-            break;
-
-        case DATE:
-            item.setDateVal((Date) value);
-
-            break;
-
-        default:
-            throw new PropertyException("type " + type + " not supported");
-        }
-
-        item.setType(type);
-
-        configProvider.getPropertySetDAO().setImpl(item, update);
-    }
-
-    protected Object get(int type, String key) throws PropertyException {
-        PropertySetItem item = findByKey(key);
-
-        if (item == null) {
-            return null;
-        }
-
-        if (item.getType() != type) {
-            throw new PropertyException("key '" + key + "' does not have matching type of " + type);
-        }
-
-        switch (type) {
-        case BOOLEAN:
-            return new Boolean(item.getBooleanVal());
-
-        case DOUBLE:
-            return new Double(item.getDoubleVal());
-
-        case STRING:
-        case TEXT:
-            return item.getStringVal();
-
-        case LONG:
-            return new Long(item.getLongVal());
-
-        case INT:
-            return new Integer(item.getIntVal());
-
-        case DATE:
-            return item.getDateVal();
-        }
-
-        throw new PropertyException("type " + type + " not supported");
-    }
-
-    private PropertySetItem findByKey(String key) throws PropertyException {
-        return configProvider.getPropertySetDAO().findByKey(entityName, entityId, key);
-    }
-}

providers/hibernate3/src/com/opensymphony/module/propertyset/hibernate3/HibernatePropertySetDAO.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.module.propertyset.hibernate3;
-
-import java.util.Collection;
-
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision: 169 $
- */
-public interface HibernatePropertySetDAO {
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    /**
- * Save the implementation of a PropertySetItem.
- *
- * @param item
- * @param isUpdate Boolean indicating whether or not this item already exists
- */
-    void setImpl(PropertySetItem item, boolean isUpdate);
-
-    Collection getKeys(String entityName, Long entityId, String prefix, int type);
-
-    PropertySetItem create(String entityName, long entityId, String key);
-
-    PropertySetItem findByKey(String entityName, Long entityId, String key);
-
-    void remove(String entityName, Long entityId, String key);
-
-    void remove(String entityName, Long entityId);
-}

providers/hibernate3/src/com/opensymphony/module/propertyset/hibernate3/HibernatePropertySetDAOImpl.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.module.propertyset.hibernate3;
-
-import com.opensymphony.module.propertyset.PropertyException;
-
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-
-import java.util.*;
-
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision: 169 $
- */
-public class HibernatePropertySetDAOImpl implements HibernatePropertySetDAO {
-    //~ Instance fields ////////////////////////////////////////////////////////
-
-    private SessionFactory sessionFactory;
-
-    //~ Constructors ///////////////////////////////////////////////////////////
-
-    public HibernatePropertySetDAOImpl(SessionFactory sessionFactory) {
-        this.sessionFactory = sessionFactory;
-    }
-
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    public void setImpl(PropertySetItem item, boolean isUpdate) {
-        Session session = null;
-
-        try {
-            session = this.sessionFactory.openSession();
-
-            if (isUpdate) {
-                session.update(item);
-            } else {
-                session.save(item);
-            }
-
-            session.flush();
-        } catch (HibernateException he) {
-            throw new PropertyException("Could not save key '" + item.getKey() + "':" + he.getMessage());
-        } finally {
-            try {
-                if (session != null) {
-                    if (!session.connection().getAutoCommit()) {
-                        session.connection().commit();
-                    }
-
-                    session.close();
-                }
-            } catch (Exception e) {
-            }
-        }
-    }
-
-    public Collection getKeys(String entityName, Long entityId, String prefix, int type) {
-        Session session = null;
-        List list = null;
-
-        try {
-            session = this.sessionFactory.openSession();
-            list = HibernatePropertySetDAOUtils.getKeysImpl(session, entityName, entityId, prefix, type);
-        } catch (HibernateException e) {
-            list = Collections.EMPTY_LIST;
-        } finally {
-            try {
-                if (session != null) {
-                    session.flush();
-                    session.close();
-                }
-            } catch (Exception e) {
-            }
-        }
-
-        return list;
-    }
-
-    public PropertySetItem create(String entityName, long entityId, String key) {
-        return new PropertySetItemImpl(entityName, entityId, key);
-    }
-
-    public PropertySetItem findByKey(String entityName, Long entityId, String key) {
-        Session session = null;
-        PropertySetItem item = null;
-
-        try {
-            session = this.sessionFactory.openSession();
-            item = HibernatePropertySetDAOUtils.getItem(session, entityName, entityId, key);
-            session.flush();
-        } catch (HibernateException e) {
-            return null;
-        } finally {
-            try {
-                if (session != null) {
-                    session.close();
-                }
-            } catch (Exception e) {
-            }
-        }
-
-        return item;
-    }
-
-    public void remove(String entityName, Long entityId) {
-        Session session = null;
-
-        try {
-            session = this.sessionFactory.openSession();
-
-            //hani: todo this needs to be optimised rather badly, but I have no idea how
-            Collection keys = getKeys(entityName, entityId, null, 0);
-            Iterator iter = keys.iterator();
-
-            while (iter.hasNext()) {
-                String key = (String) iter.next();
-                session.delete(HibernatePropertySetDAOUtils.getItem(session, entityName, entityId, key));
-            }
-
-            session.flush();
-        } catch (HibernateException e) {
-            throw new PropertyException("Could not remove all keys: " + e.getMessage());
-        } finally {
-            try {
-                if (session != null) {
-                    if (!session.connection().getAutoCommit()) {
-                        session.connection().commit();
-                    }
-
-                    session.close();
-                }
-            } catch (Exception e) {
-            }
-        }
-    }
-
-    public void remove(String entityName, Long entityId, String key) {
-        Session session = null;
-
-        try {
-            session = this.sessionFactory.openSession();
-            session.delete(HibernatePropertySetDAOUtils.getItem(session, entityName, entityId, key));
-            session.flush();
-        } catch (HibernateException e) {
-            throw new PropertyException("Could not remove key '" + key + "': " + e.getMessage());
-        } finally {
-            try {
-                if (session != null) {
-                    if (!session.connection().getAutoCommit()) {
-                        session.connection().commit();
-                    }
-
-                    session.close();
-                }
-            } catch (Exception e) {
-            }
-        }
-    }
-}

providers/hibernate3/src/com/opensymphony/module/propertyset/hibernate3/HibernatePropertySetDAOUtils.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.module.propertyset.hibernate3;
-
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.Session;
-
-import java.util.List;
-
-
-/**
- * Created by IntelliJ IDEA. User: Mike Date: Jul 26, 2003 Time: 5:46:58 PM
- */
-public class HibernatePropertySetDAOUtils {
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    // ~ Methods
-    // ////////////////////////////////////////////////////////////////
-    public static PropertySetItem getItem(Session session, String entityName, Long entityId, String key) throws HibernateException {
-        return (PropertySetItem) session.load(PropertySetItemImpl.class, new PropertySetItemImpl(entityName, entityId.longValue(), key));
-    }
-
-    /**
- * This is the body of the getKeys() method, so that you can reuse it
- * wrapped by your own session management.
- */
-    public static List getKeysImpl(Session session, String entityName, Long entityId, String prefix, int type) throws HibernateException {
-        Query query;
-
-        if ((prefix != null) && (type > 0)) {
-            query = session.getNamedQuery("all_keys_with_type_like");
-            query.setString("like", prefix + '%');
-            query.setInteger("type", type);
-        } else if (prefix != null) {
-            query = session.getNamedQuery("all_keys_like");
-            query.setString("like", prefix + '%');
-        } else if (type > 0) {
-            query = session.getNamedQuery("all_keys_with_type");
-            query.setInteger("type", type);
-        } else {
-            query = session.getNamedQuery("all_keys");
-        }
-
-        query.setString("entityName", entityName);
-        query.setLong("entityId", entityId.longValue());
-
-        return query.list();
-    }
-}

providers/hibernate3/src/com/opensymphony/module/propertyset/hibernate3/PropertySetItem.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.module.propertyset.hibernate3;
-
-import java.util.Date;
-
-
-/**
- * Interface to be implemented by the concrete class that hibernate persists.
- * @author $author$
- * @version $Revision: 169 $
- */
-public interface PropertySetItem {
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    void setBooleanVal(boolean booleanVal);
-
-    boolean getBooleanVal();
-
-    void setDateVal(Date dateVal);
-
-    Date getDateVal();
-
-    void setDoubleVal(double doubleVal);
-
-    double getDoubleVal();
-
-    void setEntityId(long entityId);
-
-    long getEntityId();
-
-    void setEntityName(String entityName);
-
-    String getEntityName();
-
-    void setIntVal(int intVal);
-
-    int getIntVal();
-
-    void setKey(String key);
-
-    String getKey();
-
-    void setLongVal(long longVal);
-
-    long getLongVal();
-
-    void setStringVal(String stringVal);
-
-    String getStringVal();
-
-    void setType(int type);
-
-    int getType();
-}

providers/hibernate3/src/com/opensymphony/module/propertyset/hibernate3/PropertySetItemImpl.hbm.xml

-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
-
-<hibernate-mapping>
-    <class name="com.opensymphony.module.propertyset.hibernate3.PropertySetItemImpl" table="OS_PROPERTYENTRY">
-        <composite-id>
-            <key-property name="entityName" column="entity_name" length="125" />
-            <key-property name="entityId" column="entity_id" />
-            <key-property name="key" column="entity_key" />
-        </composite-id>
-
-        <property name="type" column="key_type" />
-        <property name="booleanVal" column="boolean_val" />
-        <property name="doubleVal" column="double_val" />
-        <property name="stringVal" column="string_val" />
-        <property name="longVal" column="long_val" />
-        <property name="intVal" column="int_val" />
-        <property name="dateVal" type="timestamp" column="date_val" />
-    </class>
-	<query name="all_keys"><![CDATA[
-		select item.key from item in class com.opensymphony.module.propertyset.hibernate3.PropertySetItem
-		where item.entityName = :entityName and item.entityId = :entityId
-	]]></query>
-	<query name="all_keys_with_type"><![CDATA[
-		select item.key from item in class com.opensymphony.module.propertyset.hibernate3.PropertySetItem
-		where item.entityName = :entityName and item.entityId = :entityId and item.type = :type
-	]]></query>
-	<query name="all_keys_like"><![CDATA[
-		select item.key from item in class com.opensymphony.module.propertyset.hibernate3.PropertySetItem
-		where item.entityName = :entityName and item.entityId = :entityId and item.key LIKE :like
-	]]></query>
-	<query name="all_keys_with_type_like"><![CDATA[
-		select item.key from item in class com.opensymphony.module.propertyset.hibernate3.PropertySetItem
-		where item.entityName = :entityName and item.entityId = :entityId
-		and item.type = :type and item.key LIKE :like
-	]]></query>
-
-</hibernate-mapping>

providers/hibernate3/src/com/opensymphony/module/propertyset/hibernate3/PropertySetItemImpl.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.module.propertyset.hibernate3;
-
-import java.io.Serializable;
-
-import java.util.Date;
-
-
-/**
- *
- *
- * @author $Author: hani $
- * @version $Revision: 169 $
- */
-public class PropertySetItemImpl implements Serializable, PropertySetItem {
-    //~ Instance fields ////////////////////////////////////////////////////////
-
-    Date dateVal;
-    String entityName;
-    String key;
-    String stringVal;
-    boolean booleanVal;
-    double doubleVal;
-    int intVal;
-    int type;
-    long entityId;
-    long longVal;
-
-    //~ Constructors ///////////////////////////////////////////////////////////
-
-    //needed for hibernate
-    public PropertySetItemImpl() {
-    }
-
-    public PropertySetItemImpl(String entityName, long entityId, String key) {
-        this.entityName = entityName;
-        this.entityId = entityId;
-        this.key = key;
-    }
-
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    public void setBooleanVal(boolean booleanVal) {
-        this.booleanVal = booleanVal;
-    }
-
-    public boolean getBooleanVal() {
-        return booleanVal;
-    }
-
-    public void setDateVal(Date dateVal) {
-        this.dateVal = dateVal;
-    }
-
-    public Date getDateVal() {
-        return dateVal;
-    }
-
-    public void setDoubleVal(double doubleVal) {
-        this.doubleVal = doubleVal;
-    }
-
-    public double getDoubleVal() {
-        return doubleVal;
-    }
-
-    public void setEntityId(long entityId) {
-        this.entityId = entityId;
-    }
-
-    public long getEntityId() {
-        return entityId;
-    }
-
-    public void setEntityName(String entityName) {
-        this.entityName = entityName;
-    }
-
-    public String getEntityName() {
-        return entityName;
-    }
-
-    public void setIntVal(int intVal) {
-        this.intVal = intVal;
-    }
-
-    public int getIntVal() {
-        return intVal;
-    }
-
-    public void setKey(String key) {
-        this.key = key;
-    }
-
-    public String getKey() {
-        return key;
-    }
-
-    public void setLongVal(long longVal) {
-        this.longVal = longVal;
-    }
-
-    public long getLongVal() {
-        return longVal;
-    }
-
-    public void setStringVal(String stringVal) {
-        this.stringVal = stringVal;
-    }
-
-    public String getStringVal() {
-        return stringVal;
-    }
-
-    public void setType(int type) {
-        this.type = type;
-    }
-
-    public int getType() {
-        return type;
-    }
-
-    public boolean equals(Object obj) {
-        if (!(obj instanceof PropertySetItem)) {
-            return false;
-        }
-
-        PropertySetItem item = (PropertySetItem) obj;
-
-        return ((item.getEntityId() == entityId) && item.getEntityName().equals(entityName) && item.getKey().equals(key));
-    }
-
-    public int hashCode() {
-        return (int) (entityId + entityName.hashCode() + key.hashCode());
-    }
-}

providers/hibernate3/src/main/java/com/opensymphony/module/propertyset/hibernate3/DefaultHibernateConfigurationProvider.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.module.propertyset.hibernate3;
+
+import org.hibernate.HibernateException;
+import org.hibernate.SessionFactory;
+
+import org.hibernate.cfg.Configuration;
+
+import java.util.Iterator;
+import java.util.Map;
+
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Mike
+ * Date: Jul 26, 2003
+ * Time: 5:05:55 PM
+ * To change this template use Options | File Templates.
+ */
+public class DefaultHibernateConfigurationProvider implements HibernateConfigurationProvider {
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    private Configuration configuration;
+    private HibernatePropertySetDAO propertySetDAO;
+    private SessionFactory sessionFactory;
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public void setConfiguration(Configuration configuration) {
+        this.configuration = configuration;
+    }
+
+    public Configuration getConfiguration() {
+        return configuration;
+    }
+
+    public HibernatePropertySetDAO getPropertySetDAO() {
+        if (propertySetDAO == null) {
+            propertySetDAO = new HibernatePropertySetDAOImpl(sessionFactory);
+        }
+
+        return propertySetDAO;
+    }
+
+    public void setSessionFactory(SessionFactory sessionFactory) {
+        this.sessionFactory = sessionFactory;
+    }
+
+    public void setupConfiguration(Map configurationProperties) {
+        // loaded hibernate config
+        try {
+            configuration = new Configuration().addClass(PropertySetItemImpl.class);
+
+            Iterator itr = configurationProperties.keySet().iterator();
+
+            while (itr.hasNext()) {
+                String key = (String) itr.next();
+
+                if (key.startsWith("hibernate3")) {
+                    configuration.setProperty(key, (String) configurationProperties.get(key));
+                }
+            }
+
+            this.sessionFactory = configuration.buildSessionFactory();
+        } catch (HibernateException e) {
+        }
+    }
+}

providers/hibernate3/src/main/java/com/opensymphony/module/propertyset/hibernate3/HibernateConfigurationProvider.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.module.propertyset.hibernate3;
+
+import org.hibernate.cfg.Configuration;
+
+import java.util.Map;
+
+
+/**
+ * Use this class to provide your own configurations to the PropertySet hibernate providers.
+ * <p>
+ * Simply implement this interface and return a Hibernate Configuration object.
+ * <p>
+ * This is setup by using the configuration.provider.class property, with the classname
+ * of your implementation.
+ */
+public interface HibernateConfigurationProvider {
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    /**
+* Get a Hibernate configuration object
+*/
+    public Configuration getConfiguration();
+
+    HibernatePropertySetDAO getPropertySetDAO();
+
+    /**
+* Setup a Hibernate configuration object with the given properties.
+*
+* This will always be called before getConfiguration().
+*/
+    void setupConfiguration(Map properties);
+}

providers/hibernate3/src/main/java/com/opensymphony/module/propertyset/hibernate3/HibernatePropertySet.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.module.propertyset.hibernate3;
+
+import com.opensymphony.module.propertyset.AbstractPropertySet;
+import com.opensymphony.module.propertyset.PropertyException;
+import com.opensymphony.module.propertyset.PropertySet;
+
+import com.opensymphony.util.ClassLoaderUtil;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+
+
+/**
+ * This is the property set implementation for storing properties using Hibernate.
+ * <p>
+ *
+ * <b>Required Args</b>
+ * <ul>
+ *  <li><b>entityId</b> - Long that holds the ID of this entity.</li>
+ *  <li><b>entityName</b> - String that holds the name of this entity type</li>
+ * </ul>
+ *
+ * if "<b>sessionFactory</b> - hibernate sessionFactory" is not passed as an arg then init will use: <br />
+ *  <b>hibernate.*</b> - config params needed to create a hibernate sessionFactory in the propertyset config xml.
+ * <br />
+ * This can be any of the configs avail from hibernate.
+ * <p>
+ *
+ * @author $Author: hani $
+ * @version $Revision: 169 $
+ */
+public class HibernatePropertySet extends AbstractPropertySet {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    protected static Log log = LogFactory.getLog(HibernatePropertySet.class.getName());
+
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    private HibernateConfigurationProvider configProvider;
+    private Long entityId;
+    private String entityName;
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public Collection getKeys(String prefix, int type) throws PropertyException {
+        return configProvider.getPropertySetDAO().getKeys(entityName, entityId, prefix, type);
+    }
+
+    public int getType(String key) throws PropertyException {
+        return findByKey(key).getType();
+    }
+
+    public boolean exists(String key) throws PropertyException {
+        try {
+            if (findByKey(key) != null) {
+                return true;
+            }
+
+            return false;
+        } catch (PropertyException e) {
+            return false;
+        }
+    }
+
+    public void init(Map config, Map args) {
+        super.init(config, args);
+        this.entityId = (Long) args.get("entityId");
+        this.entityName = (String) args.get("entityName");
+
+        // first let's see if we got given a configuration provider to use already
+        configProvider = (HibernateConfigurationProvider) args.get("configurationProvider");
+
+        if (configProvider == null) // if we did not get given one in the args, we need to set a config provider up
+         {
+            // lets see if we need to use a configurationProvider from a class
+            String configProviderClass = (String) config.get("configuration.provider.class");
+
+            if (configProviderClass != null) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Setting up property set provider of class: " + configProviderClass);
+                }
+
+                try {
+                    configProvider = (HibernateConfigurationProvider) ClassLoaderUtil.loadClass(configProviderClass, this.getClass()).newInstance();
+                } catch (Exception e) {
+                    log.error("Unable to load configuration provider class: " + configProviderClass, e);
+
+                    return;
+                }
+            } else {
+                if (log.isDebugEnabled()) {
+                    log.debug("Setting up property set with DefaultHibernateConfigurationProvider");
+                }
+
+                configProvider = new DefaultHibernateConfigurationProvider();
+            }
+
+            configProvider.setupConfiguration(config);
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug("Setting up property set with hibernate provider passed in args.");
+            }
+        }
+    }
+
+    public void remove(String key) throws PropertyException {
+        configProvider.getPropertySetDAO().remove(entityName, entityId, key);
+    }
+
+    public void remove() throws PropertyException {
+        configProvider.getPropertySetDAO().remove(entityName, entityId);
+    }
+
+    public boolean supportsType(int type) {
+        switch (type) {
+        case PropertySet.DATA:
+        case PropertySet.OBJECT:
+        case PropertySet.PROPERTIES:
+        case PropertySet.XML:
+            return false;
+        }
+
+        return true;
+    }
+
+    protected void setImpl(int type, String key, Object value) throws PropertyException {
+        PropertySetItem item = null;
+
+        boolean update = true;
+        item = configProvider.getPropertySetDAO().findByKey(entityName, entityId, key);
+
+        if (item == null) {
+            update = false;
+            item = configProvider.getPropertySetDAO().create(entityName, entityId.longValue(), key);
+        } else if (item.getType() != type) {
+            throw new PropertyException("Existing key '" + key + "' does not have matching type of " + type);
+        }
+
+        switch (type) {
+        case BOOLEAN:
+            item.setBooleanVal(((Boolean) value).booleanValue());
+
+            break;
+
+        case DOUBLE:
+            item.setDoubleVal(((Double) value).doubleValue());
+
+            break;
+
+        case STRING:
+        case TEXT:
+            item.setStringVal((String) value);
+
+            break;
+
+        case LONG:
+            item.setLongVal(((Long) value).longValue());
+
+            break;
+
+        case INT:
+            item.setIntVal(((Integer) value).intValue());
+
+            break;
+
+        case DATE:
+            item.setDateVal((Date) value);
+
+            break;
+
+        default:
+            throw new PropertyException("type " + type + " not supported");
+        }
+
+        item.setType(type);
+
+        configProvider.getPropertySetDAO().setImpl(item, update);
+    }
+
+    protected Object get(int type, String key) throws PropertyException {
+        PropertySetItem item = findByKey(key);
+
+        if (item == null) {
+            return null;
+        }
+
+        if (item.getType() != type) {
+            throw new PropertyException("key '" + key + "' does not have matching type of " + type);
+        }
+
+        switch (type) {
+        case BOOLEAN:
+            return new Boolean(item.getBooleanVal());
+
+        case DOUBLE:
+            return new Double(item.getDoubleVal());
+
+        case STRING:
+        case TEXT:
+            return item.getStringVal();
+
+        case LONG:
+            return new Long(item.getLongVal());
+
+        case INT:
+            return new Integer(item.getIntVal());
+
+        case DATE:
+            return item.getDateVal();
+        }
+
+        throw new PropertyException("type " + type + " not supported");
+    }
+
+    private PropertySetItem findByKey(String key) throws PropertyException {
+        return configProvider.getPropertySetDAO().findByKey(entityName, entityId, key);
+    }
+}

providers/hibernate3/src/main/java/com/opensymphony/module/propertyset/hibernate3/HibernatePropertySetDAO.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.module.propertyset.hibernate3;
+
+import java.util.Collection;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision: 169 $
+ */
+public interface HibernatePropertySetDAO {
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    /**
+ * Save the implementation of a PropertySetItem.
+ *
+ * @param item
+ * @param isUpdate Boolean indicating whether or not this item already exists
+ */
+    void setImpl(PropertySetItem item, boolean isUpdate);
+
+    Collection getKeys(String entityName, Long entityId, String prefix, int type);
+
+    PropertySetItem create(String entityName, long entityId, String key);
+
+    PropertySetItem findByKey(String entityName, Long entityId, String key);
+
+    void remove(String entityName, Long entityId, String key);
+
+    void remove(String entityName, Long entityId);
+}

providers/hibernate3/src/main/java/com/opensymphony/module/propertyset/hibernate3/HibernatePropertySetDAOImpl.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.module.propertyset.hibernate3;
+
+import com.opensymphony.module.propertyset.PropertyException;
+
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+
+import java.util.*;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision: 169 $
+ */
+public class HibernatePropertySetDAOImpl implements HibernatePropertySetDAO {
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    private SessionFactory sessionFactory;
+
+    //~ Constructors ///////////////////////////////////////////////////////////
+
+    public HibernatePropertySetDAOImpl(SessionFactory sessionFactory) {
+        this.sessionFactory = sessionFactory;
+    }
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public void setImpl(PropertySetItem item, boolean isUpdate) {
+        Session session = null;
+
+        try {
+            session = this.sessionFactory.openSession();
+
+            if (isUpdate) {
+                session.update(item);
+            } else {
+                session.save(item);
+            }
+
+            session.flush();
+        } catch (HibernateException he) {
+            throw new PropertyException("Could not save key '" + item.getKey() + "':" + he.getMessage());
+        } finally {
+            try {
+                if (session != null) {
+                    if (!session.connection().getAutoCommit()) {
+                        session.connection().commit();
+                    }
+
+                    session.close();
+                }
+            } catch (Exception e) {
+            }
+        }
+    }
+
+    public Collection getKeys(String entityName, Long entityId, String prefix, int type) {
+        Session session = null;
+        List list = null;
+
+        try {
+            session = this.sessionFactory.openSession();
+            list = HibernatePropertySetDAOUtils.getKeysImpl(session, entityName, entityId, prefix, type);
+        } catch (HibernateException e) {
+            list = Collections.EMPTY_LIST;
+        } finally {
+            try {
+                if (session != null) {
+                    session.flush();
+                    session.close();
+                }
+            } catch (Exception e) {
+            }
+        }
+
+        return list;
+    }
+
+    public PropertySetItem create(String entityName, long entityId, String key) {
+        return new PropertySetItemImpl(entityName, entityId, key);
+    }
+
+    public PropertySetItem findByKey(String entityName, Long entityId, String key) {
+        Session session = null;
+        PropertySetItem item = null;
+
+        try {
+            session = this.sessionFactory.openSession();
+            item = HibernatePropertySetDAOUtils.getItem(session, entityName, entityId, key);
+            session.flush();
+        } catch (HibernateException e) {
+            return null;
+        } finally {
+            try {
+                if (session != null) {
+                    session.close();
+                }
+            } catch (Exception e) {
+            }
+        }
+
+        return item;
+    }
+
+    public void remove(String entityName, Long entityId) {
+        Session session = null;
+
+        try {
+            session = this.sessionFactory.openSession();
+
+            //hani: todo this needs to be optimised rather badly, but I have no idea how
+            Collection keys = getKeys(entityName, entityId, null, 0);
+            Iterator iter = keys.iterator();
+
+            while (iter.hasNext()) {
+                String key = (String) iter.next();
+                session.delete(HibernatePropertySetDAOUtils.getItem(session, entityName, entityId, key));
+            }
+
+            session.flush();
+        } catch (HibernateException e) {
+            throw new PropertyException("Could not remove all keys: " + e.getMessage());
+        } finally {
+            try {
+                if (session != null) {
+                    if (!session.connection().getAutoCommit()) {
+                        session.connection().commit();
+                    }
+
+                    session.close();
+                }
+            } catch (Exception e) {
+            }
+        }
+    }
+
+    public void remove(String entityName, Long entityId, String key) {
+        Session session = null;
+
+        try {
+            session = this.sessionFactory.openSession();
+            session.delete(HibernatePropertySetDAOUtils.getItem(session, entityName, entityId, key));
+            session.flush();
+        } catch (HibernateException e) {
+            throw new PropertyException("Could not remove key '" + key + "': " + e.getMessage());
+        } finally {
+            try {
+                if (session != null) {
+                    if (!session.connection().getAutoCommit()) {
+                        session.connection().commit();
+                    }
+
+                    session.close();
+                }
+            } catch (Exception e) {
+            }
+        }
+    }
+}

providers/hibernate3/src/main/java/com/opensymphony/module/propertyset/hibernate3/HibernatePropertySetDAOUtils.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.module.propertyset.hibernate3;
+
+import org.hibernate.HibernateException;
+import org.hibernate.Query;
+import org.hibernate.Session;
+
+import java.util.List;
+
+
+/**
+ * Created by IntelliJ IDEA. User: Mike Date: Jul 26, 2003 Time: 5:46:58 PM
+ */
+public class HibernatePropertySetDAOUtils {
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    // ~ Methods
+    // ////////////////////////////////////////////////////////////////
+    public static PropertySetItem getItem(Session session, String entityName, Long entityId, String key) throws HibernateException {
+        return (PropertySetItem) session.load(PropertySetItemImpl.class, new PropertySetItemImpl(entityName, entityId.longValue(), key));
+    }
+
+    /**
+ * This is the body of the getKeys() method, so that you can reuse it
+ * wrapped by your own session management.
+ */
+    public static List getKeysImpl(Session session, String entityName, Long entityId, String prefix, int type) throws HibernateException {
+        Query query;
+
+        if ((prefix != null) && (type > 0)) {
+            query = session.getNamedQuery("all_keys_with_type_like");
+            query.setString("like", prefix + '%');
+            query.setInteger("type", type);
+        } else if (prefix != null) {
+            query = session.getNamedQuery("all_keys_like");
+            query.setString("like", prefix + '%');
+        } else if (type > 0) {
+            query = session.getNamedQuery("all_keys_with_type");
+            query.setInteger("type", type);
+        } else {
+            query = session.getNamedQuery("all_keys");
+        }
+
+        query.setString("entityName", entityName);
+        query.setLong("entityId", entityId.longValue());
+
+        return query.list();
+    }
+}

providers/hibernate3/src/main/java/com/opensymphony/module/propertyset/hibernate3/PropertySetItem.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.module.propertyset.hibernate3;
+
+import java.util.Date;
+
+
+/**
+ * Interface to be implemented by the concrete class that hibernate persists.
+ * @author $author$
+ * @version $Revision: 169 $
+ */
+public interface PropertySetItem {
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    void setBooleanVal(boolean booleanVal);
+
+    boolean getBooleanVal();
+
+    void setDateVal(Date dateVal);
+
+    Date getDateVal();
+
+    void setDoubleVal(double doubleVal);
+
+    double getDoubleVal();
+
+    void setEntityId(long entityId);
+
+    long getEntityId();
+
+    void setEntityName(String entityName);
+
+    String getEntityName();
+
+    void setIntVal(int intVal);
+
+    int getIntVal();
+
+    void setKey(String key);
+
+    String getKey();
+
+    void setLongVal(long longVal);
+
+    long getLongVal();
+
+    void setStringVal(String stringVal);
+
+    String getStringVal();
+
+    void setType(int type);
+
+    int getType();
+}

providers/hibernate3/src/main/java/com/opensymphony/module/propertyset/hibernate3/PropertySetItemImpl.hbm.xml

+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
+
+<hibernate-mapping>
+    <class name="com.opensymphony.module.propertyset.hibernate3.PropertySetItemImpl" table="OS_PROPERTYENTRY">
+        <composite-id>
+            <key-property name="entityName" column="entity_name" length="125" />
+            <key-property name="entityId" column="entity_id" />
+            <key-property name="key" column="entity_key" />
+        </composite-id>
+
+        <property name="type" column="key_type" />
+        <property name="booleanVal" column="boolean_val" />
+        <property name="doubleVal" column="double_val" />
+        <property name="stringVal" column="string_val" />
+        <property name="longVal" column="long_val" />
+        <property name="intVal" column="int_val" />
+        <property name="dateVal" type="timestamp" column="date_val" />
+    </class>
+	<query name="all_keys"><![CDATA[
+		select item.key from item in class com.opensymphony.module.propertyset.hibernate3.PropertySetItem
+		where item.entityName = :entityName and item.entityId = :entityId
+	]]></query>
+	<query name="all_keys_with_type"><![CDATA[
+		select item.key from item in class com.opensymphony.module.propertyset.hibernate3.PropertySetItem
+		where item.entityName = :entityName and item.entityId = :entityId and item.type = :type
+	]]></query>
+	<query name="all_keys_like"><![CDATA[
+		select item.key from item in class com.opensymphony.module.propertyset.hibernate3.PropertySetItem
+		where item.entityName = :entityName and item.entityId = :entityId and item.key LIKE :like
+	]]></query>
+	<query name="all_keys_with_type_like"><![CDATA[
+		select item.key from item in class com.opensymphony.module.propertyset.hibernate3.PropertySetItem
+		where item.entityName = :entityName and item.entityId = :entityId
+		and item.type = :type and item.key LIKE :like
+	]]></query>
+
+</hibernate-mapping>

providers/hibernate3/src/main/java/com/opensymphony/module/propertyset/hibernate3/PropertySetItemImpl.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.module.propertyset.hibernate3;
+
+import java.io.Serializable;
+
+import java.util.Date;
+
+