Anonymous avatar Anonymous committed e006c98

Added support for hibernate3. Also need to change the build script path to osbuild.xml and include that file in the project because I don't have access to the common build directory nor would anybody that simply wants to checkout this project and build it. Also needed to include EMPTY.MF as it was required by the build and not present.

git-svn-id: http://svn.opensymphony.com/svn/propertyset/trunk@194 bf3cbcdd-1c1a-0410-9a68-d6f521e3fa7b

Comments (0)

Files changed (15)

Empty file added.

   <property name="src.test" location="src/test"/>
   <property name="src.etc" location="src/etc"/>
 
-  <property name="common.build" value="../opensymphony/common/osbuild.xml"/>
+  <property name="common.build" value="osbuild.xml"/>
   <property name="providers" location="providers"/>
 
   <import file="${common.build}"/>
     <pathelement location="${providers}/ejb/build"/>
     <pathelement location="${providers}/ejb3/build"/>
     <pathelement location="${providers}/hibernate/build"/>
+    <pathelement location="${providers}/hibernate3/build"/>
     <pathelement location="${providers}/ofbiz/build"/>
     <pathelement location="${providers}/ojb/build"/>
   </path>
     <provider-compile provider="ejb3" source="1.5" destdir="${build.java-test}" />
     <provider-compile provider="ejb" destdir="${build.java-test}" />
     <provider-compile provider="hibernate" destdir="${build.java-test}" />
+    <provider-compile provider="hibernate3" destdir="${build.java-test}" />
     <provider-compile provider="ofbiz" destdir="${build.java-test}" />
     <provider-compile provider="ojb" destdir="${build.java-test}" />
   </target>
     <provider-compile provider="ejb" />
     <provider-compile provider="ejb3" source="1.5"/>
     <provider-compile provider="hibernate" />
+    <provider-compile provider="hibernate3" />
     <provider-compile provider="ofbiz" />
     <provider-compile provider="ojb" />
   </target>
     <provider-jar provider="ejb" manifest="${src.etc}/manifest-ejb.txt" />
     <provider-jar provider="ofbiz" />
     <provider-jar provider="hibernate" />
+    <provider-jar provider="hibernate3" />
     <provider-jar provider="ejb3" />
     <provider-jar provider="ojb" />
   </target>
+<project name="common" default="jar" basedir=".">
+    <!--
+    OpenSymphony Common Build
+    =========================
+    TODO (Introduction)
+
+    Layout
+    =========================
+    TODO
+
+    Overriding
+    =========================
+    TODO
+    Example: <target name="compile" depends="myPreCompile,common.compile,myPostCompile"/>
+
+    -->
+    <!-- NOTE: this property is purely here to make a clear distinction in IDEA where the common build is -->
+    <property name="------common-properties-below------" value="Common properties below:"/>
+
+    <property name="compile.version" value="1.3"/>
+    <property name="test.compile.version" value="1.3"/>
+
+    <dirname property="common.dir" file="${ant.file.common}"/>
+    <property file="build.properties"/>
+    <property file="release.properties"/>
+    <property file="ivyrep.properties"/>
+
+    <property name="lib" location="lib"/>
+    <property name="lib.core" value="${lib}/core"/>
+    <property name="lib.build" value="${lib}/build"/>
+    <property name="lib.optional" value="${lib}/optional"/>
+
+    <property name="src" location="src"/>
+    <property name="src.java" value="${src}/java"/>
+
+    <property name="test" value="${src}/test"/>
+    <property name="src.test" value="${test}/java"/>
+
+    <property name="build" location="build"/>
+    <property name="build.test" value="${build}/test"/>
+    <property name="build.java-test" value="${build}/java-test"/>
+    <property name="build.java" value="${build}/java"/>
+    <property name="build.clover" value="${build}/clover"/>
+    <property name="dist" location="dist"/>
+
+    <property name="docs" location="docs"/>
+    <property name="docs.packages" value="com.opensymphony.*"/>
+
+    <property name="jar.manifest" value="${common.dir}/EMPTY.MF"/>
+    <property name="jar.excludes" value=""/>
+
+    <property name="testcase" value="*"/>
+    <patternset id="src.test.pattern">
+        <exclude name="**/Abstract*.java"/>
+        <include name="**/${testcase}Test.java"/>
+        <include name="**/${testcase}TestCase.java"/>
+    </patternset>
+
+    <path id="cp">
+        <fileset dir="lib">
+            <include name="**/*.jar"/>
+            <include name="**/*.zip"/>
+            <exclude name="**/jalopy/**"/>
+        </fileset>
+    </path>
+
+    <path id="junit.cp">
+        <pathelement location="${build.test}"/>
+        <pathelement location="${build.java-test}"/>
+        <path refid="cp"/>
+    </path>
+
+    <available property="junit.available" classname="junit.framework.TestCase"/>
+    <available property="clover.available" classname="org.apache.tools.ant.taskdefs.CloverCompilerAdapter"/>
+
+    <target name="init" depends="init-anthill, init-standalone">
+        <tstamp/>
+    </target>
+
+    <!-- in Anthill, the docs should be the Intranet copyDir -->
+    <target name="init-anthill" if="anthill.copyDir">
+        <property name="dist.docs" value="${anthill.copyDir}"/>
+    </target>
+
+    <!-- when building Standalone, the docs should be the normal place -->
+    <target name="init-standalone" unless="anthill.copyDir">
+        <property name="dist.docs" value="${dist}/docs"/>
+    </target>
+
+    <target name="junit-check" depends="init" unless="junit.available">
+        <fail message="Cannot run test cases. Please copy lib/build/junit-3.8.1.jar to ${ant.home}/lib"/>
+    </target>
+
+    <target name="clover-check" depends="init" unless="clover.available">
+        <fail message="Cannot run coverage tests. Please copy lib/build/clover.jar and lib/build/clover.license (if it exists) to ${ant.home}/lib"/>
+    </target>
+
+    <target name="clean" depends="init">
+        <delete dir="${build}"/>
+        <delete dir="${dist}"/>
+    </target>
+
+    <target name="precompile"/>
+
+    <macrodef name="compile">
+        <attribute name="srcdir"/>
+        <attribute name="destdir"/>
+        <attribute name="classpath" default=""/>
+        <attribute name="classpathref" default="cp"/>
+        <attribute name="excludes" default=""/>
+        <attribute name="source" default="${compile.version}"/>
+        <attribute name="target" default="${compile.version}"/>
+        <sequential>
+            <mkdir dir="@{destdir}"/>
+            <javac srcdir="@{srcdir}" destdir="@{destdir}" classpath="@{classpath}" classpathref="@{classpathref}"
+                   debug="on" source="@{source}" target="@{target}"/>
+            <copy filtering="no" todir="@{destdir}">
+                <fileset dir="@{srcdir}">
+                    <exclude name="**/*.java"/>
+                    <exclude name="**/package.html"/>
+                </fileset>
+            </copy>
+        </sequential>
+    </macrodef>
+
+    <target name="compile" depends="init,precompile" description="compile project">
+        <compile srcdir="${src.java}" destdir="${build.java}"/>
+    </target>
+
+    <target name="jar" depends="compile" description="build the project jar file">
+        <mkdir dir="${build}"/>
+
+        <jar basedir="${build.java}" excludes="${jar.excludes}" jarfile="${build}/${name}-${version}.jar"
+             manifest="${jar.manifest}">
+            <manifest>
+                <attribute name="Implementation-Title" value="${fullname}"/>
+                <attribute name="Implementation-Version" value="${version}"/>
+                <attribute name="Implementation-Vendor" value="OpenSymphony"/>
+            </manifest>
+        </jar>
+        <!--        <jar basedir="${src.java}" jarfile="${build}/${name}-${version}-src.jar">
+           <manifest>
+               <attribute name="Implementation-Title" value="${fullname}" />
+               <attribute name="Implementation-Version" value="${version}" />
+               <attribute name="Implementation-Vendor" value="OpenSymphony" />
+           </manifest>
+       </jar> -->
+    </target>
+
+    <target name="src-jar" depends="init" description="build a jar of the project source code">
+        <mkdir dir="${build}"/>
+        <jar basedir="${src.java}" jarfile="${build}/${name}-${version}-src.jar">
+            <manifest>
+                <attribute name="Implementation-Title" value="${fullname}"/>
+                <attribute name="Implementation-Version" value="${version}"/>
+                <attribute name="Implementation-Vendor" value="OpenSymphony"/>
+            </manifest>
+        </jar>
+    </target>
+
+    <target name="test-compile" unless="skip.tests">
+        <compile srcdir="${src.test}" destdir="${build.test}" classpath="${build.java}"
+                 source="${test.compile.version}" target="${test.compile.version}"/>
+
+        <taskdef resource="clovertasks"/>
+        <taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"/>
+
+        <mkdir dir="${build.clover}"/>
+        <clover-setup initString="${build.clover}/coverage.db">
+            <files>
+                <exclude name="${src.test}/**/*.java"/>
+            </files>
+        </clover-setup>
+
+        <compile srcdir="${src.java}" destdir="${build.java-test}"/>
+    </target>
+
+    <target name="test" depends="junit-check, clover-check, compile, test-compile" description="run tests"
+            unless="skip.tests">
+        <run-junit />
+    </target>
+
+    <macrodef name="run-junit">
+        <attribute name="classpathref" default="junit.cp" />
+        <sequential>
+          <mkdir dir="${dist.docs}/junit"/>
+          <junit haltonfailure="no" haltonerror="yes" fork="yes" forkmode="once" failureproperty="test.failure">
+              <jvmarg value="-Djava.awt.headless=true"/>
+              <jvmarg value="-Dorg.xml.sax.driver=org.apache.crimson.parser.XMLReaderImpl"/>
+              <classpath>
+                  <path refid="@{classpathref}"/>
+              </classpath>
+
+              <formatter type="plain" useFile="false"/>
+              <formatter type="xml"/>
+
+              <batchtest todir="${dist.docs}/junit">
+                  <fileset dir="${src.test}">
+                      <patternset refid="src.test.pattern"/>
+                  </fileset>
+              </batchtest>
+          </junit>          
+        </sequential>
+    </macrodef>
+  
+    <target name="javadocs" description="generate javadocs" depends="init">
+        <mkdir dir="${dist.docs}/api"/>
+        <javadoc sourcepath="${src.java}"
+                 destdir="${dist.docs}/api"
+                 packagenames="${docs.packages}"
+                 classpathref="cp"
+                 author="true"
+                 version="true"
+                 overview="${src.java}/overview.html"
+                 windowTitle="${fullname} API - ${version}"
+                 doctitle="${fullname} API (${version})"
+                 footer="&lt;a href=&quot;http://www.opensymphony.com/${name}/&quot; target=&quot;_top&quot;&gt;${fullname} Project Page&lt;/a&gt;"
+                 use="true"
+                 verbose="false">
+            <link href="http://java.sun.com/j2se/${compile.version}/docs/api/"/>
+            <link href="http://java.sun.com/j2ee/${compile.version}/docs/api/"/>
+        </javadoc>
+        <!-- <copy overwrite="yes" file="${docs}/main.css" tofile="${docs}/api/stylesheet.css"/> -->
+    </target>
+
+    <target name="docs.impl">
+        <copy todir="${dist.docs}">
+            <fileset dir="${docs}"/>
+        </copy>
+    </target>
+
+    <target name="reports" depends="junit.report, clover.report, javadocs"
+            description="generate javadocs and junit and coverage reports"/>
+
+    <target name="docs" depends="reports, docs.impl"/>
+
+    <target name="clover.report" depends="test" description="generate coverage reports" unless="skip.tests">
+        <clover-report>
+            <current outfile="${dist.docs}/clover">
+                <format type="html"/>
+            </current>
+        </clover-report>
+    </target>
+
+    <target name="clover.historical" depends="clover.report" description="generate coverage historical reports"
+            unless="skip.tests">
+        <clover-historypoint historyDir="${build.clover}"/>
+
+        <clover-report>
+            <historical outfile="${dist.docs}/clover" historyDir="${build.clover}">
+                <format type="html"/>
+            </historical>
+        </clover-report>
+    </target>
+
+    <target name="junit.report" depends="test" description="generate junit reports" unless="skip.tests">
+        <junitreport todir="${dist.docs}/junit">
+            <fileset dir="${dist.docs}/junit">
+                <include name="TEST-*.xml"/>
+            </fileset>
+            <report format="frames" todir="${dist.docs}/junit"/>
+        </junitreport>
+
+        <!-- we fail here (instead of in the test target) so that the reports get generated first) -->
+        <fail if="test.failure" message="Tests did not all pass, failing!"/>
+    </target>
+
+    <target name="predist"/>
+
+    <target name="predist.zip"/>
+
+    <target name="dist" depends="jar, docs, predist" description="generate distribution zip file">
+        <copy todir="${dist}">
+            <fileset dir="${build}">
+                <include name="*.jar"/>
+            </fileset>
+        </copy>
+
+        <copy todir="${dist}/src">
+            <fileset dir="${src}"/>
+        </copy>
+
+        <mkdir dir="${dist}/lib"/>
+        <copy todir="${dist}/lib">
+            <fileset dir="${lib}">
+                <exclude name="**/no_dist/**"/>
+            </fileset>
+        </copy>
+
+        <copy todir="${dist}">
+            <fileset dir="${basedir}">
+                <include name="*build.*"/>
+                <include name="readme.txt"/>
+                <include name="license.txt"/>
+            </fileset>
+        </copy>
+
+        <!-- give a chance for project builds to do more before the zip is made. -->
+        <antcall target="predist.zip"/>
+
+        <zip zipfile="${build}/${name}-${version}.zip" basedir="${dist}">
+            <exclude name="docs/clover/**/*"/>
+            <exclude name="docs/junit/**/*"/>
+        </zip>
+    </target>
+
+    <target name="website" depends="javadocs, docs.impl"/>
+
+    <target name="ivyrep" depends="jar">
+        <tstamp>
+            <format property="TIME" pattern="yyyyMMddHHmmss"/>
+        </tstamp>
+
+        <!-- make sure we have the latest -->
+        <echo>svn update</echo>
+        <exec executable="svn">
+            <arg value="update"/>
+            <arg line="${ivyrep.path}/opensymphony/${name}"/>
+        </exec>
+
+        <!-- delete the old timestamped builds and commit -->
+        <fileset dir="${ivyrep.path}/opensymphony/${name}" id="filesref">
+            <include name="${name}-${version}-*"/>
+            <include name="ivy-${version}-*"/>
+        </fileset>
+        <pathconvert property="files" refid="filesref" pathsep=" "/>
+        <echo>svn delete: ${files}</echo>
+        <exec executable="svn">
+            <arg value="delete"/>
+            <arg line="${files}"/>
+        </exec>
+
+        <!-- copy over the new build -->
+        <copy file="${build}/${name}-${version}.jar"
+              tofile="${ivyrep.path}/opensymphony/${name}/${name}-${version}-${TIME}.jar"/>
+        <echo>svn add (jar)</echo>
+        <exec executable="svn">
+            <arg value="add"/>
+            <arg value="${ivyrep.path}/opensymphony/${name}/${name}-${version}-${TIME}.jar"/>
+        </exec>
+
+        <antcall target="ivyrep.copy-ivy"/>
+        <exec executable="svn">
+            <arg value="add"/>
+            <arg value="${ivyrep.path}/opensymphony/${name}/ivy-${version}-${TIME}.xml"/>
+        </exec>
+
+        <!-- now commit everything -->
+        <echo>svn commit</echo>
+        <exec executable="svn">
+            <arg value="commit"/>
+            <arg value="--username"/>
+            <arg value="${ivyrep.username}"/>
+            <arg value="--password"/>
+            <arg value="${ivyrep.password}"/>
+            <arg value="--non-interactive"/>
+            <arg value="-m"/>
+            <arg value="automatic commit"/>
+            <arg value="${ivyrep.path}/opensymphony/${name}"/>
+        </exec>
+    </target>
+
+    <target name="ivyrep.copy-ivy">
+        <!--
+        Note: Default implementation does not use Ivy itself to generate these files.
+              However, Ivy is really the best way to generate these, so projects that
+              do use Ivy should override this target like so:
+
+              <ivy-deliver deliverpattern="${ivyrep.path}/opensymphony/${name}/[artifact]-[revision].[ext]"
+                           pubrevision="${version}-${TIME}" pubdate="${TIME}"/>
+
+              Over time as more projects adopt Ivy, this may become built in to the
+              common build.
+        -->
+        <copy file="ivy.xml" tofile="${ivyrep.path}/opensymphony/${name}/ivy-${version}-${TIME}.xml">
+            <filterset id="ivy.filter">
+                <filter token="VERSION" value="${version}-${TIME}"/>
+                <filter token="STATUS" value="${status}"/>
+                <filter token="PUBLICATION" value="${TIME}"/>
+            </filterset>
+        </copy>
+    </target>
+</project>

providers/hibernate3/hibenrate.iml

+<?xml version="1.0" encoding="UTF-8"?>
+<module relativePaths="true" type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="false">
+    <output url="file://$MODULE_DIR$/build" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="module" module-name="propertyset" />
+    <orderEntry type="module-library" exported="">
+      <library>
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/lib/hibernate-3.0.5.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntryProperties />
+  </component>
+</module>
+

providers/hibernate3/hibernate.iml

+<?xml version="1.0" encoding="UTF-8"?>
+<module version="4" relativePaths="true" type="JAVA_MODULE">
+  <component name="ModuleRootManager" />
+  <component name="NewModuleRootManager">
+    <output url="file://$MODULE_DIR$/build" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="module" module-name="propertyset" />
+    <orderEntry type="module-library" exported="">
+      <library>
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/lib/hibernate-3.0.5.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntryProperties />
+  </component>
+</module>
+
Add a comment to this file

providers/hibernate3/lib/hibernate3.jar

Binary file added.

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());
+    }
+}
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.