Permalink
Browse files

Modified the table and db constructors.

  • Loading branch information...
1 parent d7e1345 commit 46a98797a6f656e600502c4dcd17fb3e13f275c3 @mikeobrien committed May 17, 2012
Showing with 33 additions and 12 deletions.
  1. +20 −9 src/Gribble/Database.cs
  2. +13 −3 src/Gribble/Table.cs
View
@@ -14,13 +14,9 @@ public class Database : IDatabase
private readonly IProfiler _profiler;
private readonly EntityMappingCollection _mappingCollection;
- public Database(IConnectionManager connectionManager) :
- this(connectionManager, new EntityMappingCollection(Enumerable.Empty<IClassMap>()), null) { }
+ public Database(IConnectionManager connectionManager, EntityMappingCollection mappingCollection) : this(connectionManager, mappingCollection, null) { }
- public Database(IConnectionManager connectionManager, EntityMappingCollection mappingCollection) :
- this(connectionManager, mappingCollection, null) { }
-
- private Database(IConnectionManager connectionManager, EntityMappingCollection mappingCollection, IProfiler profiler)
+ internal Database(IConnectionManager connectionManager, EntityMappingCollection mappingCollection, IProfiler profiler)
{
_connectionManager = connectionManager;
_profiler = profiler;
@@ -29,17 +25,32 @@ private Database(IConnectionManager connectionManager, EntityMappingCollection m
public static IDatabase Create(SqlConnection connection, TimeSpan? commandTimeout = null, IProfiler profiler = null)
{
- return Create(connection, new EntityMappingCollection(Enumerable.Empty<IClassMap>()), commandTimeout, profiler);
+ return Create(new ConnectionManager(connection, commandTimeout ?? new TimeSpan(0, 5, 0)), profiler);
+ }
+
+ public static IDatabase Create(IConnectionManager connectionManager, IProfiler profiler = null)
+ {
+ return new Database(connectionManager, new EntityMappingCollection(Enumerable.Empty<IClassMap>()), profiler ?? new ConsoleProfiler());
}
public static IDatabase Create(SqlConnection connection, string keyColumn, TimeSpan? commandTimeout = null, IProfiler profiler = null)
{
- return Create(connection, new EntityMappingCollection(new IClassMap[] { new GuidKeyEntityMap(keyColumn), new IntKeyEntityMap(keyColumn) }), commandTimeout, profiler);
+ return Create(new ConnectionManager(connection, commandTimeout ?? new TimeSpan(0, 5, 0)), keyColumn, profiler);
+ }
+
+ public static IDatabase Create(IConnectionManager connectionManager, string keyColumn, IProfiler profiler = null)
+ {
+ return new Database(connectionManager, new EntityMappingCollection(new IClassMap[] { new GuidKeyEntityMap(keyColumn), new IntKeyEntityMap(keyColumn) }), profiler ?? new ConsoleProfiler());
}
public static IDatabase Create(SqlConnection connection, EntityMappingCollection mappingCollection, TimeSpan? commandTimeout = null, IProfiler profiler = null)
{
- return new Database(new ConnectionManager(connection, commandTimeout ?? new TimeSpan(0, 5, 0)), mappingCollection, profiler);
+ return Create(new ConnectionManager(connection, commandTimeout ?? new TimeSpan(0, 5, 0)), mappingCollection, profiler);
+ }
+
+ public static IDatabase Create(IConnectionManager connectionManager, EntityMappingCollection mappingCollection, IProfiler profiler = null)
+ {
+ return new Database(connectionManager, mappingCollection, profiler ?? new ConsoleProfiler());
}
public void CallProcedure(string name)
View
@@ -33,13 +33,23 @@ public Table(IConnectionManager connectionManagerManager, string table, IEntityM
public static ITable<TEntity> Create<TKey>(SqlConnection connection, string tableName, string keyColumn, TimeSpan? commandTimeout = null, IProfiler profiler = null)
{
+ return Create<TKey>(new ConnectionManager(connection, commandTimeout ?? new TimeSpan(0, 5, 0)), keyColumn, tableName, profiler ?? new ConsoleProfiler());
+ }
+
+ public static ITable<TEntity> Create<TKey>(ConnectionManager connectionManager, string tableName, string keyColumn, IProfiler profiler = null)
+ {
var mapping = new EntityMapping(typeof(Guid) == typeof(TKey) ? new GuidKeyEntityMap(keyColumn) : (typeof(int) == typeof(TKey) ? (IClassMap)new IntKeyEntityMap(keyColumn) : null));
- return new Table<TEntity>(new ConnectionManager(connection, commandTimeout ?? new TimeSpan(0, 5, 0)), tableName, mapping, profiler ?? new ConsoleProfiler());
+ return new Table<TEntity>(connectionManager, tableName, mapping, profiler ?? new ConsoleProfiler());
}
public static ITable<TEntity> Create(SqlConnection connection, string tableName, IEntityMapping entityMapping, TimeSpan? commandTimeout = null, IProfiler profiler = null)
{
- return new Table<TEntity>(new ConnectionManager(connection, commandTimeout ?? new TimeSpan(0, 5, 0)), tableName, entityMapping, profiler ?? new ConsoleProfiler());
+ return Create(new ConnectionManager(connection, commandTimeout ?? new TimeSpan(0, 5, 0)), tableName, entityMapping, profiler ?? new ConsoleProfiler());
+ }
+
+ public static ITable<TEntity> Create(ConnectionManager connectionManager, string tableName, IEntityMapping entityMapping, IProfiler profiler = null)
+ {
+ return new Table<TEntity>(connectionManager, tableName, entityMapping, profiler ?? new ConsoleProfiler());
}
public string Name { get { return _table; } }
@@ -152,7 +162,7 @@ private IQueryable<TEntity> CopyInto(Select select)
{
var hasIdentityKey = _map.Key.KeyType == PrimaryKeyType.IdentitySeed;
var keyColumnName = _map.Key.GetColumnName();
- var database = new Database(_connectionManager);
+ var database = new Database(_connectionManager, null, _profiler);
var columns = database.TableExists(select.Target.Table.Name) ?
GetColumnNames(select, hasIdentityKey, keyColumnName) :

0 comments on commit 46a9879

Please sign in to comment.