Justin Koke avatar Justin Koke committed 05541ef

Adding Hibernate 4 support

Comments (0)

Files changed (12)

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

 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.*;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
 
 
 /**
  * @author $author$
  * @version $Revision: 169 $
  */
-public class HibernatePropertySetDAOImpl implements HibernatePropertySetDAO {
+public class HibernatePropertySetDAOImpl implements HibernatePropertySetDAO
+{
     //~ Instance fields ////////////////////////////////////////////////////////
 
     private SessionFactory sessionFactory;
 
     //~ Constructors ///////////////////////////////////////////////////////////
 
-    public HibernatePropertySetDAOImpl(SessionFactory sessionFactory) {
+    public HibernatePropertySetDAOImpl(SessionFactory sessionFactory)
+    {
         this.sessionFactory = sessionFactory;
     }
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
-    public void setImpl(PropertySetItem item, boolean isUpdate) {
+    public void setImpl(PropertySetItem item, boolean isUpdate)
+    {
         Session session = null;
 
-        try {
+        try
+        {
             session = this.sessionFactory.openSession();
 
-            if (isUpdate) {
+            if (isUpdate)
+            {
                 session.update(item);
-            } else {
+            }
+            else
+            {
                 session.save(item);
             }
 
             session.flush();
-        } catch (HibernateException he) {
+        }
+        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();
-                    }
-
+        }
+        finally
+        {
+            try
+            {
+                if (session != null)
+                {
+                    session.flush();
                     session.close();
                 }
-            } catch (Exception e) {
+            }
+            catch (Exception e)
+            {
             }
         }
     }
 
-    public Collection getKeys(String entityName, Long entityId, String prefix, int type) {
+    public Collection getKeys(String entityName, Long entityId, String prefix, int type)
+    {
         Session session = null;
         List list = null;
 
-        try {
+        try
+        {
             session = this.sessionFactory.openSession();
             list = HibernatePropertySetDAOUtils.getKeysImpl(session, entityName, entityId, prefix, type);
-        } catch (HibernateException e) {
+        }
+        catch (HibernateException e)
+        {
             list = Collections.EMPTY_LIST;
-        } finally {
-            try {
-                if (session != null) {
+        }
+        finally
+        {
+            try
+            {
+                if (session != null)
+                {
                     session.flush();
                     session.close();
                 }
-            } catch (Exception e) {
+            }
+            catch (Exception e)
+            {
             }
         }
 
         return list;
     }
 
-    public PropertySetItem create(String entityName, long entityId, String key) {
+    public PropertySetItem create(String entityName, long entityId, String key)
+    {
         return new PropertySetItemImpl(entityName, entityId, key);
     }
 
-    public PropertySetItem findByKey(String entityName, Long entityId, String key) {
+    public PropertySetItem findByKey(String entityName, Long entityId, String key)
+    {
         Session session = null;
         PropertySetItem item = null;
 
-        try {
+        try
+        {
             session = this.sessionFactory.openSession();
             item = HibernatePropertySetDAOUtils.getItem(session, entityName, entityId, key);
             session.flush();
-        } catch (HibernateException e) {
+        }
+        catch (HibernateException e)
+        {
             return null;
-        } finally {
-            try {
-                if (session != null) {
+        }
+        finally
+        {
+            try
+            {
+                if (session != null)
+                {
                     session.close();
                 }
-            } catch (Exception e) {
+            }
+            catch (Exception e)
+            {
             }
         }
 
         return item;
     }
 
-    public void remove(String entityName, Long entityId) {
+    public void remove(String entityName, Long entityId)
+    {
         Session session = null;
 
-        try {
+        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()) {
+            while (iter.hasNext())
+            {
                 String key = (String) iter.next();
                 session.delete(HibernatePropertySetDAOUtils.getItem(session, entityName, entityId, key));
             }
 
             session.flush();
-        } catch (HibernateException e) {
+        }
+        catch (HibernateException e)
+        {
             throw new PropertyException("Could not remove all keys: " + e.getMessage());
-        } finally {
-            try {
-                if (session != null) {
-                    if (!session.connection().getAutoCommit()) {
+        }
+        finally
+        {
+            try
+            {
+                if (session != null)
+                {
+                    if (!session.connection().getAutoCommit())
+                    {
                         session.connection().commit();
                     }
 
                     session.close();
                 }
-            } catch (Exception e) {
+            }
+            catch (Exception e)
+            {
             }
         }
     }
 
-    public void remove(String entityName, Long entityId, String key) {
+    public void remove(String entityName, Long entityId, String key)
+    {
         Session session = null;
 
-        try {
+        try
+        {
             session = this.sessionFactory.openSession();
             session.delete(HibernatePropertySetDAOUtils.getItem(session, entityName, entityId, key));
             session.flush();
-        } catch (HibernateException e) {
+        }
+        catch (HibernateException e)
+        {
             throw new PropertyException("Could not remove key '" + key + "': " + e.getMessage());
-        } finally {
-            try {
-                if (session != null) {
-                    if (!session.connection().getAutoCommit()) {
+        }
+        finally
+        {
+            try
+            {
+                if (session != null)
+                {
+                    if (!session.connection().getAutoCommit())
+                    {
                         session.connection().commit();
                     }
 
                     session.close();
                 }
-            } catch (Exception e) {
+            }
+            catch (Exception e)
+            {
             }
         }
     }

providers/hibernate4/pom.xml

+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>com.opensymphony.propertyset.providers</groupId>
+        <artifactId>providers</artifactId>
+        <version>1.6.0-SNAPSHOT</version>
+    </parent>
+
+    <groupId>com.opensymphony.propertyset.providers</groupId>
+    <artifactId>hibernate4</artifactId>
+
+    <packaging>jar</packaging>
+
+    <name>PropertySet Providers Hibernate 4</name>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-source-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.opensymphony.propertyset</groupId>
+            <artifactId>api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.hibernate</groupId>
+            <artifactId>hibernate-core</artifactId>
+            <version>4.1.7.Final</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>

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

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.module.propertyset.hibernate4;
+
+import org.hibernate.HibernateException;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+
+import java.util.Iterator;
+import java.util.Map;
+
+
+public class DefaultHibernateConfigurationProvider
+        implements com.opensymphony.module.propertyset.hibernate4.HibernateConfigurationProvider
+{
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    private Configuration configuration;
+    private com.opensymphony.module.propertyset.hibernate4.HibernatePropertySetDAO propertySetDAO;
+    private SessionFactory sessionFactory;
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public void setConfiguration(Configuration configuration)
+    {
+        this.configuration = configuration;
+    }
+
+    public Configuration getConfiguration()
+    {
+        return configuration;
+    }
+
+    public com.opensymphony.module.propertyset.hibernate4.HibernatePropertySetDAO getPropertySetDAO()
+    {
+        if (propertySetDAO == null)
+        {
+            propertySetDAO = new com.opensymphony.module.propertyset.hibernate4.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/hibernate4/src/main/java/com/opensymphony/module/propertyset/hibernate4/HibernateConfigurationProvider.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.module.propertyset.hibernate4;
+
+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.
+     * <p/>
+     * This will always be called before getConfiguration().
+     */
+    void setupConfiguration(Map properties);
+}

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

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.module.propertyset.hibernate4;
+
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+
+
+/**
+ * This is the property set implementation for storing properties using Hibernate.
+ * <p/>
+ * <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>
+ * <p/>
+ * 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 /////////////////////////////////////////////
+
+    private static final Logger log = LoggerFactory.getLogger(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/hibernate4/src/main/java/com/opensymphony/module/propertyset/hibernate4/HibernatePropertySetDAO.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.module.propertyset.hibernate4;
+
+import java.util.Collection;
+
+public interface HibernatePropertySetDAO
+{
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    /**
+     * Save the implementation of a PropertySetItem.
+     *
+     * @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/hibernate4/src/main/java/com/opensymphony/module/propertyset/hibernate4/HibernatePropertySetDAOImpl.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.module.propertyset.hibernate4;
+
+import com.opensymphony.module.propertyset.PropertyException;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+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)
+                {
+                    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)
+                {
+                    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)
+                {
+                    session.close();
+                }
+            }
+            catch (Exception e)
+            {
+            }
+        }
+    }
+}

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

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.module.propertyset.hibernate4;
+
+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.get(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/hibernate4/src/main/java/com/opensymphony/module/propertyset/hibernate4/PropertySetItem.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.module.propertyset.hibernate4;
+
+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/hibernate4/src/main/java/com/opensymphony/module/propertyset/hibernate4/PropertySetItemImpl.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.module.propertyset.hibernate4;
+
+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/hibernate4/src/main/resources/com/opensymphony/module/propertyset/hibernate4/PropertySetItemImpl.hbm.xml

+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping>
+    <class name="com.opensymphony.module.propertyset.hibernate4.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.hibernate4.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.hibernate4.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.hibernate4.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.hibernate4.PropertySetItem
+		where item.entityName = :entityName and item.entityId = :entityId
+		and item.type = :type and item.key LIKE :like
+	]]></query>
+
+</hibernate-mapping>

providers/pom.xml

         <module>ejb3</module>
         <module>hibernate2</module>
         <module>hibernate3</module>
+        <module>hibernate4</module>
         <module>jdbc</module>
         <module>ofbiz2</module>
         <module>ojb</module>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.