diff --git a/src/AddIns/Misc/SharpDbTools/Project/SharpDbTools.csproj b/src/AddIns/Misc/SharpDbTools/Project/SharpDbTools.csproj
index 9fb1d6b854..a3263c55a2 100644
--- a/src/AddIns/Misc/SharpDbTools/Project/SharpDbTools.csproj
+++ b/src/AddIns/Misc/SharpDbTools/Project/SharpDbTools.csproj
@@ -60,7 +60,9 @@
-
+
+
+
diff --git a/src/AddIns/Misc/SharpDbTools/Project/Src/Model/ColumnNames.cs b/src/AddIns/Misc/SharpDbTools/Project/Src/Model/ColumnNames.cs
new file mode 100644
index 0000000000..55f5a37948
--- /dev/null
+++ b/src/AddIns/Misc/SharpDbTools/Project/Src/Model/ColumnNames.cs
@@ -0,0 +1,21 @@
+/*
+ * User: dickon
+ * Date: 30/07/2006
+ * Time: 23:37
+ *
+ */
+
+using System;
+
+namespace SharpDbTools.Model
+{
+ ///
+ /// Description of Columns.
+ ///
+ public sealed class ColumnNames
+ {
+ public const string InvariantName = "invariantName";
+ public const string Name = "name";
+ public const string ConnectionString = "connectionString";
+ }
+}
diff --git a/src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfo.cs b/src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfo.cs
index 6c0c576e23..897c204f39 100644
--- a/src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfo.cs
+++ b/src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfo.cs
@@ -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));
diff --git a/src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfoFactory.cs b/src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfoFactory.cs
deleted file mode 100644
index c56a2e0ee6..0000000000
--- a/src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfoFactory.cs
+++ /dev/null
@@ -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
-{
- ///
- /// Description of Class1.
- ///
- 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;
- }
- }
-}
diff --git a/src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfoService.cs b/src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfoService.cs
new file mode 100644
index 0000000000..310952069f
--- /dev/null
+++ b/src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfoService.cs
@@ -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
+{
+ ///
+ /// 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
+ ///
+ public class DbModelInfoService
+ {
+ static DbModelInfoService instance = new DbModelInfoService();
+
+ SortedList cache;
+
+ DbModelInfoService()
+ {
+ cache = new SortedList();
+ }
+
+ 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
+ }
+ }
+}
diff --git a/src/AddIns/Misc/SharpDbTools/Project/Src/Model/TableNames.cs b/src/AddIns/Misc/SharpDbTools/Project/Src/Model/TableNames.cs
new file mode 100644
index 0000000000..4ae2303899
--- /dev/null
+++ b/src/AddIns/Misc/SharpDbTools/Project/Src/Model/TableNames.cs
@@ -0,0 +1,20 @@
+/*
+ * User: dickon
+ * Date: 30/07/2006
+ * Time: 23:35
+ *
+ */
+
+using System;
+
+namespace SharpDbTools.Model
+{
+ ///
+ /// Description of Tables.
+ ///
+ public sealed class TableNames
+ {
+ public const string MetaDataCollections = "MetaDataCollections";
+ public const string ConnectionInfo = "ConnectionInfo";
+ }
+}
diff --git a/src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserTool.cs b/src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserTool.cs
index 3b3c4cb8dc..b419c0f29e 100644
--- a/src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserTool.cs
+++ b/src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserTool.cs
@@ -25,11 +25,13 @@ namespace SharpDbTools
///
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();
diff --git a/src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserToolController.cs b/src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserToolController.cs
index f2e8df9a41..6fc61bbbbf 100644
--- a/src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserToolController.cs
+++ b/src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserToolController.cs
@@ -10,12 +10,29 @@ using System;
namespace SharpDbTools
{
///
- /// 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.
///
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;
}
}
}