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.Adapter, table.GetQualifiedName()).Where(criteria); //var data = dataStrategy.Find(table.GetQualifiedName(), criteria); //return CreateSimpleResultSet(table, dataStrategy, 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; } }
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)); }
private static object InsertEntity(object entity, DataStrategy dataStrategy, string tableName, ErrorCallback onError, bool resultRequired) { var dictionary = entity as IDictionary<string, object>; if (dictionary != null) return dataStrategy.Insert(tableName, dictionary, resultRequired); var list = entity as IEnumerable<IDictionary<string, object>>; if (list != null) return dataStrategy.InsertMany(tableName, list, onError, resultRequired); var entityList = entity as IEnumerable; if (entityList != null) { var array = entityList.Cast<object>().ToArray(); var rows = new List<IDictionary<string, object>>(); foreach (var o in array) { dictionary = (o as IDictionary<string, object>) ?? o.ObjectToDictionary(); if (dictionary.Count == 0) { throw new SimpleDataException("Could not discover data in object."); } rows.Add(dictionary); } return dataStrategy.InsertMany(tableName, rows, onError, resultRequired); } dictionary = entity.ObjectToDictionary(); if (dictionary.Count == 0) throw new SimpleDataException("Could not discover data in object."); return dataStrategy.Insert(tableName, dictionary, resultRequired); }
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; } }
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); } }
public async Task <IEnumerable <CurrencyParams> > GetData <T>(T path) { try { var data = new DataStrategy <T>(path); return(await data.GetData <BankJSON, CurrencyParams>()); } catch (ArgumentException e) { MessageBox.Show(e.Message, "ArgumentException", MessageBoxButton.OK, MessageBoxImage.Error); return(null); } catch (InvalidOperationException e) { MessageBox.Show(e.Message, "InvalidOperationException", MessageBoxButton.OK, MessageBoxImage.Error); return(null); } catch (AggregateException e) { MessageBox.Show(e.InnerException.Message, "AggregateException", MessageBoxButton.OK, MessageBoxImage.Error); return(null); } catch (Exception e) { MessageBox.Show(e.Message, "Exception", MessageBoxButton.OK, MessageBoxImage.Error); return(null); } }
public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args) { var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args)); var data = dataStrategy.FindOne(table.GetQualifiedName(), criteriaExpression); return(data != null ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy) : null); }
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; } }
internal static object UpdateByKeyFields(string tableName, DataStrategy dataStrategy, object entity, IEnumerable<string> keyFieldNames) { var record = ObjectToDictionary(entity); var criteria = GetCriteria(keyFieldNames, record); var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(tableName, criteria); return dataStrategy.Update(tableName, record, criteriaExpression); }
public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args) { var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args)); var data = dataStrategy.Find(table.GetQualifiedName(), criteria); return(CreateSimpleResultSet(table, dataStrategy, data)); }
public ExecuteFunctionCommand(DataStrategy database, IAdapterWithFunctions adapter, string functionName, IDictionary<string, object> arguments) { _database = database; _adapter = adapter; _functionName = functionName; _arguments = arguments; }
public ExecuteFunctionCommand(DataStrategy database, IAdapterWithFunctions adapter, string functionName, IDictionary<string, object> arguments) { _database = database; _adapter = adapter; _functionName = functionName; _arguments = arguments; }
public object Execute(DataStrategy dataStrategy, SimpleQuery query, InvokeMemberBinder binder, object[] args) { var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(query.TableName, CreateCriteriaDictionary(binder, args)); query = query.Where(criteriaExpression).Take(1); return query.FirstOrDefault(); }
public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args) { var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), CreateCriteriaDictionary(binder, args)); var data = dataStrategy.Run.FindOne(table.GetQualifiedName(), criteriaExpression); return data != null ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy) : null; }
public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args) { var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args)); var data = dataStrategy.Find(table.GetQualifiedName(), criteria); return new SimpleResultSet(data != null ? data.Select(dict => new SimpleRecord(dict, table.GetQualifiedName(), dataStrategy)) : Enumerable.Empty<SimpleRecord>()); }
/// <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 criteriaDictionary = ArgumentHelper.CreateCriteriaDictionary(binder, args, "ExistsBy", "exists_by", "AnyBy", "any_by"); if (criteriaDictionary == null) return null; var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteriaDictionary); return new SimpleQuery(dataStrategy, table.GetQualifiedName()).Where(criteria).Exists(); }
private static object DoInsert(InvokeMemberBinder binder, object[] args, DataStrategy dataStrategy, string tableName) { return(binder.HasSingleUnnamedArgument() ? InsertEntity(args[0], dataStrategy, tableName) : InsertDictionary(binder, args, dataStrategy, tableName)); }
internal static object UpdateByKeyFields(string tableName, DataStrategy dataStrategy, object entity, IEnumerable <string> keyFieldNames) { var record = ObjectToDictionary(entity); var criteria = GetCriteria(keyFieldNames, record); var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(tableName, criteria); return(dataStrategy.Update(tableName, record, criteriaExpression)); }
private static IDictionary<string, object> DoInsert(InvokeMemberBinder binder, object[] args, DataStrategy dataStrategy, string tableName) { return binder.HasSingleUnnamedArgument() ? InsertEntity(args[0], dataStrategy, tableName) : InsertDictionary(binder, args, dataStrategy, tableName); }
public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args) { var result = dataStrategy.Run.Get(table.GetName(), args); if (result == null || result.Count == 0) return null; return binder.Name.Equals("get", StringComparison.OrdinalIgnoreCase) ? new SimpleRecord(result, table.GetQualifiedName(), dataStrategy) : result.First().Value; }
public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args) { var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args)); var data = dataStrategy.Find(table.GetQualifiedName(), criteria); return(new SimpleResultSet(data != null ? data.Where(dict => dict != null).Select(dict => new SimpleRecord(dict, table.GetQualifiedName(), dataStrategy)) : Enumerable.Empty <SimpleRecord>())); }
/// <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, table.GetQualifiedName()).Where((SimpleExpression)args[0])); } throw new BadExpressionException("FindAll only accepts a criteria expression."); }
/// <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.Adapter, table.GetQualifiedName()).Where((SimpleExpression)args[0])); } return(null); }
public object Execute(DataStrategy dataStrategy, SimpleQuery query, InvokeMemberBinder binder, object[] args) { var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(query.TableName, CreateCriteriaDictionary(binder, args)); query = query.Where(criteriaExpression).Take(1); return(query.FirstOrDefault()); }
/// <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, table.GetQualifiedName()).Where((SimpleExpression)args[0]); } return null; }
/// <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, table.GetQualifiedName()).Where((SimpleExpression)args[0]); } throw new BadExpressionException("FindAll only accepts a criteria expression."); }
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.UpdateMany(table.GetQualifiedName(), list); var dict = record as IDictionary<string, object>; return dataStrategy.Update(table.GetQualifiedName(), dict); }
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; }
/// <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) { var data = dataStrategy.Find(table.GetQualifiedName(), (SimpleExpression)args[0]).FirstOrDefault(); return(data != null ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy) : null); } return(null); }
public static object TypeResult(object result, DynamicTable table, DataStrategy dataStrategy) { var dictionary = result as IDictionary<string, object>; if (dictionary != null) return dictionary.ToDynamicRecord(table.GetQualifiedName(), dataStrategy); var list = result as IEnumerable<IDictionary<string, object>>; if (list != null) return new SimpleResultSet(list.Select(d => d.ToDynamicRecord(table.GetQualifiedName(), dataStrategy))); return null; }
public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args) { var criteria = args.OfType<SimpleExpression>().SingleOrDefault() ?? new SimpleEmptyExpression(); var data = binder.NamedArgumentsToDictionary(args).Where(kv=>!(kv.Value is SimpleExpression)).ToDictionary(); var updatedCount = dataStrategy.Update(table.GetQualifiedName(), data, criteria); return updatedCount.ResultSetFromModifiedRowCount(); }
/// <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) { var data = dataStrategy.Run.FindOne(table.GetQualifiedName(), (SimpleExpression)args[0]); return(data != null ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy) : null); } throw new BadExpressionException("Find only accepts a criteria expression."); }
/// <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) { var data = dataStrategy.Run.FindOne(table.GetQualifiedName(), (SimpleExpression)args[0]); return data != null ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy) : null; } throw new BadExpressionException("Find only accepts a criteria expression."); }
/// <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) { var data = dataStrategy.FindOne(table.GetQualifiedName(), (SimpleExpression)args[0]); return data != null ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy) : null; } return null; }
/// <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 query = new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName()); if (args.Length == 1 && args[0] is SimpleExpression) { query = query.Where((SimpleExpression)args[0]); } return query.Count(); }
private static IDictionary<string,object> InsertEntity(object entity, DataStrategy dataStrategy, string tableName) { var dictionary = entity as IDictionary<string, object>; if (dictionary == null) { dictionary = ObjectEx.ObjectToDictionary(entity); if (dictionary.Count == 0) throw new SimpleDataException("Could not discover data in object."); } return dataStrategy.Insert(tableName, dictionary); }
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 record = ObjectToDictionary(args[0]); var list = record as IList<IDictionary<string, object>>; if (list != null) return dataStrategy.UpdateMany(table.GetQualifiedName(), list); var dict = record as IDictionary<string, object>; return dataStrategy.Update(table.GetQualifiedName(), dict); }
public AutoCompleter(DataStrategy database) { if (database != null) { var adoAdapter = database.GetAdapter() as AdoAdapter; if (adoAdapter != null) { _schemaProvider = adoAdapter.SchemaProvider; } } }
/// <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 query = new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName()); if (args.Length == 1 && args[0] is SimpleExpression) { query = query.Where((SimpleExpression)args[0]); } return(query.Count()); }
public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args) { if (args.Length == 0 || args.Length > 2) throw new ArgumentException("Incorrect number of arguments to Update method."); if (args.Length == 1) { return UpdateUsingKeys(dataStrategy, table, args); } return UpdateUsingOriginalValues(dataStrategy, table, args); }
internal static object UpdateByKeyFields(string tableName, DataStrategy dataStrategy, object entity, IEnumerable<string> keyFieldNames) { var record = ObjectToDictionary(entity); var list = record as IList<IDictionary<string, object>>; if (list != null) return dataStrategy.UpdateMany(tableName, list, keyFieldNames.ToList()); var dict = record as IDictionary<string, object>; var criteria = GetCriteria(keyFieldNames, dict); var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(tableName, criteria); return dataStrategy.Update(tableName, dict, criteriaExpression); }
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.Adapter.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); }
public AutoCompleter(DataStrategy database) { if (database != null) { var adoAdapter = database.GetAdapter() as AdoAdapter; if (adoAdapter != null) { _schemaProvider = adoAdapter.SchemaProvider; } } }
internal static object UpsertByKeyFields(string tableName, DataStrategy dataStrategy, object entity, IEnumerable<string> keyFieldNames, bool isResultRequired, ErrorCallback errorCallback) { var record = UpdateCommand.ObjectToDictionary(entity); var list = record as IList<IDictionary<string, object>>; if (list != null) return dataStrategy.UpsertMany(tableName, list, keyFieldNames, isResultRequired, errorCallback); var dict = record as IDictionary<string, object>; var criteria = GetCriteria(keyFieldNames, dict); var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(tableName, criteria); return dataStrategy.Upsert(tableName, dict, criteriaExpression, isResultRequired); }
public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args) { SimpleExpression criteriaExpression = null; if (args.Length == 1 && args[0] is SimpleExpression) { criteriaExpression = args[0] as SimpleExpression; } var columName = binder.Name.Substring(3); var data = dataStrategy.Max(table.GetQualifiedName(), columName, criteriaExpression); return 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) { if (args.Length == 1 && args[0] is SimpleExpression) { var data = dataStrategy.Find(table.GetQualifiedName(), (SimpleExpression)args[0]); return(new SimpleResultSet(data != null ? data.Select(dict => new SimpleRecord(dict, table.GetQualifiedName(), dataStrategy)) : Enumerable.Empty <SimpleRecord>())); } return(null); }
public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args) { var result = dataStrategy.Run.Get(table.GetName(), args); if (result == null || result.Count == 0) { return(null); } return(binder.Name.Equals("get", StringComparison.OrdinalIgnoreCase) ? new SimpleRecord(result, table.GetQualifiedName(), dataStrategy) : result.First().Value); }
/// <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 criteriaDictionary = ArgumentHelper.CreateCriteriaDictionary(binder, args, "ExistsBy", "exists_by", "AnyBy", "any_by"); if (criteriaDictionary == null) { return(null); } var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteriaDictionary); return(new SimpleQuery(dataStrategy, table.GetQualifiedName()).Where(criteria).Exists()); }
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; }); }
/// <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) { if (binder.Name.Equals("GetCountBy") || binder.Name.Equals("get_count_by")) { ArgumentHelper.CheckFindArgs(args, binder); } var criteriaDictionary = ArgumentHelper.CreateCriteriaDictionary(binder, args, "GetCountBy", "get_count_by"); var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteriaDictionary); return(new SimpleQuery(dataStrategy, table.GetQualifiedName()).Where(criteria).Count()); }
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); }
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)); }
public Func <object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args) { var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args)); try { var func = dataStrategy.Adapter.CreateFindOneDelegate(table.GetQualifiedName(), criteriaExpression); return(a => new SimpleRecord(func(a), table.GetQualifiedName(), dataStrategy)); } catch (NotImplementedException) { return(null); } }
public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args) { if (args.Length == 0 || args.Length > 2) { throw new ArgumentException("Incorrect number of arguments to Update method."); } if (args.Length == 1) { return(UpdateUsingKeys(dataStrategy, table, args)); } return(UpdateUsingOriginalValues(dataStrategy, table, args)); }
public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args) { SimpleExpression criteriaExpression = null; if (args.Length == 1 && args[0] is SimpleExpression) { criteriaExpression = args[0] as SimpleExpression; } var columName = binder.Name.Substring(3); var data = dataStrategy.Max(table.GetQualifiedName(), columName, criteriaExpression); return(data); }
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.UpdateMany(table.GetQualifiedName(), list)); } var dict = record as IDictionary <string, object>; return(dataStrategy.Update(table.GetQualifiedName(), dict)); }
private static IDictionary <string, object> InsertEntity(object entity, DataStrategy dataStrategy, string tableName) { var dictionary = entity as IDictionary <string, object>; if (dictionary == null) { dictionary = ObjectEx.ObjectToDictionary(entity); if (dictionary.Count == 0) { throw new SimpleDataException("Could not discover data in object."); } } return(dataStrategy.Insert(tableName, dictionary)); }
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.Adapter.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)); }
internal static object UpdateByKeyFields(string tableName, DataStrategy dataStrategy, object entity, IEnumerable <string> keyFieldNames) { var record = UpdateCommand.ObjectToDictionary(entity); var list = record as IList <IDictionary <string, object> >; if (list != null) { return(dataStrategy.UpdateMany(tableName, list, keyFieldNames)); } var dict = record as IDictionary <string, object>; var criteria = GetCriteria(keyFieldNames, dict); var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(tableName, criteria); return(dataStrategy.Update(tableName, dict, criteriaExpression)); }