Revision: 176
http://svn.sourceforge.net/nmailserver/?rev=176&view=rev
Author: tmyroadctfig
Date: 2007-03-12 22:05:16 -0700 (Mon, 12 Mar 2007)
Log Message:
-----------
Work on NHibernate local store data mappings.
Modified Paths:
--------------
NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateLocalStoreData.cs
NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.csproj
Added Paths:
-----------
NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/
NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.ACLs.StoreFolderAcl.hbm.xml
NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.Calendar.Attendee.hbm.xml
NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.Calendar.Calendar.hbm.xml
NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.Calendar.CalendarEntry.hbm.xml
NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.LocalStoreGroup.hbm.xml
NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.LocalStoreUser.hbm.xml
NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.MailDomain.hbm.xml
NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.StoreFolder.hbm.xml
Removed Paths:
-------------
NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.Auth.hbm.xml
NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.UserMap.hbm.xml
NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.hbm.xml
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.ACLs.StoreFolderAcl.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.ACLs.StoreFolderAcl.hbm.xml (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.ACLs.StoreFolderAcl.hbm.xml 2007-03-13 05:05:16 UTC (rev 176)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NMail" assembly="NMail" default-lazy="false">
+
+ <class name="NMail.DataTypes.ACLs.StoreFolderAcl" table="StoreFolderAcl">
+ <id name="AclId" type="Int32" unsaved-value="0">
+ <column name="AclId" not-null="true"/>
+ <generator class="native" />
+ </id>
+
+ <many-to-one name="Folder" cascade="all" class="NMail.DataTypes.LocalStore.StoreFolder" not-null="true"/>
+
+ <map name="entries" access="field" table="StoreFolderAclEntries">
+ <key column="IdentifierId" />
+ <index column="Identifier" type="String" />
+ <element column="StoreFolderPrivilege" type="Int32" />
+ </map>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.Calendar.Attendee.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.Calendar.Attendee.hbm.xml (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.Calendar.Attendee.hbm.xml 2007-03-13 05:05:16 UTC (rev 176)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NMail" assembly="NMail" default-lazy="false">
+
+ <class name="NMail.DataTypes.Calendar.Attendee" table="Attendee">
+ <id type="Int32">
+ <column name="AttendeeId" not-null="true"/>
+ <generator class="native" />
+ </id>
+
+ <property name="Address" not-null="true"/>
+
+ <many-to-one name="CalendarEntry"
+ class="NMail.DataTypes.Calendar.CalendarEntry"
+ column="CalendarEntryId" />
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.Calendar.Calendar.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.Calendar.Calendar.hbm.xml (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.Calendar.Calendar.hbm.xml 2007-03-13 05:05:16 UTC (rev 176)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NMail" assembly="NMail" default-lazy="false">
+
+ <class name="NMail.DataTypes.Calendar.Calendar" table="Calendar">
+ <id name="CalendarId" type="Int32" unsaved-value="0">
+ <column name="CalendarId" not-null="true"/>
+ <generator class="native" />
+ </id>
+
+ <property name="Name" not-null="true"/>
+
+ <!-- TODO: make this a many to one relationship with folder -->
+ <property name="ParentFolderId" />
+
+ <!-- TODO: make this a many to one relationship with user -->
+ <property name="OwnerUserId" />
+
+ <list name="Entries" cascade="all">
+ <key column="CalendarEntryId" />
+ <index column="CategoryEntryIndex" type="Int32" />
+ <one-to-many class="NMail.DataTypes.Calendar.CalendarEntry" />
+ </list>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.Calendar.CalendarEntry.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.Calendar.CalendarEntry.hbm.xml (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.Calendar.CalendarEntry.hbm.xml 2007-03-13 05:05:16 UTC (rev 176)
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NMail" assembly="NMail" default-lazy="false">
+
+ <class name="NMail.DataTypes.Calendar.CalendarEntry" table="CalendarEntry">
+ <id name="EntryId" type="Int32" unsaved-value="0">
+ <column name="CalendarEntryId" not-null="true"/>
+ <generator class="native" />
+ </id>
+
+
+ <!--
+ - Descriptive Properties
+ -->
+ <property name="Classification" not-null="true" />
+
+ <list name="Categories" table="CalendarEventCategories" cascade="all">
+ <key column="CalendarEntryId" />
+ <index column="CategoryIndex" type="Int32" />
+ <element column="Category" type="String" />
+ </list>
+
+ <property name="Description" />
+
+ <!--<property name="Status" />-->
+
+ <property name="Summary" />
+
+
+ <!--
+ - Date/Time Properties
+ -->
+ <property name="StartTime" not-null="true" />
+
+
+ <!--
+ - Relationship Component Properties
+ -->
+ <list name="Attendees" cascade="all">
+ <key column="CalendarEntryId" />
+ <index column="AttendeeIndex" />
+ <one-to-many class="NMail.DataTypes.Calendar.Attendee" />
+ </list>
+
+ <property name="Organiser" type="String" />
+
+ <!-- TODO: make this a many to one relationship with user -->
+ <property name="OwnerUserId" />
+
+ <many-to-one name="Calendar"
+ class="NMail.DataTypes.Calendar.Calendar"
+ column="CalendarId" />
+
+
+ <!--
+ - Recurrence Component Properties
+ -->
+
+ <!-- one to many <property name="Recurrence" /> -->
+
+ <property name="RecurrenceId" />
+
+
+ <!--
+ - Change Management Component Properties
+ -->
+ <property name="Created" />
+
+ <property name="TimeStamp" />
+
+ <property name="LastModified" />
+
+ <property name="Sequence" />
+
+ <!--
+ -
+ - Calendar Event
+ -
+ -->
+ <joined-subclass name="NMail.DataTypes.Calendar.EventEntry" table="EventEntry">
+ <key column="CalendarEntryId"/>
+ </joined-subclass>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.LocalStoreGroup.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.LocalStoreGroup.hbm.xml (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.LocalStoreGroup.hbm.xml 2007-03-13 05:05:16 UTC (rev 176)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NMail" assembly="NMail" default-lazy="false">
+
+ <class name="NMail.DataTypes.LocalStore.LocalStoreGroup" table="t_Group">
+ <id name="GroupId" type="Int32" unsaved-value="0">
+ <column name="GroupId" not-null="true"/>
+ <generator class="native" />
+ </id>
+
+ <property name="Name" not-null="true"/>
+
+ <list name="SubGroupIds" table="GroupSubGroups">
+ <key column="ParentGroupId" />
+ <index column="ChildIndex" type="Int32" />
+ <many-to-many column="GroupId" class="NMail.DataTypes.LocalStore.LocalStoreGroup" />
+ </list>
+
+ <list name="UserIds" table="GroupUsers">
+ <key column="GroupId" />
+ <index column="ChildIndex" type="Int32" />
+ <many-to-many column="UserId" class="NMail.DataTypes.LocalStore.LocalStoreUser" />
+ </list>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.LocalStoreUser.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.LocalStoreUser.hbm.xml (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.LocalStoreUser.hbm.xml 2007-03-13 05:05:16 UTC (rev 176)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NMail" assembly="NMail" default-lazy="false">
+
+ <class name="NMail.DataTypes.LocalStore.LocalStoreUser" table="t_User">
+ <id name="UserId" type="Int32" unsaved-value="0">
+ <column name="UserId" not-null="true"/>
+ <generator class="native" />
+ </id>
+
+ <property name="Username" not-null="true"/>
+
+ <many-to-one name="UserFolderId" class="NMail.DataTypes.LocalStore.StoreFolder" foreign-key="FolderId" />
+
+ <property name="QuotaHardLimit" />
+
+ <property name="QuotaWarnLimit" />
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.MailDomain.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.MailDomain.hbm.xml (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.MailDomain.hbm.xml 2007-03-13 05:05:16 UTC (rev 176)
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NMail" assembly="NMail" default-lazy="false">
+
+ <class name="NMail.DataTypes.LocalStore.MailDomain" table="MailDomain">
+ <id name="MailDomainId" type="Int32" unsaved-value="0">
+ <column name="MailDomainId" not-null="true"/>
+ <generator class="native" />
+ </id>
+
+ <property name="PrimaryHost" not-null="true" />
+
+ <list name="GroupIds" table="MailDomainGroups">
+ <key column="MailDomainId" />
+ <index column="ChildIndex" type="Int32" />
+ <many-to-many column="GroupId" class="NMail.DataTypes.LocalStore.LocalStoreGroup" />
+ </list>
+
+ <list name="UserIds" table="MailDomainUsers">
+ <key column="MailDomainId" />
+ <index column="ChildIndex" type="Int32" />
+ <many-to-many column="UserId" class="NMail.DataTypes.LocalStore.LocalStoreUser" />
+ </list>
+
+ <list name="AdditionalHosts" table="MailDomainHosts">
+ <key column="MailDomainId" />
+ <index column="ChildIndex" type="Int32" />
+ <element column="Host" unique="true" type="Serializable" />
+ </list>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.StoreFolder.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.StoreFolder.hbm.xml (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.StoreFolder.hbm.xml 2007-03-13 05:05:16 UTC (rev 176)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NMail" assembly="NMail" default-lazy="false">
+
+ <class name="NMail.DataTypes.LocalStore.StoreFolder" table="Folder">
+ <id name="FolderId" type="Int32" unsaved-value="0">
+ <column name="FolderId" not-null="true"/>
+ <generator class="native" />
+ </id>
+
+ <property name="FullFolderName" not-null="true"/>
+
+ <property name="NameSpace" not-null="true" />
+
+ <!-- TODO: lookup how best to implement this nullable type... -->
+ <!-- <many-to-one name="ParentId" foreign-key="FolderId" /> -->
+ <!--<property name="ParentId" type="Int32?" />-->
+
+ <many-to-one name="OwnerUserId" class="NMail.DataTypes.LocalStore.LocalStoreUser" foreign-key="UserId"/>
+
+ <list name="ChildrenIds" cascade="all">
+ <key column="FolderId" />
+ <index column="ChildIndex" type="Int32" />
+ <one-to-many class="NMail.DataTypes.LocalStore.StoreFolder" />
+ </list>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Modified: NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateLocalStoreData.cs
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateLocalStoreData.cs 2007-03-13 05:04:17 UTC (rev 175)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateLocalStoreData.cs 2007-03-13 05:05:16 UTC (rev 176)
@@ -919,113 +919,23 @@
/// <param name="username">The username to look up.</param>
/// <returns>The matching user or null if non is found.</returns>
public LocalStoreUser GetUser(string name) {
- //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // return getUser(name, cnn, null);
- //}
- throw new NotImplementedException();
+ using (ISession session = this.hibernateFactory.OpenSession()) {
+ return session.CreateCriteria(typeof(LocalStoreUser))
+ .Add(Expression.Like("Username", name))
+ .UniqueResult<LocalStoreUser>();
+ }
}
- //private LocalStoreUser getUser(string name, MySqlConnection cnn, MySqlTransaction transaction) {
- // using (MySqlCommand cmd = cnn.CreateCommand()) {
- // cmd.Transaction = transaction;
- // cmd.CommandType = CommandType.StoredProcedure;
- // cmd.CommandText = "GetUserFromName";
- // cmd.Parameters.Add("?Name", name);
- // cmd.Parameters.Add("?UserId", MySqlDbType.Int32);
- // cmd.Parameters.Add("?QuotaHardLimit", MySqlDbType.Int32);
- // cmd.Parameters.Add("?QuotaWarnLimit", MySqlDbType.Int32);
- // cmd.Parameters.Add("?UserFolderId", MySqlDbType.Int32);
- // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
- // cmd.Parameters["UserId"].Direction = ParameterDirection.Output;
- // cmd.Parameters["QuotaHardLimit"].Direction = ParameterDirection.Output;
- // cmd.Parameters["QuotaWarnLimit"].Direction = ParameterDirection.Output;
- // cmd.Parameters["UserFolderId"].Direction = ParameterDirection.Output;
- // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
-
- // cmd.ExecuteNonQuery();
-
- // int resultValue = (int) cmd.Parameters["Result"].Value;
- // LocalStoreUserResult result = (LocalStoreUserResult) resultValue;
-
- // // Check if the lookup succeeded
- // if (result != LocalStoreUserResult.OkSuccessful) {
- // return null;
- // }
-
- // // Parse out all the returned values
- // int userId = (int) cmd.Parameters["UserId"].Value;
- // object quotaHardLimit = cmd.Parameters["QuotaHardLimit"].Value;
- // object quotaWarnLimit = cmd.Parameters["QuotaWarnLimit"].Value;
- // int userFolderId = (int) cmd.Parameters["UserFolderId"].Value;
-
- // int? quotaHardLimitVal = (quotaHardLimit == DBNull.Value) ? null : (int?) quotaHardLimit;
- // int? quotaWarnLimitVal = (quotaWarnLimit == DBNull.Value) ? null : (int?) quotaWarnLimit;
-
- // // Return the user object
- // return new LocalStoreUser(name,
- // userId,
- // userFolderId,
- // quotaWarnLimitVal,
- // quotaHardLimitVal);
- // }
- //}
-
/// <summary>
/// Gets the user for the given user Id.
/// </summary>
/// <param name="userId">The Id of the user to look up.</param>
/// <returns>The matching user or null if non is found.</returns>
public LocalStoreUser GetUser(int userId) {
- //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // return getUser(userId, cnn, null);
- //}
- throw new NotImplementedException();
+ using (ISession session = this.hibernateFactory.OpenSession()) {
+ return session.Load<LocalStoreUser>(userId);
+ }
}
-
- //public LocalStoreUser getUser(int userId, MySqlConnection cnn, MySqlTransaction transaction) {
- // using (MySqlCommand cmd = cnn.CreateCommand()) {
- // cmd.Transaction = transaction;
- // cmd.CommandType = CommandType.StoredProcedure;
- // cmd.CommandText = "GetUserFromId";
- // cmd.Parameters.Add("?UserId", userId);
- // cmd.Parameters.Add("?Name", MySqlDbType.VarChar);
- // cmd.Parameters.Add("?QuotaHardLimit", MySqlDbType.Int32);
- // cmd.Parameters.Add("?QuotaWarnLimit", MySqlDbType.Int32);
- // cmd.Parameters.Add("?UserFolderId", MySqlDbType.Int32);
- // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
- // cmd.Parameters["Name"].Direction = ParameterDirection.Output;
- // cmd.Parameters["QuotaHardLimit"].Direction = ParameterDirection.Output;
- // cmd.Parameters["QuotaWarnLimit"].Direction = ParameterDirection.Output;
- // cmd.Parameters["UserFolderId"].Direction = ParameterDirection.Output;
- // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
-
- // cmd.ExecuteNonQuery();
-
- // int resultValue = (int) cmd.Parameters["Result"].Value;
- // LocalStoreUserResult result = (LocalStoreUserResult) resultValue;
-
- // // Check if the lookup succeeded
- // if (result != LocalStoreUserResult.OkSuccessful) {
- // return null;
- // }
-
- // // Parse out all the returned values
- // string name = (string) cmd.Parameters["Name"].Value;
- // object quotaHardLimit = cmd.Parameters["QuotaHardLimit"].Value;
- // object quotaWarnLimit = cmd.Parameters["QuotaWarnLimit"].Value;
- // int userFolderId = (int) cmd.Parameters["UserFolderId"].Value;
-
- // int? quotaHardLimitVal = (quotaHardLimit == DBNull.Value) ? null : (int?) quotaHardLimit;
- // int? quotaWarnLimitVal = (quotaWarnLimit == DBNull.Value) ? null : (int?) quotaWarnLimit;
-
- // // Return the user object
- // return new LocalStoreUser(name,
- // userId,
- // userFolderId,
- // quotaWarnLimitVal,
- // quotaHardLimitVal);
- // }
- //}
#endregion
#region Get Users
@@ -1033,74 +943,60 @@
/// Gets the list of users that currently exist in the local store.
/// </summary>
/// <returns>The list of users.</returns>
- public LocalStoreUser[] GetUsers() {
- //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // MySqlTransaction transaction = cnn.BeginTransaction();
+ public IList<LocalStoreUser> GetUsers() {
+ using (ISession session = this.hibernateFactory.OpenSession()) {
+ return session.CreateCriteria(typeof(LocalStoreUser)).List<LocalStoreUser>();
+ }
+ }
+ #endregion
- // try {
- // MySqlCommand cmd = cnn.CreateCommand();
- // cmd.Transaction = transaction;
+ #region Create User
+ /// <summary>
+ /// Creates a new user in the local store and creates an initial folder.
+ /// </summary>
+ /// <param name="user">The user to create.</param>
+ /// <exception cref="System.Data.DuplicateNameException">If a user with the same name already exists.</exception>
+ /// <exception cref="System.InvalidOperationException">Changes to the user are not permitted.</exception>
+ /// <exception cref="System.ArgumentException">The user is invalid.</exception>
+ public void CreateUser(LocalStoreUser user) {
+ using (ISession session = this.hibernateFactory.OpenSession()) {
+ using (ITransaction tx = session.BeginTransaction()) {
+ if (user.UserId != 0) {
+ throw new InvalidOperationException("Can't save an existing user with this method.");
+ }
- // cmd.CommandType = CommandType.StoredProcedure;
- // cmd.CommandText = "GetUserIds";
- // MySqlDataReader reader = cmd.ExecuteReader();
- // List<int> userIds = new List<int>();
+ // Check if any other user with the same name exists in the system
+ IList existing = session.CreateCriteria(typeof(LocalStoreUser))
+ .Add(Expression.Like("Username", user.Username))
+ .List();
- // while (reader.Read()) {
- // int userId = (int) reader["UserId"];
- // userIds.Add(userId);
- // }
- // reader.Close();
+ if (existing.Count > 0) {
+ throw new DuplicateNameException("User with the same name already exists in the system.");
+ }
- // List<LocalStoreUser> users = new List<LocalStoreUser>();
- // foreach (int userId in userIds) {
- // users.Add(getUser(userId, cnn, transaction));
- // }
+ session.Save(user);
- // transaction.Commit();
- // return users.ToArray();
+ // Create the user's folder
+ StoreFolder userFolder = new StoreFolder();
+ userFolder.NameSpace = DefaultNameSpace;
+ userFolder.FullFolderName = user.Username;
+ userFolder.OwnerUserId = user.UserId;
- // } catch (Exception ex) {
- // if (transaction != null) {
- // transaction.Rollback();
- // }
+ session.Save(userFolder);
- // throw ex;
- // }
- //}
- throw new NotImplementedException();
- }
- #endregion
+ // Create the user's folder
+ StoreFolder inboxFolder = new StoreFolder();
+ inboxFolder.NameSpace = DefaultNameSpace;
+ inboxFolder.FullFolderName = string.Format("{0}{1}{2}", user.Username, userFolder.Delimiter, Folder.Inbox);
+ inboxFolder.ParentId = userFolder.FolderId;
+ inboxFolder.OwnerUserId = user.UserId;
- #region Create User
- /// <summary>
- /// Creates a new user in the local store and creates an initial folder.
- /// </summary>
- /// <param name="userName">The name of the new user.</param>
- /// <param name="warnQuota">The warning quota level.</param>
- /// <param name="hardQuota">The hard quota.</param>
- /// <returns>The result of the attemp to create a new user.</returns>
- public LocalStoreUserResult CreateUser(string username, int? warnQuota, int? hardQuota) {
- //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // using (MySqlCommand cmd = cnn.CreateCommand()) {
- // cmd.CommandType = CommandType.StoredProcedure;
- // cmd.CommandText = "CreateUser";
- // cmd.Parameters.Add("?Name", username);
- // cmd.Parameters.Add("?QuotaHardLimit", hardQuota);
- // cmd.Parameters.Add("?QuotaWarnLimit", warnQuota);
- // cmd.Parameters.Add("?UserId", MySqlDbType.Int32);
- // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
- // cmd.Parameters["UserId"].Direction = ParameterDirection.Output;
- // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
-
- // cmd.ExecuteNonQuery();
-
- // int result = (int) cmd.Parameters["Result"].Value;
-
- // return (LocalStoreUserResult) result;
- // }
- //}
- throw new NotImplementedException();
+ session.Save(inboxFolder);
+
+ tx.Commit();
+ session.Close();
+ }
+ }
}
#endregion
@@ -1110,23 +1006,16 @@
/// </summary>
/// <param name="userId">The Id of the user to delete.</param>
/// <returns>The result of the attempt to delete a user.</returns>
- public LocalStoreUserResult DeleteUser(int userId) {
- //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // using (MySqlCommand cmd = cnn.CreateCommand()) {
- // cmd.CommandType = CommandType.StoredProcedure;
- // cmd.CommandText = "DeleteUser";
- // cmd.Parameters.Add("?DeleteUserId", userId);
- // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
- // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
+ public void DeleteUser(int userId) {
+ using (ISession session = this.hibernateFactory.OpenSession()) {
+ using (ITransaction tx = session.BeginTransaction()) {
+ LocalStoreUser user = session.Load<LocalStoreUser>(userId);
+ session.Delete(user);
- // cmd.ExecuteNonQuery();
-
- // int result = (int) cmd.Parameters["Result"].Value;
-
- // return (LocalStoreUserResult) result;
- // }
- //}
- throw new NotImplementedException();
+ tx.Commit();
+ }
+ session.Close();
+ }
}
#endregion
@@ -1136,62 +1025,42 @@
/// </summary>
/// <param name="user">The user details to update.</param>
/// <returns>The result of the attempt to update the user.</returns>
- public LocalStoreUserResult UpdateUser(LocalStoreUser user) {
- //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // using (MySqlCommand cmd = cnn.CreateCommand()) {
- // cmd.CommandType = CommandType.StoredProcedure;
- // cmd.CommandText = "UpdateUser";
- // cmd.Parameters.Add("?UserId", user.UserId);
- // cmd.Parameters.Add("?Name", user.Username);
- // cmd.Parameters.Add("?QuotaHardLimit", user.QuotaHardLimit);
- // cmd.Parameters.Add("?QuotaWarnLimit", user.QuotaWarnLimit);
- // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
- // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
+ public void UpdateUser(LocalStoreUser user) {
+ using (ISession session = this.hibernateFactory.OpenSession()) {
+ using (ITransaction tx = session.BeginTransaction()) {
+ // Check if any other user with the same name exists in the system
+ IList existing = session.CreateCriteria(typeof(LocalStoreUser))
+ .Add(Expression.Like("Username", user.Username))
+ .List();
- // cmd.ExecuteNonQuery();
+ if (existing.Count > 0) {
+ throw new DuplicateNameException("User with the same name already exists in the system.");
+ }
- // int result = (int) cmd.Parameters["Result"].Value;
+ session.Update(user);
- // return (LocalStoreUserResult) result;
- // }
- //}
- throw new NotImplementedException();
+ tx.Commit();
+ session.Close();
+ }
+ }
}
#endregion
+ #region Get User Folders
/// <summary>
/// Gets a list of folders that belong to the user with the given user Id.
/// </summary>
/// <param name="userId">The Id of the user to get the folder for.</param>
/// <returns>The list of folders or null if the user Id is invalid.</returns>
- public StoreFolder[] GetUserFolders(int userId) {
- //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // using (MySqlCommand cmd = cnn.CreateCommand()) {
- // cmd.CommandType = CommandType.StoredProcedure;
- // cmd.CommandText = "GetUserFolders";
- // cmd.Parameters.Add("?UserId", userId);
-
- // List<StoreFolder> folders = new List<StoreFolder>();
- // MySqlDataReader reader = cmd.ExecuteReader();
-
- // while (reader.Read()) {
- // int folderId = (int) reader["FolderId"];
- // string nameSpace = (string) reader["NameSpace"];
- // string name = (string) reader["Name"];
- // int? parentId = (reader["ParentFolderId"] == DBNull.Value)
- // ? null
- // : (int?) reader["ParentFolderId"];
-
- // // TODO: Get HasChildren from the reader
- // folders.Add(new StoreFolder(nameSpace, name, folderId, parentId, false));
- // }
-
- // return folders.ToArray();
- // }
- //}
- throw new NotImplementedException();
+ public IList<StoreFolder> GetUserFolders(int userId) {
+ using (ISession session = this.hibernateFactory.OpenSession()) {
+ return session.CreateCriteria(typeof(StoreFolder))
+ .Add(Expression.Eq("OwnerUserId", userId))
+ .List<StoreFolder>();
+ }
}
#endregion
+ #endregion
#region Group Management
#region GetGroup
@@ -1810,10 +1679,15 @@
session.Delete("from CalendarEntry as calE where calE.EntryId = ?", entryId, NHibernateUtil.Int64);
}
}
- #endregion
public void ReinstallSchema() {
new global::NHibernate.Tool.hbm2ddl.SchemaExport(this.hibernateCfg).Create(false, true);
}
+ #endregion
+
+ /// <summary>
+ /// The default namespace.
+ /// </summary>
+ public const string DefaultNameSpace = "Local";
}
}
Deleted: NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.Auth.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.Auth.hbm.xml 2007-03-13 05:04:17 UTC (rev 175)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.Auth.hbm.xml 2007-03-13 05:05:16 UTC (rev 176)
@@ -1,131 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NMail" assembly="NMail" default-lazy="false">
- <!--
- -
- - Calendar
- -
- -->
- <class name="NMail.DataTypes.Calendar.Calendar" table="Calendar">
- <id name="CalendarId" type="Int32" unsaved-value="0">
- <column name="CalendarId" not-null="true"/>
- <generator class="native" />
- </id>
-
- <property name="Name" not-null="true"/>
-
- <!-- TODO: make this a many to one relationship with folder -->
- <property name="ParentFolderId" />
-
- <!-- TODO: make this a many to one relationship with user -->
- <property name="OwnerUserId" />
-
- <list name="Entries" cascade="all">
- <key column="CalendarEntryId" />
- <index column="CategoryEntryIndex" type="Int32" />
- <one-to-many class="NMail.DataTypes.Calendar.CalendarEntry" />
- </list>
- </class>
-
- <!--
- -
- - Calendar Entry
- -
- -->
- <class name="NMail.DataTypes.Calendar.CalendarEntry" table="CalendarEntry">
- <id name="EntryId" type="Int32" unsaved-value="0">
- <column name="CalendarEntryId" not-null="true"/>
- <generator class="native" />
- </id>
-
-
- <!--
- - Descriptive Properties
- -->
- <property name="Classification" not-null="true" />
-
- <list name="Categories" table="CalendarEventCategories" cascade="all">
- <key column="CalendarEntryId" />
- <index column="CategoryIndex" type="Int32" />
- <element column="Category" type="String" />
- </list>
-
- <property name="Description" />
-
- <!--<property name="Status" />-->
-
- <property name="Summary" />
-
-
- <!--
- - Date/Time Properties
- -->
- <property name="StartTime" not-null="true" />
-
-
- <!--
- - Relationship Component Properties
- -->
- <list name="Attendees" cascade="all">
- <key column="CalendarEntryId" />
- <index column="AttendeeIndex" />
- <one-to-many class="NMail.DataTypes.Calendar.Attendee" />
- </list>
-
- <property name="Organiser" type="String" />
-
- <!-- TODO: make this a many to one relationship with user -->
- <property name="OwnerUserId" />
-
- <many-to-one name="Calendar"
- class="NMail.DataTypes.Calendar.Calendar"
- column="CalendarId" />
-
-
- <!--
- - Recurrence Component Properties
- -->
-
- <!-- one to many <property name="Recurrence" /> -->
-
- <property name="RecurrenceId" />
-
-
- <!--
- - Change Management Component Properties
- -->
- <property name="Created" />
-
- <property name="TimeStamp" />
-
- <property name="LastModified" />
-
- <property name="Sequence" />
-
- <!--
- -
- - Calendar Event
- -
- -->
- <joined-subclass name="NMail.DataTypes.Calendar.EventEntry" table="EventEntry">
- <key column="CalendarEntryId"/>
- </joined-subclass>
- </class>
-
- <!--
- -
- - Attendee
- -
- -->
- <class name="NMail.DataTypes.Calendar.Attendee" table="Attendee">
- <id type="Int32">
- <column name="AttendeeId" not-null="true"/>
- <generator class="native" />
- </id>
-
- <property name="Address" not-null="true"/>
-
- <many-to-one name="CalendarEntry"
- class="NMail.DataTypes.Calendar.CalendarEntry"
- column="CalendarEntryId" />
- </class>
-</hibernate-mapping>
\ No newline at end of file
Deleted: NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.UserMap.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.UserMap.hbm.xml 2007-03-13 05:04:17 UTC (rev 175)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.UserMap.hbm.xml 2007-03-13 05:05:16 UTC (rev 176)
@@ -1,131 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NMail" assembly="NMail" default-lazy="false">
- <!--
- -
- - Calendar
- -
- -->
- <class name="NMail.DataTypes.Calendar.Calendar" table="Calendar">
- <id name="CalendarId" type="Int32" unsaved-value="0">
- <column name="CalendarId" not-null="true"/>
- <generator class="native" />
- </id>
-
- <property name="Name" not-null="true"/>
-
- <!-- TODO: make this a many to one relationship with folder -->
- <property name="ParentFolderId" />
-
- <!-- TODO: make this a many to one relationship with user -->
- <property name="OwnerUserId" />
-
- <list name="Entries" cascade="all">
- <key column="CalendarEntryId" />
- <index column="CategoryEntryIndex" type="Int32" />
- <one-to-many class="NMail.DataTypes.Calendar.CalendarEntry" />
- </list>
- </class>
-
- <!--
- -
- - Calendar Entry
- -
- -->
- <class name="NMail.DataTypes.Calendar.CalendarEntry" table="CalendarEntry">
- <id name="EntryId" type="Int32" unsaved-value="0">
- <column name="CalendarEntryId" not-null="true"/>
- <generator class="native" />
- </id>
-
-
- <!--
- - Descriptive Properties
- -->
- <property name="Classification" not-null="true" />
-
- <list name="Categories" table="CalendarEventCategories" cascade="all">
- <key column="CalendarEntryId" />
- <index column="CategoryIndex" type="Int32" />
- <element column="Category" type="String" />
- </list>
-
- <property name="Description" />
-
- <!--<property name="Status" />-->
-
- <property name="Summary" />
-
-
- <!--
- - Date/Time Properties
- -->
- <property name="StartTime" not-null="true" />
-
-
- <!--
- - Relationship Component Properties
- -->
- <list name="Attendees" cascade="all">
- <key column="CalendarEntryId" />
- <index column="AttendeeIndex" />
- <one-to-many class="NMail.DataTypes.Calendar.Attendee" />
- </list>
-
- <property name="Organiser" type="String" />
-
- <!-- TODO: make this a many to one relationship with user -->
- <property name="OwnerUserId" />
-
- <many-to-one name="Calendar"
- class="NMail.DataTypes.Calendar.Calendar"
- column="CalendarId" />
-
-
- <!--
- - Recurrence Component Properties
- -->
-
- <!-- one to many <property name="Recurrence" /> -->
-
- <property name="RecurrenceId" />
-
-
- <!--
- - Change Management Component Properties
- -->
- <property name="Created" />
-
- <property name="TimeStamp" />
-
- <property name="LastModified" />
-
- <property name="Sequence" />
-
- <!--
- -
- - Calendar Event
- -
- -->
- <joined-subclass name="NMail.DataTypes.Calendar.EventEntry" table="EventEntry">
- <key column="CalendarEntryId"/>
- </joined-subclass>
- </class>
-
- <!--
- -
- - Attendee
- -
- -->
- <class name="NMail.DataTypes.Calendar.Attendee" table="Attendee">
- <id type="Int32">
- <column name="AttendeeId" not-null="true"/>
- <generator class="native" />
- </id>
-
- <property name="Address" not-null="true"/>
-
- <many-to-one name="CalendarEntry"
- class="NMail.DataTypes.Calendar.CalendarEntry"
- column="CalendarEntryId" />
- </class>
-</hibernate-mapping>
\ No newline at end of file
Modified: NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.csproj
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.csproj 2007-03-13 05:04:17 UTC (rev 175)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.csproj 2007-03-13 05:05:16 UTC (rev 176)
@@ -52,23 +52,36 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
- <EmbeddedResource Include="NMail.LocalStoreData.NHibernate.hbm.xml" />
+ <EmbeddedResource Include="hibernate-configuration.xml" />
</ItemGroup>
<ItemGroup>
- <EmbeddedResource Include="hibernate-configuration.xml" />
+ <ProjectReference Include="..\NMail\NMail.csproj">
+ <Project>{5A5A5012-B157-49B1-A35F-67EC9680112A}</Project>
+ <Name>NMail</Name>
+ </ProjectReference>
</ItemGroup>
<ItemGroup>
- <EmbeddedResource Include="NMail.LocalStoreData.NHibernate.Auth.hbm.xml" />
+ <EmbeddedResource Include="Mappings\NMail.DataTypes.LocalStore.LocalStoreUser.hbm.xml" />
+ <EmbeddedResource Include="Mappings\NMail.DataTypes.LocalStore.StoreFolder.hbm.xml" />
</ItemGroup>
<ItemGroup>
- <EmbeddedResource Include="NMail.LocalStoreData.NHibernate.UserMap.hbm.xml" />
+ <EmbeddedResource Include="Mappings\NMail.DataTypes.LocalStore.LocalStoreGroup.hbm.xml" />
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\NMail\NMail.csproj">
- <Project>{5A5A5012-B157-49B1-A35F-67EC9680112A}</Project>
- <Name>NMail</Name>
- </ProjectReference>
+ <EmbeddedResource Include="Mappings\NMail.DataTypes.Calendar.Calendar.hbm.xml" />
</ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Mappings\NMail.DataTypes.Calendar.CalendarEntry.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Mappings\NMail.DataTypes.Calendar.Attendee.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Mappings\NMail.DataTypes.LocalStore.MailDomain.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Mappings\NMail.DataTypes.ACLs.StoreFolderAcl.hbm.xml" />
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Deleted: NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.hbm.xml 2007-03-13 05:04:17 UTC (rev 175)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.hbm.xml 2007-03-13 05:05:16 UTC (rev 176)
@@ -1,170 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NMail" assembly="NMail" default-lazy="false">
- <!--
-
- TODO:
- - Message (parts)
- - Objects
- - Users
- - Groups
- - Folder
- - ACLs (folder & system)
- - Mail domain
-
- -->
-
- <!--
- -
- - Folder
- -
- -->
- <class name="NMail.DataTypes.LocalStore.StoreFolder" table="Folder">
- <id name="FolderId" type="Int32" unsaved-value="0">
- <column name="FolderId" not-null="true"/>
- <generator class="native" />
- </id>
-
- <property name="Name" not-null="true"/>
-
- <property name="NameSpace" not-null="true" />
-
- <many-to-one name="ParentId" foreign-key="FolderId" />
-
- <many-to-one name="OwnerUserId" class="NMail.DataTypes.LocalStore.LocalStoreUser" foreign-key="UserId"/>
-
- <list name="ChildrenIds" cascade="all">
- <key column="FolderId" />
- <index column="ChildIndex" type="Int32" />
- <one-to-many class="NMail.DataTypes.LocalStore.StoreFolder" />
- </list>
- </class>
-
- <!--
- -
- - Calendar
- -
- -->
- <class name="NMail.DataTypes.Calendar.Calendar" table="Calendar">
- <id name="CalendarId" type="Int32" unsaved-value="0">
- <column name="CalendarId" not-null="true"/>
- <generator class="native" />
- </id>
-
- <property name="Name" not-null="true"/>
-
- <!-- TODO: make this a many to one relationship with folder -->
- <property name="ParentFolderId" />
-
- <!-- TODO: make this a many to one relationship with user -->
- <property name="OwnerUserId" />
-
- <list name="Entries" cascade="all">
- <key column="CalendarEntryId" />
- <index column="CategoryEntryIndex" type="Int32" />
- <one-to-many class="NMail.DataTypes.Calendar.CalendarEntry" />
- </list>
- </class>
-
- <!--
- -
- - Calendar Entry
- -
- -->
- <class name="NMail.DataTypes.Calendar.CalendarEntry" table="CalendarEntry">
- <id name="EntryId" type="Int32" unsaved-value="0">
- <column name="CalendarEntryId" not-null="true"/>
- <generator class="native" />
- </id>
-
-
- <!--
- - Descriptive Properties
- -->
- <property name="Classification" not-null="true" />
-
- <list name="Categories" table="CalendarEventCategories" cascade="all">
- <key column="CalendarEntryId" />
- <index column="CategoryIndex" type="Int32" />
- <element column="Category" type="String" />
- </list>
-
- <property name="Description" />
-
- <!--<property name="Status" />-->
-
- <property name="Summary" />
-
-
- <!--
- - Date/Time Properties
- -->
- <property name="StartTime" not-null="true" />
-
-
- <!--
- - Relationship Component Properties
- -->
- <list name="Attendees" cascade="all">
- <key column="CalendarEntryId" />
- <index column="AttendeeIndex" />
- <one-to-many class="NMail.DataTypes.Calendar.Attendee" />
- </list>
-
- <property name="Organiser" type="String" />
-
- <!-- TODO: make this a many to one relationship with user -->
- <property name="OwnerUserId" />
-
- <many-to-one name="Calendar"
- class="NMail.DataTypes.Calendar.Calendar"
- column="CalendarId" />
-
-
- <!--
- - Recurrence Component Properties
- -->
-
- <!-- one to many <property name="Recurrence" /> -->
-
- <property name="RecurrenceId" />
-
-
- <!--
- - Change Management Component Properties
- -->
- <property name="Created" />
-
- <property name="TimeStamp" />
-
- <property name="LastModified" />
-
- <property name="Sequence" />
-
- <!--
- -
- - Calendar Event
- -
- -->
- <joined-subclass name="NMail.DataTypes.Calendar.EventEntry" table="EventEntry">
- <key column="CalendarEntryId"/>
- </joined-subclass>
- </class>
-
- <!--
- -
- - Attendee
- -
- -->
- <class name="NMail.DataTypes.Calendar.Attendee" table="Attendee">
- <id type="Int32">
- <column name="AttendeeId" not-null="true"/>
- <generator class="native" />
- </id>
-
- <property name="Address" not-null="true"/>
-
- <many-to-one name="CalendarEntry"
- class="NMail.DataTypes.Calendar.CalendarEntry"
- column="CalendarEntryId" />
- </class>
-</hibernate-mapping>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|