// ---------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
//
// ---------------------------------------------------------------------
namespace Microsoft.Database.Isam
{
using System;
///
/// A Key Column is a segment of an index used to determine the order of
/// records in a table as seen through that index. This object can be used
/// to explore the schema of an existing index and to create the definition
/// of a new index.
///
public class KeyColumn
{
///
/// The columnid
///
private readonly Columnid columnid;
///
/// The name
///
private string name = null;
///
/// The is ascending
///
private bool isAscending = false;
///
/// The read only
///
private bool readOnly = false;
///
/// Initializes a new instance of the class.
/// For use when defining a new key column in an
/// index.
///
///
/// The name of the column in the table to be used for this key column.
///
///
/// True if the sort order of this key column is ascending, false if descending.
///
public KeyColumn(string name, bool isAscending)
{
this.columnid = null;
this.name = name;
this.isAscending = isAscending;
}
///
/// Initializes a new instance of the class.
///
/// The columnid.
/// if set to true [is ascending].
internal KeyColumn(Columnid columnid, bool isAscending)
{
this.columnid = columnid;
this.name = columnid.Name;
this.isAscending = isAscending;
this.readOnly = true;
}
///
/// Gets the column ID of the column used for this key column.
///
///
/// The column ID is undefined if this key column will be used to
/// define a new index
///
public Columnid Columnid
{
get
{
return this.columnid;
}
}
///
/// Gets or sets the name of the column used for this key column.
///
public string Name
{
get
{
return this.name;
}
set
{
this.CheckReadOnly();
this.name = value;
}
}
///
/// Gets the type of the column used for this key column.
///
///
/// The column type is undefined if this key column will be used to
/// define a new index.
///
public Type Type
{
get
{
return this.columnid.Type;
}
}
///
/// Gets or sets a value indicating whether the sort order of the key column is ascending.
///
///
/// true if [is ascending]; otherwise, false.
///
public bool IsAscending
{
get
{
return this.isAscending;
}
set
{
this.CheckReadOnly();
this.isAscending = value;
}
}
///
/// Gets a value indicating whether [is read only].
///
///
/// true if [is read only]; otherwise, false.
///
public bool IsReadOnly
{
get
{
return this.readOnly;
}
}
///
/// Sets a value indicating whether [read only].
///
///
/// true if [read only]; otherwise, false.
///
internal bool ReadOnly
{
set
{
this.readOnly = value;
}
}
///
/// Checks the read only.
///
/// this key column definition cannot be changed
private void CheckReadOnly()
{
if (this.readOnly)
{
throw new NotSupportedException("this key column definition cannot be changed");
}
}
}
}