[Commits] (bcm) replace core implementation of UserDAO and RoleDAO with Hibernate

commits at osafoundation.org commits at osafoundation.org
Tue Feb 22 21:17:35 PST 2005


Commit by: bcm
Modified files:
server/core/build.xml 1.2 1.3
server/core/db/.cvsignore None 1.1
server/core/db/schema.sql None 1.1
server/core/etc/ehcache.xml None 1.1
server/core/etc/applicationContext.xml 1.1.1.1 1.2
server/core/src/org/osaf/chandler/server/dao/ShareDAO.java None 1.1
server/core/src/org/osaf/chandler/server/dao/RoleDAO.java 1.1.1.1 1.2
server/core/src/org/osaf/chandler/server/dao/UserDAO.java 1.1.1.1 1.2
server/core/src/org/osaf/chandler/server/dao/hibernate/RoleDAOHibernate.java None 1.1
server/core/src/org/osaf/chandler/server/dao/hibernate/UserDAOHibernate.java None 1.1
server/core/src/org/osaf/chandler/server/dao/slide/ShareDAOSlide.java None 1.1
server/core/src/org/osaf/chandler/server/dao/slide/RoleDAOSlide.java 1.1.1.1 None
server/core/src/org/osaf/chandler/server/dao/slide/UserDAOSlide.java 1.1.1.1 None
server/core/src/org/osaf/chandler/server/manager/ProvisioningManager.java 1.1.1.1 1.2
server/core/src/org/osaf/chandler/server/manager/impl/ProvisioningManagerImpl.java 1.1.1.1 1.2
server/core/src/org/osaf/chandler/server/model/Role.java 1.1.1.1 1.2
server/core/src/org/osaf/chandler/server/model/User.java 1.1.1.1 1.2
server/core/test/org/osaf/chandler/server/dao/ShareDAOTest.java None 1.1
server/core/test/org/osaf/chandler/server/dao/RoleDAOTest.java 1.1.1.1 1.2
server/core/test/org/osaf/chandler/server/dao/UserDAOTest.java 1.1.1.1 1.2
server/core/test/org/osaf/chandler/server/manager/ProvisioningManagerTest.java 1.1.1.1 1.2

Log message:
replace core implementation of UserDAO and RoleDAO with Hibernate
implementations. rework DAO and Manager APIs to get rid of crapisms inflicted
by WebDAV implementations. add new ShareDAO for managing things in the shared
file store (just homedirs right now). default to embedded hsqldb database for
users and roles. next step: custom principal store for Slide.


ViewCVS links:
http://cvs.osafoundation.org/index.cgi/server/core/build.xml.diff?r1=text&tr1=1.2&r2=text&tr2=1.3
http://cvs.osafoundation.org/index.cgi/server/core/db/.cvsignore?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/server/core/db/schema.sql?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/server/core/etc/ehcache.xml?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/server/core/etc/applicationContext.xml.diff?r1=text&tr1=1.1.1.1&r2=text&tr2=1.2
http://cvs.osafoundation.org/index.cgi/server/core/src/org/osaf/chandler/server/dao/ShareDAO.java?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/server/core/src/org/osaf/chandler/server/dao/RoleDAO.java.diff?r1=text&tr1=1.1.1.1&r2=text&tr2=1.2
http://cvs.osafoundation.org/index.cgi/server/core/src/org/osaf/chandler/server/dao/UserDAO.java.diff?r1=text&tr1=1.1.1.1&r2=text&tr2=1.2
http://cvs.osafoundation.org/index.cgi/server/core/src/org/osaf/chandler/server/dao/hibernate/RoleDAOHibernate.java?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/server/core/src/org/osaf/chandler/server/dao/hibernate/UserDAOHibernate.java?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/server/core/src/org/osaf/chandler/server/dao/slide/ShareDAOSlide.java?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/server/core/src/org/osaf/chandler/server/dao/slide/RoleDAOSlide.java.diff?r1=text&tr1=1.1.1.1&r2=text&tr2=None
http://cvs.osafoundation.org/index.cgi/server/core/src/org/osaf/chandler/server/dao/slide/UserDAOSlide.java.diff?r1=text&tr1=1.1.1.1&r2=text&tr2=None
http://cvs.osafoundation.org/index.cgi/server/core/src/org/osaf/chandler/server/manager/ProvisioningManager.java.diff?r1=text&tr1=1.1.1.1&r2=text&tr2=1.2
http://cvs.osafoundation.org/index.cgi/server/core/src/org/osaf/chandler/server/manager/impl/ProvisioningManagerImpl.java.diff?r1=text&tr1=1.1.1.1&r2=text&tr2=1.2
http://cvs.osafoundation.org/index.cgi/server/core/src/org/osaf/chandler/server/model/Role.java.diff?r1=text&tr1=1.1.1.1&r2=text&tr2=1.2
http://cvs.osafoundation.org/index.cgi/server/core/src/org/osaf/chandler/server/model/User.java.diff?r1=text&tr1=1.1.1.1&r2=text&tr2=1.2
http://cvs.osafoundation.org/index.cgi/server/core/test/org/osaf/chandler/server/dao/ShareDAOTest.java?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/server/core/test/org/osaf/chandler/server/dao/RoleDAOTest.java.diff?r1=text&tr1=1.1.1.1&r2=text&tr2=1.2
http://cvs.osafoundation.org/index.cgi/server/core/test/org/osaf/chandler/server/dao/UserDAOTest.java.diff?r1=text&tr1=1.1.1.1&r2=text&tr2=1.2
http://cvs.osafoundation.org/index.cgi/server/core/test/org/osaf/chandler/server/manager/ProvisioningManagerTest.java.diff?r1=text&tr1=1.1.1.1&r2=text&tr2=1.2

Index: server/core/src/org/osaf/chandler/server/model/Role.java
diff -u server/core/src/org/osaf/chandler/server/model/Role.java:1.1.1.1 server/core/src/org/osaf/chandler/server/model/Role.java:1.2
--- server/core/src/org/osaf/chandler/server/model/Role.java:1.1.1.1	Wed Feb 16 11:30:53 2005
+++ server/core/src/org/osaf/chandler/server/model/Role.java	Tue Feb 22 21:17:33 2005
@@ -9,21 +9,27 @@
 import org.apache.commons.lang.builder.HashCodeBuilder;
 
 /**
+ * @hibernate.class table="role"
+ * @hibernate.cache usage="read-write"
  */
 public class Role extends BaseModelObject {
 
     private String name;
     private Date dateCreated;
     private Date dateModified;
-    private Set usernames;
+    private Set users;
 
     /**
      */
     public Role() {
-        usernames = new HashSet();
+        users = new HashSet();
     }
 
     /**
+     * @hibernate.id column="name" unsaved-value="null"
+     *               generator-class="assigned"
+     * @hibernate.column name="name" sql-type="string" length="32"
+     *                   not-null="true"
      */
     public String getName() {
         return name;
@@ -36,6 +42,7 @@
     }
 
     /**
+     * @hibernate.property column="dateCreated" not=null="true"
      */
     public Date getDateCreated() {
         return dateCreated;
@@ -48,6 +55,7 @@
     }
 
     /**
+     * @hibernate.property column="dateModified" not=null="true"
      */
     public Date getDateModified() {
         return dateModified;
@@ -60,27 +68,20 @@
     }
 
     /**
+     * @hibernate.set name="users" table="roleusers" cascade="all"
+     *                lazy="true"
+     * @hibernate.collection-key column="rolename"
+     * @hibernate.collection-many-to-many column="username"
+     *                class="org.osaf.chandler.server.model.User"
      */
-    public Set getUsernames() {
-        return usernames;
+    public Set getUsers() {
+        return users;
     }
 
     /**
      */
-    public void addUsername(String username) {
-        usernames.add(username);
-    }
-
-    /**
-     */
-    public void removeUsername(String username) {
-        usernames.remove(username);
-    }
-
-    /**
-     */
-    public void setUsernames(Set usernames) {
-        this.usernames = usernames;
+    public void setUsers(Set users) {
+        this.users = users;
     }
 
     /**

Index: server/core/test/org/osaf/chandler/server/dao/RoleDAOTest.java
diff -u server/core/test/org/osaf/chandler/server/dao/RoleDAOTest.java:1.1.1.1 server/core/test/org/osaf/chandler/server/dao/RoleDAOTest.java:1.2
--- server/core/test/org/osaf/chandler/server/dao/RoleDAOTest.java:1.1.1.1	Wed Feb 16 11:30:53 2005
+++ server/core/test/org/osaf/chandler/server/dao/RoleDAOTest.java	Tue Feb 22 21:17:33 2005
@@ -5,6 +5,7 @@
 import org.osaf.chandler.server.BaseServerTestCase;
 import org.osaf.chandler.server.TestHelper;
 import org.osaf.chandler.server.dao.RoleDAO;
+import org.osaf.chandler.server.dao.UserDAO;
 import org.osaf.chandler.server.model.Role;
 import org.osaf.chandler.server.model.User;
 
@@ -17,7 +18,9 @@
  */
 public class RoleDAOTest extends BaseServerTestCase {
     private static final String DAO_BEAN = "roleDAO";
+    private static final String USER_DAO_BEAN = "userDAO";
     private RoleDAO dao = null;
+    private UserDAO userDao = null;
 
     /**
      */
@@ -28,11 +31,13 @@
     protected void setUp() throws Exception {
         super.setUp();
         dao = (RoleDAO) ctx.getBean(DAO_BEAN);
+        userDao = (UserDAO) ctx.getBean(USER_DAO_BEAN);
     }
 
     protected void tearDown() throws Exception {
         super.tearDown();
         dao = null;
+        userDao = null;
     }
 
     public void testCRUDRole() throws Exception {
@@ -64,10 +69,9 @@
         }
 
         List roles = dao.getRoles();
-        assertTrue(roles.size() == 2);
     }
 
-    public void testAddRemoveUserNewRole() throws Exception {
+    public void testAddRemoveUser() throws Exception {
         if (log.isDebugEnabled()) {
             log.debug("BEGIN");
         }
@@ -76,40 +80,21 @@
         dao.saveRole(role);
 
         User user = TestHelper.makeDummyUser();
+        userDao.saveUser(user);
 
-        dao.addUserToRole(role, user.getUsername());
-        assertTrue(role.getUsernames().size() == 1);
+        role.getUsers().add(user);
+        dao.updateRole(role);
 
         Role role2 = dao.getRole(role.getName());
-        assertTrue(role.getUsernames().size() == 1);
+        assertTrue(role.getUsers().size() == 1);
 
-        dao.removeUserFromRole(role, user.getUsername());
-        assertTrue(role.getUsernames().isEmpty());
+        role.getUsers().remove(user);
+        dao.updateRole(role);
 
         Role role3 = dao.getRole(role.getName());
-        assertTrue(role.getUsernames().isEmpty());
+        assertTrue(role.getUsers().isEmpty());
 
         dao.removeRole(role);
-    }
-
-    public void testAddRemoveUserExistingRole() throws Exception {
-        if (log.isDebugEnabled()) {
-            log.debug("BEGIN");
-        }
-
-        Role role = dao.getRole("root");
-        User user = TestHelper.makeDummyUser();
-
-        dao.addUserToRole(role, user.getUsername());
-        assertTrue(role.getUsernames().contains(user.getUsername()));
-
-        Role role2 = dao.getRole(role.getName());
-        assertTrue(role.getUsernames().contains(user.getUsername()));
-
-        dao.removeUserFromRole(role, user.getUsername());
-        assertTrue(! role.getUsernames().contains(user.getUsername()));
-
-        Role role3 = dao.getRole(role.getName());
-        assertTrue(! role.getUsernames().contains(user.getUsername()));
+        userDao.removeUser(user);
     }
 }

Index: server/core/test/org/osaf/chandler/server/manager/ProvisioningManagerTest.java
diff -u server/core/test/org/osaf/chandler/server/manager/ProvisioningManagerTest.java:1.1.1.1 server/core/test/org/osaf/chandler/server/manager/ProvisioningManagerTest.java:1.2
--- server/core/test/org/osaf/chandler/server/manager/ProvisioningManagerTest.java:1.1.1.1	Wed Feb 16 11:30:53 2005
+++ server/core/test/org/osaf/chandler/server/manager/ProvisioningManagerTest.java	Tue Feb 22 21:17:33 2005
@@ -40,14 +40,16 @@
         }
 
         User user = TestHelper.makeDummyUser();
+        mgr.saveUser(user);
 
-        User user2 = mgr.saveUser(user);
+        User user2 = mgr.getUser(user.getUsername());
         assertTrue(user.equals(user2));
         assertEquals(user.hashCode(), user2.hashCode());
 
         user2.setPassword("new password");
+        mgr.updateUser(user2);
 
-        User user3 = mgr.updateUser(user2);
+        User user3 = mgr.getUser(user2.getUsername());
         assertTrue(! user.getPassword().equals(user3.getPassword()));
 
         mgr.removeUser(user.getUsername());

Index: server/core/src/org/osaf/chandler/server/manager/impl/ProvisioningManagerImpl.java
diff -u server/core/src/org/osaf/chandler/server/manager/impl/ProvisioningManagerImpl.java:1.1.1.1 server/core/src/org/osaf/chandler/server/manager/impl/ProvisioningManagerImpl.java:1.2
--- server/core/src/org/osaf/chandler/server/manager/impl/ProvisioningManagerImpl.java:1.1.1.1	Wed Feb 16 11:30:52 2005
+++ server/core/src/org/osaf/chandler/server/manager/impl/ProvisioningManagerImpl.java	Tue Feb 22 21:17:32 2005
@@ -3,6 +3,7 @@
 import java.util.List;
 
 import org.osaf.chandler.server.dao.RoleDAO;
+import org.osaf.chandler.server.dao.ShareDAO;
 import org.osaf.chandler.server.dao.UserDAO;
 import org.osaf.chandler.server.manager.ProvisioningManager;
 import org.osaf.chandler.server.model.Role;
@@ -20,6 +21,7 @@
     private static final Log log =
         LogFactory.getLog(ProvisioningManagerImpl.class);
     private RoleDAO roleDao;
+    private ShareDAO shareDao;
     private UserDAO userDao;
 
     /**
@@ -30,6 +32,12 @@
 
     /**
      */
+    public void setShareDAO(ShareDAO shareDao) {
+        this.shareDao = shareDao;
+    }
+
+    /**
+     */
     public void setUserDAO(UserDAO userDao) {
         this.userDao = userDao;
     }
@@ -48,35 +56,32 @@
 
     /**
      */
-    public User saveUser(User user) {
+    public void saveUser(User user) {
         // XXX: hash the user's password
-        User newUser = userDao.saveUser(user);
-        userDao.createHomedir(newUser.getUsername());
+        userDao.saveUser(user);
 
         // XXX: until we get user-level access controls in place, add
         // the user to the root role. this will allow him to see the
         // entire Slide namespace.
         Role rootRole = roleDao.getRole("root");
-        roleDao.addUserToRole(rootRole, newUser.getUsername());
+        rootRole.getUsers().add(user);
 
-        return newUser;
+        shareDao.createHomedir(user.getUsername());
     }
 
     /**
      */
-    public User updateUser(User user) {
-        // XXX: hash the user's password if it has changed
-        return userDao.updateUser(user);
+    public void updateUser(User user) {
+        // XXX: hash the user's password
+        userDao.updateUser(user);
     }
 
     /**
      */
     public void removeUser(String username) {
         // XXX: remove user-level access controls
-        Role rootRole = roleDao.getRole("root");
-        roleDao.removeUserFromRole(rootRole, username);
 
-        userDao.deleteHomedir(username);
+        shareDao.deleteHomedir(username);
         userDao.removeUser(username);
     }
 }

Index: server/core/src/org/osaf/chandler/server/dao/UserDAO.java
diff -u server/core/src/org/osaf/chandler/server/dao/UserDAO.java:1.1.1.1 server/core/src/org/osaf/chandler/server/dao/UserDAO.java:1.2
--- server/core/src/org/osaf/chandler/server/dao/UserDAO.java:1.1.1.1	Wed Feb 16 11:30:52 2005
+++ server/core/src/org/osaf/chandler/server/dao/UserDAO.java	Tue Feb 22 21:17:30 2005
@@ -21,11 +21,11 @@
 
     /**
      */
-    public User saveUser(User user);
+    public void saveUser(User user);
 
     /**
      */
-    public User updateUser(User user);
+    public void updateUser(User user);
 
     /**
      */
@@ -33,9 +33,5 @@
 
     /**
      */
-    public void createHomedir(String username);
-
-    /**
-     */
-    public void deleteHomedir(String username);
+    public void removeUser(User user);
 }

Index: server/core/src/org/osaf/chandler/server/manager/ProvisioningManager.java
diff -u server/core/src/org/osaf/chandler/server/manager/ProvisioningManager.java:1.1.1.1 server/core/src/org/osaf/chandler/server/manager/ProvisioningManager.java:1.2
--- server/core/src/org/osaf/chandler/server/manager/ProvisioningManager.java:1.1.1.1	Wed Feb 16 11:30:52 2005
+++ server/core/src/org/osaf/chandler/server/manager/ProvisioningManager.java	Tue Feb 22 21:17:32 2005
@@ -21,11 +21,11 @@
 
     /**
      */
-    public User saveUser(User user);
+    public void saveUser(User user);
 
     /**
      */
-    public User updateUser(User user);
+    public void updateUser(User user);
 
     /**
      */

Index: server/core/etc/applicationContext.xml
diff -u server/core/etc/applicationContext.xml:1.1.1.1 server/core/etc/applicationContext.xml:1.2
--- server/core/etc/applicationContext.xml:1.1.1.1	Wed Feb 16 11:30:52 2005
+++ server/core/etc/applicationContext.xml	Tue Feb 22 21:17:30 2005
@@ -29,8 +29,46 @@
     </property>
   </bean>
 
+  <!-- Hibernate resources -->
+
+  <bean id="sessionFactory"
+        class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
+    <property name="configLocation">
+      <value>classpath:hibernate.cfg.xml</value>
+    </property>
+  </bean>
+
+  <bean id="transactionManager"
+        class="org.springframework.orm.hibernate.HibernateTransactionManager">
+    <property name="sessionFactory">
+      <ref local="sessionFactory"/>
+    </property>
+  </bean>
+
   <!-- DAOs -->
 
+  <bean id="roleDAO"
+        class="org.osaf.chandler.server.dao.hibernate.RoleDAOHibernate">
+    <property name="sessionFactory">
+      <ref local="sessionFactory"/>
+    </property>
+  </bean>
+
+  <bean id="userDAO"
+        class="org.osaf.chandler.server.dao.hibernate.UserDAOHibernate">
+    <property name="sessionFactory">
+      <ref local="sessionFactory"/>
+    </property>
+  </bean>
+
+  <bean id="shareDAO"
+        class="org.osaf.chandler.server.dao.slide.ShareDAOSlide">
+    <property name="httpURL">
+      <ref local="serverBaseURL"/>
+    </property>
+  </bean>
+
+<!--
   <bean id="roleDAO" class="org.osaf.chandler.server.dao.slide.RoleDAOSlide">
     <property name="httpURL">
       <ref local="serverBaseURL"/>
@@ -42,9 +80,42 @@
       <ref local="serverBaseURL"/>
     </property>
   </bean>
+-->
 
   <!-- Managers -->
 
+  <bean id="provisioningManagerTarget"
+        class="org.osaf.chandler.server.manager.impl.ProvisioningManagerImpl">
+    <property name="roleDAO">
+      <ref local="roleDAO"/>
+    </property>
+    <property name="shareDAO">
+      <ref local="shareDAO"/>
+    </property>
+    <property name="userDAO">
+      <ref local="userDAO"/>
+    </property>
+  </bean>
+
+  <bean id="provisioningManager"
+        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
+    <property name="transactionManager">
+      <ref local="transactionManager"/>
+    </property>
+    <property name="target">
+      <ref local="provisioningManagerTarget"/>
+    </property>
+    <property name="transactionAttributes">
+      <props>
+        <prop key="save*">PROPAGATION_REQUIRED</prop>
+        <prop key="update*">PROPAGATION_REQUIRED</prop>
+        <prop key="remove*">PROPAGATION_REQUIRED</prop>
+        <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
+      </props>
+    </property>
+  </bean>
+
+<!--
   <bean id="provisioningManager"
         class="org.osaf.chandler.server.manager.impl.ProvisioningManagerImpl">
     <property name="roleDAO">
@@ -53,6 +124,10 @@
     <property name="userDAO">
       <ref local="userDAO"/>
     </property>
+    <property name="shareDAO">
+      <ref local="shareDAO"/>
+    </property>
   </bean>
+-->
 
 </beans>

Index: server/core/build.xml
diff -u server/core/build.xml:1.2 server/core/build.xml:1.3
--- server/core/build.xml:1.2	Wed Feb 16 13:13:50 2005
+++ server/core/build.xml	Tue Feb 22 21:17:29 2005
@@ -6,6 +6,7 @@
 
   <property environment="env"/>
   <property name="catalina.home"       value="${env.CATALINA_HOME}"/>
+  <property name="xdoclet.home"        value="${env.XDOCLET_HOME}"/>
 
   <property name="compile.debug"       value="true"/>
   <property name="compile.deprecation" value="true"/>
@@ -17,22 +18,61 @@
   <property name="core.build"          value="${core.home}/build"/>
   <property name="core.src"            value="${core.home}/src"/>
   <property name="core.etc"            value="${core.home}/etc"/>
+  <property name="core.db"             value="${core.home}/db"/>
   <property name="core.test"           value="${core.home}/test"/>
 
+  <property name="chandler.server.test.userdb.dialect"
+            value="net.sf.hibernate.dialect.HSQLDialect"/>
+  <property name="chandler.server.test.userdb.driver"
+            value="org.hsqldb.jdbcDriver"/>
+  <property name="chandler.server.test.userdb.database"
+            value="userdb"/>
+  <property name="chandler.server.test.userdb.url"
+            value="jdbc:hsqldb:file:db/${chandler.server.test.userdb.database}"/>
+  <property name="chandler.server.test.userdb.username"
+            value="sa"/>
+  <property name="chandler.server.test.userdb.password"
+            value=""/>
+
+  <taskdef name="hibernatedoclet"
+           classname="xdoclet.modules.hibernate.HibernateDocletTask">
+    <classpath>
+      <fileset dir="${xdoclet.home}/lib">
+        <include name="*.jar"/>
+      </fileset>
+    </classpath>
+  </taskdef>
+
   <!-- DEPENDENCIES -->
 
+  <property name="aopalliance.jar"
+            value="${core.ext}/aopalliance.jar"/>
+  <property name="cglib.jar"
+            value="${core.ext}/cglib-full-2.0.2.jar"/>
   <property name="commons-httpclient.jar"
             value="${core.ext}/commons-httpclient-2.0.2.jar"/>
   <property name="commons-lang.jar"
             value="${core.ext}/commons-lang-2.0.jar"/>
   <property name="commons-logging.jar"
             value="${core.ext}/commons-logging.jar"/>
+  <property name="dom4j.jar"
+            value="${core.ext}/dom4j-1.4.jar"/>
+  <property name="ehcache.jar"
+            value="${core.ext}/ehcache-1.1.jar"/>
+  <property name="hibernate.jar"
+            value="${core.ext}/hibernate2.jar"/>
+  <property name="hsqldb.jar"
+            value="${core.ext}/hsqldb.jar"/>
   <property name="jdom.jar"
             value="${core.ext}/jdom.jar"/>
   <property name="joda-time.jar"
             value="${core.ext}/joda-time-0.98.jar"/>
+  <property name="jta.jar"
+            value="${core.ext}/jta.jar"/>
   <property name="log4j.jar"
             value="${core.ext}/log4j-1.2.8.jar"/>
+  <property name="odmg.jar"
+            value="${core.ext}/odmg-3.0.jar"/>
   <property name="slide-webdavlib.jar"
             value="${core.ext}/jakarta-slide-webdavlib-2.1.jar"/>
   <property name="spring.jar"
@@ -47,6 +87,7 @@
     <pathelement location="${commons-httpclient.jar}"/>
     <pathelement location="${commons-lang.jar}"/>
     <pathelement location="${commons-logging.jar}"/>
+    <pathelement location="${hibernate.jar}"/>
     <pathelement location="${jdom.jar}"/>
     <pathelement location="${joda-time.jar}"/>
     <pathelement location="${log4j.jar}"/>
@@ -61,7 +102,21 @@
     <mkdir dir="${core.build}/classes"/>
   </target>
 
-  <target name="compile" depends="prepare"
+  <target name="gen" depends="prepare"
+          description="generate Hibernate mapping files">
+    <hibernatedoclet destDir="${core.build}/classes"
+                     excludedtags="@version, at author, at todo"
+                     verbose="${hibernate.verbose}">
+      <fileset dir="${core.src}">
+        <include name="**/*.java"/>
+      </fileset>
+      <hibernate version="2.0"/>
+      <hibernatecfg dataSource="${chandler.server.userdb.dataSource}"
+                    dialect="${chandler.server.userdb.dialect}"/>
+    </hibernatedoclet>
+  </target>
+
+  <target name="compile" depends="prepare,gen"
           description="build the source">
     <javac srcdir="${core.src}"
            destdir="${core.build}/classes"
@@ -72,10 +127,10 @@
   </target>
 
   <target name="pack-jar" description="pack the jar">
-    <copy file="${core.etc}/applicationContext.xml"
-          todir="${core.build}/classes"/>
     <jar destfile="${core.build}/chandler-server-core.jar"
-         basedir="${core.build}/classes"/>
+         basedir="${core.build}/classes">
+      <exclude name="hibernate.cfg.xml"/>
+    </jar>
   </target>
 
   <target name="all" depends="compile,pack-jar"
@@ -93,7 +148,24 @@
     <mkdir dir="${core.test}/data"/>
   </target>
 
-  <target name="test-compile" depends="test-prepare"
+  <target name="test-gen" depends="test-prepare"
+          description="generate Hibernate mapping files">
+    <hibernatedoclet destDir="${core.build}/testclasses"
+                     excludedtags="@version, at author, at todo"
+                     verbose="${hibernate.verbose}">
+      <fileset dir="${core.src}">
+        <include name="**/*.java"/>
+      </fileset>
+      <hibernate version="2.0"/>
+      <hibernatecfg dialect="${chandler.server.test.userdb.dialect}"
+                    driver="${chandler.server.test.userdb.driver}"
+                    jdbcUrl="${chandler.server.test.userdb.url}"
+                    username="${chandler.server.test.userdb.username}"
+                    password="${chandler.server.test.userdb.password}"/>
+    </hibernatedoclet>
+  </target>
+
+  <target name="test-compile" depends="test-prepare,test-gen"
           description="build the test source">
     <javac srcdir="${core.test}"
            destdir="${core.build}/testclasses"
@@ -115,7 +187,9 @@
         <include name="log4j.xml"/>
       </fileset>
       <fileset dir="${core.etc}">
+        <include name="applicationContext.xml"/>
         <include name="chandler.properties"/>
+        <include name="ehcache.xml"/>
       </fileset>
     </copy>
     <junit printsummary="no" fork="true"
@@ -124,6 +198,13 @@
         <path refid="ext.classpath"/>
         <fileset dir="${core.build}" includes="*.jar"/>
         <path location="${core.build}/testclasses"/>
+        <pathelement location="${aopalliance.jar}"/>
+        <pathelement location="${cglib.jar}"/>
+        <pathelement location="${dom4j.jar}"/>
+        <pathelement location="${ehcache.jar}"/>
+        <pathelement location="${hsqldb.jar}"/>
+        <pathelement location="${jta.jar}"/>
+        <pathelement location="${odmg.jar}"/>
       </classpath>
       <formatter type="xml"/>
       <formatter type="brief" usefile="false"/>
@@ -151,4 +232,19 @@
     <delete dir="${core.test}/data"/>
   </target>
 
+  <!-- DATABASE TARGETS -->
+
+  <target name="userdb-setup"
+          description="set up the user database">
+    <echo>Setting up db ${chandler.server.test.userdb.database}</echo>
+    <sql driver="${chandler.server.test.userdb.driver}"
+         url="${chandler.server.test.userdb.url}"
+         userid="${chandler.server.test.userdb.username}"
+         password="${chandler.server.test.userdb.password}">
+      <fileset dir="${core.db}">
+        <include name="schema.sql"/>
+      </fileset>
+    </sql>
+  </target>
+
 </project>

Index: server/core/src/org/osaf/chandler/server/model/User.java
diff -u server/core/src/org/osaf/chandler/server/model/User.java:1.1.1.1 server/core/src/org/osaf/chandler/server/model/User.java:1.2
--- server/core/src/org/osaf/chandler/server/model/User.java:1.1.1.1	Wed Feb 16 11:30:53 2005
+++ server/core/src/org/osaf/chandler/server/model/User.java	Tue Feb 22 21:17:33 2005
@@ -2,11 +2,15 @@
 package org.osaf.chandler.server.model;
 
 import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
 
 /**
+ * @hibernate.class table="user"
+ * @hibernate.cache usage="read-write"
  */
 public class User extends BaseModelObject {
 
@@ -16,13 +20,19 @@
     private String homedir;
     private Date dateCreated;
     private Date dateModified;
+    private Set roles;
 
     /**
      */
     public User() {
+        roles = new HashSet();
     }
 
     /**
+     * @hibernate.id column="username" unsaved-value="null"
+     *               generator-class="assigned"
+     * @hibernate.column name="username" sql-type="string" length="32"
+     *                   not-null="true"
      */
     public String getUsername() {
         return username;
@@ -35,6 +45,8 @@
     }
 
     /**
+     * @hibernate.property column="password" length="32"
+     *                     not=null="true"
      */
     public String getPassword() {
         return password;
@@ -47,6 +59,8 @@
     }
 
     /**
+     * @hibernate.property column="email" length="32"
+     *                     not=null="true"
      */
     public String getEmail() {
         return email;
@@ -59,18 +73,7 @@
     }
 
     /**
-     */
-    public String getHomedir() {
-        return homedir;
-    }
-
-    /**
-     */
-    public void setHomedir(String homedir) {
-        this.homedir = homedir;
-    }
-
-    /**
+     * @hibernate.property column="dateCreated" not=null="true"
      */
     public Date getDateCreated() {
         return dateCreated;
@@ -83,6 +86,7 @@
     }
 
     /**
+     * @hibernate.property column="dateModified" not=null="true"
      */
     public Date getDateModified() {
         return dateModified;
@@ -95,6 +99,23 @@
     }
 
     /**
+     * @hibernate.set name="roles" table="roleusers" cascade="all"
+     *                lazy="true"
+     * @hibernate.collection-key column="username"
+     * @hibernate.collection-many-to-many column="rolename"
+     *                class="org.osaf.chandler.server.model.Role"
+     */
+    public Set getRoles() {
+        return roles;
+    }
+
+    /**
+     */
+    public void setRoles(Set roles) {
+        this.roles = roles;
+    }
+
+    /**
      */
     public boolean equals(Object o) {
         if (! (o instanceof User)) {

Index: server/core/src/org/osaf/chandler/server/dao/RoleDAO.java
diff -u server/core/src/org/osaf/chandler/server/dao/RoleDAO.java:1.1.1.1 server/core/src/org/osaf/chandler/server/dao/RoleDAO.java:1.2
--- server/core/src/org/osaf/chandler/server/dao/RoleDAO.java:1.1.1.1	Wed Feb 16 11:30:52 2005
+++ server/core/src/org/osaf/chandler/server/dao/RoleDAO.java	Tue Feb 22 21:17:30 2005
@@ -27,11 +27,7 @@
 
     /**
      */
-    public void addUserToRole(Role role, String username);
-
-    /**
-     */
-    public void removeUserFromRole(Role role, String username);
+    public void updateRole(Role role);
 
     /**
      */

Index: server/core/test/org/osaf/chandler/server/dao/UserDAOTest.java
diff -u server/core/test/org/osaf/chandler/server/dao/UserDAOTest.java:1.1.1.1 server/core/test/org/osaf/chandler/server/dao/UserDAOTest.java:1.2
--- server/core/test/org/osaf/chandler/server/dao/UserDAOTest.java:1.1.1.1	Wed Feb 16 11:30:53 2005
+++ server/core/test/org/osaf/chandler/server/dao/UserDAOTest.java	Tue Feb 22 21:17:33 2005
@@ -40,20 +40,20 @@
         }
 
         User user = TestHelper.makeDummyUser();
+        dao.saveUser(user);
 
-        User user2 = dao.saveUser(user);
+        User user2 = dao.getUser(user.getUsername());
         assertTrue(user2.equals(user));
         assertEquals(user2.hashCode(), user.hashCode());
         assertNotNull(user2.getEmail());
-        assertNotNull(user2.getHomedir());
 
         user2.setPassword("changed password");
+        dao.updateUser(user2);
 
-        User user3 = dao.updateUser(user2);
+        User user3 = dao.getUser(user2.getUsername());
         assertEquals(user2.getPassword(), user3.getPassword());
         assertTrue(! user.getPassword().equals(user3.getPassword()));
         assertEquals(user.getEmail(), user3.getEmail());
-        assertEquals(user.getHomedir(), user3.getHomedir());
 
         dao.removeUser(user.getUsername());
         try {
@@ -64,12 +64,6 @@
         }
     }
 
-    public void testCDHomedir() throws Exception {
-        User user = TestHelper.makeDummyUser();
-        dao.createHomedir(user.getUsername());
-        dao.deleteHomedir(user.getUsername());
-    }
-
     public void testListUsers() throws Exception {
         if (log.isDebugEnabled()) {
             log.debug("BEGIN");



More information about the Commits mailing list