Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1627 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
7 changed files with 36 additions and 211 deletions
@ -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
|
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue