Permalink
Browse files

First Commit to Add SAP HANA Support DataBase

  • Loading branch information...
Fabio Nascimento
Fabio Nascimento committed Sep 21, 2014
1 parent 0d3aa03 commit e9a7e88c514e53797356cd9f11051f897cd9e234
Showing with 7,185 additions and 0 deletions.
  1. BIN lib/Hana/Sap.Data.Hana.v3.5.dll
  2. +17 −0 lib/Hana/Sap.Data.Hana.v3.5.dll.config
  3. +4,092 −0 lib/Hana/Sap.Data.Hana.v3.5.xml
  4. BIN lib/Hana/Sap.VSPackage.Hana.dll
  5. BIN lib/Hana/SetupNet.v3.5.exe
  6. BIN lib/Hana/policy.1.0.Sap.Data.Hana.v3.5.dll
  7. +8 −0 src/FluentMigrator.Runner/FluentMigrator.Runner.csproj
  8. +89 −0 src/FluentMigrator.Runner/Generators/Hana/HanaColumn.cs
  9. +43 −0 src/FluentMigrator.Runner/Generators/Hana/HanaDescriptionGenerator.cs
  10. +199 −0 src/FluentMigrator.Runner/Generators/Hana/HanaGenerator.cs
  11. +23 −0 src/FluentMigrator.Runner/Generators/Hana/HanaQuoter.cs
  12. +69 −0 src/FluentMigrator.Runner/Generators/Hana/HanaTypeMap.cs
  13. +10 −0 src/FluentMigrator.Runner/Processors/Hana/HanaDbFactory.cs
  14. +181 −0 src/FluentMigrator.Runner/Processors/Hana/HanaProcessor.cs
  15. +17 −0 src/FluentMigrator.Runner/Processors/Hana/HanaProcessorFactory.cs
  16. +23 −0 src/FluentMigrator.Tests/FluentMigrator.Tests.csproj
  17. +74 −0 src/FluentMigrator.Tests/Helpers/HanaTestSequence.cs
  18. +126 −0 src/FluentMigrator.Tests/Helpers/HanaTestTable.cs
  19. +99 −0 src/FluentMigrator.Tests/Integration/Processors/Hana/HanaColumnTests.cs
  20. +117 −0 src/FluentMigrator.Tests/Integration/Processors/Hana/HanaConstraintTests.cs
  21. +111 −0 src/FluentMigrator.Tests/Integration/Processors/Hana/HanaIndexTests.cs
  22. +85 −0 src/FluentMigrator.Tests/Integration/Processors/Hana/HanaProcessorTests.cs
  23. +99 −0 src/FluentMigrator.Tests/Integration/Processors/Hana/HanaSchemaExtensionsTests.cs
  24. +51 −0 src/FluentMigrator.Tests/Integration/Processors/Hana/HanaSchemaTests.cs
  25. +67 −0 src/FluentMigrator.Tests/Integration/Processors/Hana/HanaSequenceTests.cs
  26. +73 −0 src/FluentMigrator.Tests/Integration/Processors/Hana/HanaTableTests.cs
  27. +6 −0 src/FluentMigrator.Tests/IntegrationTestOptions.cs
  28. +172 −0 src/FluentMigrator.Tests/Unit/Generators/Hana/HanaColumnTests.cs
  29. +470 −0 src/FluentMigrator.Tests/Unit/Generators/Hana/HanaConstraintsTests.cs
  30. +172 −0 src/FluentMigrator.Tests/Unit/Generators/Hana/HanaDataTests.cs
  31. +165 −0 src/FluentMigrator.Tests/Unit/Generators/Hana/HanaGeneratorTests.cs
  32. +123 −0 src/FluentMigrator.Tests/Unit/Generators/Hana/HanaIndexTests.cs
  33. +51 −0 src/FluentMigrator.Tests/Unit/Generators/Hana/HanaSchemaTests.cs
  34. +60 −0 src/FluentMigrator.Tests/Unit/Generators/Hana/HanaSequenceTests.cs
  35. +285 −0 src/FluentMigrator.Tests/Unit/Generators/Hana/HanaTableTests.cs
  36. +8 −0 src/FluentMigrator.Tests/Unit/Runners/MigrationProcessorFactoryProviderTests.cs
View
Binary file not shown.
@@ -0,0 +1,17 @@
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity
name="Sap.Data.Hana.v3.5"
publicKeyToken="0326b8ea63db4bc4"
culture="neutral"
/>
<bindingRedirect
oldVersion="1.0.80.0-1.0.80.0"
newVersion="1.0.80.0"
/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Large diffs are not rendered by default.

Oops, something went wrong.
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
@@ -135,6 +135,11 @@
<Compile Include="Announcers\TextWriterAnnouncer.cs" />
<Compile Include="Announcers\TextWriterWithGoAnnouncer.cs" />
<Compile Include="CompatabilityMode.cs" />
<Compile Include="Generators\Hana\HanaColumn.cs" />
<Compile Include="Generators\Hana\HanaDescriptionGenerator.cs" />
<Compile Include="Generators\Hana\HanaGenerator.cs" />
<Compile Include="Generators\Hana\HanaQuoter.cs" />
<Compile Include="Generators\Hana\HanaTypeMap.cs" />
<Compile Include="MaintenanceLoader.cs" />
<Compile Include="IMaintenanceLoader.cs" />
<Compile Include="Extensions\SqlServerExtensions.cs" />
@@ -163,6 +168,9 @@
<Compile Include="InvalidMigrationException.cs" />
<Compile Include="MigrationScopeHandler.cs" />
<Compile Include="MigrationValidator.cs" />
<Compile Include="Processors\Hana\HanaProcessor.cs" />
<Compile Include="Processors\Hana\HanaProcessorFactory.cs" />
<Compile Include="Processors\Hana\HanaDbFactory.cs" />
<Compile Include="Processors\Oracle\OracleManagedDbFactory.cs" />
<Compile Include="Processors\Oracle\OracleManagedProcessorFactory.cs" />
<Compile Include="Processors\Db2\Db2DbFactory.cs" />
@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentMigrator.Exceptions;
using FluentMigrator.Model;
using FluentMigrator.Runner.Generators.Base;
namespace FluentMigrator.Runner.Generators.Hana
{
internal class HanaColumn : ColumnBase
{
private const int HanaObjectNameMaxLength = 30;
public HanaColumn(IQuoter quoter)
: base(new HanaTypeMap(), quoter)
{
var a = ClauseOrder.IndexOf(FormatDefaultValue);
var b = ClauseOrder.IndexOf(FormatNullable);
// Hana requires DefaultValue before nullable
if (a <= b) return;
ClauseOrder[b] = FormatDefaultValue;
ClauseOrder[a] = FormatNullable;
}
protected override string FormatIdentity(ColumnDefinition column)
{
return column.IsIdentity ? "GENERATED BY DEFAULT AS IDENTITY" : string.Empty;
}
protected override string FormatNullable(ColumnDefinition column)
{
if (!(column.DefaultValue is ColumnDefinition.UndefinedDefaultValue))
return string.Empty;
return column.IsNullable.HasValue
? (column.IsNullable.Value ? "NULL" : "NOT NULL")
: String.Empty;
}
protected override string FormatSystemMethods(SystemMethods systemMethod)
{
switch (systemMethod)
{
case SystemMethods.CurrentDateTime:
return "CURRENT_TIMESTAMP";
case SystemMethods.CurrentUTCDateTime:
return "CURRENT_UTCTIMESTAMP";
}
return null;
}
protected override string GetPrimaryKeyConstraintName(IEnumerable<ColumnDefinition> primaryKeyColumns, string tableName)
{
if (primaryKeyColumns == null)
throw new ArgumentNullException("primaryKeyColumns");
if (tableName == null)
throw new ArgumentNullException("tableName");
var primaryKeyName = primaryKeyColumns.First().PrimaryKeyName;
if (string.IsNullOrEmpty(primaryKeyName))
{
return string.Empty;
}
if (primaryKeyName.Length > HanaObjectNameMaxLength)
throw new DatabaseOperationNotSupportedException(
string.Format(
"Hana does not support length of primary key name greater than {0} characters. Reduce length of primary key name. ({1})",
HanaObjectNameMaxLength, primaryKeyName));
var result = string.Format("CONSTRAINT {0} ", Quoter.QuoteConstraintName(primaryKeyName));
return result;
}
public override string AddPrimaryKeyConstraint(string tableName, IEnumerable<ColumnDefinition> primaryKeyColumns)
{
var keyColumns = String.Join(", ", primaryKeyColumns.Select(x => Quoter.QuoteColumnName(x.Name)).ToArray());
return String.Format(", PRIMARY KEY ({0})", keyColumns);
}
}
}
@@ -0,0 +1,43 @@
using FluentMigrator.Runner.Generators.Generic;
namespace FluentMigrator.Runner.Generators.Hana
{
public class HanaDescriptionGenerator : GenericDescriptionGenerator
{
#region Constants
private const string TableDescriptionTemplate = "COMMENT ON TABLE {0} IS '{1}'";
private const string ColumnDescriptionTemplate = "COMMENT ON COLUMN {0}.{1} IS '{2}'";
#endregion
private string GetFullTableName(string schemaName, string tableName)
{
return string.IsNullOrEmpty(schemaName)
? tableName
: string.Format("{0}.{1}", schemaName, tableName);
}
protected override string GenerateTableDescription(
string schemaName, string tableName, string tableDescription)
{
if (string.IsNullOrEmpty(tableDescription))
return string.Empty;
return string.Format(TableDescriptionTemplate, GetFullTableName(schemaName, tableName), tableDescription);
}
protected override string GenerateColumnDescription(
string schemaName, string tableName, string columnName, string columnDescription)
{
if (string.IsNullOrEmpty(columnDescription))
return string.Empty;
return string.Format(
ColumnDescriptionTemplate,
GetFullTableName(schemaName, tableName),
columnName,
columnDescription);
}
}
}
@@ -0,0 +1,199 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentMigrator.Expressions;
using FluentMigrator.Model;
using FluentMigrator.Runner.Generators.Generic;
namespace FluentMigrator.Runner.Generators.Hana
{
public class HanaGenerator : GenericGenerator
{
public HanaGenerator()
: base(new HanaColumn(new HanaQuoter()), new HanaQuoter(), new HanaDescriptionGenerator())
{
}
public override string DropTable
{
get
{
return "DROP TABLE {0}";
}
}
public override string Generate(DeleteTableExpression expression)
{
return String.Format(DropTable, ExpandTableName(Quoter.QuoteTableName(expression.SchemaName), Quoter.QuoteTableName(expression.TableName)));
}
public override string Generate(CreateSequenceExpression expression)
{
var result = new StringBuilder(string.Format("CREATE SEQUENCE "));
var seq = expression.Sequence;
if (string.IsNullOrEmpty(seq.SchemaName))
{
result.AppendFormat(Quoter.QuoteSequenceName(seq.Name));
}
else
{
result.AppendFormat("{0}.{1}", Quoter.QuoteSchemaName(seq.SchemaName), Quoter.QuoteSequenceName(seq.Name));
}
if (seq.Increment.HasValue)
{
result.AppendFormat(" INCREMENT BY {0}", seq.Increment);
}
if (seq.MinValue.HasValue)
{
result.AppendFormat(" MINVALUE {0}", seq.MinValue);
}
if (seq.MaxValue.HasValue)
{
result.AppendFormat(" MAXVALUE {0}", seq.MaxValue);
}
if (seq.StartWith.HasValue)
{
result.AppendFormat(" START WITH {0}", seq.StartWith);
}
if (seq.Cache.HasValue)
{
result.AppendFormat(" CACHE {0}", seq.Cache);
}
if (seq.Cycle)
{
result.Append(" CYCLE");
}
return result.ToString();
}
public override string AddColumn
{
get { return "ALTER TABLE {0} ADD ({1})"; }
}
public override string AlterColumn
{
get { return "ALTER TABLE {0} ALTER ({1})"; }
}
public override string DropColumn
{
get { return "ALTER TABLE {0} DROP ({1})"; }
}
public override string RenameColumn { get { return "RENAME COLUMN {0}.{1} TO {2}"; } }
private string ExpandTableName(string schema, string table)
{
return String.IsNullOrEmpty(schema) ? table : String.Concat(schema, ".", table);
}
public override string Generate(DeleteDataExpression expression)
{
return string.Format("{0};", base.Generate(expression));
}
public override string Generate(InsertDataExpression expression)
{
return string.Format("{0};", base.Generate(expression));
}
private string InnerGenerate(CreateTableExpression expression)
{
var tableName = Quoter.QuoteTableName(expression.TableName);
var schemaName = Quoter.QuoteSchemaName(expression.SchemaName);
return string.Format("CREATE COLUMN TABLE {0} ({1})", ExpandTableName(schemaName, tableName), Column.Generate(expression.Columns, tableName));
}
public override string Generate(CreateTableExpression expression)
{
var descriptionStatements = DescriptionGenerator.GenerateDescriptionStatements(expression);
var statements = descriptionStatements as string[] ?? descriptionStatements.ToArray();
if (!statements.Any())
return InnerGenerate(expression);
var wrappedCreateTableStatement = InnerGenerate(expression);
var createTableWithDescriptionsBuilder = new StringBuilder(wrappedCreateTableStatement);
foreach (var descriptionStatement in statements)
{
if (!string.IsNullOrEmpty(descriptionStatement))
{
createTableWithDescriptionsBuilder.Append(descriptionStatement);
}
}
return WrapInBlock(createTableWithDescriptionsBuilder.ToString());
}
public override string Generate(AlterTableExpression expression)
{
var descriptionStatement = DescriptionGenerator.GenerateDescriptionStatement(expression);
if (string.IsNullOrEmpty(descriptionStatement))
return base.Generate(expression);
return descriptionStatement;
}
public override string Generate(CreateColumnExpression expression)
{
var descriptionStatement = DescriptionGenerator.GenerateDescriptionStatement(expression);
if (string.IsNullOrEmpty(descriptionStatement))
return base.Generate(expression);
var wrappedCreateColumnStatement = base.Generate(expression);
var createColumnWithDescriptionBuilder = new StringBuilder(wrappedCreateColumnStatement);
createColumnWithDescriptionBuilder.Append(descriptionStatement);
return WrapInBlock(createColumnWithDescriptionBuilder.ToString());
}
public override string Generate(AlterColumnExpression expression)
{
var descriptionStatement = DescriptionGenerator.GenerateDescriptionStatement(expression);
if (string.IsNullOrEmpty(descriptionStatement))
return base.Generate(expression);
var wrappedAlterColumnStatement = base.Generate(expression);
var alterColumnWithDescriptionBuilder = new StringBuilder(wrappedAlterColumnStatement);
alterColumnWithDescriptionBuilder.Append(descriptionStatement);
return WrapInBlock(alterColumnWithDescriptionBuilder.ToString());
}
public override string Generate(AlterDefaultConstraintExpression expression)
{
return compatabilityMode.HandleCompatabilty("Default constraints are not supported");
}
public override string Generate(DeleteDefaultConstraintExpression expression)
{
return compatabilityMode.HandleCompatabilty("Default constraints are not supported");
}
private static string WrapInBlock(string sql)
{
return string.IsNullOrEmpty(sql)
? string.Empty
: string.Format("BEGIN {0} END;", sql);
}
}
}
Oops, something went wrong.

0 comments on commit e9a7e88

Please sign in to comment.