//----------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. // //----------------------------------------------------------------------- namespace Microsoft.Isam.Esent.Interop { using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.InteropServices; using Microsoft.Isam.Esent.Interop.Implementation; #if !MANAGEDESENT_ON_WSA // Not exposed in MSDK /// /// The native version of the structure. This includes callbacks, /// space hints, and uses NATIVE_INDEXCREATE. /// [StructLayout(LayoutKind.Sequential)] [SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "This should match the unmanaged API, which isn't capitalized.")] [SuppressMessage( "Microsoft.StyleCop.CSharp.NamingRules", "SA1307:AccessibleFieldsMustBeginWithUpperCaseLetter", Justification = "This should match the unmanaged API, which isn't capitalized.")] internal unsafe struct NATIVE_TABLECREATE2 { /// /// Size of the structure. /// public uint cbStruct; /// /// Name of the table to create. /// [MarshalAs(UnmanagedType.LPTStr)] public string szTableName; /// /// Name of the table from which to inherit base DDL. /// [MarshalAs(UnmanagedType.LPTStr)] public string szTemplateTableName; /// /// Initial pages to allocate for table. /// public uint ulPages; /// /// Table density. /// public uint ulDensity; /// /// Array of column creation info. /// public NATIVE_COLUMNCREATE* rgcolumncreate; /// /// Number of columns to create. /// public uint cColumns; /// /// Array of indices to create, pointer to . /// public IntPtr rgindexcreate; /// /// Number of indices to create. /// public uint cIndexes; /// /// Callback function to use for the table. /// [MarshalAs(UnmanagedType.LPTStr)] public string szCallback; /// /// Type of the callback function. /// public JET_cbtyp cbtyp; /// /// Table options. /// public uint grbit; /// /// Returned tabledid. /// public IntPtr tableid; /// /// Count of objects created (columns+table+indexes+callbacks). /// public uint cCreated; } /// /// The native version of the structure. This includes callbacks, /// space hints, and uses NATIvE_INDEXCREATE2. /// [StructLayout(LayoutKind.Sequential)] [SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "This should match the unmanaged API, which isn't capitalized.")] [SuppressMessage( "Microsoft.StyleCop.CSharp.NamingRules", "SA1307:AccessibleFieldsMustBeginWithUpperCaseLetter", Justification = "This should match the unmanaged API, which isn't capitalized.")] internal unsafe struct NATIVE_TABLECREATE3 { /// /// Size of the structure. /// public uint cbStruct; /// /// Name of the table to create. /// [MarshalAs(UnmanagedType.LPWStr)] public string szTableName; /// /// Name of the table from which to inherit base DDL. /// [MarshalAs(UnmanagedType.LPWStr)] public string szTemplateTableName; /// /// Initial pages to allocate for table. /// public uint ulPages; /// /// Table density. /// public uint ulDensity; /// /// Array of column creation info. /// public NATIVE_COLUMNCREATE* rgcolumncreate; /// /// Number of columns to create. /// public uint cColumns; /// /// Array of indices to create, pointer to . /// public IntPtr rgindexcreate; /// /// Number of indices to create. /// public uint cIndexes; /// /// Callback function to use for the table. /// [MarshalAs(UnmanagedType.LPWStr)] public string szCallback; /// /// Type of the callback function. /// public JET_cbtyp cbtyp; /// /// Table options. /// public uint grbit; /// /// Space allocation, maintenance, and usage hints for default sequential index. /// public NATIVE_SPACEHINTS* pSeqSpacehints; /// /// Space allocation, maintenance, and usage hints for Separated LV tree. /// public NATIVE_SPACEHINTS* pLVSpacehints; /// /// Heuristic size to separate a intrinsic LV from the primary record. /// public uint cbSeparateLV; /// /// Returned tabledid. /// public IntPtr tableid; /// /// Count of objects created (columns+table+indexes+callbacks). /// public uint cCreated; } #endif // !MANAGEDESENT_ON_WSA /// /// Contains the information needed to create a table in an ESE database. /// [SuppressMessage( "Microsoft.StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "This should match the unmanaged API, which isn't capitalized.")] [Serializable] public partial class JET_TABLECREATE : IContentEquatable, IDeepCloneable { /// /// Name of the table to create. /// private string tableName; /// /// Name of the table from which to inherit base DDL. /// private string templateTableName; /// /// Initial pages to allocate for table. /// private int initialPageAllocation; /// /// Table density. /// private int tableDensity; /// /// Array of column creation info. /// private JET_COLUMNCREATE[] columnCreates; /// /// Number of columns to create. /// private int columnCreateCount; /// /// Array of indices to create, pointer to . /// private JET_INDEXCREATE[] indexCreates; /// /// Number of indices to create. /// private int indexCreateCount; /// /// Callback function to use for the table. /// private string callbackFunction; /// /// Type of the callback function. /// private JET_cbtyp callbackType; /// /// Table options. /// private CreateTableColumnIndexGrbit options; /// /// Space allocation, maintenance, and usage hints for default sequential index. /// private JET_SPACEHINTS seqSpacehints; /// /// Space allocation, maintenance, and usage hints for Separated LV tree. /// private JET_SPACEHINTS longValueSpacehints; /// /// Heuristic size to separate a intrinsic LV from the primary record. /// private int separateLvThresholdHint; /// /// Returned tabledid. /// [NonSerialized] private JET_TABLEID tableIdentifier; /// /// Count of objects created (columns+table+indexes+callbacks). /// private int objectsCreated; /// /// Gets or sets the name of the table to create. /// public string szTableName { [DebuggerStepThrough] get { return this.tableName; } set { this.tableName = value; } } /// /// Gets or sets the name of the table from which to inherit base DDL. /// public string szTemplateTableName { [DebuggerStepThrough] get { return this.templateTableName; } set { this.templateTableName = value; } } /// /// Gets or sets the initial pages to allocate for table. /// public int ulPages { [DebuggerStepThrough] get { return this.initialPageAllocation; } set { this.initialPageAllocation = value; } } /// /// Gets or sets the table density. /// public int ulDensity { [DebuggerStepThrough] get { return this.tableDensity; } set { this.tableDensity = value; } } /// /// Gets or sets an array of column creation info, of type . /// public JET_COLUMNCREATE[] rgcolumncreate { [DebuggerStepThrough] get { return this.columnCreates; } set { this.columnCreates = value; } } /// /// Gets or sets the number of columns to create. /// public int cColumns { [DebuggerStepThrough] get { return this.columnCreateCount; } set { this.columnCreateCount = value; } } /// /// Gets or sets an array of indices to create, of type . /// public JET_INDEXCREATE[] rgindexcreate { [DebuggerStepThrough] get { return this.indexCreates; } set { this.indexCreates = value; } } /// /// Gets or sets the number of indices to create. /// public int cIndexes { [DebuggerStepThrough] get { return this.indexCreateCount; } set { this.indexCreateCount = value; } } /// /// Gets or sets a callback function to use for the table. This is in the form "module!functionName", /// and assumes unmanaged code. See for an alternative. /// public string szCallback { [DebuggerStepThrough] get { return this.callbackFunction; } set { this.callbackFunction = value; } } /// /// Gets or sets a type of the callback function. /// public JET_cbtyp cbtyp { [DebuggerStepThrough] get { return this.callbackType; } set { this.callbackType = value; } } /// /// Gets or sets the table options. /// public CreateTableColumnIndexGrbit grbit { [DebuggerStepThrough] get { return this.options; } set { this.options = value; } } /// /// Gets or sets space allocation, maintenance, and usage hints for default sequential index. /// public JET_SPACEHINTS pSeqSpacehints { [DebuggerStepThrough] get { return this.seqSpacehints; } set { this.seqSpacehints = value; } } /// /// Gets or sets space allocation, maintenance, and usage hints for Separated LV tree, of type . /// public JET_SPACEHINTS pLVSpacehints { [DebuggerStepThrough] get { return this.longValueSpacehints; } set { this.longValueSpacehints = value; } } /// /// Gets or sets the heuristic size to separate a intrinsic LV from the primary record. /// public int cbSeparateLV { [DebuggerStepThrough] get { return this.separateLvThresholdHint; } set { this.separateLvThresholdHint = value; } } /// /// Gets or sets the returned tabledid. /// public JET_TABLEID tableid { [DebuggerStepThrough] get { return this.tableIdentifier; } set { this.tableIdentifier = value; } } /// /// Gets or sets the count of objects created (columns+table+indexes+callbacks). /// public int cCreated { [DebuggerStepThrough] get { return this.objectsCreated; } set { this.objectsCreated = value; } } #region IContentEquatable /// /// Returns a value indicating whether this instance is equal /// to another instance. /// /// An instance to compare with this instance. /// True if the two instances are equal. public bool ContentEquals(JET_TABLECREATE other) { if (null == other) { return false; } this.CheckMembersAreValid(); other.CheckMembersAreValid(); bool notYetPublishedEquals = true; this.NotYetPublishedEquals(other, ref notYetPublishedEquals); return notYetPublishedEquals && this.szTableName == other.szTableName && this.szTemplateTableName == other.szTemplateTableName && this.ulPages == other.ulPages && this.ulDensity == other.ulDensity && this.cColumns == other.cColumns && this.cIndexes == other.cIndexes && this.szCallback == other.szCallback && this.cbtyp == other.cbtyp && this.grbit == other.grbit && this.cbSeparateLV == other.cbSeparateLV && Util.ObjectContentEquals(this.pSeqSpacehints, other.pSeqSpacehints) && Util.ObjectContentEquals(this.pLVSpacehints, other.pLVSpacehints) && this.tableid == other.tableid && this.cCreated == other.cCreated && Util.ArrayObjectContentEquals(this.rgcolumncreate, other.rgcolumncreate, this.cColumns) && Util.ArrayObjectContentEquals(this.rgindexcreate, other.rgindexcreate, this.cIndexes); } #endregion #region IDeepCloneable /// /// Returns a deep copy of the object. /// /// A deep copy of the object. public JET_TABLECREATE DeepClone() { JET_TABLECREATE result = (JET_TABLECREATE)this.MemberwiseClone(); result.rgcolumncreate = Util.DeepCloneArray(this.rgcolumncreate); result.rgindexcreate = Util.DeepCloneArray(this.rgindexcreate); result.seqSpacehints = (null == this.seqSpacehints) ? null : this.seqSpacehints.DeepClone(); result.pLVSpacehints = (null == this.pLVSpacehints) ? null : this.pLVSpacehints.DeepClone(); return result; } #endregion /// /// Generate a string representation of the instance. /// /// The structure as a string. public override string ToString() { return string.Format( CultureInfo.InvariantCulture, "JET_TABLECREATE({0}:{1} columns:{2} indices)", this.szTableName, this.cColumns, this.cIndexes); } /// /// Check this object to make sure its parameters are valid. /// internal void CheckMembersAreValid() { if (this.cColumns < 0) { throw new ArgumentOutOfRangeException("cColumns", this.cColumns, "cannot be negative"); } if (this.rgcolumncreate != null && this.cColumns > this.rgcolumncreate.Length) { throw new ArgumentOutOfRangeException("cColumns", this.cColumns, "cannot be greater than rgcolumncreate.Length"); } if (this.rgcolumncreate == null && this.cColumns != 0) { throw new ArgumentOutOfRangeException("cColumns", this.cColumns, "must be zero when rgcolumncreate is null"); } if (this.cIndexes < 0) { throw new ArgumentOutOfRangeException("cIndexes", this.cIndexes, "cannot be negative"); } if (this.rgindexcreate != null && this.cIndexes > this.rgindexcreate.Length) { throw new ArgumentOutOfRangeException("cIndexes", this.cIndexes, "cannot be greater than rgindexcreate.Length"); } if (this.rgindexcreate == null && this.cIndexes != 0) { throw new ArgumentOutOfRangeException("cIndexes", this.cIndexes, "must be zero when rgindexcreate is null"); } } #if !MANAGEDESENT_ON_WSA // Not exposed in MSDK /// /// Gets the native (interop) version of this object. The following members are /// NOT converted: , , /// , and . /// /// The native (interop) version of this object. internal NATIVE_TABLECREATE2 GetNativeTableCreate2() { this.CheckMembersAreValid(); var native = new NATIVE_TABLECREATE2(); native.cbStruct = checked((uint)Marshal.SizeOf(typeof(NATIVE_TABLECREATE2))); native.szTableName = this.szTableName; native.szTemplateTableName = this.szTemplateTableName; native.ulPages = checked((uint)this.ulPages); native.ulDensity = checked((uint)this.ulDensity); // native.rgcolumncreate is done at pinvoke time. native.cColumns = checked((uint)this.cColumns); // native.rgindexcreate is done at pinvoke time. native.cIndexes = checked((uint)this.cIndexes); native.szCallback = this.szCallback; native.cbtyp = this.cbtyp; native.grbit = checked((uint)this.grbit); native.tableid = this.tableid.Value; native.cCreated = checked((uint)this.cCreated); return native; } /// /// Gets the native (interop) version of this object. The following members are /// NOT converted: , , /// , and . /// /// The native (interop) version of this object. internal NATIVE_TABLECREATE3 GetNativeTableCreate3() { this.CheckMembersAreValid(); var native = new NATIVE_TABLECREATE3(); native.cbStruct = checked((uint)Marshal.SizeOf(typeof(NATIVE_TABLECREATE3))); native.szTableName = this.szTableName; native.szTemplateTableName = this.szTemplateTableName; native.ulPages = checked((uint)this.ulPages); native.ulDensity = checked((uint)this.ulDensity); // native.rgcolumncreate is done at pinvoke time. native.cColumns = checked((uint)this.cColumns); // native.rgindexcreate is done at pinvoke time. native.cIndexes = checked((uint)this.cIndexes); native.szCallback = this.szCallback; native.cbtyp = this.cbtyp; native.grbit = checked((uint)this.grbit); // native.pSeqSpacehints is done at pinvoke time. // native.pLVSpacehints is done at pinvoke time. native.cbSeparateLV = checked((uint)this.cbSeparateLV); native.tableid = this.tableid.Value; native.cCreated = checked((uint)this.cCreated); return native; } #endif // !MANAGEDESENT_ON_WSA /// /// Provides a hook to allow comparison of additional fields in /// a different file. These additonal fields are not yet published /// on MSDN. /// /// The structure to compare with. /// Whether the additional fields in /// are the same as this. partial void NotYetPublishedEquals(JET_TABLECREATE other, ref bool notYetPublishedEquals); } }