SPRNET-1102: Updating NHibernate Northwind example to NH 2.1, some minor UI adjustments

This commit is contained in:
lahma
2009-07-24 19:03:28 +00:00
parent 0bc02e8db1
commit 9635c82336
40 changed files with 544 additions and 236 deletions

View File

@@ -15,9 +15,9 @@
<!-- Database and NHibernate Configuration -->
<db:provider id="DbProvider"
provider="SqlServer-2.0"
connectionString="Data Source=.\SQLExpress;Integrated Security=true;User Instance=true;AttachDBFilename=|DataDirectory|\Northwnd.mdf"/>
connectionString="Data Source=(local);Integrated Security=true;User Instance=true;AttachDBFilename=|DataDirectory|\Northwnd.mdf"/>
<object id="NHibernateSessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate12">
<object id="NHibernateSessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate21">
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingAssemblies">
<list>
@@ -26,16 +26,10 @@
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2000Dialect"/>
<entry key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"/>
<entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="dialect" value="NHibernate.Dialect.MsSql2000Dialect"/>
<entry key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
<entry key="proxyfactory.factory_class" value="NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu" />
</dictionary>
</property>
@@ -46,26 +40,20 @@
<object id="transactionManager"
type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate12">
type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate21">
<property name="DbProvider" ref="DbProvider"/>
<property name="SessionFactory" ref="NHibernateSessionFactory"/>
</object>
<object id="HibernateTemplate" type="Spring.Data.NHibernate.HibernateTemplate">
<property name="SessionFactory" ref="NHibernateSessionFactory" />
<property name="TemplateFlushMode" value="Auto" />
<property name="CacheQueries" value="true" />
</object>
<!-- Data Access Objects -->
<object id="CustomerDao" type="Spring.Northwind.Dao.NHibernate.HibernateCustomerDao, Spring.Northwind.Dao.NHibernate">
<property name="HibernateTemplate" ref="HibernateTemplate"/>
<property name="SessionFactory" ref="NHibernateSessionFactory"/>
</object>
<object id="OrderDao" type="Spring.Northwind.Dao.NHibernate.HibernateOrderDao, Spring.Northwind.Dao.NHibernate">
<property name="HibernateTemplate" ref="HibernateTemplate"/>
<property name="SessionFactory" ref="NHibernateSessionFactory"/>
</object>

View File

@@ -20,10 +20,8 @@
#region Imports
using System.Collections;
using Spring.Data.NHibernate.Support;
using System.Collections.Generic;
using Spring.Stereotype;
using Spring.Transaction.Interceptor;
using Spring.Northwind.Domain;
@@ -32,16 +30,19 @@ using Spring.Northwind.Domain;
namespace Spring.Northwind.Dao.NHibernate
{
public class HibernateCustomerDao : HibernateDaoSupport, ICustomerDao
[Repository]
public class HibernateCustomerDao : HibernateDao, ICustomerDao
{
public Customer FindById(string customerId)
[Transaction(ReadOnly = true)]
public Customer Get(string customerId)
{
return HibernateTemplate.Load(typeof (Customer), customerId) as Customer;
return Session.Get<Customer>(customerId);
}
public IList FindAll()
[Transaction(ReadOnly = true)]
public IList<Customer> GetAll()
{
return HibernateTemplate.LoadAll(typeof (Customer));
return GetAll<Customer>();
}
// Note that the transaction demaraction is here only for the case when
@@ -57,23 +58,21 @@ namespace Spring.Northwind.Dao.NHibernate
// same settings as started from the transactional layer.
[Transaction(ReadOnly = false)]
public Customer Save(Customer customer)
public string Save(Customer customer)
{
HibernateTemplate.Save(customer);
return customer;
return (string) Session.Save(customer);
}
[Transaction(ReadOnly = false)]
public Customer SaveOrUpdate(Customer customer)
public void SaveOrUpdate(Customer customer)
{
HibernateTemplate.SaveOrUpdate(customer);
return customer;
Session.SaveOrUpdate(customer);
}
[Transaction(ReadOnly = false)]
public void Delete(Customer customer)
{
HibernateTemplate.Delete(customer);
Session.Delete(customer);
}
}
}

View File

@@ -0,0 +1,37 @@
using System.Collections.Generic;
using NHibernate;
namespace Spring.Northwind.Dao.NHibernate
{
/// <summary>
/// Base class for data access operations.
/// </summary>
public abstract class HibernateDao
{
private ISessionFactory sessionFactory;
/// <summary>
/// Session factory for sub-classes.
/// </summary>
public ISessionFactory SessionFactory
{
protected get { return sessionFactory; }
set { sessionFactory = value; }
}
/// <summary>
/// Get's the current active session. Uses
/// Open Session In View in the background.
/// </summary>
protected ISession Session
{
get { return sessionFactory.GetCurrentSession(); }
}
protected IList<T> GetAll<T>() where T : class
{
ICriteria criteria = Session.CreateCriteria<T>();
return criteria.List<T>();
}
}
}

View File

@@ -21,7 +21,8 @@
#region Imports
using System.Collections;
using System.Collections.Generic;
using Spring.Data.NHibernate.Generic;
using Spring.Data.NHibernate.Support;
using Spring.Northwind.Domain;
@@ -30,34 +31,32 @@ using Spring.Northwind.Domain;
namespace Spring.Northwind.Dao.NHibernate
{
public class HibernateOrderDao : HibernateDaoSupport, IOrderDao
public class HibernateOrderDao : HibernateDao, IOrderDao
{
public Order FindById(int orderId)
public Order Get(int orderId)
{
return HibernateTemplate.Load(typeof(Order), orderId) as Order;
return Session.Get<Order>(orderId);
}
public IList FindAll()
public IList<Order> GetAll()
{
return HibernateTemplate.LoadAll(typeof(Order));
return GetAll<Order>();
}
public Order Save(Order order)
public int Save(Order order)
{
HibernateTemplate.Save(order);
return order;
return (int) Session.Save(order);
}
public Order SaveOrUpdate(Order order)
public void SaveOrUpdate(Order order)
{
HibernateTemplate.SaveOrUpdate(order);
return order;
Session.SaveOrUpdate(order);
}
public void Delete(Order order)
{
HibernateTemplate.Delete(order);
Session.Delete(order);
}
}
}

View File

@@ -21,7 +21,7 @@
#region Imports
using System.Collections;
using System.Collections.Generic;
using Spring.Data.NHibernate.Support;
using Spring.Northwind.Domain;
@@ -30,34 +30,32 @@ using Spring.Northwind.Domain;
namespace Spring.Northwind.Dao.NHibernate
{
public class HibernateProductDao : HibernateDaoSupport, IProductDao
public class HibernateProductDao : HibernateDao, IProductDao
{
public Product FindById(int productId)
public Product Get(int productId)
{
return HibernateTemplate.Load(typeof(Product), productId) as Product;
return Session.Get<Product>(productId);
}
public IList FindAll()
public IList<Product> GetAll()
{
return HibernateTemplate.LoadAll(typeof(Product));
return GetAll<Product>();
}
public Product Save(Product product)
public int Save(Product product)
{
HibernateTemplate.Save(product);
return product;
return (int) Session.Save(product);
}
public Product SaveOrUpdate(Product product)
public void SaveOrUpdate(Product product)
{
HibernateTemplate.SaveOrUpdate(product);
return product;
Session.SaveOrUpdate(product);
}
public void Delete(Product product)
{
HibernateTemplate.Delete(product);
Session.Delete(product);
}
}
}

View File

@@ -32,29 +32,21 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\net\2.0\antlr.runtime.dll</HintPath>
</Reference>
<Reference Include="Castle.DynamicProxy, Version=1.1.5.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\NHibernate12\net\2.0\Castle.DynamicProxy.dll</HintPath>
</Reference>
<Reference Include="Common.Logging, Version=1.0.2.0, Culture=neutral, PublicKeyToken=af08829b84f0328e">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="Common.Logging.Log4Net, Version=1.2.0.2, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\Common.Logging.Log4Net.dll</HintPath>
</Reference>
<Reference Include="Iesi.Collections, Version=1.0.0.3, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\NHibernate12\net\2.0\Iesi.Collections.dll</HintPath>
<HintPath>..\..\..\..\..\lib\NHibernate21\net\2.0\Iesi.Collections.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\NHibernate12\net\2.0\log4net.dll</HintPath>
<HintPath>..\..\..\..\..\lib\NHibernate21\net\2.0\log4net.dll</HintPath>
</Reference>
<Reference Include="NHibernate, Version=1.2.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\NHibernate12\net\2.0\NHibernate.dll</HintPath>
<HintPath>..\..\..\..\..\lib\NHibernate21\net\2.0\NHibernate.dll</HintPath>
</Reference>
<Reference Include="Spring.Core, Version=1.1.0.2, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -64,9 +56,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\Spring.Data.dll</HintPath>
</Reference>
<Reference Include="Spring.Data.NHibernate12, Version=1.1.1.20093, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="Spring.Data.NHibernate21, Version=1.1.1.20093, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\Spring.Data.NHibernate12.dll</HintPath>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\Spring.Data.NHibernate21.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
@@ -76,6 +68,7 @@
<Compile Include="Dao\NHibernate\HibernateCustomerDao.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Dao\NHibernate\HibernateDao.cs" />
<Compile Include="Dao\NHibernate\HibernateOrderDao.cs">
<SubType>Code</SubType>
</Compile>

View File

@@ -21,19 +21,14 @@
#region Imports
using System.Collections;
using System.Collections.Generic;
using Spring.Northwind.Domain;
#endregion
namespace Spring.Northwind.Dao
{
public interface ICustomerDao
public interface ICustomerDao : IDao<Customer, string>, ISupportsDeleteDao<Customer>, ISupportsSave<Customer, string>
{
Customer FindById(string customerId);
IList FindAll();
Customer Save(Customer customer);
Customer SaveOrUpdate(Customer customer);
void Delete(Customer customer);
}
}

View File

@@ -0,0 +1,24 @@
using System.Collections.Generic;
namespace Spring.Northwind.Dao
{
public interface IDao<TEntity, TId>
{
/// <summary>
/// Finds entity with given id.
/// </summary>
/// <param name="id">The id to search with.</param>
/// <returns>Found entity or null if not found.</returns>
TEntity Get(TId id);
/// <summary>
/// Returns all entities of given type.
/// The result may be different than in database based on
/// filters or other locked search criteria for search.
/// </summary>
/// <returns></returns>
IList<TEntity> GetAll();
}
}

View File

@@ -28,12 +28,10 @@ using Spring.Northwind.Domain;
namespace Spring.Northwind.Dao
{
public interface IOrderDao
public interface IOrderDao : IDao<Order, int>, ISupportsDeleteDao<Order>
{
Order FindById(int orderId);
IList FindAll();
Order Save(Order order);
Order SaveOrUpdate(Order order);
void Delete(Order order);
int Save(Order order);
void SaveOrUpdate(Order order);
}
}

View File

@@ -28,12 +28,8 @@ using Spring.Northwind.Domain;
namespace Spring.Northwind.Dao
{
public interface IProductDao
public interface IProductDao : IDao<Product, int>, ISupportsDeleteDao<Product>, ISupportsSave<Product, int>
{
Product FindById(int productId);
IList FindAll();
Product Save(Product product);
Product SaveOrUpdate(Product product);
void Delete(Product product);
}
}

View File

@@ -0,0 +1,7 @@
namespace Spring.Northwind.Dao
{
public interface ISupportsDeleteDao<TEntity>
{
void Delete(TEntity entity);
}
}

View File

@@ -0,0 +1,18 @@
namespace Spring.Northwind.Dao
{
public interface ISupportsSave<TEntity, TId>
{
/// <summary>
/// Saves the given entity.
/// </summary>
/// <param name="entity">Entity to save.</param>
/// <returns>The id for saved entity.</returns>
TId Save(TEntity entity);
/// <summary>
/// Saves or updates the entity. Behavior depends on the current state of entity's ID.
/// </summary>
/// <param name="entity">Entity to save or update.</param>
void SaveOrUpdate(TEntity entity);
}
}

View File

@@ -32,8 +32,11 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Dao\ICustomerDao.cs" />
<Compile Include="Dao\IDao.cs" />
<Compile Include="Dao\IOrderDao.cs" />
<Compile Include="Dao\IProductDao.cs" />
<Compile Include="Dao\ISupportsDeleteDao.cs" />
<Compile Include="Dao\ISupportsSave.cs" />
<Compile Include="Domain\Customer.cs" />
<Compile Include="Domain\Order.cs" />
<Compile Include="Domain\OrderDetail.cs" />

View File

@@ -82,7 +82,7 @@ namespace Spring.Northwind.Service
public void ProcessCustomer(string customerId)
{
//Find all orders for customer
Customer customer = CustomerDao.FindById(customerId);
Customer customer = CustomerDao.Get(customerId);
foreach (Order order in customer.Orders)
{

View File

@@ -32,9 +32,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\antlr.runtime.dll</HintPath>
</Reference>
<Reference Include="Castle.DynamicProxy, Version=1.1.5.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<Reference Include="Antlr3.Runtime, Version=3.1.0.39271, Culture=neutral, PublicKeyToken=3a9cab8f8d22bfb7, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\NHibernate12\net\2.0\Castle.DynamicProxy.dll</HintPath>
<HintPath>..\..\..\..\..\lib\NHibernate21\net\2.0\Antlr3.Runtime.dll</HintPath>
</Reference>
<Reference Include="Common.Logging, Version=1.2.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e">
<SpecificVersion>False</SpecificVersion>
@@ -42,19 +42,27 @@
</Reference>
<Reference Include="Common.Logging.Log4Net, Version=1.2.0.2, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\net\2.0\Common.Logging.Log4Net.dll</HintPath>
<HintPath>..\..\lib\net\2.0\Common.Logging.Log4Net.dll</HintPath>
</Reference>
<Reference Include="Iesi.Collections, Version=1.0.0.3, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<Reference Include="Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\NHibernate12\net\2.0\Iesi.Collections.dll</HintPath>
<HintPath>..\..\..\..\..\lib\NHibernate21\net\2.0\Iesi.Collections.dll</HintPath>
</Reference>
<Reference Include="LinFu.DynamicProxy, Version=1.0.3.14911, Culture=neutral, PublicKeyToken=62a6874124340d6e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\NHibernate21\net\2.0\LinFu.DynamicProxy.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\NHibernate12\net\2.0\log4net.dll</HintPath>
<HintPath>..\..\lib\net\2.0\log4net.dll</HintPath>
</Reference>
<Reference Include="NHibernate, Version=1.2.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<Reference Include="NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\NHibernate12\net\2.0\NHibernate.dll</HintPath>
<HintPath>..\..\..\..\..\lib\NHibernate21\net\2.0\NHibernate.dll</HintPath>
</Reference>
<Reference Include="NHibernate.ByteCode.LinFu, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\NHibernate21\net\2.0\NHibernate.ByteCode.LinFu.dll</HintPath>
</Reference>
<Reference Include="Spring.Core, Version=1.1.0.2, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -64,10 +72,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\Spring.Data.dll</HintPath>
</Reference>
<Reference Include="Spring.Data.NHibernate12, Version=1.1.1.20093, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\Spring.Data.NHibernate12.dll</HintPath>
</Reference>
<Reference Include="Spring.Web, Version=1.1.0.2, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\Spring.Web.dll</HintPath>

View File

@@ -2,7 +2,7 @@ using Spring.Northwind.Domain;
public interface ICustomerEditController
{
void EditCustomer(Customer customer);
void Clear();
Customer CurrentCustomer { get; }
void EditCustomer(Customer customer);
void Clear();
Customer CurrentCustomer { get; }
}

View File

@@ -1,5 +1,3 @@
using System.Web;
using NHibernate;
using Spring.Data.NHibernate;
using Spring.Northwind.Domain;
@@ -7,42 +5,38 @@ using Spring.Northwind.Domain;
/// <summary>
/// </summary>
/// <author>erich.eichinger</author>
/// <version>$Id: NHibernateCustomerEditController.cs,v 1.1 2007/09/29 21:32:09 oakinger Exp $</version>
public class NHibernateCustomerEditController:ICustomerEditController
public class NHibernateCustomerEditController : ICustomerEditController
{
private readonly ISessionFactory sessionFactory;
private Customer currentCustomer;
private readonly ISessionFactory sessionFactory;
private Customer currentCustomer;
public NHibernateCustomerEditController(ISessionFactory sessionFactory)
{
this.sessionFactory = sessionFactory;
}
private ISession Session
{
get
public NHibernateCustomerEditController(ISessionFactory sessionFactory)
{
return SessionFactoryUtils.GetSession( sessionFactory,false );
this.sessionFactory = sessionFactory;
}
}
public void EditCustomer(Customer customer)
{
currentCustomer = customer;
}
public void Clear()
{
currentCustomer = null;
}
public Customer CurrentCustomer
{
get
private ISession Session
{
Customer customer = currentCustomer;
Session.Lock(customer, LockMode.None);
return customer;
get { return sessionFactory.GetCurrentSession(); }
}
public void EditCustomer(Customer customer)
{
currentCustomer = customer;
}
public void Clear()
{
currentCustomer = null;
}
public Customer CurrentCustomer
{
get
{
Customer customer = currentCustomer;
Session.Lock(customer, LockMode.None);
return customer;
}
}
}
}

View File

@@ -0,0 +1,129 @@
body {
margin: 0px;
padding: 0px;
background-color: #dfeac1;
text-align: center;
}
.logo {
position:relative;
top:-8px;
left:22px;
float:left;
}
#ad {
float:right;
position:relative;
right: 22px;
top:-8px;
}
.navigation {
position:relative;
left: 25px;
font-family: Verdana, Arial, Helvetica, sans;
font-size: 12px;
color: #000000;
text-decoration: none;
width:150px;
}
.navigation a, .navigation a:active, .navigation a:visited {
font-family: Verdana, Arial, Helvetica, sans;
font-size: 12px;
color: #7E7E7E;
text-decoration: none;
}
.navigation a:hover {
font-family: Verdana, Arial, Helvetica, sans;
font-size: 12px;
color: #000000;
text-decoration: none;
}
h4.navbar {
position:relative;
left: 0px;
font-family: Verdana, Arial, Helvetica, sans;
font-size: 12px;
color: #5F5F5F;
text-decoration: none;
margin-bottom: 2px;
}
h1 {
font-family: Verdana, Arial, Helvetica, sans;
font-size: 14px;
font-weight: normal;
color: #90A720;
}
a, a:active, a:visited {
font-family: Verdana, Arial, Helvetica, sans;
font-size: 12px;
color: #606060;
text-decoration: underline;
}
a:hover {
font-family: Verdana, Arial, Helvetica, sans;
font-size: 12px;
color: #000000;
}
b {
font-family: Verdana, Arial, Helvetica, sans;
font-size: 12px;
font-weight: bold;
color: #606060;
}
i {
font-family: Verdana, Arial, Helvetica, sans;
font-size: 12px;
color: #606060;
}
table {
font-family: Verdana, Arial, Helvetica, sans;
font-size: 12px;
color: #606060;
}
.news {
border: 1px solid;
border-color: #C9C9C9;
padding: 12px;
font-family: Verdana, Arial, Helvetica, sans;
font-size: 12px;
color: #606060;
background-color: #F5F5F5;
margin-top: 20px;
margin-bottom: 20px;
}
.news b {
font-family: Verdana, Arial, Helvetica, sans;
font-size: 11px;
font-weight: normal;
color: #90A720;
}
.news u {
font-family: Verdana, Arial, Helvetica, sans;
font-size: 12px;
font-weight: bold;
color: #606060;
text-decoration: none;
}
li {
margin-bottom: 12px;
}
li.newslist {
margin-bottom: 2px;
}
ul.newslist {
margin-left: 10px;
margin-top: 10px;
}
ul {
margin-left: 25px;
margin-top: 10px;
}

View File

@@ -1,21 +1,23 @@
<%@ Page Language="C#" CodeFile="CustomerEditor.aspx.cs" Inherits="CustomerEditor" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="C#" MasterPageFile="~/Shared/MasterPage.master" CodeFile="CustomerEditor.aspx.cs"
Inherits="CustomerEditor" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<spring:DataBindingPanel runat="server">
<table>
<tr><td>ID:</td><td><asp:TextBox runat="server" BindingTarget="CurrentCustomer.Id" BindingDirection="TargetToSource" readonly="true" /></td></tr>
<tr><td>Contact:</td><td><asp:TextBox runat="server" BindingTarget="CurrentCustomer.ContactName" /></td></tr>
</table>
</spring:DataBindingPanel>
</div>
<asp:Button runat="server" id="btnSave" Text="Save" />
</form>
</body>
</html>
<asp:Content ID="content" ContentPlaceHolderID="content" runat="server">
<spring:DataBindingPanel runat="server">
<table>
<tr>
<td>
ID:</td>
<td>
<asp:TextBox runat="server" BindingTarget="CurrentCustomer.Id" BindingDirection="TargetToSource"
ReadOnly="true" /></td>
</tr>
<tr>
<td>
Contact:</td>
<td>
<asp:TextBox runat="server" BindingTarget="CurrentCustomer.ContactName" /></td>
</tr>
</table>
</spring:DataBindingPanel>
<asp:Button runat="server" ID="btnSave" Text="Save" />
</asp:Content>

View File

@@ -1,14 +1,8 @@
<%@ Page Language="C#" CodeFile="CustomerList.aspx.cs" Inherits="CustomerList" %>
<%@ Page Language="C#" MasterPageFile="~/Shared/MasterPage.master" CodeFile="CustomerList.aspx.cs" Inherits="CustomerList" %>
<%@ Reference page="CustomerEditor.aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Content ID="content" ContentPlaceHolderID="content" runat="server">
<asp:DataGrid id="customerList" runat="server"
AllowPaging="true"
AllowSorting="false"
@@ -21,14 +15,12 @@
<Columns>
<asp:BoundColumn HeaderText="Id" DataField="ID" />
<asp:BoundColumn HeaderText="Name" DataField="ContactName" />
<asp:TemplateColumn HeaderText="Name">
<ItemTemplate><a href="CustomerView.aspx?id="><%# Eval("ContactName")%></a></ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Company" DataField="CompanyName"/>
<asp:ButtonColumn CommandName="EditCustomer" Text="Edit" />
<asp:ButtonColumn CommandName="ViewOrders" Text="Orders" />
</Columns>
</asp:DataGrid>
</div>
</form>
</body>
</html>
</asp:Content>

View File

@@ -54,7 +54,7 @@ public partial class CustomerList : Spring.Web.UI.Page
private void Page_InitializeControls(object sender, EventArgs e)
{
// create/initialize controls here
customerList.DataSource = customerDao.FindAll();
customerList.DataSource = customerDao.GetAll();
customerList.ItemCommand+=new DataGridCommandEventHandler(CustomerList_ItemCommand);
customerList.PageIndexChanged+=new DataGridPageChangedEventHandler(CustomerList_PageIndexChanged);
if (!IsPostBack)

View File

@@ -1,32 +1,14 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CustomerOrders.aspx.cs" Inherits="CustomerOrders" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataGrid id="customerOrders" runat="server"
AllowPaging="false"
AllowSorting="false"
BorderColor="black"
BorderWidth="1"
CellPadding="3"
AutoGenerateColumns="false"
ShowFooter="true"
>
<Columns>
<%@ Page Language="C#" MasterPageFile="~/Shared/MasterPage.master" AutoEventWireup="true"
CodeFile="CustomerOrders.aspx.cs" Inherits="CustomerOrders" %>
<asp:Content ID="content" ContentPlaceHolderID="content" runat="server">
<asp:DataGrid ID="customerOrders" runat="server" AllowPaging="false" AllowSorting="false"
BorderColor="black" BorderWidth="1" CellPadding="3" AutoGenerateColumns="false"
ShowFooter="true">
<Columns>
<asp:BoundColumn HeaderText="OrderID" DataField="ID" />
<asp:BoundColumn HeaderText="OrderDate" DataField="OrderDate" />
<asp:BoundColumn HeaderText="ShippedDate" DataField="ShippedDate"/>
</Columns>
</asp:DataGrid>
</div>
</form>
</body>
</html>
<asp:BoundColumn HeaderText="OrderDate" DataFormatString="{0:d}" DataField="OrderDate" />
<asp:BoundColumn HeaderText="ShippedDate" DataFormatString="{0:d}" DataField="ShippedDate" />
</Columns>
</asp:DataGrid>
</asp:Content>

View File

@@ -0,0 +1,25 @@
<%@ Page Language="C#" MasterPageFile="~/Shared/MasterPage.master" CodeFile="CustomerEditor.aspx.cs"
Inherits="CustomerEditor" %>
<asp:Content ID="content" ContentPlaceHolderID="content" runat="server">
<spring:DataBindingPanel runat="server" ID="panel">
<fieldset title="Customer details">
<table>
<tr>
<td>
ID:</td>
<td>
<asp:Label runat="server" BindingTarget="CurrentCustomer.Id" BindingDirection="TargetToSource"
ReadOnly="true" /></td>
</tr>
<tr>
<td>
Contact:</td>
<td>
<asp:Label runat="server" BindingTarget="CurrentCustomer.ContactName" /></td>
</tr>
</table>
</fieldset>
</spring:DataBindingPanel>
<asp:Button runat="server" ID="btnSave" Text="Edit" />
</asp:Content>

View File

@@ -0,0 +1,65 @@
using System;
using System.Web;
using Spring.Northwind.Dao;
using Spring.Northwind.Domain;
using Spring.Web.UI;
public partial class CustomerView : Page
{
private ICustomerEditController customerEditController;
private ICustomerDao customerDao;
public ICustomerDao CustomerDao
{
set { this.customerDao = value; }
}
public ICustomerEditController CustomerEditController
{
set { this.customerEditController = value; }
}
public Customer CurrentCustomer
{
get { return customerEditController.CurrentCustomer; }
}
// public static void Edit( Customer customer )
// {
// HttpContext.Current.Session[typeof(CustomerEditor).FullName + ".Customer"] = customer;
// }
public CustomerView()
{
this.InitializeControls += new EventHandler(Page_InitializeControls);
this.DataBound += new EventHandler(Page_DataBound);
this.DataUnbound += new EventHandler(Page_DataUnbound);
}
override protected void InitializeDataBindings()
{
base.InitializeDataBindings();
// do the "one time" setup for databinding
}
private void Page_DataBound(object sender, EventArgs e)
{
// perform custom tasks for binding data from model to the form
}
private void Page_DataUnbound(object sender, EventArgs e)
{
// perform custom tasks for unbinding data from form to the model
}
private void Page_InitializeControls(object sender, EventArgs e)
{
btnSave.Click += new EventHandler(BtnSave_Click);
}
private void BtnSave_Click(object sender, EventArgs e)
{
customerDao.SaveOrUpdate(CurrentCustomer);
}
}

View File

@@ -29,7 +29,7 @@ public partial class _Default : Spring.Web.UI.Page
string customerId = "ERNSH";
// check, if exists
Customer customer = customerDao.FindById(customerId);
Customer customer = customerDao.Get(customerId);
//Find all orders for customer and ship them
this.fulfillmentService.ProcessCustomer(customer.Id);

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@@ -0,0 +1,59 @@
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="Shared_MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Spring.NET NHibernate Northwind Example</title>
<link type="text/css" rel="Stylesheet" href="../CSS/style.css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td background="img/header-spring.png" height="150" width="719">
<div class="logo">
<a href="~/Default.aspx" runat="server">
<img src="img/logo.png" border="0" height="84" width="271"></a></div>
</td>
</tr>
<tr>
<td style="background-image: url(img/bg-spring.png);" align="left" valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="700">
<tbody>
<tr>
<td colspan="2">
<br>
<br>
</td>
</tr>
<tr>
<td style="height: 4721px" valign="top" width="210">
<!-- Navigation: Start -->
</td>
<td style="height: 4721px" valign="top">
<!-- Inhalt: Start -->
<asp:ContentPlaceHolder ID="content" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
<tr>
<td colspan="2">
<br>
<br>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style="background-image: url(img/footern.gif);" align="center" height="29">
</td>
</tr>
</tbody>
</table>
</div>
</form>
</body>
</html>

View File

@@ -0,0 +1,9 @@
using System;
public partial class Shared_MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}

View File

@@ -55,7 +55,7 @@
<system.web>
<httpModules>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
<add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate12"/>
<add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate21"/>
</httpModules>
<httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>

View File

@@ -74,13 +74,13 @@ namespace Spring.Northwind.IntegrationTests
[Test]
public void CustomerDaoTests()
{
Assert.AreEqual(91, customerDao.FindAll().Count);
Assert.AreEqual(91, customerDao.GetAll().Count);
Customer c = new Customer();
c.Id = "MPOLL";
c.CompanyName = "Interface21";
customerDao.Save(c);
c = customerDao.FindById("MPOLL");
c = customerDao.Get("MPOLL");
Assert.AreEqual(c.Id, "MPOLL");
Assert.AreEqual(c.CompanyName, "Interface21");
@@ -95,13 +95,13 @@ namespace Spring.Northwind.IntegrationTests
customerCount = (int)AdoTemplate.ExecuteScalar(CommandType.Text, "select count(*) from Customers");
Assert.AreEqual(92, customerCount);
Assert.AreEqual(92, customerDao.FindAll().Count);
Assert.AreEqual(92, customerDao.GetAll().Count);
c.CompanyName = "SpringSource";
customerDao.SaveOrUpdate(c);
c = customerDao.FindById("MPOLL");
c = customerDao.Get("MPOLL");
Assert.AreEqual(c.Id, "MPOLL");
Assert.AreEqual(c.CompanyName, "SpringSource");
@@ -114,7 +114,7 @@ namespace Spring.Northwind.IntegrationTests
try
{
c = customerDao.FindById("MPOLL");
c = customerDao.Get("MPOLL");
Assert.Fail("Should have thrown HibernateObjectRetrievalFailureException when finding customer with Id = MPOLL");
}
catch (HibernateObjectRetrievalFailureException e)
@@ -127,16 +127,16 @@ namespace Spring.Northwind.IntegrationTests
[Test]
public void ProductDaoTests()
{
Assert.AreEqual(830, orderDao.FindAll().Count);
Assert.AreEqual(830, orderDao.GetAll().Count);
Order order = new Order();
Customer customer = customerDao.FindById("PICCO");
Customer customer = customerDao.Get("PICCO");
order.Customer = customer;
order.ShipCity = "New York";
orderDao.Save(order);
int orderId = order.Id;
order = orderDao.FindById(orderId);
order = orderDao.Get(orderId);
Assert.AreEqual("PICCO", order.Customer.Id);
Assert.AreEqual("New York", order.ShipCity);
@@ -146,12 +146,12 @@ namespace Spring.Northwind.IntegrationTests
int ordersCount = (int)AdoTemplate.ExecuteScalar(CommandType.Text, "select count(*) from Orders");
Assert.AreEqual(831, ordersCount);
Assert.AreEqual(831, orderDao.FindAll().Count);
Assert.AreEqual(831, orderDao.GetAll().Count);
order.ShipCity = "Sao Paulo";
orderDao.SaveOrUpdate(order);
order = orderDao.FindById(orderId);
order = orderDao.Get(orderId);
Assert.AreEqual("PICCO", order.Customer.Id);
Assert.AreEqual("Sao Paulo", order.ShipCity);
@@ -166,7 +166,7 @@ namespace Spring.Northwind.IntegrationTests
try
{
order = orderDao.FindById(orderId);
order = orderDao.Get(orderId);
Assert.Fail("Should have thrown HibernateObjectRetrievalFailureException when finding order with Id = " + orderId);
}
catch (HibernateObjectRetrievalFailureException e)

View File

@@ -32,29 +32,21 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\Net\2.0\antlr.runtime.dll</HintPath>
</Reference>
<Reference Include="Castle.DynamicProxy, Version=1.1.5.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\NHibernate12\net\2.0\Castle.DynamicProxy.dll</HintPath>
</Reference>
<Reference Include="Common.Logging, Version=1.1.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\Net\2.0\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="Common.Logging.Log4Net, Version=1.2.0.2, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\Common.Logging.Log4Net.dll</HintPath>
</Reference>
<Reference Include="Iesi.Collections, Version=1.0.0.3, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\NHibernate12\net\2.0\Iesi.Collections.dll</HintPath>
<HintPath>..\..\..\..\..\lib\NHibernate21\net\2.0\Iesi.Collections.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\NHibernate12\net\2.0\log4net.dll</HintPath>
<HintPath>..\..\..\..\..\lib\NHibernate21\net\2.0\log4net.dll</HintPath>
</Reference>
<Reference Include="NHibernate, Version=1.2.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\NHibernate12\net\2.0\NHibernate.dll</HintPath>
<HintPath>..\..\..\..\..\lib\NHibernate21\net\2.0\NHibernate.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -68,9 +60,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\Spring.Data.dll</HintPath>
</Reference>
<Reference Include="Spring.Data.NHibernate12, Version=1.1.2.20153, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="Spring.Data.NHibernate21, Version=1.1.2.20153, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\Spring.Data.NHibernate12.dll</HintPath>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\Spring.Data.NHibernate21.dll</HintPath>
</Reference>
<Reference Include="Spring.Testing.NUnit, Version=1.1.2.20153, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>