Skip to content

Add support for SAP HANA #1662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 9, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions ShowBuildMenu.bat
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ echo E. Add a test configuration for Oracle.
echo F. Add a test configuration for Oracle with managed driver.
echo G. Add a test configuration for SQL Server Compact.
echo H. Add a test configuration for MySql.
echo I. Add a test configuration for SAP HANA.
echo.
echo X. Exit to main menu.
echo.

%BUILDTOOL% prompt ABCDEFGHX
if errorlevel 8 goto main-menu
%BUILDTOOL% prompt ABCDEFGHIX
if errorlevel 9 goto main-menu
if errorlevel 8 goto test-setup-hana
if errorlevel 7 goto test-setup-mysql
if errorlevel 6 goto test-setup-sqlserverce
if errorlevel 5 goto test-setup-oracle-managed
Expand Down Expand Up @@ -122,6 +124,13 @@ set LIB_FILES=
set LIB_FILES2=
goto test-setup-generic

:test-setup-hana
set CONFIG_NAME=HANA
set TEST_PLATFORM=AnyCPU
set LIB_FILES=
set LIB_FILES2=
goto test-setup-generic

:test-setup-generic
set CFGNAME=
set /p CFGNAME=Enter a name for your test configuration or press enter to use default name:
Expand Down
15 changes: 15 additions & 0 deletions src/NHibernate.Config.Templates/HANA.cfg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This template was written to work with NHibernate.Test.
Copy the template to your NHibernate.Test project folder and rename it in hibernate.cfg.xml and change it
for your own use before compile tests in VisualStudio.
-->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="NHibernate.Test">
<property name="connection.driver_class">NHibernate.Driver.HanaDriver</property>
<property name="connection.connection_string">
Server=localhost:39015;UserID=nhibernate;Password=
</property>
<property name="dialect">NHibernate.Dialect.HanaColumnStoreDialect</property>
</session-factory>
</hibernate-configuration>
3 changes: 2 additions & 1 deletion src/NHibernate.Test/Ado/GenericBatchingBatcherFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ protected override bool AppliesTo(Dialect.Dialect dialect)
{
return !(dialect is FirebirdDialect) &&
!(dialect is Oracle8iDialect) &&
!(dialect is MsSqlCeDialect);
!(dialect is MsSqlCeDialect) &&
!(dialect is AbstractHanaDialect);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ protected override bool AppliesTo(Dialect.Dialect dialect)
{
return !(dialect is FirebirdDialect) &&
!(dialect is Oracle8iDialect) &&
!(dialect is MsSqlCeDialect);
!(dialect is MsSqlCeDialect) &&
!(dialect is AbstractHanaDialect);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System;
using System.Collections;
using NHibernate.Criterion;
using NHibernate.Dialect;
using NUnit.Framework;

namespace NHibernate.Test.Criteria.Lambda
Expand All @@ -19,6 +20,11 @@ namespace NHibernate.Test.Criteria.Lambda
[TestFixture]
public class FunctionsIntegrationFixtureAsync : TestCase
{
protected override bool AppliesTo(Dialect.Dialect dialect)
{
return TestDialect.SupportsEmptyInserts;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This surprises me, because we already test a database which is not supposed to support this, and which does not fail in all these tests modified by this PR. I have to check what is going on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, the test uses the native generator, which resolves to identity if it is supported, otherwise sequence if supported, otherwise hilo. The other db not supporting empty inserts does override NativeIdentifierGeneratorClass for using hilo, thus it has a value to insert.

Then the exact condition here should be TestDialect.SupportsEmptyInserts || dialect.NativeIdentifierGeneratorClass != typeof(IdentityGenerator).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the check for the NativeIdentifierGeneratorClass be included in TestDialect.SupportsEmptyInserts then? It seems strange that you'd have to check for TestDialect.SupportsEmptyInserts and basically everywhere add the check for the NativeIdentifierGeneratorClass right after it. If TestDialect.SupportsEmptyInserts really means something else, would it make sense to introduce a new property like TestDialect.SupportsEmptyInsertsWithNativeIdentifierGenerator?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the mapped class was using identity directly instead, testing on NativeIdentifierGeneratorClass inside SupportsEmptyInserts would defeat its purpose.

The test here does empty inserts only if the native generator does resolves to identity, otherwise it does not perform empty inserts. So when the dialect does not support empty inserts but does not resolves native to identity, it is irrelevant to disable that test.

SupportsEmptyInsertsWithNativeIdentifierGenerator is not meaningful. But since the case is very frequent, why not adding a SupportsEmptyInsertsOrHasNonIdentityNativeGenerator. It could be something like:

/// <summary>
/// Either supports inserting in a table without any column specified in the insert, or has a native
/// generator strategy resolving to something else than identity.
/// </summary>
/// <remarks>This property is useful for cases where empty inserts happens only when the entities
/// generator is <c>native</c> while the dialect uses <c>identity</c> for this generator.</remarks>
public bool SupportsEmptyInsertsOrHasNonIdentityNativeGenerator
	=> SupportsEmptyInserts || _dialect.NativeIdentifierGeneratorClass != typeof(IdentityGenerator);

}

protected override string MappingsAssembly => "NHibernate.Test";

protected override IList Mappings => new[] { "Criteria.Lambda.Mappings.hbm.xml" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using NUnit.Framework;

using NHibernate.Criterion;
using NHibernate.Dialect;

namespace NHibernate.Test.Criteria.Lambda
{
Expand All @@ -24,6 +25,11 @@ namespace NHibernate.Test.Criteria.Lambda
[TestFixture]
public class IntegrationFixtureAsync : TestCase
{
protected override bool AppliesTo(Dialect.Dialect dialect)
{
return TestDialect.SupportsEmptyInserts;
}

protected override string MappingsAssembly { get { return "NHibernate.Test"; } }

protected override IList Mappings
Expand Down Expand Up @@ -455,4 +461,4 @@ public async Task StatelessSessionAsync()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Collections;
using System.Linq;
using NHibernate.Criterion;
using NHibernate.Dialect;
using NHibernate.Transform;
using NUnit.Framework;

Expand All @@ -20,6 +21,11 @@ namespace NHibernate.Test.Criteria.Lambda
[TestFixture]
public class ProjectIntegrationFixtureAsync : TestCase
{
protected override bool AppliesTo(Dialect.Dialect dialect)
{
return TestDialect.SupportsEmptyInserts;
}

protected override string MappingsAssembly
{
get { return "NHibernate.Test"; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


using System.Collections;
using NHibernate.Dialect;
using NUnit.Framework;

namespace NHibernate.Test.Criteria.Lambda
Expand All @@ -17,6 +18,11 @@ namespace NHibernate.Test.Criteria.Lambda
[TestFixture]
public class SimpleIntegrationFixtureAsync : TestCase
{
protected override bool AppliesTo(Dialect.Dialect dialect)
{
return TestDialect.SupportsEmptyInserts;
}

protected override string MappingsAssembly
{
get { return "NHibernate.Test"; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Collections;
using System.Linq;
using NHibernate.Criterion;
using NHibernate.Dialect;
using NUnit.Framework;

namespace NHibernate.Test.Criteria.Lambda
Expand All @@ -19,6 +20,11 @@ namespace NHibernate.Test.Criteria.Lambda
[TestFixture]
public class SubQueryIntegrationFixtureAsync : TestCase
{
protected override bool AppliesTo(Dialect.Dialect dialect)
{
return TestDialect.SupportsEmptyInserts;
}

protected override string MappingsAssembly
{
get { return "NHibernate.Test"; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using NHibernate.Collection;
using NHibernate.Collection.Generic;
using NHibernate.Event;
using NHibernate.Dialect;
using NHibernate.Test.Events.Collections.Association.Bidirectional.ManyToMany;
using NUnit.Framework;

Expand All @@ -23,6 +24,11 @@ namespace NHibernate.Test.Events.Collections
[TestFixture]
public abstract class AbstractCollectionEventFixtureAsync : TestCase
{
protected override bool AppliesTo(Dialect.Dialect dialect)
{
return TestDialect.SupportsEmptyInserts;
}

protected override string MappingsAssembly
{
get { return "NHibernate.Test"; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override string MappingsAssembly

protected override bool AppliesTo(Dialect.Dialect dialect)
{
return dialect.SupportsSequences && !(dialect is Dialect.MsSql2012Dialect);
return dialect.SupportsSequences && !(dialect is Dialect.MsSql2012Dialect) && !(dialect is Dialect.AbstractHanaDialect);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no way to provide a proper Dialect.AddIdentifierOutParameterToInsert override for supporting this? (I think the MsSql2012Dialect is just lacking it here, and should have it indeed. Better not add another case where the override would be just missing.)

If there is no solution, please add a comment for telling why HANA is excluded, like "SAP HANA does not support a syntax allowing to return the inserted id as an output parameter or a return value".

}

[Test]
Expand All @@ -49,4 +49,4 @@ public async Task SequenceIdentityGeneratorAsync()
session.Close();
}
}
}
}
7 changes: 6 additions & 1 deletion src/NHibernate.Test/Async/GenericTest/Overall/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using System;
using System.Collections;
using System.Collections.Generic;

using NHibernate.Dialect;
using NUnit.Framework;

namespace NHibernate.Test.GenericTest.Overall
Expand All @@ -20,6 +20,11 @@ namespace NHibernate.Test.GenericTest.Overall
[TestFixture]
public class FixtureAsync : TestCase
{
protected override bool AppliesTo(Dialect.Dialect dialect)
{
return TestDialect.SupportsEmptyInserts;
}

protected override IList Mappings
{
get { return new[] { "GenericTest.Overall.Mappings.hbm.xml" }; }
Expand Down
7 changes: 7 additions & 0 deletions src/NHibernate.Test/Async/Hql/HQLFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,13 @@ public async Task CastAsync()
throw;
}
}
else if (Dialect is AbstractHanaDialect)
{
string msgToCheck =
"not a GROUP BY expression: 'ANIMAL0_.BODYWEIGHT' must be in group by clause";
if (!ex.InnerException.Message.Contains(msgToCheck))
throw;
}
else
{
string msgToCheck =
Expand Down
5 changes: 5 additions & 0 deletions src/NHibernate.Test/Async/Legacy/FooBarTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ private static byte[] GetBytes(string str)
return Encoding.Unicode.GetBytes(str);
}

protected override bool AppliesTo(Dialect.Dialect dialect)
{
return TestDialect.SupportsEmptyInserts;
}

protected override IList Mappings
{
get
Expand Down
8 changes: 7 additions & 1 deletion src/NHibernate.Test/Async/Legacy/FumTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Runtime.Serialization.Formatters.Binary;
using NHibernate.DomainModel;
using NHibernate.Criterion;
using NHibernate.Dialect;
using NHibernate.Type;
using NUnit.Framework;

Expand All @@ -29,6 +30,11 @@ public class FumTestAsync : TestCase
{
protected static short fumKeyShort = 1;

protected override bool AppliesTo(Dialect.Dialect dialect)
{
return TestDialect.SupportsEmptyInserts;
}

protected override IList Mappings
{
get
Expand Down Expand Up @@ -727,4 +733,4 @@ private ISession SpoofSerialization(ISession session)
return (ISession) formatter.Deserialize(stream);
}
}
}
}
5 changes: 5 additions & 0 deletions src/NHibernate.Test/Async/Legacy/MasterDetailTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ namespace NHibernate.Test.Legacy
[TestFixture]
public class MasterDetailTestAsync : TestCase
{
protected override bool AppliesTo(Dialect.Dialect dialect)
{
return TestDialect.SupportsEmptyInserts;
}

protected override IList Mappings
{
get
Expand Down
Loading