Skip to content

Commit 8f23086

Browse files
authored
Merge branch 'master' into NH-4034
2 parents 415f138 + a4cbae9 commit 8f23086

File tree

14 files changed

+116
-19
lines changed

14 files changed

+116
-19
lines changed

ShowBuildMenu.bat

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ echo F. Add a test configuration for PostgreSQL.
5050
echo G. Add a test configuration for Oracle.
5151
echo H. Add a test configuration for SQL Server Compact (x86).
5252
echo I. Add a test configuration for SQL Server Compact (x64).
53+
echo J. Add a test configuration for MySql.
5354
echo.
5455
echo X. Exit to main menu.
5556
echo.
5657

57-
%BUILDTOOL% prompt ABCDEFGHIX
58-
if errorlevel 9 goto main-menu
58+
%BUILDTOOL% prompt ABCDEFGHIJX
59+
if errorlevel 10 goto main-menu
60+
if errorlevel 9 goto test-setup-mysql
5961
if errorlevel 8 goto test-setup-sqlservercex64
6062
if errorlevel 7 goto test-setup-sqlservercex86
6163
if errorlevel 6 goto test-setup-oracle
@@ -120,6 +122,13 @@ set LIB_FILES=lib\teamcity\postgresql\*.dll
120122
set LIB_FILES2=
121123
goto test-setup-generic
122124

125+
:test-setup-mysql
126+
set CONFIG_NAME=MySql
127+
set PLATFORM=AnyCPU
128+
set LIB_FILES=lib\teamcity\mysql\*.dll
129+
set LIB_FILES2=
130+
goto test-setup-generic
131+
123132
:test-setup-oracle
124133
set CONFIG_NAME=Oracle
125134
set PLATFORM=x86

src/NHibernate.Config.Templates/MySql.cfg.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ This template was written to work with NHibernate.Test.
44
Copy the template to your NHibernate.Test project folder and rename it in hibernate.cfg.xml and change it
55
for your own use before compile tests in VisualStudio.
66
-->
7-
<!-- This is the ByteFX.Data.dll provider for MySql -->
87
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
98
<session-factory name="NHibernate.Test">
109
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
1110
<property name="connection.connection_string">
12-
Database=test;Data Source=someip;User Id=blah;Password=blah
11+
Database=nhibernate;Data Source=localhost;User Id=nhibernate;Password=;
12+
Protocol=memory;Old Guids=True;
1313
</property>
14-
<property name="dialect">NHibernate.Dialect.MySQLDialect</property>
14+
<property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
1515
</session-factory>
1616
</hibernate-configuration>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using NUnit.Framework;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH2241
4+
{
5+
[TestFixture]
6+
public class Fixture : BugTestCase
7+
{
8+
protected override void OnSetUp()
9+
{
10+
using (var session = OpenSession())
11+
using (var tran = session.BeginTransaction())
12+
{
13+
var country = new Country {CountryCode = "SE", CountryName = "Sweden"};
14+
session.Save(country);
15+
tran.Commit();
16+
}
17+
}
18+
19+
protected override void OnTearDown()
20+
{
21+
using (var session = OpenSession())
22+
using (var tran = session.BeginTransaction())
23+
{
24+
session.Delete("from Country");
25+
session.Delete("from User");
26+
tran.Commit();
27+
}
28+
}
29+
30+
[Test]
31+
public void CanInsertUsingStatelessEvenWhenAssociatedEntityHasCacheStategy()
32+
{
33+
using (var ss = Sfi.OpenStatelessSession())
34+
using (var tx = ss.BeginTransaction())
35+
{
36+
var user = new User();
37+
user.Country = new Country {CountryCode = "SE", CountryName = "Sweden"};
38+
39+
ss.Insert(user);
40+
tx.Commit();
41+
}
42+
}
43+
}
44+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
3+
assembly="NHibernate.Test"
4+
namespace="NHibernate.Test.NHSpecificTest.NH2241">
5+
6+
<class name="User" table="Users">
7+
<id name="Id">
8+
<generator class="native"/>
9+
</id>
10+
11+
<many-to-one name="Country" column="CountryCode" cascade="none" />
12+
</class>
13+
14+
<class name="Country">
15+
<cache region="ShortTerm" usage="read-write" />
16+
17+
<id name="CountryCode">
18+
<generator class="assigned"/>
19+
</id>
20+
21+
<property name="CountryName" />
22+
23+
</class>
24+
25+
</hibernate-mapping>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace NHibernate.Test.NHSpecificTest.NH2241
2+
{
3+
public class User
4+
{
5+
public virtual int Id { get; set; }
6+
7+
public virtual Country Country { get; set; }
8+
}
9+
10+
public class Country
11+
{
12+
public virtual string CountryCode { get; set; }
13+
14+
public virtual string CountryName { get; set; }
15+
}
16+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,8 @@
760760
<Compile Include="NHSpecificTest\EntityWithUserTypeCanHaveLinqGenerators\Fixture.cs" />
761761
<Compile Include="NHSpecificTest\EntityWithUserTypeCanHaveLinqGenerators\FooExample.cs" />
762762
<Compile Include="NHSpecificTest\EntityWithUserTypeCanHaveLinqGenerators\IExample.cs" />
763+
<Compile Include="NHSpecificTest\NH2241\Fixture.cs" />
764+
<Compile Include="NHSpecificTest\NH2241\Model.cs" />
763765
<Compile Include="Insertordering\NH3931Entities.cs" />
764766
<Compile Include="NHSpecificTest\NH4004\Entity.cs" />
765767
<Compile Include="NHSpecificTest\NH4004\Fixture.cs" />
@@ -3287,6 +3289,7 @@
32873289
</ItemGroup>
32883290
<ItemGroup>
32893291
<EmbeddedResource Include="TransactionTest\Person.hbm.xml" />
3292+
<EmbeddedResource Include="NHSpecificTest\NH2241\Mappings.hbm.xml" />
32903293
<EmbeddedResource Include="Futures\Mappings.hbm.xml" />
32913294
<EmbeddedResource Include="SessionBuilder\Mappings.hbm.xml" />
32923295
<EmbeddedResource Include="IdTest\IdentityClass.hbm.xml" />

src/NHibernate/Engine/BatchFetchQueue.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public object[] GetEntityBatch(IEntityPersister persister,object id,int batchSiz
236236

237237
private bool IsCached(EntityKey entityKey, IEntityPersister persister)
238238
{
239-
if (persister.HasCache)
239+
if (persister.HasCache && context.Session.CacheMode.HasFlag(CacheMode.Get))
240240
{
241241
CacheKey key = context.Session.GenerateCacheKey(entityKey.Identifier, persister.IdentifierType, entityKey.EntityName);
242242
return persister.Cache.Cache.Get(key) != null;
@@ -246,12 +246,12 @@ private bool IsCached(EntityKey entityKey, IEntityPersister persister)
246246

247247
private bool IsCached(object collectionKey, ICollectionPersister persister)
248248
{
249-
if (persister.HasCache)
249+
if (persister.HasCache && context.Session.CacheMode.HasFlag(CacheMode.Get))
250250
{
251251
CacheKey cacheKey = context.Session.GenerateCacheKey(collectionKey, persister.KeyType, persister.Role);
252252
return persister.Cache.Cache.Get(cacheKey) != null;
253253
}
254254
return false;
255255
}
256256
}
257-
}
257+
}

src/NHibernate/Engine/Loading/CollectionLoadContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private void EndLoadingCollection(LoadingCollectionEntry lce, ICollectionPersist
260260
}
261261

262262
bool addToCache = hasNoQueuedAdds && persister.HasCache &&
263-
((session.CacheMode & CacheMode.Put) == CacheMode.Put) && !ce.IsDoremove; // and this is not a forced initialization during flush
263+
session.CacheMode.HasFlag(CacheMode.Put) && !ce.IsDoremove; // and this is not a forced initialization during flush
264264

265265
if (addToCache)
266266
{

src/NHibernate/Engine/TwoPhaseLoad.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static void InitializeEntity(object entity, bool readOnly, ISessionImplem
9898

9999
ISessionFactoryImplementor factory = session.Factory;
100100

101-
if (persister.HasCache && ((session.CacheMode & CacheMode.Put) == CacheMode.Put))
101+
if (persister.HasCache && session.CacheMode.HasFlag(CacheMode.Put))
102102
{
103103
if (log.IsDebugEnabled)
104104
log.Debug("adding entity to second-level cache: " + MessageHelper.InfoString(persister, id, session.Factory));

src/NHibernate/Event/Default/DefaultInitializeCollectionEventListener.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private bool InitializeCollectionFromCache(object id, ICollectionPersister persi
7070
return false;
7171
}
7272

73-
bool useCache = persister.HasCache && ((source.CacheMode & CacheMode.Get) == CacheMode.Get);
73+
bool useCache = persister.HasCache && source.CacheMode.HasFlag(CacheMode.Get);
7474

7575
if (!useCache)
7676
{

src/NHibernate/Event/Default/DefaultLoadEventListener.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ protected virtual object LoadFromSessionCache(LoadEvent @event, EntityKey keyToL
413413
protected virtual object LoadFromSecondLevelCache(LoadEvent @event, IEntityPersister persister, LoadType options)
414414
{
415415
ISessionImplementor source = @event.Session;
416-
bool useCache = persister.HasCache && ((source.CacheMode & CacheMode.Get) == CacheMode.Get)
416+
bool useCache = persister.HasCache && source.CacheMode .HasFlag(CacheMode.Get)
417417
&& @event.LockMode.LessThan(LockMode.Read);
418418

419419
if (useCache)

src/NHibernate/Impl/MultiCriteriaImpl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private IList ListUsingQueryCache()
137137
log.Debug("Cache miss for multi criteria query");
138138
IList list = DoList();
139139
result = list;
140-
if ((session.CacheMode & CacheMode.Put) == CacheMode.Put)
140+
if (session.CacheMode.HasFlag(CacheMode.Put))
141141
{
142142
bool put = queryCache.Put(key, new ICacheAssembler[] { assembler }, new object[] { list }, combinedParameters.NaturalKeyLookup, session);
143143
if (put && factory.Statistics.IsStatisticsEnabled)
@@ -476,4 +476,4 @@ private void ThrowIfKeyAlreadyExists(string key)
476476
throw new InvalidOperationException(String.Format("The key '{0}' already exists", key));
477477
}
478478
}
479-
}
479+
}

src/NHibernate/Loader/Loader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ private IList GetResultFromQueryCache(ISessionImplementor session, QueryParamete
15821582
{
15831583
IList result = null;
15841584

1585-
if ((!queryParameters.ForceCacheRefresh) && (session.CacheMode & CacheMode.Get) == CacheMode.Get)
1585+
if (!queryParameters.ForceCacheRefresh && session.CacheMode.HasFlag(CacheMode.Get))
15861586
{
15871587
IPersistenceContext persistenceContext = session.PersistenceContext;
15881588

@@ -1620,7 +1620,7 @@ private IList GetResultFromQueryCache(ISessionImplementor session, QueryParamete
16201620
private void PutResultInQueryCache(ISessionImplementor session, QueryParameters queryParameters, IType[] resultTypes,
16211621
IQueryCache queryCache, QueryKey key, IList result)
16221622
{
1623-
if ((session.CacheMode & CacheMode.Put) == CacheMode.Put)
1623+
if (session.CacheMode.HasFlag(CacheMode.Put))
16241624
{
16251625
bool put = queryCache.Put(key, key.ResultTransformer.GetCachedResultTypes(resultTypes), result, queryParameters.NaturalKeyLookup, session);
16261626
if (put && _factory.Statistics.IsStatisticsEnabled)
@@ -1858,4 +1858,4 @@ protected bool TryGetLimitString(Dialect.Dialect dialect, SqlString queryString,
18581858

18591859
#endregion
18601860
}
1861-
}
1861+
}

src/NHibernate/Persister/Entity/AbstractEntityPersister.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ public virtual object InitializeLazyProperty(string fieldName, object entity, IS
12451245
MessageHelper.InfoString(this, id, Factory), fieldName));
12461246
}
12471247

1248-
if (HasCache)
1248+
if (HasCache && session.CacheMode.HasFlag(CacheMode.Get))
12491249
{
12501250
CacheKey cacheKey = session.GenerateCacheKey(id, IdentifierType, EntityName);
12511251
object ce = Cache.Get(cacheKey, session.Timestamp);
@@ -3818,7 +3818,7 @@ public virtual void AfterReassociate(object entity, ISessionImplementor session)
38183818
}
38193819

38203820
// check to see if it is in the second-level cache
3821-
if (HasCache)
3821+
if (HasCache && session.CacheMode.HasFlag(CacheMode.Get))
38223822
{
38233823
CacheKey ck = session.GenerateCacheKey(id, IdentifierType, RootEntityName);
38243824
if (Cache.Get(ck, session.Timestamp) != null)

0 commit comments

Comments
 (0)