Beispiel #1
0
        public override IDataReader ExecuteReader(ServiceCursorDef cursorDef, IDataParameterCollection parms, CommandBehavior behavior)
        {
            Initialize();
            Query query = cursorDef.Query as Query;
            Dictionary <string, AttributeValue> valuesAux = new Dictionary <string, AttributeValue>();
            Dictionary <string, AttributeValue> values    = new Dictionary <string, AttributeValue>();

            if (parms.Count > 0)
            {
                for (int i = 0; i < parms.Count; i++)
                {
                    ServiceParameter parm = parms[i] as ServiceParameter;
                    DynamoDBHelper.GXToDynamoQueryParameter(":", values, parm);
                }
            }

            List <string> filtersAux = new List <string>();
            List <string> filters    = new List <string>();

            filters.AddRange(query.Filters);

            foreach (var item in query.Vars)
            {
                values.Add(item.Name, DynamoDBHelper.ToAttributeValue(item));
            }

            try
            {
                DynamoDBDataReader    dataReader;
                AmazonDynamoDBRequest req;
                CreateDynamoQuery(query, values, filters.ToArray(), out dataReader, out req);
                RequestWrapper reqWrapper = new RequestWrapper(mDynamoDB, req);
                dataReader = new DynamoDBDataReader(cursorDef, reqWrapper, parms);
                return(dataReader);
            }
            catch (AmazonDynamoDBException e) { throw e; }
            catch (AmazonServiceException e) { throw e; }
            catch (Exception e) { throw e; }
        }
Beispiel #2
0
        public override int ExecuteNonQuery(ServiceCursorDef cursorDef, IDataParameterCollection parms, CommandBehavior behavior)
        {
            Initialize();
            Query query = cursorDef.Query as Query;

            Dictionary <string, AttributeValue> values = new Dictionary <string, AttributeValue>();

            if (parms.Count > 0)
            {
                for (int i = 0; i < parms.Count; i++)
                {
                    ServiceParameter parm = parms[i] as ServiceParameter;
                    DynamoDBHelper.GXToDynamoQueryParameter("", values, parm);
                }
            }
            var pattern = @"\((.*) = :(.*)\)";
            Dictionary <string, AttributeValue> keyCondition = new Dictionary <string, AttributeValue>();
            List <string> filters = new List <string>();

            foreach (var keyFilter in query.Filters)
            {
                var    match   = Regex.Match(keyFilter, pattern);
                String varName = match.Groups[2].Value;
                if (match.Groups.Count > 1)
                {
                    keyCondition[match.Groups[1].Value] = values[varName];
                }
            }
            AmazonDynamoDBRequest request = null;

            switch (query.CursorType)
            {
            case ServiceCursorDef.CursorType.Select:
                throw new NotImplementedException();

            case ServiceCursorDef.CursorType.Delete:
                request = new DeleteItemRequest()
                {
                    TableName = query.TableName,
                    Key       = keyCondition
                };
                mDynamoDB.DeleteItem((DeleteItemRequest)request);

                break;

            case ServiceCursorDef.CursorType.Insert:
                request = new PutItemRequest
                {
                    TableName = query.TableName,
                    Item      = values
                };
                mDynamoDB.PutItem((PutItemRequest)request);
                break;

            case ServiceCursorDef.CursorType.Update:
                request = new UpdateItemRequest
                {
                    TableName        = query.TableName,
                    Key              = keyCondition,
                    AttributeUpdates = ToAttributeUpdates(keyCondition, values)
                };
                mDynamoDB.UpdateItem((UpdateItemRequest)request);
                break;

            default:
                break;
            }

            return(0);
        }
Beispiel #3
0
 public abstract int ExecuteNonQuery(ServiceCursorDef cursorDef, IDataParameterCollection parms, CommandBehavior behavior);
Beispiel #4
0
 public abstract IDataReader ExecuteReader(ServiceCursorDef cursorDef, IDataParameterCollection parms, CommandBehavior behavior);