using System;
using System.Collections.Specialized;
using Persist.Sql;
namespace Persist.Config{
/// <summary>
/// Manage a RelationalDatabase object
/// </summary>
public class RelationalDatabaseHolder
{
private string theName;
private string theTypeName;
private NameValueCollection theParameters;
private RelationalDatabase theRelationalDatabase;
private bool isInitialized;
/// <summary>
/// Manage a RelationalDatabase object
/// </summary>
/// <param name="name">the RelationalDatabase name</param>
/// <param name="typeName">the Type name</param>
/// <param name="parameters">the Parameters used during initialization of the Relationaldatabase object</param>
public RelationalDatabaseHolder(string name,string typeName,NameValueCollection parameters)
{
theName = name;
theTypeName = typeName;
theParameters = parameters;
isInitialized = false;
}
/// <summary>
/// Initialize the RelationalDatabaseHolder
/// </summary>
public void Init()
{
lock(this)
{
if(isInitialized)
{
throw new ConfigurationException("DatabaseHolder Already Initialized");
}
theRelationalDatabase = (RelationalDatabase)Activator.CreateInstance(Type.GetType(theTypeName));
theRelationalDatabase.Name = theName;
theRelationalDatabase.Init(theParameters);
isInitialized = true;
}
}
/// <summary>
/// The RelationalDatabase name
/// Cannot be changed once Initialized
/// </summary>
public string Name
{
get{return theName;}
set
{
if(isInitialized) throw new Exception("Name of RelationalDatabaseHolder cannot be changed once initialized");
theName = value;
}
}
/// <summary>
/// The RelationalDatabase TypeName
/// Cannot be changed once Initialized
/// </summary>
public string TypeName
{
get{return theTypeName;}
set
{
if(isInitialized) throw new Exception("TypeName of RelationalDatabaseHolder cannot be changed once initialized");
theTypeName = value;
}
}
/// <summary>
/// the RelationalDatabase Initialization parameters
/// Any change after initialization will not be taken into account
/// </summary>
public NameValueCollection Parameters
{
get{return theParameters;}
}
/// <summary>
/// Return the RelationalDatabase Instance
/// </summary>
public RelationalDatabase Instance
{
get
{
if(!isInitialized)throw new Exception("RelationalDatabaseHolder not Initialized, cannot return Instance");
return theRelationalDatabase;
}
}
}
}
|