Skip to content

Commit f39efbe

Browse files
author
Tom Barrett
committed
*** empty log message ***
SVN: trunk@3
1 parent 49db476 commit f39efbe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+3191
-0
lines changed

src/NHibernate/ADOException.cs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Data;
3+
4+
namespace NHibernate {
5+
/// <summary>
6+
/// Wraps an <c>DataException</c>. Indicates that an exception occurred during an ADO.NET call.
7+
/// </summary>
8+
public class ADOException : HibernateException {
9+
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(ADOException));
10+
private Exception sqle;
11+
12+
public ADOException(DataException root) : this("DataException occurred", root) { }
13+
14+
public ADOException(string str, Exception root) : base(str, root) {
15+
sqle = root;
16+
log.Error(str, root);
17+
}
18+
19+
}
20+
}

src/NHibernate/AssemblyInfo.cs

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
4+
//
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
//
9+
[assembly: AssemblyTitle("")]
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyConfiguration("")]
12+
[assembly: AssemblyCompany("")]
13+
[assembly: AssemblyProduct("")]
14+
[assembly: AssemblyCopyright("")]
15+
[assembly: AssemblyTrademark("")]
16+
[assembly: AssemblyCulture("")]
17+
18+
//
19+
// Version information for an assembly consists of the following four values:
20+
//
21+
// Major Version
22+
// Minor Version
23+
// Build Number
24+
// Revision
25+
//
26+
// You can specify all the values or you can default the Revision and Build Numbers
27+
// by using the '*' as shown below:
28+
29+
[assembly: AssemblyVersion("1.0.*")]
30+
31+
//
32+
// In order to sign your assembly you must specify a key to use. Refer to the
33+
// Microsoft .NET Framework documentation for more information on assembly signing.
34+
//
35+
// Use the attributes below to control which key is used for signing.
36+
//
37+
// Notes:
38+
// (*) If no key is specified, the assembly is not signed.
39+
// (*) KeyName refers to a key that has been installed in the Crypto Service
40+
// Provider (CSP) on your machine. KeyFile refers to a file which contains
41+
// a key.
42+
// (*) If the KeyFile and the KeyName values are both specified, the
43+
// following processing occurs:
44+
// (1) If the KeyName can be found in the CSP, that key is used.
45+
// (2) If the KeyName does not exist and the KeyFile does exist, the key
46+
// in the KeyFile is installed into the CSP and used.
47+
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
48+
// When specifying the KeyFile, the location of the KeyFile should be
49+
// relative to the project output directory which is
50+
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
51+
// located in the project directory, you would specify the AssemblyKeyFile
52+
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
53+
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
54+
// documentation for more information on this.
55+
//
56+
[assembly: AssemblyDelaySign(false)]
57+
[assembly: AssemblyKeyFile("")]
58+
[assembly: AssemblyKeyName("")]

src/NHibernate/AssertionFailure.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
3+
namespace NHibernate {
4+
5+
/// <summary>
6+
/// Indicates failure of an assertion: a possible bug in NHibernate
7+
/// </summary>
8+
public class AssertionFailure : ApplicationException {
9+
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(AssertionFailure));
10+
11+
public AssertionFailure(string s) : base(s) {
12+
log.Error("An AssertionFailure occured - this may indicate a bug in NHibernate", this);
13+
}
14+
15+
public AssertionFailure(string s, Exception e) : base(s, e) {
16+
log.Error("An AssertionFailure occured - this may indicate a bug in NHibernate", e);
17+
}
18+
}
19+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace NHibernate.Cache {
4+
5+
/// <summary>
6+
/// Represents any exception from an <c>ICache</c>
7+
/// </summary>
8+
public class CacheException : HibernateException {
9+
10+
public CacheException(string s) : base(s) { }
11+
12+
public CacheException(Exception e) : base(e) { }
13+
}
14+
15+
}

src/NHibernate/Cache/CachedItem.cs

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
3+
namespace NHibernate.Cache {
4+
5+
/// <summary>
6+
/// An item of cached data, timestamped with the time it was cached, when it was locked,
7+
/// when it was unlocked
8+
/// </summary>
9+
[Serializable]
10+
public class CachedItem {
11+
private long freshTimestamp;
12+
private bool fresh;
13+
private long unlockTimestamp;
14+
private int theLock;
15+
private object value;
16+
17+
public CachedItem(object value) {
18+
this.value = value;
19+
freshTimestamp = Timestamper.Next();
20+
fresh = true;
21+
unlockTimestamp = -1;
22+
}
23+
24+
public long FreshTimestamp {
25+
get { return freshTimestamp; }
26+
}
27+
28+
public long UnlockTimestamp {
29+
get { return unlockTimestamp; }
30+
}
31+
32+
public object Value {
33+
get { return value; }
34+
}
35+
36+
public bool IsFresh {
37+
get { return fresh; }
38+
}
39+
40+
public void Lock() {
41+
if ( 0 == theLock++ ) {
42+
fresh = false;
43+
value = null;
44+
}
45+
}
46+
public void Unlock() {
47+
if ( --theLock == 0 ) {
48+
unlockTimestamp = Timestamper.Next();
49+
}
50+
}
51+
public bool IsUnlocked {
52+
get { return theLock == 0; }
53+
}
54+
55+
}
56+
}

src/NHibernate/Cache/ICache.cs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
3+
namespace NHibernate.Cache {
4+
5+
/// <summary>
6+
/// Implementors define a caching algorithm.
7+
/// </summary>
8+
/// <remarks>
9+
/// All implementations MUST be threadsafe
10+
/// </remarks>
11+
public interface ICache {
12+
13+
/// <summary>
14+
/// Gets or sets cached data
15+
/// </summary>
16+
/// <value>The cached object or <c>null</c></value>
17+
/// <exception cref="CacheException"></exception>
18+
object this [object key] {
19+
get;
20+
set;
21+
}
22+
23+
}
24+
25+
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
3+
namespace NHibernate.Cache {
4+
5+
/// <summary>
6+
/// Implementors manage transactional access to cached data.
7+
/// </summary>
8+
/// <remarks>
9+
/// Transactions pass in a timestamp indicating transaction start time.
10+
/// </remarks>
11+
public interface ICacheConcurrencyStrategy {
12+
13+
/// <summary>
14+
/// Attempt to cache an object
15+
/// </summary>
16+
/// <param name="key">The key</param>
17+
/// <param name="txTimestamp">A timestamp prior to the transaction start time</param>
18+
/// <returns>The cached object or <c>null</c></returns>
19+
/// <exception cref="CacheException"></exception>
20+
object Get(object key, long txTimestamp);
21+
22+
/// <summary>
23+
/// Attempt to retrieve an object from the cache
24+
/// </summary>
25+
/// <param name="key">The key</param>
26+
/// <param name="value">The value</param>
27+
/// <param name="txTimestamp">A timestamp prior to the transaction start time</param>
28+
/// <returns><c>true</c> if the object was successfully cached</returns>
29+
/// <exception cref="CacheException"></exception>
30+
bool Put(object key, object value, long txTimestamp);
31+
32+
/// <summary>
33+
/// We are going to attempt to update/delete the keyed object
34+
/// </summary>
35+
/// <param name="key">The key</param>
36+
/// <exception cref="CacheException"></exception>
37+
void Lock(object key);
38+
39+
/// <summary>
40+
/// We have finished the attempted update/delete (which may or may not have been successful)
41+
/// </summary>
42+
/// <param name="key">The key</param>
43+
/// <exception cref="CacheException"></exception>
44+
void Release(object key);
45+
}
46+
}

src/NHibernate/Cache/ICacheTest.cs

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using System;
2+
using NUnit.Framework;
3+
4+
namespace NHibernate.Cache {
5+
6+
[TestFixture]
7+
public class ICacheTest {
8+
9+
[Test]
10+
public void TestSimpleCache() {
11+
DoTestCache( new SimpleCache() );
12+
}
13+
14+
public void DoTestCache(ICache cache) {
15+
long longBefore = Timestamper.Next();
16+
17+
System.Threading.Thread.Sleep(15);
18+
19+
long before = Timestamper.Next();
20+
21+
System.Threading.Thread.Sleep(15);
22+
23+
ICacheConcurrencyStrategy ccs = new ReadWriteCache(cache);
24+
25+
// cache something
26+
27+
Assertion.Assert( ccs.Put("foo", "foo", before) );
28+
29+
System.Threading.Thread.Sleep(15);
30+
31+
long after = Timestamper.Next();
32+
33+
Assertion.AssertNull( ccs.Get("foo", longBefore) );
34+
Assertion.AssertEquals( "foo", ccs.Get("foo", after) );
35+
Assertion.Assert( !ccs.Put("foo", "foo", before) );
36+
37+
// update it;
38+
39+
ccs.Lock("foo");
40+
41+
Assertion.AssertNull( ccs.Get("foo", after) );
42+
Assertion.AssertNull( ccs.Get("foo", longBefore) );
43+
Assertion.Assert( !ccs.Put("foo", "foo", before) );
44+
45+
System.Threading.Thread.Sleep(15);
46+
47+
long whileLocked = Timestamper.Next();
48+
49+
Assertion.Assert( !ccs.Put("foo", "foo", whileLocked) );
50+
51+
System.Threading.Thread.Sleep(15);
52+
53+
ccs.Release("foo");
54+
55+
Assertion.AssertNull( ccs.Get("foo", after) );
56+
Assertion.AssertNull( ccs.Get("foo", longBefore) );
57+
Assertion.Assert( !ccs.Put("foo", "bar", whileLocked) );
58+
Assertion.Assert( !ccs.Put("foo", "bar", after) );
59+
60+
System.Threading.Thread.Sleep(15);
61+
62+
long longAfter = Timestamper.Next();
63+
64+
Assertion.Assert( ccs.Put("foo", "baz", longAfter) );
65+
Assertion.AssertNull( ccs.Get("foo", after) );
66+
Assertion.AssertNull( ccs.Get("foo", whileLocked) );
67+
68+
System.Threading.Thread.Sleep(15);
69+
70+
long longLongAfter = Timestamper.Next();
71+
72+
Assertion.AssertEquals("baz", ccs.Get("foo", longLongAfter) );
73+
74+
// update it again, with multiple locks
75+
76+
ccs.Lock("foo");
77+
ccs.Lock("foo");
78+
79+
Assertion.AssertNull( ccs.Get("foo", longLongAfter) );
80+
81+
System.Threading.Thread.Sleep(15);
82+
83+
whileLocked = Timestamper.Next();
84+
85+
Assertion.Assert( !ccs.Put("foo", "foo", whileLocked) );
86+
87+
System.Threading.Thread.Sleep(15);
88+
89+
ccs.Release("foo");
90+
91+
System.Threading.Thread.Sleep(15);
92+
93+
long betweenReleases = Timestamper.Next();
94+
95+
Assertion.Assert( !ccs.Put("foo", "bar", betweenReleases) );
96+
Assertion.AssertNull( ccs.Get("foo", betweenReleases) );
97+
98+
System.Threading.Thread.Sleep(15);
99+
100+
ccs.Release("foo");
101+
102+
Assertion.Assert( !ccs.Put("foo", "bar", whileLocked) );
103+
104+
System.Threading.Thread.Sleep(15);
105+
106+
longAfter = Timestamper.Next();
107+
108+
Assertion.Assert( ccs.Put("foo", "baz", longAfter) );
109+
Assertion.AssertNull( ccs.Get("foo", whileLocked) );
110+
111+
System.Threading.Thread.Sleep(15);
112+
113+
longLongAfter = Timestamper.Next();
114+
115+
Assertion.AssertEquals("baz", ccs.Get("foo", longLongAfter) );
116+
117+
}
118+
}
119+
}

0 commit comments

Comments
 (0)