コード例 #1
0
ファイル: GetCommand.cs プロジェクト: rposbo/Simple.Data
 public Func<object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
 {
     var func = dataStrategy.GetAdapter().OptimizingDelegateFactory.CreateGetDelegate(dataStrategy.GetAdapter(),
                                                                                  table.GetName(), args);
         return a =>
                    {
                        var data = func(a);
                        return (data != null && data.Count > 0)
                                   ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy)
                                   : null;
                    };
 }
コード例 #2
0
ファイル: FindByCommand.cs プロジェクト: hlach/Simple.Data
        public Func<object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            if (dataStrategy is SimpleTransaction) return null;

            var criteriaDictionary = CreateCriteriaDictionary(binder, args);
            if (criteriaDictionary == null) return null;

            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteriaDictionary);
            try
            {
                var adapter = dataStrategy.GetAdapter();
                var func = adapter.OptimizingDelegateFactory.CreateFindOneDelegate(adapter, table.GetQualifiedName(), criteriaExpression);
                return a =>
                           {
                               var data = func(a);
                               return (data != null && data.Count > 0)
                                          ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy)
                                          : null;
                           };
            }
            catch (NotImplementedException)
            {
                return null;
            }
        }
コード例 #3
0
        public Func<object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            if (dataStrategy is SimpleTransaction) return null;

            if (binder.Name.Equals("FindBy") || binder.Name.Equals("find_by"))
            {
                ArgumentHelper.CheckFindArgs(args, binder);
                if (args.Length == 1 && args[0].IsAnonymous()) return null;
            }

            var criteriaDictionary = ArgumentHelper.CreateCriteriaDictionary(binder, args, "FindBy", "find_by");
            if (criteriaDictionary == null) return null;

            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteriaDictionary);
            try
            {
                var adapter = dataStrategy.GetAdapter();
                var func = adapter.OptimizingDelegateFactory.CreateFindOneDelegate(adapter, table.GetQualifiedName(), criteriaExpression);
                return a =>
                           {
                               var data = func(a);
                               return (data != null && data.Count > 0)
                                          ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy)
                                          : null;
                           };
            }
            catch (NotImplementedException)
            {
                return null;
            }
        }
コード例 #4
0
        private static object UpsertUsingKeys(DataStrategy dataStrategy, DynamicTable table, object[] args, bool isResultRequired)
        {
            var record = ObjectToDictionary(args[0]);
            var list   = record as IList <IDictionary <string, object> >;

            if (list != null)
            {
                ErrorCallback errorCallback = (args.Length == 2 ? args[1] as ErrorCallback : null) ??
                                              ((item, exception) => false);
                return(dataStrategy.Run.UpsertMany(table.GetQualifiedName(), list, isResultRequired, errorCallback));
            }

            var dict = record as IDictionary <string, object>;

            if (dict == null)
            {
                throw new InvalidOperationException("Could not resolve data from passed object.");
            }
            var key = dataStrategy.GetAdapter().GetKey(table.GetQualifiedName(), dict);

            if (key == null)
            {
                throw new InvalidOperationException(string.Format("No key columns defined for table \"{0}\"", table.GetQualifiedName()));
            }
            if (key.Count == 0)
            {
                return(dataStrategy.Run.Insert(table.GetQualifiedName(), dict, isResultRequired));
            }
            var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), key);

            return(dataStrategy.Run.Upsert(table.GetQualifiedName(), dict, criteria, isResultRequired));
        }
コード例 #5
0
ファイル: FindByCommand.cs プロジェクト: kotsaris/Simple.Data
        public Func<object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            if (dataStrategy is SimpleTransaction) return null;

            if (binder.Name.Equals("FindBy") || binder.Name.Equals("find_by"))
            {
                if (args.Length == 0) throw new ArgumentException("FindBy requires arguments.");
                if (args.Length == 1)
                {
                    if (ReferenceEquals(args[0], null)) throw new ArgumentException("FindBy does not accept unnamed null argument.");
                    if (args[0].GetType().Namespace == null) return null;
                }
            }

            var criteriaDictionary = CreateCriteriaDictionary(binder, args);
            if (criteriaDictionary == null) return null;

            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteriaDictionary);
            try
            {
                var adapter = dataStrategy.GetAdapter();
                var func = adapter.OptimizingDelegateFactory.CreateFindOneDelegate(adapter, table.GetQualifiedName(), criteriaExpression);
                return a =>
                           {
                               var data = func(a);
                               return (data != null && data.Count > 0)
                                          ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy)
                                          : null;
                           };
            }
            catch (NotImplementedException)
            {
                return null;
            }
        }
コード例 #6
0
        public Func <object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            if (dataStrategy is SimpleTransaction)
            {
                return(null);
            }

            var criteriaDictionary = CreateCriteriaDictionary(binder, args);

            if (criteriaDictionary == null)
            {
                return(null);
            }

            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteriaDictionary);

            try
            {
                var adapter = dataStrategy.GetAdapter();
                var func    = adapter.OptimizingDelegateFactory.CreateFindOneDelegate(adapter, table.GetQualifiedName(), criteriaExpression);
                return(a =>
                {
                    var data = func(a);
                    return (data != null && data.Count > 0)
                                          ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy)
                                          : null;
                });
            }
            catch (NotImplementedException)
            {
                return(null);
            }
        }
コード例 #7
0
ファイル: GetCommand.cs プロジェクト: kotsaris/Simple.Data
 public object Execute(DataStrategy dataStrategy, SimpleQuery query, InvokeMemberBinder binder, object[] args)
 {
     var keyNames = dataStrategy.GetAdapter().GetKeyNames(query.TableName);
     var dict = keyNames.Select((k, i) => new KeyValuePair<string, object>(k, args[i]));
     query = query.Where(ExpressionHelper.CriteriaDictionaryToExpression(query.TableName, dict)).Take(1);
     var result = query.FirstOrDefault();
     if (result == null) return null;
     return binder.Name.Equals("get", StringComparison.OrdinalIgnoreCase) ? result : ((IDictionary<string, object>) result).First().Value;
 }
コード例 #8
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="dataStrategy">The database or transaction</param>
        /// <param name="table"></param>
        /// <param name="binder">The binder from the <see cref="DynamicTable"/> method invocation.</param>
        /// <param name="args">The arguments from the <see cref="DynamicTable"/> method invocation.</param>
        /// <returns></returns>
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            if (args.Length == 1 && args[0] is SimpleExpression)
            {
                return new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName()).Where((SimpleExpression)args[0]);
            }

            return null;
        }
コード例 #9
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="dataStrategy">The database or transaction</param>
        /// <param name="table"></param>
        /// <param name="binder">The binder from the <see cref="DynamicTable"/> method invocation.</param>
        /// <param name="args">The arguments from the <see cref="DynamicTable"/> method invocation.</param>
        /// <returns></returns>
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            if (args.Length == 1 && args[0] is SimpleExpression)
            {
                return(new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName()).Where((SimpleExpression)args[0]));
            }

            return(null);
        }
コード例 #10
0
 public AutoCompleter(DataStrategy database)
 {
     if (database != null)
     {
         var adoAdapter = database.GetAdapter() as AdoAdapter;
         if (adoAdapter != null)
         {
             _schemaProvider = adoAdapter.SchemaProvider;
         }
     }
 }
コード例 #11
0
 public AutoCompleter(DataStrategy database)
 {
     if (database != null)
     {
         var adoAdapter = database.GetAdapter() as AdoAdapter;
         if (adoAdapter != null)
         {
             _schemaProvider = adoAdapter.SchemaProvider;
         }
     }
 }
コード例 #12
0
ファイル: UpdateCommand.cs プロジェクト: vansha/Simple.Data
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            if (args.Length != 1) throw new ArgumentException("Incorrect number of arguments to Update method.");
            var keyFieldNames = dataStrategy.GetAdapter().GetKeyFieldNames(table.GetQualifiedName()).ToArray();
            if (keyFieldNames.Length == 0)
            {
                throw new NotSupportedException("Adapter does not support key-based update for this object.");
            }

            return UpdateByKeyFields(table.GetQualifiedName(), dataStrategy, args[0], keyFieldNames);
        }
コード例 #13
0
 public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
 {
     SimpleExpression criteriaExpression;
     if (binder.Name.Equals("FindAllBy") || binder.Name.Equals("find_all_by"))
     {
         criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), binder.NamedArgumentsToDictionary(args));
     }
     else
     {
         criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));
     }
     return new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName()).Where(criteriaExpression);
 }
コード例 #14
0
        public Func <object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            var func = dataStrategy.GetAdapter().OptimizingDelegateFactory.CreateGetDelegate(dataStrategy.GetAdapter(),
                                                                                             table.GetName(), args);

            return(a =>
            {
                var data = func(a);
                return (data != null && data.Count > 0)
                                          ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy)
                                          : null;
            });
        }
コード例 #15
0
        private static object UpdateUsingKeys(DataStrategy dataStrategy, DynamicTable table, object[] args)
        {
            var record = ObjectToDictionary(args[0]);
            var list = record as IList<IDictionary<string, object>>;
            if (list != null) return dataStrategy.Run.UpdateMany(table.GetQualifiedName(), list);

            var dict = record as IDictionary<string, object>;
            if (dict == null) throw new InvalidOperationException("Could not resolve data from passed object.");
            var key = dataStrategy.GetAdapter().GetKey(table.GetQualifiedName(), dict);
            dict = dict.Where(kvp => key.All(keyKvp => keyKvp.Key.Homogenize() != kvp.Key.Homogenize())).ToDictionary();
            var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), key);
            return dataStrategy.Run.Update(table.GetQualifiedName(), dict, criteria);
        }
コード例 #16
0
        public object Execute(DataStrategy dataStrategy, SimpleQuery query, InvokeMemberBinder binder, object[] args)
        {
            var keyNames = dataStrategy.GetAdapter().GetKeyNames(query.TableName);
            var dict     = keyNames.Select((k, i) => new KeyValuePair <string, object>(k, args[i]));

            query = query.Where(ExpressionHelper.CriteriaDictionaryToExpression(query.TableName, dict)).Take(1);
            var result = query.FirstOrDefault();

            if (result == null)
            {
                return(null);
            }
            return(binder.Name.Equals("get", StringComparison.OrdinalIgnoreCase) ? result : ((IDictionary <string, object>)result).First().Value);
        }
コード例 #17
0
 public Func<object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
 {
     throw new NotImplementedException();
     var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));
     try
     {
         var func = dataStrategy.GetAdapter().CreateFindDelegate(table.GetQualifiedName(), criteriaExpression);
         return a => CreateSimpleResultSet(table, dataStrategy, func(a));
     }
     catch (NotImplementedException)
     {
         return null;
     }
 }
コード例 #18
0
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            SimpleExpression criteriaExpression;

            if (binder.Name.Equals("FindAllBy") || binder.Name.Equals("find_all_by"))
            {
                criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), binder.NamedArgumentsToDictionary(args));
            }
            else
            {
                criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));
            }
            return(new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName()).Where(criteriaExpression));
        }
コード例 #19
0
ファイル: UpsertCommand.cs プロジェクト: remcok/Simple.Data
        private static object UpsertUsingKeys(DataStrategy dataStrategy, DynamicTable table, object[] args, bool isResultRequired)
        {
            var record = ObjectToDictionary(args[0]);
            var list = record as IList<IDictionary<string, object>>;
            if (list != null)
            {
                ErrorCallback errorCallback = (args.Length == 2 ? args[1] as ErrorCallback : null) ??
                 ((item, exception) => false);
                return dataStrategy.Run.UpsertMany(table.GetQualifiedName(), list, isResultRequired, errorCallback);
            }

            var dict = record as IDictionary<string, object>;
            if (dict == null) throw new InvalidOperationException("Could not resolve data from passed object.");
            var key = dataStrategy.GetAdapter().GetKey(table.GetQualifiedName(), dict);
            if (key == null) throw new InvalidOperationException(string.Format("No key columns defined for table \"{0}\"",table.GetQualifiedName()));
            var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), key);
            return dataStrategy.Run.Upsert(table.GetQualifiedName(), dict, criteria, isResultRequired);
        }
コード例 #20
0
        public Func <object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            if (dataStrategy is SimpleTransaction)
            {
                return(null);
            }

            if (binder.Name.Equals("FindBy") || binder.Name.Equals("find_by"))
            {
                ArgumentHelper.CheckFindArgs(args, binder);
                if (args.Length == 1 && args[0].IsAnonymous())
                {
                    return(null);
                }
            }

            var criteriaDictionary = ArgumentHelper.CreateCriteriaDictionary(binder, args, "FindBy", "find_by");

            if (criteriaDictionary == null)
            {
                return(null);
            }

            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteriaDictionary);

            try
            {
                var adapter = dataStrategy.GetAdapter();
                var func    = adapter.OptimizingDelegateFactory.CreateFindOneDelegate(adapter, table.GetQualifiedName(), criteriaExpression);
                return(a =>
                {
                    var data = func(a);
                    return (data != null && data.Count > 0)
                                          ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy)
                                          : null;
                });
            }
            catch (NotImplementedException)
            {
                return(null);
            }
        }
コード例 #21
0
        private static object UpdateUsingKeys(DataStrategy dataStrategy, DynamicTable table, object[] args)
        {
            var record = ObjectToDictionary(args[0]);
            var list   = record as IList <IDictionary <string, object> >;

            if (list != null)
            {
                return(dataStrategy.Run.UpdateMany(table.GetQualifiedName(), list));
            }

            var dict = record as IDictionary <string, object>;

            if (dict == null)
            {
                throw new InvalidOperationException("Could not resolve data from passed object.");
            }
            var key = dataStrategy.GetAdapter().GetKey(table.GetQualifiedName(), dict);

            dict = dict.Where(kvp => key.All(keyKvp => keyKvp.Key.Homogenize() != kvp.Key.Homogenize())).ToDictionary();
            var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), key);

            return(dataStrategy.Run.Update(table.GetQualifiedName(), dict, criteria));
        }
コード例 #22
0
ファイル: QueryByCommand.cs プロジェクト: moacap/Simple.Data
        private static object CreateSimpleQuery(DynamicTable table, InvokeMemberBinder binder, object[] args, DataStrategy dataStrategy)
        {
            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));

            return(new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName()).Where(criteriaExpression));
        }
コード例 #23
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="dataStrategy">The data strategy.</param>
        /// <param name="table"></param>
        /// <param name="binder">The binder from the <see cref="DynamicTable"/> method invocation.</param>
        /// <param name="args">The arguments from the <see cref="DynamicTable"/> method invocation.</param>
        /// <returns></returns>
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));

            return(new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName()).Where(criteria).Count());
        }
コード例 #24
0
 private static object CreateSimpleQuery(DynamicTable table, InvokeMemberBinder binder, object[] args, DataStrategy dataStrategy)
 {
     var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));
     return new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName()).Where(criteriaExpression);
 }
コード例 #25
0
ファイル: GetCommand.cs プロジェクト: rposbo/Simple.Data
 public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
 {
     return dataStrategy.GetAdapter().Get(table.GetName(), args);
 }
コード例 #26
0
 public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
 {
     return(dataStrategy.GetAdapter().Get(table.GetName(), args));
 }
コード例 #27
0
 public Func<object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
 {
     return a => new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName());
 }
コード例 #28
0
 public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
 {
     return new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName());
 }
コード例 #29
0
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="dataStrategy">The data strategy.</param>
 /// <param name="table"></param>
 /// <param name="binder">The binder from the <see cref="DynamicTable"/> method invocation.</param>
 /// <param name="args">The arguments from the <see cref="DynamicTable"/> method invocation.</param>
 /// <returns></returns>
 public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
 {
     var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));
     return new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName()).Where(criteria).Count();
 }
コード例 #30
0
ファイル: AllCommand.cs プロジェクト: vansha/Simple.Data
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="database">The database.</param>
 /// <param name="table"></param>
 /// <param name="binder">The binder from the <see cref="DynamicTable"/> method invocation.</param>
 /// <param name="args">The arguments from the <see cref="DynamicTable"/> method invocation.</param>
 /// <returns></returns>
 public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
 {
     return new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName());
     //return new SimpleResultSet(dataStrategy.Find(table.GetQualifiedName(), null)
     //    .Select(dict => new SimpleRecord(dict, table.GetQualifiedName(), dataStrategy)));
 }
コード例 #31
0
ファイル: QueryByCommand.cs プロジェクト: moacap/Simple.Data
 public Func <object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
 {
     return(a => new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName()));
 }
コード例 #32
0
ファイル: AllCommand.cs プロジェクト: moacap/Simple.Data
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="dataStrategy">The database or transaction.</param>
 /// <param name="table"></param>
 /// <param name="binder">The binder from the <see cref="DynamicTable"/> method invocation.</param>
 /// <param name="args">The arguments from the <see cref="DynamicTable"/> method invocation.</param>
 /// <returns></returns>
 public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
 {
     return(new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName()));
     //return new SimpleResultSet(dataStrategy.Find(table.GetQualifiedName(), null)
     //    .Select(dict => new SimpleRecord(dict, table.GetQualifiedName(), dataStrategy)));
 }
コード例 #33
0
ファイル: QueryByCommand.cs プロジェクト: moacap/Simple.Data
 public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
 {
     return(new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName()));
 }