public IRouteValue Generate(PredicateBetweenRightValue predicateRightValue, Column column, ParameterContext parameterContext)
        {
            IComparable betweenRouteValue = new ConditionValue(predicateRightValue.BetweenExpression, parameterContext).GetValue();
            IComparable andRouteValue     = new ConditionValue(predicateRightValue.AndExpression, parameterContext).GetValue();

            if (betweenRouteValue != null && andRouteValue != null)
            {
                return(new RangeRouteValue(column.Name, column.TableName, Range.Closed(betweenRouteValue, andRouteValue)));
            }
            var date = SPITimeService.GetInstance().GetTime();

            if (betweenRouteValue == null && ExpressionConditionUtils.IsNowExpression(predicateRightValue.BetweenExpression))
            {
                betweenRouteValue = date;
            }
            if (andRouteValue == null && ExpressionConditionUtils.IsNowExpression(predicateRightValue.AndExpression))
            {
                andRouteValue = date;
            }
            if (betweenRouteValue != null && andRouteValue != null)
            {
                return(new RangeRouteValue(column.Name, column.TableName, Range.Closed(betweenRouteValue, andRouteValue)));
            }
            return(null);
        }
        public IRouteValue Generate(PredicateInRightValue predicateRightValue, Column column, ParameterContext parameterContext)
        {
            ICollection <IComparable> routeValues = new LinkedList <IComparable>();
            SPITimeService            timeService = SPITimeService.GetInstance();

            foreach (var sqlExpression in predicateRightValue.SqlExpressions)
            {
                var routeValue = new ConditionValue(sqlExpression, parameterContext).GetValue();
                if (routeValue != null)
                {
                    routeValues.Add(routeValue);
                    continue;
                }
                if (ExpressionConditionUtils.IsNowExpression(sqlExpression))
                {
                    routeValues.Add(timeService.GetTime());
                }
            }
            return(routeValues.IsEmpty() ? null : new ListRouteValue(column.Name, column.TableName, routeValues));
        }
Exemplo n.º 3
0
        public IRouteValue Generate(PredicateCompareRightValue predicateRightValue, Column column, ParameterContext parameterContext)
        {
            string @operator = predicateRightValue.GetOperator();

            if (!IsSupportedOperator(@operator))
            {
                return(null);
            }
            IComparable routeValue = new ConditionValue(predicateRightValue.GetExpression(), parameterContext).GetValue();

            if (routeValue != null)
            {
                return(Generate(routeValue, column, @operator));
            }
            if (ExpressionConditionUtils.IsNowExpression(predicateRightValue.GetExpression()))
            {
                return(Generate(SPITimeService.GetInstance().GetTime(), column, @operator));
            }
            return(null);
        }
        private ShardingCondition CreateShardingCondition(string tableName, IEnumerator <string> columnNames,
                                                          InsertValueContext insertValueContext, ParameterContext parameterContext)
        {
            ShardingCondition result      = new ShardingCondition();
            SPITimeService    timeService = SPITimeService.GetInstance();


            foreach (var valueExpression in insertValueContext.GetValueExpressions())
            {
                string columnName = columnNames.Next();
                if (_shardingRule.IsShardingColumn(columnName, tableName))
                {
                    if (valueExpression is ISimpleExpressionSegment simpleExpressionSegment)
                    {
                        result.RouteValues.Add(new ListRouteValue(columnName, tableName,
                                                                  new List <IComparable>()
                        {
                            GetRouteValue(simpleExpressionSegment, parameterContext)
                        }));
                    }
                    else if (ExpressionConditionUtils.IsNowExpression(valueExpression))
                    {
                        result.RouteValues.Add(new ListRouteValue(columnName, tableName,
                                                                  new List <IComparable>()
                        {
                            timeService.GetTime()
                        }));
                    }
                    else if (ExpressionConditionUtils.IsNullExpression(valueExpression))
                    {
                        throw new ShardingException("Insert clause sharding column can't be null.");
                    }
                }
            }

            return(result);
        }