This commit is contained in:
@@ -773,7 +773,10 @@ namespace DynamORM
|
|||||||
|
|
||||||
IsDisposed = true;
|
IsDisposed = true;
|
||||||
|
|
||||||
|
_command.Parameters.Clear();
|
||||||
|
|
||||||
_command.Dispose();
|
_command.Dispose();
|
||||||
|
_command = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -980,6 +983,9 @@ namespace DynamORM
|
|||||||
/// <summary>Gets schema columns cache.</summary>
|
/// <summary>Gets schema columns cache.</summary>
|
||||||
internal Dictionary<string, Dictionary<string, DynamicSchemaColumn>> Schema { get; private set; }
|
internal Dictionary<string, Dictionary<string, DynamicSchemaColumn>> Schema { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>Gets active builders that weren't disposed.</summary>
|
||||||
|
internal List<IDynamicQueryBuilder> RemainingBuilders { get; private set; }
|
||||||
|
|
||||||
#if !DYNAMORM_OMMIT_OLDSYNTAX
|
#if !DYNAMORM_OMMIT_OLDSYNTAX
|
||||||
|
|
||||||
/// <summary>Gets tables cache for this database instance.</summary>
|
/// <summary>Gets tables cache for this database instance.</summary>
|
||||||
@@ -1050,6 +1056,7 @@ namespace DynamORM
|
|||||||
TransactionPool = new Dictionary<IDbConnection, Stack<IDbTransaction>>();
|
TransactionPool = new Dictionary<IDbConnection, Stack<IDbTransaction>>();
|
||||||
CommandsPool = new Dictionary<IDbConnection, List<IDbCommand>>();
|
CommandsPool = new Dictionary<IDbConnection, List<IDbCommand>>();
|
||||||
Schema = new Dictionary<string, Dictionary<string, DynamicSchemaColumn>>();
|
Schema = new Dictionary<string, Dictionary<string, DynamicSchemaColumn>>();
|
||||||
|
RemainingBuilders = new List<IDynamicQueryBuilder>();
|
||||||
#if !DYNAMORM_OMMIT_OLDSYNTAX
|
#if !DYNAMORM_OMMIT_OLDSYNTAX
|
||||||
TablesCache = new Dictionary<string, DynamicTable>();
|
TablesCache = new Dictionary<string, DynamicTable>();
|
||||||
#endif
|
#endif
|
||||||
@@ -1134,6 +1141,22 @@ namespace DynamORM
|
|||||||
|
|
||||||
#endregion Table
|
#endregion Table
|
||||||
|
|
||||||
|
/// <summary>Adds cached builder.</summary>
|
||||||
|
/// <param name="builder">New dynamic builder.</param>
|
||||||
|
internal void AddToCache(IDynamicQueryBuilder builder)
|
||||||
|
{
|
||||||
|
lock (SyncLock)
|
||||||
|
RemainingBuilders.Add(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Removes cached builder.</summary>
|
||||||
|
/// <param name="builder">Disposed dynamic builder.</param>
|
||||||
|
internal void RemoveFromCache(IDynamicQueryBuilder builder)
|
||||||
|
{
|
||||||
|
lock (SyncLock)
|
||||||
|
RemainingBuilders.Remove(builder);
|
||||||
|
}
|
||||||
|
|
||||||
#region From/Insert/Update/Delete
|
#region From/Insert/Update/Delete
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1846,7 +1869,11 @@ namespace DynamORM
|
|||||||
{
|
{
|
||||||
lock (SyncLock)
|
lock (SyncLock)
|
||||||
if (Schema.ContainsKey(table.FullName))
|
if (Schema.ContainsKey(table.FullName))
|
||||||
|
{
|
||||||
|
if (Schema[table.FullName] != null)
|
||||||
|
Schema[table.FullName].Clear();
|
||||||
Schema.Remove(table.FullName);
|
Schema.Remove(table.FullName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Clears the all schemas from cache.</summary>
|
/// <summary>Clears the all schemas from cache.</summary>
|
||||||
@@ -1854,7 +1881,13 @@ namespace DynamORM
|
|||||||
public void ClearSchema()
|
public void ClearSchema()
|
||||||
{
|
{
|
||||||
lock (SyncLock)
|
lock (SyncLock)
|
||||||
|
{
|
||||||
|
foreach (var s in Schema)
|
||||||
|
if (s.Value != null)
|
||||||
|
s.Value.Clear();
|
||||||
|
|
||||||
Schema.Clear();
|
Schema.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Get schema describing objects from reader.</summary>
|
/// <summary>Get schema describing objects from reader.</summary>
|
||||||
@@ -2175,6 +2208,7 @@ namespace DynamORM
|
|||||||
|
|
||||||
// Dispose the corpse
|
// Dispose the corpse
|
||||||
connection.Dispose();
|
connection.Dispose();
|
||||||
|
connection = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2268,6 +2302,8 @@ namespace DynamORM
|
|||||||
TablesCache.Clear();
|
TablesCache.Clear();
|
||||||
|
|
||||||
tables.ForEach(t => t.Dispose());
|
tables.ForEach(t => t.Dispose());
|
||||||
|
tables.Clear();
|
||||||
|
tables = null;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
foreach (var con in TransactionPool)
|
foreach (var con in TransactionPool)
|
||||||
@@ -2279,6 +2315,8 @@ namespace DynamORM
|
|||||||
tmp.ForEach(cmd => cmd.Dispose());
|
tmp.ForEach(cmd => cmd.Dispose());
|
||||||
|
|
||||||
CommandsPool[con.Key].Clear();
|
CommandsPool[con.Key].Clear();
|
||||||
|
tmp.Clear();
|
||||||
|
CommandsPool[con.Key] = tmp = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rollback remaining transactions
|
// Rollback remaining transactions
|
||||||
@@ -2297,13 +2335,23 @@ namespace DynamORM
|
|||||||
con.Key.Dispose();
|
con.Key.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (RemainingBuilders.Count > 0)
|
||||||
|
RemainingBuilders.First().Dispose();
|
||||||
|
|
||||||
// Clear pools
|
// Clear pools
|
||||||
lock (SyncLock)
|
lock (SyncLock)
|
||||||
{
|
{
|
||||||
TransactionPool.Clear();
|
TransactionPool.Clear();
|
||||||
CommandsPool.Clear();
|
CommandsPool.Clear();
|
||||||
|
RemainingBuilders.Clear();
|
||||||
|
|
||||||
|
TransactionPool = null;
|
||||||
|
CommandsPool = null;
|
||||||
|
RemainingBuilders = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClearSchema();
|
||||||
|
|
||||||
IsDisposed = true;
|
IsDisposed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5025,7 +5073,7 @@ namespace DynamORM
|
|||||||
|
|
||||||
/// <summary>Dynamic query builder base interface.</summary>
|
/// <summary>Dynamic query builder base interface.</summary>
|
||||||
/// <remarks>This interface it publically available. Implementation should be hidden.</remarks>
|
/// <remarks>This interface it publically available. Implementation should be hidden.</remarks>
|
||||||
public interface IDynamicQueryBuilder
|
public interface IDynamicQueryBuilder : IExtendedDisposable
|
||||||
{
|
{
|
||||||
/// <summary>Gets <see cref="DynamicDatabase"/> instance.</summary>
|
/// <summary>Gets <see cref="DynamicDatabase"/> instance.</summary>
|
||||||
DynamicDatabase Database { get; }
|
DynamicDatabase Database { get; }
|
||||||
@@ -5357,7 +5405,7 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Interface describing parameter info.</summary>
|
/// <summary>Interface describing parameter info.</summary>
|
||||||
public interface IParameter
|
public interface IParameter : IExtendedDisposable
|
||||||
{
|
{
|
||||||
/// <summary>Gets the parameter position in command.</summary>
|
/// <summary>Gets the parameter position in command.</summary>
|
||||||
/// <remarks>Available after filling the command.</remarks>
|
/// <remarks>Available after filling the command.</remarks>
|
||||||
@@ -5380,7 +5428,7 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Interface describing table information.</summary>
|
/// <summary>Interface describing table information.</summary>
|
||||||
public interface ITableInfo
|
public interface ITableInfo : IExtendedDisposable
|
||||||
{
|
{
|
||||||
/// <summary>Gets table owner name.</summary>
|
/// <summary>Gets table owner name.</summary>
|
||||||
string Owner { get; }
|
string Owner { get; }
|
||||||
@@ -5988,6 +6036,19 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion Insert
|
#endregion Insert
|
||||||
|
|
||||||
|
#region IExtendedDisposable
|
||||||
|
|
||||||
|
/// <summary>Performs application-defined tasks associated with
|
||||||
|
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
base.Dispose();
|
||||||
|
|
||||||
|
_columns = _values = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion IExtendedDisposable
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Base query builder for insert/update/delete statements.</summary>
|
/// <summary>Base query builder for insert/update/delete statements.</summary>
|
||||||
@@ -6054,6 +6115,7 @@ namespace DynamORM
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal TableInfo()
|
internal TableInfo()
|
||||||
{
|
{
|
||||||
|
IsDisposed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -6064,6 +6126,7 @@ namespace DynamORM
|
|||||||
/// <param name="alias">The table alias.</param>
|
/// <param name="alias">The table alias.</param>
|
||||||
/// <param name="owner">The table owner.</param>
|
/// <param name="owner">The table owner.</param>
|
||||||
public TableInfo(DynamicDatabase db, string name, string alias = null, string owner = null)
|
public TableInfo(DynamicDatabase db, string name, string alias = null, string owner = null)
|
||||||
|
: this()
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Alias = alias;
|
Alias = alias;
|
||||||
@@ -6081,6 +6144,7 @@ namespace DynamORM
|
|||||||
/// <param name="alias">The table alias.</param>
|
/// <param name="alias">The table alias.</param>
|
||||||
/// <param name="owner">The table owner.</param>
|
/// <param name="owner">The table owner.</param>
|
||||||
public TableInfo(DynamicDatabase db, Type type, string alias = null, string owner = null)
|
public TableInfo(DynamicDatabase db, Type type, string alias = null, string owner = null)
|
||||||
|
: this()
|
||||||
{
|
{
|
||||||
var mapper = DynamicMapperCache.GetMapper(type);
|
var mapper = DynamicMapperCache.GetMapper(type);
|
||||||
|
|
||||||
@@ -6104,6 +6168,20 @@ namespace DynamORM
|
|||||||
|
|
||||||
/// <summary>Gets or sets table schema.</summary>
|
/// <summary>Gets or sets table schema.</summary>
|
||||||
public Dictionary<string, DynamicSchemaColumn> Schema { get; internal set; }
|
public Dictionary<string, DynamicSchemaColumn> Schema { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>Gets a value indicating whether this instance is disposed.</summary>
|
||||||
|
public bool IsDisposed { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>Performs application-defined tasks associated with
|
||||||
|
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||||
|
public virtual void Dispose()
|
||||||
|
{
|
||||||
|
IsDisposed = true;
|
||||||
|
|
||||||
|
Schema.Clear();
|
||||||
|
Owner = Name = Alias = null;
|
||||||
|
Schema = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Generic based table information.</summary>
|
/// <summary>Generic based table information.</summary>
|
||||||
@@ -6129,6 +6207,13 @@ namespace DynamORM
|
|||||||
/// <summary>Interface describing parameter info.</summary>
|
/// <summary>Interface describing parameter info.</summary>
|
||||||
internal class Parameter : IParameter
|
internal class Parameter : IParameter
|
||||||
{
|
{
|
||||||
|
/// <summary>Initializes a new instance of the
|
||||||
|
/// <see cref="Parameter"/> class.</summary>
|
||||||
|
public Parameter()
|
||||||
|
{
|
||||||
|
IsDisposed = false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Gets or sets the parameter position in command.</summary>
|
/// <summary>Gets or sets the parameter position in command.</summary>
|
||||||
/// <remarks>Available after filling the command.</remarks>
|
/// <remarks>Available after filling the command.</remarks>
|
||||||
public int Ordinal { get; internal set; }
|
public int Ordinal { get; internal set; }
|
||||||
@@ -6147,6 +6232,19 @@ namespace DynamORM
|
|||||||
|
|
||||||
/// <summary>Gets or sets the parameter schema information.</summary>
|
/// <summary>Gets or sets the parameter schema information.</summary>
|
||||||
public DynamicSchemaColumn? Schema { get; set; }
|
public DynamicSchemaColumn? Schema { get; set; }
|
||||||
|
|
||||||
|
/// <summary>Gets a value indicating whether this instance is disposed.</summary>
|
||||||
|
public bool IsDisposed { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>Performs application-defined tasks associated with
|
||||||
|
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||||
|
public virtual void Dispose()
|
||||||
|
{
|
||||||
|
IsDisposed = true;
|
||||||
|
|
||||||
|
Name = null;
|
||||||
|
Schema = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Parameter
|
#endregion Parameter
|
||||||
@@ -6159,6 +6257,7 @@ namespace DynamORM
|
|||||||
/// <param name="db">The database.</param>
|
/// <param name="db">The database.</param>
|
||||||
public DynamicQueryBuilder(DynamicDatabase db)
|
public DynamicQueryBuilder(DynamicDatabase db)
|
||||||
{
|
{
|
||||||
|
IsDisposed = false;
|
||||||
VirtualMode = false;
|
VirtualMode = false;
|
||||||
Tables = new List<ITableInfo>();
|
Tables = new List<ITableInfo>();
|
||||||
Parameters = new Dictionary<string, IParameter>();
|
Parameters = new Dictionary<string, IParameter>();
|
||||||
@@ -6167,6 +6266,9 @@ namespace DynamORM
|
|||||||
OpenBracketsCount = 0;
|
OpenBracketsCount = 0;
|
||||||
|
|
||||||
Database = db;
|
Database = db;
|
||||||
|
if (Database != null)
|
||||||
|
Database.AddToCache(this);
|
||||||
|
|
||||||
SupportSchema = (db.Options & DynamicDatabaseOptions.SupportSchema) == DynamicDatabaseOptions.SupportSchema;
|
SupportSchema = (db.Options & DynamicDatabaseOptions.SupportSchema) == DynamicDatabaseOptions.SupportSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6318,7 +6420,9 @@ namespace DynamORM
|
|||||||
// If node is a delegate, parse it to create the logical tree...
|
// If node is a delegate, parse it to create the logical tree...
|
||||||
if (node is Delegate)
|
if (node is Delegate)
|
||||||
{
|
{
|
||||||
node = DynamicParser.Parse((Delegate)node).Result;
|
using (var p = DynamicParser.Parse((Delegate)node))
|
||||||
|
node = p.Result;
|
||||||
|
|
||||||
return Parse(node, ref columnSchema, pars, rawstr, decorate: decorate); // Intercept containers as in (x => "string")
|
return Parse(node, ref columnSchema, pars, rawstr, decorate: decorate); // Intercept containers as in (x => "string")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6801,6 +6905,44 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion Helpers
|
#endregion Helpers
|
||||||
|
|
||||||
|
#region IExtendedDisposable
|
||||||
|
|
||||||
|
/// <summary>Gets a value indicating whether this instance is disposed.</summary>
|
||||||
|
public bool IsDisposed { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>Performs application-defined tasks associated with
|
||||||
|
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||||
|
public virtual void Dispose()
|
||||||
|
{
|
||||||
|
IsDisposed = true;
|
||||||
|
|
||||||
|
if (Database != null)
|
||||||
|
Database.RemoveFromCache(this);
|
||||||
|
|
||||||
|
if (Parameters != null)
|
||||||
|
{
|
||||||
|
foreach (var p in Parameters)
|
||||||
|
p.Value.Dispose();
|
||||||
|
|
||||||
|
Parameters.Clear();
|
||||||
|
Parameters = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Tables != null)
|
||||||
|
{
|
||||||
|
foreach (var t in Tables)
|
||||||
|
t.Dispose();
|
||||||
|
|
||||||
|
Tables.Clear();
|
||||||
|
Tables = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
WhereCondition = null;
|
||||||
|
Database = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion IExtendedDisposable
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Implementation of dynamic select query builder.</summary>
|
/// <summary>Implementation of dynamic select query builder.</summary>
|
||||||
@@ -8060,6 +8202,19 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion Helpers
|
#endregion Helpers
|
||||||
|
|
||||||
|
#region IExtendedDisposable
|
||||||
|
|
||||||
|
/// <summary>Performs application-defined tasks associated with
|
||||||
|
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
base.Dispose();
|
||||||
|
|
||||||
|
_select = _from = _join = _groupby = _orderby = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion IExtendedDisposable
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Update query builder.</summary>
|
/// <summary>Update query builder.</summary>
|
||||||
@@ -8190,7 +8345,11 @@ namespace DynamORM
|
|||||||
index++;
|
index++;
|
||||||
if (f == null)
|
if (f == null)
|
||||||
throw new ArgumentNullException(string.Format("Specification #{0} cannot be null.", index));
|
throw new ArgumentNullException(string.Format("Specification #{0} cannot be null.", index));
|
||||||
var result = DynamicParser.Parse(f).Result;
|
|
||||||
|
object result = null;
|
||||||
|
|
||||||
|
using (var p = DynamicParser.Parse(f))
|
||||||
|
result = p.Result;
|
||||||
|
|
||||||
if (result == null)
|
if (result == null)
|
||||||
throw new ArgumentException(string.Format("Specification #{0} resolves to null.", index));
|
throw new ArgumentException(string.Format("Specification #{0} resolves to null.", index));
|
||||||
@@ -8343,6 +8502,19 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion Where
|
#endregion Where
|
||||||
|
|
||||||
|
#region IExtendedDisposable
|
||||||
|
|
||||||
|
/// <summary>Performs application-defined tasks associated with
|
||||||
|
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
base.Dispose();
|
||||||
|
|
||||||
|
_columns = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion IExtendedDisposable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8930,6 +9102,8 @@ namespace DynamORM
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class Node : IDynamicMetaObjectProvider, IExtendedDisposable, ISerializable
|
public class Node : IDynamicMetaObjectProvider, IExtendedDisposable, ISerializable
|
||||||
{
|
{
|
||||||
|
private DynamicParser _parser = null;
|
||||||
|
|
||||||
#region MetaNode
|
#region MetaNode
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -9639,6 +9813,23 @@ namespace DynamORM
|
|||||||
|
|
||||||
return string.Format("({0} {1} {2})", Host.Sketch(), Operation, Right.Sketch());
|
return string.Format("({0} {1} {2})", Host.Sketch(), Operation, Right.Sketch());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Performs application-defined tasks associated with
|
||||||
|
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
base.Dispose();
|
||||||
|
|
||||||
|
if (Right != null && Right is Node)
|
||||||
|
{
|
||||||
|
Node n = (Node)Right;
|
||||||
|
|
||||||
|
if (!n.IsDisposed)
|
||||||
|
n.Dispose();
|
||||||
|
|
||||||
|
Right = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Binary
|
#endregion Binary
|
||||||
@@ -9765,7 +9956,16 @@ namespace DynamORM
|
|||||||
public Node Host { get; internal set; }
|
public Node Host { get; internal set; }
|
||||||
|
|
||||||
/// <summary>Gets reference to the parser.</summary>
|
/// <summary>Gets reference to the parser.</summary>
|
||||||
public DynamicParser Parser { get; internal set; }
|
public DynamicParser Parser
|
||||||
|
{
|
||||||
|
get { return _parser; }
|
||||||
|
internal set
|
||||||
|
{
|
||||||
|
_parser = value;
|
||||||
|
if (_parser != null)
|
||||||
|
_parser._allNodes.Add(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Node"/> class.
|
/// Initializes a new instance of the <see cref="Node"/> class.
|
||||||
@@ -9858,12 +10058,18 @@ namespace DynamORM
|
|||||||
/// <summary>Gets a value indicating whether this instance is disposed.</summary>
|
/// <summary>Gets a value indicating whether this instance is disposed.</summary>
|
||||||
public bool IsDisposed { get; private set; }
|
public bool IsDisposed { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>Performs application-defined tasks associated with
|
||||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||||
/// </summary>
|
public virtual void Dispose()
|
||||||
public void Dispose()
|
|
||||||
{
|
{
|
||||||
IsDisposed = true;
|
IsDisposed = true;
|
||||||
|
|
||||||
|
if (Host != null && !Host.IsDisposed)
|
||||||
|
Host.Dispose();
|
||||||
|
|
||||||
|
Host = null;
|
||||||
|
|
||||||
|
Parser = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Implementation of IExtendedDisposable
|
#endregion Implementation of IExtendedDisposable
|
||||||
@@ -9893,6 +10099,7 @@ namespace DynamORM
|
|||||||
#region Data
|
#region Data
|
||||||
|
|
||||||
private List<Node.Argument> _arguments = new List<Node.Argument>();
|
private List<Node.Argument> _arguments = new List<Node.Argument>();
|
||||||
|
private List<Node> _allNodes = new List<Node>();
|
||||||
private object _uncertainResult;
|
private object _uncertainResult;
|
||||||
|
|
||||||
#endregion Data
|
#endregion Data
|
||||||
@@ -10005,6 +10212,34 @@ namespace DynamORM
|
|||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
IsDisposed = true;
|
IsDisposed = true;
|
||||||
|
|
||||||
|
if (_uncertainResult != null && _uncertainResult is Node)
|
||||||
|
{
|
||||||
|
((Node)_uncertainResult).Dispose();
|
||||||
|
_uncertainResult = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Last != null && !Last.IsDisposed)
|
||||||
|
{
|
||||||
|
Last.Dispose();
|
||||||
|
Last = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_arguments != null)
|
||||||
|
{
|
||||||
|
_arguments.ForEach(x => { if (!x.IsDisposed) x.Dispose(); });
|
||||||
|
|
||||||
|
_arguments.Clear();
|
||||||
|
_arguments = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_allNodes != null)
|
||||||
|
{
|
||||||
|
_allNodes.ForEach(x => { if (!x.IsDisposed) x.Dispose(); });
|
||||||
|
|
||||||
|
_allNodes.Clear();
|
||||||
|
_allNodes = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Implementation of IExtendedDisposable
|
#endregion Implementation of IExtendedDisposable
|
||||||
@@ -10013,7 +10248,7 @@ namespace DynamORM
|
|||||||
/// <summary>Class that allows to use interfaces as dynamic objects.</summary>
|
/// <summary>Class that allows to use interfaces as dynamic objects.</summary>
|
||||||
/// <typeparam name="T">Type of class to proxy.</typeparam>
|
/// <typeparam name="T">Type of class to proxy.</typeparam>
|
||||||
/// <remarks>This is temporary solution. Which allows to use builders as a dynamic type.</remarks>
|
/// <remarks>This is temporary solution. Which allows to use builders as a dynamic type.</remarks>
|
||||||
public class DynamicProxy<T> : DynamicObject
|
public class DynamicProxy<T> : DynamicObject, IDisposable
|
||||||
{
|
{
|
||||||
private T _proxy;
|
private T _proxy;
|
||||||
private Type _type;
|
private Type _type;
|
||||||
@@ -10033,15 +10268,15 @@ namespace DynamORM
|
|||||||
_proxy = proxiedObject;
|
_proxy = proxiedObject;
|
||||||
_type = typeof(T);
|
_type = typeof(T);
|
||||||
|
|
||||||
var members = GetAllMembers(_type);
|
var mapper = Mapper.DynamicMapperCache.GetMapper<T>();
|
||||||
|
|
||||||
_properties = members
|
_properties = mapper
|
||||||
.Where(x => x is PropertyInfo)
|
.ColumnsMap
|
||||||
.ToDictionary(
|
.ToDictionary(
|
||||||
k => k.Name,
|
k => k.Value.Name,
|
||||||
v => new DynamicPropertyInvoker((PropertyInfo)v, null));
|
v => v.Value);
|
||||||
|
|
||||||
_methods = members
|
_methods = GetAllMembers(_type)
|
||||||
.Where(x => x is MethodInfo)
|
.Where(x => x is MethodInfo)
|
||||||
.Cast<MethodInfo>()
|
.Cast<MethodInfo>()
|
||||||
.Where(m => !((m.Name.StartsWith("set_") && m.ReturnType == typeof(void)) || m.Name.StartsWith("get_")))
|
.Where(m => !((m.Name.StartsWith("set_") && m.ReturnType == typeof(void)) || m.Name.StartsWith("get_")))
|
||||||
@@ -10286,6 +10521,21 @@ namespace DynamORM
|
|||||||
|
|
||||||
return type.GetMembers(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance);
|
return type.GetMembers(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Performs application-defined tasks associated with
|
||||||
|
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
object res;
|
||||||
|
TryInvokeMethod("Dispose", out res, new object[] { });
|
||||||
|
|
||||||
|
_properties.Clear();
|
||||||
|
|
||||||
|
_methods = null;
|
||||||
|
_properties = null;
|
||||||
|
_type = null;
|
||||||
|
_proxy = default(T);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10654,7 +10904,7 @@ namespace DynamORM
|
|||||||
var propertyMap = new Dictionary<string, string>();
|
var propertyMap = new Dictionary<string, string>();
|
||||||
var ignored = new List<string>();
|
var ignored = new List<string>();
|
||||||
|
|
||||||
foreach (var pi in Type.GetProperties())
|
foreach (var pi in GetAllMembers(Type).Where(x => x is PropertyInfo).Cast<PropertyInfo>())
|
||||||
{
|
{
|
||||||
ColumnAttribute attr = null;
|
ColumnAttribute attr = null;
|
||||||
|
|
||||||
@@ -10714,6 +10964,46 @@ namespace DynamORM
|
|||||||
return destination;
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerable<MemberInfo> GetAllMembers(Type type)
|
||||||
|
{
|
||||||
|
if (type.IsInterface)
|
||||||
|
{
|
||||||
|
var members = new List<MemberInfo>();
|
||||||
|
|
||||||
|
var considered = new List<Type>();
|
||||||
|
var queue = new Queue<Type>();
|
||||||
|
|
||||||
|
considered.Add(type);
|
||||||
|
queue.Enqueue(type);
|
||||||
|
|
||||||
|
while (queue.Count > 0)
|
||||||
|
{
|
||||||
|
var subType = queue.Dequeue();
|
||||||
|
foreach (var subInterface in subType.GetInterfaces())
|
||||||
|
{
|
||||||
|
if (considered.Contains(subInterface)) continue;
|
||||||
|
|
||||||
|
considered.Add(subInterface);
|
||||||
|
queue.Enqueue(subInterface);
|
||||||
|
}
|
||||||
|
|
||||||
|
var typeProperties = subType.GetMembers(
|
||||||
|
BindingFlags.FlattenHierarchy
|
||||||
|
| BindingFlags.Public
|
||||||
|
| BindingFlags.Instance);
|
||||||
|
|
||||||
|
var newPropertyInfos = typeProperties
|
||||||
|
.Where(x => !members.Contains(x));
|
||||||
|
|
||||||
|
members.InsertRange(0, newPropertyInfos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return members;
|
||||||
|
}
|
||||||
|
|
||||||
|
return type.GetMembers(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance);
|
||||||
|
}
|
||||||
|
|
||||||
#region Type command cache
|
#region Type command cache
|
||||||
|
|
||||||
internal string InsertCommandText { get; set; }
|
internal string InsertCommandText { get; set; }
|
||||||
|
|||||||
@@ -67,9 +67,7 @@ namespace DynamORM.Helpers.Dynamics
|
|||||||
k => k.Value.Name,
|
k => k.Value.Name,
|
||||||
v => v.Value);
|
v => v.Value);
|
||||||
|
|
||||||
_methods = mapper.MethodsMap;
|
_methods = GetAllMembers(_type)
|
||||||
|
|
||||||
/*GetAllMembers(_type)
|
|
||||||
.Where(x => x is MethodInfo)
|
.Where(x => x is MethodInfo)
|
||||||
.Cast<MethodInfo>()
|
.Cast<MethodInfo>()
|
||||||
.Where(m => !((m.Name.StartsWith("set_") && m.ReturnType == typeof(void)) || m.Name.StartsWith("get_")))
|
.Where(m => !((m.Name.StartsWith("set_") && m.ReturnType == typeof(void)) || m.Name.StartsWith("get_")))
|
||||||
@@ -86,7 +84,7 @@ namespace DynamORM.Helpers.Dynamics
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});*/
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Provides implementation for type conversion operations.
|
/// <summary>Provides implementation for type conversion operations.
|
||||||
@@ -238,7 +236,7 @@ namespace DynamORM.Helpers.Dynamics
|
|||||||
|
|
||||||
if (d != null)
|
if (d != null)
|
||||||
{
|
{
|
||||||
result = d.DynamicInvoke(CompleteArguments(mi.GetParameters().ToArray(), args).ToArray());
|
result = d.DynamicInvoke(CompleteArguments(mi.GetParameters().ToArray(), args));
|
||||||
|
|
||||||
if (d.Method.ReturnType == _type && result is T)
|
if (d.Method.ReturnType == _type && result is T)
|
||||||
result = new DynamicProxy<T>((T)result);
|
result = new DynamicProxy<T>((T)result);
|
||||||
@@ -247,7 +245,7 @@ namespace DynamORM.Helpers.Dynamics
|
|||||||
}
|
}
|
||||||
else if (mi != null)
|
else if (mi != null)
|
||||||
{
|
{
|
||||||
result = mi.Invoke(_proxy, CompleteArguments(mi.GetParameters().ToArray(), args).Skip(1).ToArray());
|
result = mi.Invoke(_proxy, CompleteArguments(mi.GetParameters().ToArray(), args));
|
||||||
|
|
||||||
if (mi.ReturnType == _type && result is T)
|
if (mi.ReturnType == _type && result is T)
|
||||||
result = new DynamicProxy<T>((T)result);
|
result = new DynamicProxy<T>((T)result);
|
||||||
@@ -270,9 +268,9 @@ namespace DynamORM.Helpers.Dynamics
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<object> CompleteArguments(ParameterInfo[] parameters, object[] arguments)
|
private object[] CompleteArguments(ParameterInfo[] parameters, object[] arguments)
|
||||||
{
|
{
|
||||||
return new object[] { _proxy }.Union(arguments.Concat(parameters.Skip(arguments.Length).Select(p => p.DefaultValue)));
|
return arguments.Concat(parameters.Skip(arguments.Length).Select(p => p.DefaultValue)).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<MemberInfo> GetAllMembers(Type type)
|
private IEnumerable<MemberInfo> GetAllMembers(Type type)
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ namespace DynamORM.Mapper
|
|||||||
/// <summary>Represents type columnMap.</summary>
|
/// <summary>Represents type columnMap.</summary>
|
||||||
public class DynamicTypeMap
|
public class DynamicTypeMap
|
||||||
{
|
{
|
||||||
private Dictionary<MethodInfo, Delegate> _methods = null;
|
|
||||||
|
|
||||||
/// <summary>Gets mapper destination type creator.</summary>
|
/// <summary>Gets mapper destination type creator.</summary>
|
||||||
public Type Type { get; private set; }
|
public Type Type { get; private set; }
|
||||||
|
|
||||||
@@ -52,17 +50,6 @@ namespace DynamORM.Mapper
|
|||||||
/// <remarks>Key: Column name (lower), Value: <see cref="DynamicPropertyInvoker"/>.</remarks>
|
/// <remarks>Key: Column name (lower), Value: <see cref="DynamicPropertyInvoker"/>.</remarks>
|
||||||
public Dictionary<string, DynamicPropertyInvoker> ColumnsMap { get; private set; }
|
public Dictionary<string, DynamicPropertyInvoker> ColumnsMap { get; private set; }
|
||||||
|
|
||||||
/// <summary>Gets map of methods to open instance delegates.</summary>
|
|
||||||
public Dictionary<MethodInfo, Delegate> MethodsMap
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_methods == null)
|
|
||||||
_methods = CreateMethodToDelegateMap();
|
|
||||||
return _methods;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Gets map of properties to column.</summary>
|
/// <summary>Gets map of properties to column.</summary>
|
||||||
/// <remarks>Key: Property name, Value: Column name.</remarks>
|
/// <remarks>Key: Property name, Value: Column name.</remarks>
|
||||||
public Dictionary<string, string> PropertyMap { get; private set; }
|
public Dictionary<string, string> PropertyMap { get; private set; }
|
||||||
@@ -85,29 +72,6 @@ namespace DynamORM.Mapper
|
|||||||
CreateColumnAndPropertyMap();
|
CreateColumnAndPropertyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<MethodInfo, Delegate> CreateMethodToDelegateMap()
|
|
||||||
{
|
|
||||||
return GetAllMembers(Type)
|
|
||||||
.Where(x => x is MethodInfo)
|
|
||||||
.Cast<MethodInfo>()
|
|
||||||
.Where(m => !((m.Name.StartsWith("set_") && m.ReturnType == typeof(void)) || m.Name.StartsWith("get_")))
|
|
||||||
.Where(m => !m.IsStatic && !m.IsGenericMethod)
|
|
||||||
.ToDictionary(
|
|
||||||
k => k,
|
|
||||||
v =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return Delegate.CreateDelegate(Expression.GetDelegateType(new Type[] { v.DeclaringType }.Union(v.GetParameters().Select(t => t.ParameterType).Concat(new[] { v.ReflectedType })).ToArray()), v);
|
|
||||||
////return Delegate.CreateDelegate(Expression.GetDelegateType(v.GetParameters().Select(t => t.ParameterType).Concat(new[] { v.ReflectedType }).ToArray()), _proxy, v.Name);
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateColumnAndPropertyMap()
|
private void CreateColumnAndPropertyMap()
|
||||||
{
|
{
|
||||||
var columnMap = new Dictionary<string, DynamicPropertyInvoker>();
|
var columnMap = new Dictionary<string, DynamicPropertyInvoker>();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using DynamORM.Mapper;
|
using DynamORM.Mapper;
|
||||||
|
|
||||||
namespace Tester
|
namespace Tester
|
||||||
@@ -41,28 +42,34 @@ namespace Tester
|
|||||||
while (Console.In.ReadLine() != "q")
|
while (Console.In.ReadLine() != "q")
|
||||||
{
|
{
|
||||||
Console.Out.WriteLine("Bombardment...");
|
Console.Out.WriteLine("Bombardment...");
|
||||||
using (var db = GetORM())
|
BombsAway();
|
||||||
for (int i = 0; i < 1000; i++)
|
|
||||||
{
|
|
||||||
//var session = db.From(x => x.mom_Sessions.As(x.s))
|
|
||||||
// .Where(s => s.ms_id == Guid.Empty && s.ms_mus_id == Guid.Empty)
|
|
||||||
// .Execute<Session>()
|
|
||||||
// .FirstOrDefault();
|
|
||||||
//var session = db.From(x => x.mom_Sessions.As(x.s))
|
|
||||||
// .Where(s => s.ms_id == Guid.Empty && s.ms_mus_id == Guid.Empty)
|
|
||||||
// .Execute()
|
|
||||||
// .FirstOrDefault();
|
|
||||||
|
|
||||||
db.Delete(x => x.mom_Sessions)
|
|
||||||
.Where(s => s.ms_id == Guid.Empty && s.ms_mus_id == Guid.Empty)
|
|
||||||
.Execute();
|
|
||||||
|
|
||||||
//var session = (db.Table().Query("SELECT * FROM mom_Sessions WHERE ms_id = @0 AND ms_mus_id = @1", Guid.Empty, Guid.Empty)
|
|
||||||
// as IEnumerable<dynamic>).FirstOrDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.Out.WriteLine("Done.");
|
Console.Out.WriteLine("Done.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void BombsAway()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 1000; i++)
|
||||||
|
using (var db = GetORM())
|
||||||
|
{
|
||||||
|
//var session = db.From(x => x.mom_Sessions.As(x.s))
|
||||||
|
// .Where(s => s.ms_id == Guid.Empty && s.ms_mus_id == Guid.Empty)
|
||||||
|
// .Execute<Session>()
|
||||||
|
// .FirstOrDefault();
|
||||||
|
var session = db.From(x => x.mom_Sessions.As(x.s))
|
||||||
|
.Where(s => s.ms_id == Guid.Empty && s.ms_mus_id == Guid.Empty)
|
||||||
|
.Execute()
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
//db.Table("mom_Sessions").Delete()
|
||||||
|
// .Where("ms_id", Guid.Empty)
|
||||||
|
// .Where("ms_mus_id", Guid.Empty)
|
||||||
|
// .Execute();
|
||||||
|
|
||||||
|
//var session = (db.Table().Query("SELECT * FROM mom_Sessions WHERE ms_id = @0 AND ms_mus_id = @1", Guid.Empty, Guid.Empty)
|
||||||
|
// as IEnumerable<dynamic>).FirstOrDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user