Package com.alibaba.cobar.client.router.rules.ibatis

Examples of com.alibaba.cobar.client.router.rules.ibatis.IBatisSqlActionShardingRule


                        router, StringUtils.substringBeforeLast(sqlAction, "."));

                if (StringUtils.isEmpty(shardingExpression)) {
                    ruleSequence.get(1).add(new IBatisSqlActionRule(sqlAction, destinations));
                } else {
                    IBatisSqlActionShardingRule issr = new IBatisSqlActionShardingRule(sqlAction,
                            destinations, shardingExpression);
                    if (MapUtils.isNotEmpty(functionsMap)) {
                        issr.setFunctionMap(functionsMap);
                    }
                    ruleSequence.get(0).add(issr);
                }
            }
        }
View Full Code Here


            }
            if (StringUtils.isNotEmpty(sqlAction)) {
                if (StringUtils.isEmpty(shardingExpression)) {
                    sqlActionRules.add(new IBatisSqlActionRule(sqlAction, destinations));
                } else {
                    IBatisSqlActionShardingRule issr = new IBatisSqlActionShardingRule(sqlAction,
                            destinations, shardingExpression);
                    if (MapUtils.isNotEmpty(getFunctionsMap())) {
                        issr.setFunctionMap(getFunctionsMap());
                    }
                    sqlActionShardingRules.add(issr);
                }
            }
        }
View Full Code Here

    private IBatisSqlActionShardingRule rule;

    @BeforeMethod
    protected void setUp() throws Exception {
        rule = new IBatisSqlActionShardingRule(DEFAULT_TYPE_PATTEN, "shard1,shard2",
                DEFAULT_SHARDING_PATTERN);
    }
View Full Code Here

        rule = null;
    }

    public void testSqlActionShardingRuleConstructionAbnormally() {
        try {
            rule = new IBatisSqlActionShardingRule(null, "shard1,shard2", DEFAULT_SHARDING_PATTERN);
            fail();
        } catch (IllegalArgumentException e) {
            // pass
        }

        try {
            rule = new IBatisSqlActionShardingRule("", "shard1,shard2", DEFAULT_SHARDING_PATTERN);
            fail();
        } catch (IllegalArgumentException e) {
            // pass
        }

        try {
            rule = new IBatisSqlActionShardingRule(DEFAULT_TYPE_PATTEN, "",
                    DEFAULT_SHARDING_PATTERN);
            fail();
        } catch (IllegalArgumentException e) {
            // pass
        }

        try {
            rule = new IBatisSqlActionShardingRule(DEFAULT_TYPE_PATTEN, null,
                    DEFAULT_SHARDING_PATTERN);
            fail();
        } catch (IllegalArgumentException e) {
            // pass
        }

        try {
            rule = new IBatisSqlActionShardingRule(DEFAULT_TYPE_PATTEN, "shard1,shard2", null);
            fail();
        } catch (IllegalArgumentException e) {
            // pass
        }

        try {
            rule = new IBatisSqlActionShardingRule(DEFAULT_TYPE_PATTEN, "shard1,shard2", "");
            fail();
        } catch (IllegalArgumentException e) {
            // pass
        }
    }
View Full Code Here

            // pass
        }
    }

    public void testSqlActionShardingRuleWithCustomFunctions() {
        IBatisSqlActionShardingRule r = new IBatisSqlActionShardingRule(DEFAULT_TYPE_PATTEN,
                "shard1,shard2", "mod.apply(id)==3");
        Map<String, Object> functions = new HashMap<String, Object>();
        functions.put("mod", new ModFunction(18L));
        r.setFunctionMap(functions);
       
        Tweet t = new Tweet();
        t.setId(21L);
        t.setTweet("anything");
        IBatisRoutingFact fact = new IBatisRoutingFact(
                "com.alibaba.cobar.client.entity.Tweet.create", t);
        assertTrue(r.isDefinedAt(fact));
    }
View Full Code Here

                "com.alibaba.cobar.client.entity.Tweet.create", t);
        assertTrue(r.isDefinedAt(fact));
    }
   
    public void testSqlActionShardingRuleWithSimpleContextObjectType(){
        IBatisSqlActionShardingRule r = new IBatisSqlActionShardingRule(DEFAULT_TYPE_PATTEN,
                "shard1", "$ROOT.startsWith(\"J\")");
        IBatisRoutingFact fact = new IBatisRoutingFact(
                "com.alibaba.cobar.client.entity.Tweet.create", "Jack");
        assertTrue(r.isDefinedAt(fact));
       
        r = new IBatisSqlActionShardingRule(DEFAULT_TYPE_PATTEN,
                "shard1", "startsWith(\"J\")");
        assertTrue(r.isDefinedAt(fact));
       
        fact = new IBatisRoutingFact(
                "com.alibaba.cobar.client.entity.Tweet.create", "Amanda");
        assertFalse(r.isDefinedAt(fact));
       
       
    }
View Full Code Here

TOP

Related Classes of com.alibaba.cobar.client.router.rules.ibatis.IBatisSqlActionShardingRule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.