Browse Source

More work in progress on DbModelInfo and ServerBrowserTool

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1631 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Dickon Field 19 years ago
parent
commit
cea82dc11b
  1. 4
      src/AddIns/Misc/SharpDbTools/Project/SharpDbTools.csproj
  2. 21
      src/AddIns/Misc/SharpDbTools/Project/Src/Model/ColumnNames.cs
  3. 24
      src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfo.cs
  4. 47
      src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfoFactory.cs
  5. 108
      src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfoService.cs
  6. 20
      src/AddIns/Misc/SharpDbTools/Project/Src/Model/TableNames.cs
  7. 4
      src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserTool.cs
  8. 21
      src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserToolController.cs

4
src/AddIns/Misc/SharpDbTools/Project/SharpDbTools.csproj

@ -60,7 +60,9 @@ @@ -60,7 +60,9 @@
<Compile Include="Src\ServerBrowserToolController.cs" />
<Compile Include="Src\Viewer\ViewerFactory.cs" />
<Compile Include="Src\Viewer\IViewer.cs" />
<Compile Include="Src\Model\DbModelInfoFactory.cs" />
<Compile Include="Src\Model\DbModelInfoService.cs" />
<Compile Include="Src\Model\TableNames.cs" />
<Compile Include="Src\Model\ColumnNames.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Src\Model" />

21
src/AddIns/Misc/SharpDbTools/Project/Src/Model/ColumnNames.cs

@ -0,0 +1,21 @@ @@ -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";
}
}

24
src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfo.cs

@ -29,14 +29,34 @@ namespace SharpDbTools.Model @@ -29,14 +29,34 @@ namespace SharpDbTools.Model
public string Name {
get {
DataTable table = this.Tables["ConnectionInfo"];
string name = (string)table.Rows[0]["name"];
DataTable table = this.Tables[TableNames.ConnectionInfo];
string name = (string)table.Rows[0][ColumnNames.Name];
return name;
}
}
public string InvariantName {
get {
DataTable table = this.Tables[TableNames.ConnectionInfo];
string invariantName = (string)table.Rows[0][ColumnNames.InvariantName];
return invariantName;
}
}
public string ConnectionString {
get {
DataTable table = this.Tables[TableNames.ConnectionInfo];
string connectionString = (string)table.Rows[0][ColumnNames.InvariantName];
return connectionString;
}
}
public DbModelInfo(string name, string invariantName, string connectionString)
{
// create a table in the DbModelInfo to hold this initial info.
// this creates a consistent representation of the data and makes
// it easier to serialise it
DataTable table = this.Tables.Add("Connection");
table.Columns.Add("name", typeof(string));
table.Columns.Add("invariantName", typeof(string));

47
src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfoFactory.cs

@ -1,47 +0,0 @@ @@ -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;
}
}
}

108
src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfoService.cs

@ -0,0 +1,108 @@ @@ -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
}
}
}

20
src/AddIns/Misc/SharpDbTools/Project/Src/Model/TableNames.cs

@ -0,0 +1,20 @@ @@ -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";
}
}

4
src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserTool.cs

@ -25,11 +25,13 @@ namespace SharpDbTools @@ -25,11 +25,13 @@ namespace SharpDbTools
/// </summary>
public ServerBrowserTool()
{
controller = new ServerBrowserToolController();
controller = ServerBrowserToolController.GetInstance();
TreeView dbTree = new TreeView();
ctl = new Panel();
ctl.Controls.Add(dbTree);
dbTree.Dock = DockStyle.Fill;
// initialise browser tree
dbTree.BeginUpdate();

21
src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserToolController.cs

@ -10,12 +10,29 @@ using System; @@ -10,12 +10,29 @@ using System;
namespace SharpDbTools
{
/// <summary>
/// Description of Class1.
/// Manages database connections and the retrieval, storage, refresh
/// and caching of DbModelInfo's. Used primarily by the ServerBrowserTool
/// but it could be used standalone to get connections to previously
/// named db connections.
///
/// Note:
/// Each connection string can specify a different view of the same underlying
/// database server, so each should be regarded as a separate entity.
/// </summary>
public class ServerBrowserToolController
{
public ServerBrowserToolController()
static ServerBrowserToolController instance = new ServerBrowserToolController();
private ServerBrowserToolController()
{
// when this controller is instantiated there should not be
// and db connections open, so firstly initialise it by
// retrieving any previously stored DbModelInfo's.
}
public static ServerBrowserToolController GetInstance()
{
return instance;
}
}
}

Loading…
Cancel
Save