Browse Source

settled on DataSet to represent connection and model info. removed ConnectionInfo

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1627 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Dickon Field 19 years ago
parent
commit
ff6c9a0270
  1. 4
      src/AddIns/Misc/SharpDbTools/Project/SharpDbTools.csproj
  2. 130
      src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbConnectionInfo.cs
  3. 43
      src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbConnectionInfoStorage.cs
  4. 26
      src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfo.cs
  5. 29
      src/AddIns/Misc/SharpDbTools/Project/Src/Model/IConnectionInfo.cs
  6. 13
      src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserTool.cs
  7. 2
      src/AddIns/Misc/SharpDbTools/Project/Src/Viewer/ViewerFactory.cs

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

@ -50,7 +50,6 @@ @@ -50,7 +50,6 @@
<EmbeddedResource Include="Resources\MyUserControl.xfrm" />
<Compile Include="Src\ServerBrowserTool.cs" />
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\Model\DbConnectionInfo.cs" />
<Compile Include="Src\Model\DbModelInfo.cs" />
<Compile Include="Src\Connection\ConnectionStringDefinitionDialog.cs" />
<EmbeddedResource Include="Src\Connection\ConnectionStringDefinitionDialog.resx">
@ -59,10 +58,9 @@ @@ -59,10 +58,9 @@
<Compile Include="Src\Connection\ConnectionStringDefinitionDialog.Designer.cs" />
<Compile Include="Src\Connection\DbProvidersService.cs" />
<Compile Include="Src\ServerBrowserToolController.cs" />
<Compile Include="Src\Model\DbConnectionInfoStorage.cs" />
<Compile Include="Src\Model\IConnectionInfo.cs" />
<Compile Include="Src\Viewer\ViewerFactory.cs" />
<Compile Include="Src\Viewer\IViewer.cs" />
<Compile Include="Src\Model\DbModelInfoFactory.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Src\Model" />

130
src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbConnectionInfo.cs

@ -1,130 +0,0 @@ @@ -1,130 +0,0 @@
/*
* User: Dickon Field
* Date: 05/07/2006
* Time: 22:13
*
*/
using System;
using System.Data;
using System.Data.Common;
using ICSharpCode.Core;
namespace SharpDbTools.Model
{
/// <summary>
/// DbConnectionInfo object is in essence a client side cache of database
/// connection information that can be used disconnected from the database
/// for query editing and validation, database browsing etc.
///
/// It is persisted as an XML element into local storage, and can subsequently
/// be either used independently or refreshed from the database server.
///
/// </summary>
public class DbConnectionInfo: IConnectionInfo, IDisposable
{
DbConnection connection = null;
string connectionString = null;
string invariantName = null;
string name = null;
DbModelInfo dbModel = null;
private DbConnectionInfo()
{
}
public DbConnectionInfo(string name, string invariantName, string connectionString)
{
this.name = name;
this.connectionString = connectionString;
this.invariantName = invariantName;
}
public string Name {
get {
return name;
}
}
public string InvariantName {
get {
return invariantName;
}
}
public string ConnectionString {
get {
return connectionString;
}
}
public bool HasConnection {
get {
return !(connection == null);
}
}
public bool HasModel {
get {
return !(dbModel == null);
}
}
public DbConnection Connection {
get {
// return connection if defined else try and create it
if (connection != null) {
return connection;
}
else {
DbProviderFactory factory = DbProviderFactories.GetFactory(invariantName);
this.connection = factory.CreateConnection();
this.connection.ConnectionString = this.connectionString;
this.connection.Open();
return this.connection;
}
}
}
public DataSet DbModel {
get
{
if (dbModel == null)
{
dbModel = new DbModelInfo();
DbConnection connection = this.Connection;
// 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 this.dbModel;
}
}
public void Dispose()
{
try {
this.connection.Close();
}
catch(Exception e) {
LoggingService.Warn("unable to close connection: exception thrown", e);
}
}
// TODO: serialise into a store
}
}

43
src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbConnectionInfoStorage.cs

@ -1,43 +0,0 @@ @@ -1,43 +0,0 @@
/*
* User: Dickon Field
* Date: 20/07/2006
* Time: 19:07
*
*/
using System;
using System.Collections.Generic;
namespace SharpDbTools.Model
{
/// <summary>
/// Description of ConnectionInfoStorage.
/// </summary>
public class DbConnectionInfoStorage
{
const string CONNECTION_INFO_STORAGE_FILE_NAME = "ConnectionInfo.xml";
static DbConnectionInfoStorage instance = new DbConnectionInfoStorage();
private DbConnectionInfoStorage()
{
// TODO: retrieve ConnectionInfo objects from an xml file
}
public static DbConnectionInfoStorage GetInstance()
{
return instance;
}
public void AddConnectionInfo(DbConnectionInfo connectionInfo)
{
// TODO: store ConnectionInfo in an xml file
}
public List<DbConnectionInfo> GetConnectionInfoCollection()
{
// TODO: return
return null;
}
}
}

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

@ -22,12 +22,25 @@ namespace SharpDbTools.Model @@ -22,12 +22,25 @@ namespace SharpDbTools.Model
/// retrieved from its persisted data. This is intended to allow work to progress against the
/// DbModel without requiring a connection to its RDB server.
/// </summary>
///
public class DbModelInfo: DataSet
{
public const string METADATACOLLECTIONS = "MetaDataCollections";
public DbModelInfo()
public string Name {
get {
DataTable table = this.Tables["ConnectionInfo"];
string name = (string)table.Rows[0]["name"];
return name;
}
}
public DbModelInfo(string name, string invariantName, string connectionString)
{
DataTable table = this.Tables.Add("Connection");
table.Columns.Add("name", typeof(string));
table.Columns.Add("invariantName", typeof(string));
table.Columns.Add("connectionString", typeof(string));
}
public DataTable MetaDataCollections {
@ -36,7 +49,14 @@ namespace SharpDbTools.Model @@ -36,7 +49,14 @@ namespace SharpDbTools.Model
}
}
// TODO: an indexed property of MetaDataCollection
//public
public DataTable this[string collectionName] {
get {
return this.Tables[collectionName];
}
}
// public bool HasModel {
// get;
// }
}
}

29
src/AddIns/Misc/SharpDbTools/Project/Src/Model/IConnectionInfo.cs

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
/*
* User: dickon
* Date: 25/07/2006
* Time: 22:11
*
*/
using System;
namespace SharpDbTools.Model
{
/// <summary>
/// Defines the basic contract for an IConnectionInfo object. The basic idea
/// is to flag the current state of the underlying connection - has a connection
/// been made based on the information in the IConnectionInfo object? Has the
/// underlying model been built from the connection?
/// </summary>
public interface IConnectionInfo
{
bool HasConnection
{
get;
}
bool HasModel
{
get;
}
}
}

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

@ -29,8 +29,17 @@ namespace SharpDbTools @@ -29,8 +29,17 @@ namespace SharpDbTools
TreeView dbTree = new TreeView();
ctl = new Panel();
ctl.Controls.Add(dbTree);
TreeNode node = new TreeNode("test");
dbTree.Nodes.Add(node);
// initialise browser tree
dbTree.BeginUpdate();
//dbTree.Tag = "Connections";
TreeNode connection1 = new TreeNode("Test");
TreeNode[] childNodes = new TreeNode[1];
childNodes[0] = connection1;
TreeNode topNode = new TreeNode("Connections", childNodes);
dbTree.Nodes.Add(topNode);
dbTree.EndUpdate();
}

2
src/AddIns/Misc/SharpDbTools/Project/Src/Viewer/ViewerFactory.cs

@ -27,7 +27,7 @@ namespace SharpDbTools.Viewer @@ -27,7 +27,7 @@ namespace SharpDbTools.Viewer
}
public static IViewer GetViewer(string metaDataCollectionName,
DbConnectionInfo connectionInfo)
object connectionInfo)
{
return null;
}

Loading…
Cancel
Save