public DbAdapter(DbDriverType driverType, IDbConnectionInfo connectionInfo) { Driver = DbDriverFactory.GetInstance(driverType); ConnectionInfo = connectionInfo; Connection = Driver.BuildConnection(ConnectionInfo); OpenConnection(); }
public void Run(IDbConnectionInfo connectionInfo) { var db = MockDatabaseProvider.Open(connectionInfo) as TestMockDatabase; if (db == null) throw new ArgumentException("Could not open mock database from supplied connectionInfo", "connectionInfo"); db.Table.Add(new TestMockDatabase.Row {Id = 3, RowName = "Three"}); }
public void Run(IDbConnectionInfo connectionInfo) { if (ScriptType != ScriptType.Runnable) throw new ArgumentException(string.Format("ScriptType is not runnable : {0}", ScriptType), "ScriptType"); try { var rType = new ReflectionType(ScriptValue); var runMethod = rType.CreateType().GetMethod("Run"); if (runMethod == null) throw new ArgumentException(string.Format("Could not find a method named 'Run' for ScriptValue : {0}", ScriptValue), "ScriptValue"); if (runMethod.ReturnType != typeof(void)) throw new ArgumentException(string.Format("Run method does not have return type 'void' for ScriptValue : {0}", ScriptValue), "ScriptValue"); var parameters = runMethod.GetParameters(); if (parameters.Length != 1 || parameters[0].ParameterType != typeof(IDbConnectionInfo)) throw new ArgumentException( string.Format("Run method does not have a single parameter of type 'IDbConnectionInfo' for ScriptValue : {0}", ScriptValue), "ScriptValue"); runMethod.Invoke(rType.CreateObject(), BindingFlags.InvokeMethod, null, new object[] {connectionInfo}, null); } catch (Exception e) { if (e.GetType() == typeof(ArgumentException)) throw; throw new ArgumentException(string.Format("ScriptValue could not be run : {0} : {1} : {2}", ScriptValue, e.GetType(), e.Message), "ScriptValue", e); } }
/// <summary> /// Creates if the database does not exist, otherwise opens /// </summary> /// <param name="connectionInfo"></param> /// <returns></returns> public static IMockDatabase Create(IDbConnectionInfo connectionInfo) { connectionInfo = VerifyConnectionInfo(connectionInfo); var databaseType = ((IMockDbConnectionInfo)connectionInfo).DatabaseType; if (!mockDatabases.ContainsKey(databaseType)) { // Check that the type is OK var interfaces = databaseType.FindInterfaces((type, criteria) => type == typeof(IMockDatabase), null); if (interfaces.Length == 0) throw new ArgumentException(string.Format("Mock database type does not implement IMockDatabase : {0}", databaseType), "connectionInfo.DatabaseType"); if (databaseType.GetConstructor(Type.EmptyTypes) == null) throw new ArgumentException(string.Format("Mock database type does not have a parameterless constructor : {0}", databaseType), "connectionInfo.DatabaseType"); mockDatabases.Add(databaseType, new Dictionary<string, IMockDatabase>()); } if (!mockDatabases[databaseType].ContainsKey(connectionInfo.DatabaseName)) { var ctor = databaseType.GetConstructor(Type.EmptyTypes); mockDatabases[databaseType].Add(connectionInfo.DatabaseName, (IMockDatabase)ctor.Invoke(null)); } return mockDatabases[databaseType][connectionInfo.DatabaseName]; }
/// <summary> /// Creates if the database does not exist, otherwise opens /// </summary> /// <param name="connectionInfo"></param> /// <returns></returns> public static IMockDatabase Create(IDbConnectionInfo connectionInfo) { connectionInfo = VerifyConnectionInfo(connectionInfo); var databaseType = ((IMockDbConnectionInfo)connectionInfo).DatabaseType; if (!mockDatabases.ContainsKey(databaseType)) { // Check that the type is OK var interfaces = databaseType.FindInterfaces((type, criteria) => type == typeof(IMockDatabase), null); if (interfaces.Length == 0) { throw new ArgumentException(string.Format("Mock database type does not implement IMockDatabase : {0}", databaseType), "connectionInfo.DatabaseType"); } if (databaseType.GetConstructor(Type.EmptyTypes) == null) { throw new ArgumentException(string.Format("Mock database type does not have a parameterless constructor : {0}", databaseType), "connectionInfo.DatabaseType"); } mockDatabases.Add(databaseType, new Dictionary <string, IMockDatabase>()); } if (!mockDatabases[databaseType].ContainsKey(connectionInfo.DatabaseName)) { var ctor = databaseType.GetConstructor(Type.EmptyTypes); mockDatabases[databaseType].Add(connectionInfo.DatabaseName, (IMockDatabase)ctor.Invoke(null)); } return(mockDatabases[databaseType][connectionInfo.DatabaseName]); }
/// <summary> /// 快速创建命令 /// </summary> /// <param name="dbConnectionInfo">连接对象</param> /// <returns>命令</returns> public static IDbCommand CreateCommand(IDbConnectionInfo dbConnectionInfo) { var config = DatabaseConfigManager.GetConfig(dbConnectionInfo.DBID); var cmd = dbConnectionInfo.DbConnection.CreateCommand(); SetCommandPara(cmd, config); return(cmd); }
/// <summary> /// 构造函数 /// </summary> /// <param name="conInfo">连接信息对象</param> /// <param name="customRegisteEntityTypeFunc">自定义注册EF实体类型回调,已自定义注册实体返回true;否则返回false</param> public EFDbContext(IDbConnectionInfo conInfo, Func <DatabaseConfig, DbModelBuilder, bool> customRegisteEntityTypeFunc) : base(conInfo.DbConnection, false) { this._conInfo = conInfo; this._customRegisteEntityTypeFunc = customRegisteEntityTypeFunc; Database.SetInitializer <EFDbContext>(null); this.RegisteLogOutput(); }
public void Run(IDbConnectionInfo connectionInfo) { var db = MockDatabaseProvider.Open(connectionInfo) as TestMockDatabase; if (db == null) throw new ArgumentException("Could not open mock database from supplied connectionInfo", "connectionInfo"); // Schema already defined in TestMockDatabase // TODO: Is there a point to this for mock databases? }
/// <summary> /// Opens an existing database /// </summary> /// <param name="connectionInfo"></param> /// <returns></returns> public static IMockDatabase Open(IDbConnectionInfo connectionInfo) { connectionInfo = VerifyConnectionInfo(connectionInfo); var databaseType = ((IMockDbConnectionInfo) connectionInfo).DatabaseType; if (!mockDatabases.ContainsKey(databaseType)) throw new ArgumentException("Database does not exist", "connectionInfo"); if (!mockDatabases[databaseType].ContainsKey(connectionInfo.DatabaseName)) throw new ArgumentException("Database does not exist", "connectionInfo"); return mockDatabases[databaseType][connectionInfo.DatabaseName]; }
private static IDbConnectionInfo VerifyConnectionInfo(IDbConnectionInfo connectionInfo) { if (connectionInfo == null) { throw new ArgumentException("connectionInfo not provided", "connectionInfo"); } return(new MockDbConnectionInfo { ConnectionString = connectionInfo.ConnectionString }); }
public void Run(IDbConnectionInfo connectionInfo) { var db = MockDatabaseProvider.Open(connectionInfo) as TestMockDatabase; if (db == null) { throw new ArgumentException("Could not open mock database from supplied connectionInfo", "connectionInfo"); } db.Table.Add(new TestMockDatabase.Row { Id = 3, RowName = "Three" }); }
public void Run(IDbConnectionInfo connectionInfo) { var db = MockDatabaseProvider.Open(connectionInfo) as TestMockDatabase; if (db == null) { throw new ArgumentException("Could not open mock database from supplied connectionInfo", "connectionInfo"); } // Schema already defined in TestMockDatabase // TODO: Is there a point to this for mock databases? }
/// <summary> /// Destroys the database if it exists /// </summary> /// <param name="connectionInfo"></param> /// <returns></returns> public static void Destroy(IDbConnectionInfo connectionInfo) { connectionInfo = VerifyConnectionInfo(connectionInfo); var databaseType = ((IMockDbConnectionInfo)connectionInfo).DatabaseType; if(!mockDatabases.ContainsKey(databaseType)) return; mockDatabases[databaseType].Remove(connectionInfo.DatabaseName); if(mockDatabases[databaseType].Count == 0) { mockDatabases.Remove(databaseType); } }
/// <summary> /// Opens an existing database /// </summary> /// <param name="connectionInfo"></param> /// <returns></returns> public static IMockDatabase Open(IDbConnectionInfo connectionInfo) { connectionInfo = VerifyConnectionInfo(connectionInfo); var databaseType = ((IMockDbConnectionInfo)connectionInfo).DatabaseType; if (!mockDatabases.ContainsKey(databaseType)) { throw new ArgumentException("Database does not exist", "connectionInfo"); } if (!mockDatabases[databaseType].ContainsKey(connectionInfo.DatabaseName)) { throw new ArgumentException("Database does not exist", "connectionInfo"); } return(mockDatabases[databaseType][connectionInfo.DatabaseName]); }
/// <summary> /// Destroys the database if it exists /// </summary> /// <param name="connectionInfo"></param> /// <returns></returns> public static void Destroy(IDbConnectionInfo connectionInfo) { connectionInfo = VerifyConnectionInfo(connectionInfo); var databaseType = ((IMockDbConnectionInfo)connectionInfo).DatabaseType; if (!mockDatabases.ContainsKey(databaseType)) { return; } mockDatabases[databaseType].Remove(connectionInfo.DatabaseName); if (mockDatabases[databaseType].Count == 0) { mockDatabases.Remove(databaseType); } }
/// <summary> /// Builds a Postgres connection object for the given remote Postgres server. /// </summary> /// <param name="connectionInfo">The database connection information.</param> /// <returns>Connection object for the remote Postgres server.</returns> public IDbConnection BuildConnection(IDbConnectionInfo connectionInfo) { if (connectionInfo.Port == null) { throw new ArgumentException("Port cannot be null!"); } var connectionString = new NpgsqlConnectionStringBuilder() { Host = connectionInfo.Server, Port = connectionInfo.Port.Value, UserName = connectionInfo.Username, Password = connectionInfo.Password, Database = connectionInfo.DatabaseName }; return new NpgsqlConnection(connectionString); }
/// <summary> /// Builds a Postgres connection object for the given remote Postgres server. /// </summary> /// <param name="connectionInfo">The database connection information.</param> /// <returns>Connection object for the remote Postgres server.</returns> public IDbConnection BuildConnection(IDbConnectionInfo connectionInfo) { if (connectionInfo.Port == null) { throw new ArgumentException("Port cannot be null!"); } var connectionString = new NpgsqlConnectionStringBuilder() { Host = connectionInfo.Server, Port = connectionInfo.Port.Value, UserName = connectionInfo.Username, Password = connectionInfo.Password, Database = connectionInfo.DatabaseName }; return(new NpgsqlConnection(connectionString)); }
public void Run(IDbConnectionInfo connectionInfo) { if (ScriptType != ScriptType.Runnable) { throw new ArgumentException(string.Format("ScriptType is not runnable : {0}", ScriptType), "ScriptType"); } try { var rType = new ReflectionType(ScriptValue); var runMethod = rType.CreateType().GetMethod("Run"); if (runMethod == null) { throw new ArgumentException(string.Format("Could not find a method named 'Run' for ScriptValue : {0}", ScriptValue), "ScriptValue"); } if (runMethod.ReturnType != typeof(void)) { throw new ArgumentException(string.Format("Run method does not have return type 'void' for ScriptValue : {0}", ScriptValue), "ScriptValue"); } var parameters = runMethod.GetParameters(); if (parameters.Length != 1 || parameters[0].ParameterType != typeof(IDbConnectionInfo)) { throw new ArgumentException( string.Format("Run method does not have a single parameter of type 'IDbConnectionInfo' for ScriptValue : {0}", ScriptValue), "ScriptValue"); } runMethod.Invoke(rType.CreateObject(), BindingFlags.InvokeMethod, null, new object[] { connectionInfo }, null); } catch (Exception e) { if (e.GetType() == typeof(ArgumentException)) { throw; } throw new ArgumentException(string.Format("ScriptValue could not be run : {0} : {1} : {2}", ScriptValue, e.GetType(), e.Message), "ScriptValue", e); } }
public string Run(IDbConnectionInfo connectionInfo) { return(null); }
public void InvalidMethodName(IDbConnectionInfo connectionInfo) { }
public DbHelperBase(IDbConnectionInfo conn) : this(conn.ToConnectionString()) { _dbConnectionInfo = conn; }
public DataTableDbWriter(DbDriverType driverType, IDbConnectionInfo connectionInfo, DbTableInitializationOptions tableInitializationOptions = default(DbTableInitializationOptions)) { Adapter = new DbAdapter(driverType, connectionInfo); this.tableInitializationOptions = tableInitializationOptions; }
private static IDbConnectionInfo VerifyConnectionInfo(IDbConnectionInfo connectionInfo) { if (connectionInfo == null) throw new ArgumentException("connectionInfo not provided", "connectionInfo"); return new MockDbConnectionInfo {ConnectionString = connectionInfo.ConnectionString}; }
public static string CreateDbLinkConnection(IDbConnectionInfo connectionInfo) { var builder = new NpgsqlConnectionStringBuilder(connectionInfo.ConnectionString); var dbLink = new StringBuilder(); if (builder.ContainsKey(PgDbConnectionInfo.ServerAddressKey)) { if (dbLink.Length > 0) dbLink.Append(" "); dbLink.Append("host=").Append(builder[PgDbConnectionInfo.ServerAddressKey]); } if (builder.ContainsKey(PgDbConnectionInfo.ServerPortKey)) { if (dbLink.Length > 0) dbLink.Append(" "); dbLink.Append("port=").Append(builder[PgDbConnectionInfo.ServerPortKey]); } if (builder.ContainsKey(PgDbConnectionInfo.DatabaseNameKey)) { if (dbLink.Length > 0) dbLink.Append(" "); dbLink.Append("dbname=").Append(builder[PgDbConnectionInfo.DatabaseNameKey]); } if (builder.ContainsKey(PgDbConnectionInfo.UserNameKey)) { if (dbLink.Length > 0) dbLink.Append(" "); dbLink.Append("user="******" "); dbLink.Append("user="******" "); dbLink.Append("password=").Append(builder[PgDbConnectionInfo.PasswordKey]); } return dbLink.ToString(); }
public void Run(IDbConnectionInfo connectionInfo) { throw new Exception("Method was called"); }
/// <summary> /// 构造函数 /// </summary> /// <param name="conInfo">连接信息对象</param> public TestContext(IDbConnectionInfo conInfo) : base(conInfo, null) { }
public string Run(IDbConnectionInfo connectionInfo) { return null; }
/// <summary> /// Create using existing connection information /// </summary> /// <param name="connectionInfo">Connection information</param> public MicrOrmConnectionProvider(IDbConnectionInfo connectionInfo) { ConnectionInfo = connectionInfo; }