// Persist library : Persistence layer
// Copyright (C) 2003 Vincent Daron
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Data;
using Persist.Converters;
using Persist.IdGenerators;
namespace Persist.Maps{
/// <summary>
/// Summary description for ColumnMap.
/// </summary>
public class ColumnMap
{
/// <summary>
/// Type of primary Key
/// </summary>
public enum KeyTypeEnum
{
/// <summary>
/// Not a primary Key
/// </summary>
None = 0,
/// <summary>
/// Primary key
/// </summary>
Primary = 1,
/// <summary>
/// Foreign key (unused for now)
/// </summary>
Foreign = 2
};
private string theName;
private KeyTypeEnum theKeyType = KeyTypeEnum.None;
private TableMap theTableMap = null;
private DbType theDbType = DbType.Object;
private string theIdGeneratorName;
private string theConverterName;
private IIdGenerator theIdGenerator = null;
private IConverter theConverter = null;
private bool isInitialized = false;
/// <summary>
/// Creates ColumnMap.
/// </summary>
/// <param name="name">the ColumnMap name</param>
/// <param name="tableMap">the TableMap of this column map</param>
public ColumnMap(string name, TableMap tableMap)
{
theName = name;
theTableMap = tableMap;
}
/// <summary>
/// Returns fully qualifies name of this column.
/// </summary>
public string FullyQualifiedName
{
get
{
return TableMap.Name + "." + Name;
}
}
/// <summary>
/// Returns key type of this column.
/// Cannot be change once initialized (Trow an Exception)
/// </summary>
public KeyTypeEnum KeyType
{
get
{
return theKeyType;
}
set
{
if(isInitialized)throw new Exception("KeyType cannot be changed once initialized");
theKeyType = value;
}
}
/// <summary>
/// Return ID generator for this attribute map.
/// </summary>
public IIdGenerator IdGenerator
{
get{return theIdGenerator;}
}
/// <summary>
/// Return the Converter for this column
/// </summary>
public IConverter Converter
{
get
{
return theConverter;
}
}
/// <summary>
/// the IdGenerator name
/// this cannot be change once initialized (Exception will be thrown)
/// </summary>
public string IdGeneratorName
{
get{return theIdGeneratorName;}
set
{
if(isInitialized)throw new Exception("the IdGenerator name cannot be changed once initialized");
theIdGeneratorName = value;
}
}
/// <summary>
/// the Conerter Name.
/// this cannot be change once initialized (Exception will be thrown)
/// </summary>
public string ConverterName
{
get{return theConverterName;}
set
{
if(isInitialized)throw new Exception("the Converter name cannot be changed once initialized");
theConverterName = value;
}
}
/// <summary>
/// Initialize the ColumnMap
/// </summary>
/// <param name="configuration">the current configuration</param>
public void Init(Config.Configuration configuration)
{
if(theIdGeneratorName != null)
{
theIdGenerator = configuration.GetIdGenerator(theIdGeneratorName);
}
if(theConverterName == null)
{
theConverter = configuration.TrivialConverter;
}
else
{
theConverter = configuration.GetConverter(theConverterName);
}
isInitialized = true;
}
/// <summary>
/// Returns name of this column.
/// </summary>
public string Name
{
get
{
return theName;
}
}
/// <summary>
/// Returns type of this column.
/// This cannot be changed once initialized (throw exception)
/// </summary>
public DbType DbType
{
get
{
return theDbType;
}
set
{
if(isInitialized)throw new Exception("DbType cannot be changed once initialized");
theDbType = value;
}
}
/// <summary>
/// Returns TableMap for this column.
/// </summary>
public TableMap TableMap
{
get
{
return theTableMap;
}
}
}
}
|