-
Notifications
You must be signed in to change notification settings - Fork 934
Added compatibility for db2 schema update. #474
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
Closed
fabiankoebel
wants to merge
1
commit into
nhibernate:master
from
fabiankoebel:db2-schema-update-compatibility
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using System; | ||
using System.Data; | ||
using System.Data.Common; | ||
|
||
namespace NHibernate.Dialect.Schema | ||
{ | ||
public class DB2MetaData : AbstractDataBaseSchema | ||
{ | ||
public DB2MetaData(DbConnection connection) : base(connection) | ||
{ | ||
} | ||
|
||
public override ITableMetadata GetTableMetadata(DataRow rs, bool extras) | ||
{ | ||
return new DB2TableMetaData(rs, this, extras); | ||
} | ||
|
||
public override DataTable GetIndexColumns(string catalog, string schemaPattern, string tableName, string indexName) | ||
{ | ||
var restrictions = new[] { tableName, indexName}; | ||
return Connection.GetSchema("Indexes", restrictions); | ||
} | ||
} | ||
|
||
public class DB2TableMetaData : AbstractTableMetadata | ||
{ | ||
public DB2TableMetaData(DataRow rs, IDataBaseSchema meta, bool extras) : base(rs, meta, extras) {} | ||
|
||
protected override IColumnMetadata GetColumnMetadata(DataRow rs) | ||
{ | ||
return new DB2ColumnMetaData(rs); | ||
} | ||
|
||
protected override string GetColumnName(DataRow rs) | ||
{ | ||
return Convert.ToString(rs["COLUMN_NAME"]); | ||
} | ||
|
||
protected override string GetConstraintName(DataRow rs) | ||
{ | ||
//TODO validate | ||
return Convert.ToString(rs[11]); | ||
//return Convert.ToString(rs["CONSTRAINT_NAME"]); | ||
} | ||
|
||
protected override IForeignKeyMetadata GetForeignKeyMetadata(DataRow rs) | ||
{ | ||
return new DB2ForeignKeyMetaData(rs); | ||
} | ||
|
||
protected override IIndexMetadata GetIndexMetadata(DataRow rs) | ||
{ | ||
return new DB2IndexMetaData(rs); | ||
} | ||
|
||
protected override string GetIndexName(DataRow rs) | ||
{ | ||
return Convert.ToString(rs["INDEX_NAME"]); | ||
} | ||
|
||
protected override void ParseTableInfo(DataRow rs) | ||
{ | ||
Catalog = Convert.ToString(rs["TABLE_CATALOG"]); | ||
Schema = Convert.ToString(rs["TABLE_SCHEMA"]); | ||
if (string.IsNullOrEmpty(Catalog)) | ||
{ | ||
Catalog = null; | ||
} | ||
if (string.IsNullOrEmpty(Schema)) | ||
{ | ||
Schema = null; | ||
} | ||
Name = Convert.ToString(rs["TABLE_NAME"]); | ||
} | ||
} | ||
|
||
public class DB2ColumnMetaData : AbstractColumnMetaData | ||
{ | ||
public DB2ColumnMetaData(DataRow rs) : base(rs) | ||
{ | ||
Name = Convert.ToString(rs["COLUMN_NAME"]); | ||
|
||
Nullable = Convert.ToString(rs["IS_NULLABLE"]); | ||
TypeName = Convert.ToString(rs["DATA_TYPE"]); | ||
} | ||
} | ||
|
||
public class DB2IndexMetaData : AbstractIndexMetadata | ||
{ | ||
public DB2IndexMetaData(DataRow rs) : base(rs) | ||
{ | ||
Name = Convert.ToString(rs["INDEX_NAME"]); | ||
} | ||
} | ||
|
||
public class DB2ForeignKeyMetaData : AbstractForeignKeyMetadata | ||
{ | ||
public DB2ForeignKeyMetaData(DataRow rs) : base(rs) | ||
{ | ||
Name = Convert.ToString(rs[11]); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System.Data; | ||
using NHibernate.SqlTypes; | ||
using NHibernate.UserTypes; | ||
|
||
namespace NHibernate.Type | ||
{ | ||
public class IntBooleanType : BooleanType, IUserType | ||
{ | ||
public override SqlType SqlType | ||
{ | ||
get { return new SqlType(DbType.Int32);} | ||
} | ||
|
||
public SqlType[] SqlTypes | ||
{ | ||
get { return new SqlType[] { SqlType};} | ||
} | ||
|
||
public System.Type ReturnedType | ||
{ | ||
get { return typeof (bool); } | ||
} | ||
public bool Equals(object x, object y) | ||
{ | ||
if (ReferenceEquals(x, y)) return true; | ||
|
||
if (x == null || y == null) return false; | ||
|
||
return x.Equals(y); | ||
} | ||
|
||
public int GetHashCode(object x) | ||
{ | ||
return x.GetHashCode(); | ||
} | ||
|
||
public new void NullSafeSet(IDbCommand cmd, object value, int index) | ||
{ | ||
var val = !((bool) value) ? 0 : 1; | ||
NHibernateUtil.Int32.NullSafeSet(cmd, val, index); | ||
} | ||
|
||
public override void Set(IDbCommand cmd, object value, int index) | ||
{ | ||
var val = !((bool) value) ? 0 : 1; | ||
((IDataParameter) cmd.Parameters[index]).Value = val; | ||
} | ||
|
||
public object NullSafeGet(IDataReader rs, string[] names, object owner) | ||
{ | ||
return NHibernateUtil.Int32.NullSafeGet(rs, names[0]); | ||
} | ||
|
||
public object DeepCopy(object value) | ||
{ | ||
return value; | ||
} | ||
|
||
public object Replace(object original, object target, object owner) | ||
{ | ||
return original; | ||
} | ||
|
||
public object Assemble(object cached, object owner) | ||
{ | ||
return cached; | ||
} | ||
|
||
public object Disassemble(object value) | ||
{ | ||
return value; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done with query substitutions.