Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1631 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
8 changed files with 196 additions and 53 deletions
@ -0,0 +1,21 @@ |
|||||||
|
/* |
||||||
|
* User: dickon |
||||||
|
* Date: 30/07/2006 |
||||||
|
* Time: 23:37 |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace SharpDbTools.Model |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of Columns.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class ColumnNames |
||||||
|
{ |
||||||
|
public const string InvariantName = "invariantName"; |
||||||
|
public const string Name = "name"; |
||||||
|
public const string ConnectionString = "connectionString"; |
||||||
|
} |
||||||
|
} |
||||||
@ -1,47 +0,0 @@ |
|||||||
/* |
|
||||||
* User: dickon |
|
||||||
* Date: 28/07/2006 |
|
||||||
* Time: 21:55 |
|
||||||
* |
|
||||||
*/ |
|
||||||
|
|
||||||
using System; |
|
||||||
using SharpDbTools.Connection; |
|
||||||
using System.Data; |
|
||||||
using System.Data.Common; |
|
||||||
|
|
||||||
namespace SharpDbTools.Model |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Description of Class1.
|
|
||||||
/// </summary>
|
|
||||||
public sealed class DbModelInfoFactory |
|
||||||
{ |
|
||||||
DbModelInfoFactory() |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
public static DbModelInfo GetDbModelInfo(string name, string invariantName, string connectionString) |
|
||||||
{ |
|
||||||
DbModelInfo dbModel = new DbModelInfo(name, invariantName, connectionString); |
|
||||||
DbProvidersService factoryService = DbProvidersService.GetDbProvidersService(); |
|
||||||
DbProviderFactory factory = factoryService[invariantName]; |
|
||||||
DbConnection connection = factory.CreateConnection(); |
|
||||||
|
|
||||||
// get the Schema table
|
|
||||||
|
|
||||||
DataTable schemaInfo = connection.GetSchema(); |
|
||||||
|
|
||||||
// iterate through the rows in it - the first column of each is a
|
|
||||||
// schema info collection name that can be retrieved as a DbTable
|
|
||||||
// Add each one to the DbModel DataSet
|
|
||||||
|
|
||||||
foreach (DataRow collectionRow in schemaInfo.Rows) { |
|
||||||
String collectionName = (string)collectionRow[0]; |
|
||||||
DataTable nextMetaData = connection.GetSchema(collectionName); |
|
||||||
dbModel.Merge(nextMetaData); |
|
||||||
} |
|
||||||
return dbModel; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -0,0 +1,108 @@ |
|||||||
|
/* |
||||||
|
* User: dickon |
||||||
|
* Date: 28/07/2006 |
||||||
|
* Time: 21:55 |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
using System; |
||||||
|
using SharpDbTools.Connection; |
||||||
|
using System.Data; |
||||||
|
using System.Data.Common; |
||||||
|
using System.Collections.Generic; |
||||||
|
|
||||||
|
namespace SharpDbTools.Model |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Manages a collection of DbModelInfo:
|
||||||
|
/// - retrieval from files
|
||||||
|
/// - opening (essentially refreshing) from a database connection
|
||||||
|
/// - adding for new connection data (name, invariant name, connection string)
|
||||||
|
/// - saving to files
|
||||||
|
/// </summary>
|
||||||
|
public class DbModelInfoService |
||||||
|
{ |
||||||
|
static DbModelInfoService instance = new DbModelInfoService(); |
||||||
|
|
||||||
|
SortedList<string, DbModelInfo> cache; |
||||||
|
|
||||||
|
DbModelInfoService() |
||||||
|
{ |
||||||
|
cache = new SortedList<string, DbModelInfo>(); |
||||||
|
} |
||||||
|
|
||||||
|
public static DbModelInfoService GetInstance() |
||||||
|
{ |
||||||
|
return instance; |
||||||
|
} |
||||||
|
|
||||||
|
public DbModelInfo Create(string name, string invariantName, string connectionString) |
||||||
|
{ |
||||||
|
// TODO: add validation on name; invariant name
|
||||||
|
// assume that connection string is valid - if it fails an exception will be thrown later
|
||||||
|
// this allows partially defined connection strings at least to be saved and worked on later
|
||||||
|
|
||||||
|
DbModelInfo dbModel = new DbModelInfo(name, invariantName, connectionString); |
||||||
|
|
||||||
|
// add to cache
|
||||||
|
cache.Add(name, dbModel); |
||||||
|
|
||||||
|
return dbModel; |
||||||
|
} |
||||||
|
|
||||||
|
public DbModelInfo Load(string name) |
||||||
|
{ |
||||||
|
// get the DbModelInfo
|
||||||
|
|
||||||
|
DbModelInfo modelInfo = null; |
||||||
|
bool exists = cache.TryGetValue(name, out modelInfo); |
||||||
|
if (!exists) |
||||||
|
{ |
||||||
|
// TODO: add details to exception
|
||||||
|
|
||||||
|
throw new KeyNotFoundException(); |
||||||
|
} |
||||||
|
|
||||||
|
// get the invariant name and connection string
|
||||||
|
|
||||||
|
string invariantName = modelInfo.InvariantName; |
||||||
|
string connectionString = modelInfo.ConnectionString; |
||||||
|
|
||||||
|
// get a connection - wait until a connection has been successfully made
|
||||||
|
// until clearing the DbModelInfo
|
||||||
|
|
||||||
|
DbProvidersService factoryService = DbProvidersService.GetDbProvidersService(); |
||||||
|
DbProviderFactory factory = factoryService[invariantName]; |
||||||
|
DbConnection connection = factory.CreateConnection(); |
||||||
|
|
||||||
|
// TODO: clear the DbModelInfo prior to refreshing from the connection
|
||||||
|
|
||||||
|
// reload the metadata from the connection
|
||||||
|
// get the Schema table
|
||||||
|
|
||||||
|
connection.ConnectionString = connectionString; |
||||||
|
DataTable schemaInfo = connection.GetSchema(); |
||||||
|
|
||||||
|
// iterate through the rows in it - the first column of each is a
|
||||||
|
// schema info collection name that can be retrieved as a DbTable
|
||||||
|
// Add each one to the DbModel DataSet
|
||||||
|
|
||||||
|
foreach (DataRow collectionRow in schemaInfo.Rows) { |
||||||
|
String collectionName = (string)collectionRow[0]; |
||||||
|
DataTable nextMetaData = connection.GetSchema(collectionName); |
||||||
|
modelInfo.Merge(nextMetaData); |
||||||
|
} |
||||||
|
return modelInfo; |
||||||
|
} |
||||||
|
|
||||||
|
public void Save(string name) |
||||||
|
{ |
||||||
|
// TODO: save the
|
||||||
|
} |
||||||
|
|
||||||
|
public void RetrieveFromFiles() |
||||||
|
{ |
||||||
|
// TODO: load DbModelInfo's from file system
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
/* |
||||||
|
* User: dickon |
||||||
|
* Date: 30/07/2006 |
||||||
|
* Time: 23:35 |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace SharpDbTools.Model |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of Tables.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class TableNames |
||||||
|
{ |
||||||
|
public const string MetaDataCollections = "MetaDataCollections"; |
||||||
|
public const string ConnectionInfo = "ConnectionInfo"; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue