Skip to content

Commit 31b36c6

Browse files
committed
-StatelessSession (not full ported yet) and it's tests.
-Little one more step to entityName feature port. SVN: trunk@3034
1 parent 701e203 commit 31b36c6

17 files changed

+1265
-53
lines changed

src/NHibernate.DomainModel/MultiplicityType.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public object Assemble(object cached, ISessionImplementor session, Object owner)
129129
m.count = (int) o[0];
130130
m.glarch = o[1] == null ?
131131
null :
132-
(GlarchProxy) session.InternalLoad(typeof(Glarch), o[1], false, false);
132+
(GlarchProxy) session.InternalLoad(typeof(Glarch).FullName, o[1], false, false);
133133
return m;
134134
}
135135

src/NHibernate.Test/NHibernate.Test-2.0.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,9 @@
545545
<Compile Include="SqlTest\SelfReferencingCollectionLoadTest.cs" />
546546
<Compile Include="SqlTest\SpaceShip.cs" />
547547
<Compile Include="SqlTest\Speech.cs" />
548+
<Compile Include="Stateless\Document.cs" />
549+
<Compile Include="Stateless\Paper.cs" />
550+
<Compile Include="Stateless\StatelessSessionFixture.cs" />
548551
<Compile Include="SubclassFilterTest\JoinedSubclassFilterTest.cs" />
549552
<Compile Include="SubclassFilterTest\Customer.cs" />
550553
<Compile Include="SubclassFilterTest\DiscrimSubclassFilterTest.cs" />
@@ -1002,6 +1005,9 @@
10021005
<ItemGroup>
10031006
<EmbeddedResource Include="Classic\Video.hbm.xml" />
10041007
</ItemGroup>
1008+
<ItemGroup>
1009+
<EmbeddedResource Include="Stateless\Document.hbm.xml" />
1010+
</ItemGroup>
10051011
<ItemGroup>
10061012
<Folder Include="Properties\" />
10071013
</ItemGroup>
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
3+
namespace NHibernate.Test.Stateless
4+
{
5+
public class Document
6+
{
7+
private string text;
8+
private string name;
9+
private DateTime? lastModified;
10+
11+
public Document() { }
12+
13+
public Document(string text, string name)
14+
{
15+
this.text = text;
16+
this.name = name;
17+
}
18+
19+
public string Text
20+
{
21+
get { return text; }
22+
set { text = value; }
23+
}
24+
25+
public string Name
26+
{
27+
get { return name; }
28+
set { name = value; }
29+
}
30+
31+
public DateTime? LastModified
32+
{
33+
get { return lastModified; }
34+
set { lastModified = value; }
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping
3+
xmlns="urn:nhibernate-mapping-2.2"
4+
assembly="NHibernate.Test"
5+
namespace="NHibernate.Test.Stateless"
6+
default-lazy="false">
7+
8+
<class name="Document">
9+
<id name="Name">
10+
<generator class="assigned"/>
11+
</id>
12+
<timestamp name="LastModified"/>
13+
<property name="Text"/>
14+
</class>
15+
16+
<class name="Paper">
17+
<id name="Id">
18+
<generator class="native"/>
19+
</id>
20+
<property name="Color"/>
21+
</class>
22+
23+
</hibernate-mapping>
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace NHibernate.Test.Stateless
2+
{
3+
public class Paper
4+
{
5+
private int id;
6+
private string color;
7+
8+
public int Id
9+
{
10+
get { return id; }
11+
set { id = value; }
12+
}
13+
14+
public string Color
15+
{
16+
get { return color; }
17+
set { color = value; }
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
using System;
2+
using System.Collections;
3+
using NHibernate.Cfg;
4+
using NHibernate.Engine;
5+
using NHibernate.SqlCommand;
6+
using NHibernate.SqlTypes;
7+
using NHibernate.Type;
8+
using NUnit.Framework;
9+
10+
namespace NHibernate.Test.Stateless
11+
{
12+
[TestFixture]
13+
public class StatelessSessionFixture : TestCase
14+
{
15+
protected override string MappingsAssembly
16+
{
17+
get { return "NHibernate.Test"; }
18+
}
19+
20+
protected override IList Mappings
21+
{
22+
get { return new string[] { "Stateless.Document.hbm.xml" }; }
23+
}
24+
25+
[Test, Ignore("Porting in progress")]
26+
public void CreateUpdateReadDelete()
27+
{
28+
IStatelessSession ss = sessions.OpenStatelessSession();
29+
ITransaction tx = ss.BeginTransaction();
30+
Document doc = new Document("blah blah blah", "Blahs");
31+
ss.Insert(doc);
32+
Assert.IsNotNull(doc.LastModified);
33+
DateTime? initVersion = doc.LastModified;
34+
Assert.IsTrue(initVersion.HasValue);
35+
tx.Commit();
36+
37+
tx = ss.BeginTransaction();
38+
doc.Text = "blah blah blah .... blah";
39+
ss.Update(doc);
40+
Assert.IsTrue(initVersion.HasValue);
41+
Assert.AreSame(initVersion, doc.LastModified);
42+
tx.Commit();
43+
44+
tx = ss.BeginTransaction();
45+
doc.Text = "blah blah blah .... blah blay";
46+
ss.Update(doc);
47+
tx.Commit();
48+
49+
Document doc2 = (Document) ss.Get<Document>("Blahs");
50+
Assert.AreEqual("Blahs", doc2.Name);
51+
Assert.AreEqual(doc.Text, doc2.Text);
52+
53+
doc2 = (Document) ss.CreateQuery("from Document where text is not null").UniqueResult();
54+
Assert.AreEqual("Blahs", doc2.Name);
55+
Assert.AreEqual(doc.Text, doc2.Text);
56+
57+
doc2 = (Document) ss.CreateSQLQuery("select * from Document").AddEntity(typeof (Document)).UniqueResult();
58+
Assert.AreEqual("Blahs", doc2.Name);
59+
Assert.AreEqual(doc.Text, doc2.Text);
60+
61+
doc2 = (Document) ss.CreateCriteria<Document>().UniqueResult();
62+
Assert.AreEqual("Blahs", doc2.Name);
63+
Assert.AreEqual(doc.Text, doc2.Text);
64+
65+
tx = ss.BeginTransaction();
66+
ss.Delete(doc);
67+
tx.Commit();
68+
ss.Close();
69+
}
70+
71+
[Test, Ignore("Not supported yet")]
72+
public void HqlBulk()
73+
{
74+
//IStatelessSession ss = sessions.OpenStatelessSession();
75+
//ITransaction tx = ss.BeginTransaction();
76+
//Document doc = new Document("blah blah blah", "Blahs");
77+
//ss.Insert(doc);
78+
//Paper paper = new Paper();
79+
//paper.Color="White";
80+
//ss.Insert(paper);
81+
//tx.Commit();
82+
83+
//tx = ss.BeginTransaction();
84+
//int count = ss.CreateQuery("update Document set name = :newName where name = :oldName")
85+
// .SetString("newName", "Foos")
86+
// .SetString("oldName", "Blahs")
87+
// .ExecuteUpdate();
88+
//Assert.AreEqual(1, count, "hql-delete on stateless session");
89+
//count = ss.CreateQuery("update Paper set color = :newColor")
90+
// .SetString("newColor", "Goldenrod")
91+
// .ExecuteUpdate();
92+
//Assert.AreEqual(1, count, "hql-delete on stateless session");
93+
//tx.Commit();
94+
95+
//tx = ss.BeginTransaction();
96+
//count = ss.CreateQuery("delete Document").ExecuteUpdate();
97+
//Assert.AreEqual(1, count, "hql-delete on stateless session");
98+
//count = ss.CreateQuery("delete Paper").ExecuteUpdate();
99+
//Assert.AreEqual(1, count, "hql-delete on stateless session");
100+
//tx.Commit();
101+
//ss.Close();
102+
}
103+
104+
[Test, Ignore("Porting in progress")]
105+
public void InitId()
106+
{
107+
IStatelessSession ss = sessions.OpenStatelessSession();
108+
ITransaction tx = ss.BeginTransaction();
109+
Paper paper = new Paper();
110+
paper.Color = "White";
111+
ss.Insert(paper);
112+
Assert.IsTrue(paper.Id != 0);
113+
tx.Commit();
114+
115+
tx = ss.BeginTransaction();
116+
ss.Delete(ss.Get<Paper>(paper.Id));
117+
tx.Commit();
118+
ss.Close();
119+
}
120+
121+
[Test, Ignore("Porting in progress")]
122+
public void Refresh()
123+
{
124+
IStatelessSession ss = sessions.OpenStatelessSession();
125+
ITransaction tx = ss.BeginTransaction();
126+
Paper paper = new Paper();
127+
paper.Color = "whtie";
128+
ss.Insert(paper);
129+
tx.Commit();
130+
ss.Close();
131+
132+
ss = sessions.OpenStatelessSession();
133+
tx = ss.BeginTransaction();
134+
Paper p2 = (Paper) ss.Get<Paper>(paper.Id);
135+
p2.Color = "White";
136+
ss.Update(p2);
137+
tx.Commit();
138+
ss.Close();
139+
140+
ss = sessions.OpenStatelessSession();
141+
tx = ss.BeginTransaction();
142+
Assert.AreEqual("whtie", paper.Color);
143+
ss.Refresh(paper);
144+
Assert.AreEqual("White", paper.Color);
145+
ss.Delete(paper);
146+
tx.Commit();
147+
ss.Close();
148+
}
149+
}
150+
}

src/NHibernate/Engine/ISessionImplementor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public interface ISessionImplementor
3333
/// Load an instance without checking if it was deleted. If it does not exist and isn't nullable, throw an exception.
3434
/// This method may create a new proxy or return an existing proxy.
3535
/// </summary>
36-
/// <param name="persistentClass">The <see cref="System.Type"/> to load.</param>
36+
/// <param name="entityName">The entityName (or class full name) to load.</param>
3737
/// <param name="id">The identifier of the object in the database.</param>
3838
/// <param name="isNullable">Allow null instance</param>
3939
/// <param name="eager">When enabled, the object is eagerly fetched.</param>
4040
/// <returns>
4141
/// A proxy of the object or an instance of the object if the <c>persistentClass</c> does not have a proxy.
4242
/// </returns>
4343
/// <exception cref="ObjectNotFoundException">No object could be found with that <c>id</c>.</exception>
44-
object InternalLoad(System.Type persistentClass, object id, bool eager, bool isNullable);
44+
object InternalLoad(string entityName, object id, bool eager, bool isNullable);
4545

4646
/// <summary>
4747
/// Load an instance immediately. Do not return a proxy.

src/NHibernate/ISessionFactory.cs

+15-9
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ public interface ISessionFactory : IDisposable
183183

184184
Settings Settings { get; }
185185

186-
/// <summary>
187-
/// This collections allows external libraries
188-
/// to add their own configuration to the NHibernate session factory.
189-
/// This is needed in such cases where the library is tightly coupled to NHibernate, such
190-
/// as the case of NHibernate Search
191-
/// </summary>
192-
IDictionary Items { get; }
193-
194-
/// <summary>
186+
/// <summary>
187+
/// This collections allows external libraries
188+
/// to add their own configuration to the NHibernate session factory.
189+
/// This is needed in such cases where the library is tightly coupled to NHibernate, such
190+
/// as the case of NHibernate Search
191+
/// </summary>
192+
IDictionary Items { get; }
193+
194+
/// <summary>
195195
/// Obtains the current session.
196196
/// </summary>
197197
/// <remarks>
@@ -203,5 +203,11 @@ public interface ISessionFactory : IDisposable
203203
/// <returns>The current session.</returns>
204204
/// <exception cref="HibernateException">Indicates an issue locating a suitable current session.</exception>
205205
ISession GetCurrentSession();
206+
207+
/// <summary> Get a new stateless session.</summary>
208+
IStatelessSession OpenStatelessSession();
209+
210+
/// <summary> Get a new stateless session for the given ADO.NET connection.</summary>
211+
IStatelessSession OpenStatelessSession(IDbConnection connection);
206212
}
207213
}

0 commit comments

Comments
 (0)