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

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


                if (StringUtils.isEmpty(shardingExpression)) {

                    ruleSequence.get(3).add(new IBatisNamespaceRule(namespace, destinations));
                } else {
                    IBatisNamespaceShardingRule insr = new IBatisNamespaceShardingRule(namespace,
                            destinations, shardingExpression);
                    if (MapUtils.isNotEmpty(functionsMap)) {
                        insr.setFunctionMap(functionsMap);
                    }
                    ruleSequence.get(2).add(insr);
                }
            }
            if (StringUtils.isNotEmpty(sqlAction)) {
View Full Code Here


            if (StringUtils.isNotEmpty(namespace)) {
                if (StringUtils.isEmpty(shardingExpression)) {
                    namespaceRules.add(new IBatisNamespaceRule(namespace, destinations));
                } else {
                    IBatisNamespaceShardingRule insr = new IBatisNamespaceShardingRule(namespace,
                            destinations, shardingExpression);
                    if (MapUtils.isNotEmpty(getFunctionsMap())) {
                        insr.setFunctionMap(getFunctionsMap());
                    }
                    namespaceShardingRules.add(insr);
                }
            }
            if (StringUtils.isNotEmpty(sqlAction)) {
View Full Code Here

    private IBatisNamespaceShardingRule rule;

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

        }
    }

    public void testShardIdAssemblyAbnormally() {
        try {
            new IBatisNamespaceShardingRule(DEFAULT_TYPE_PATTEN, null, DEFAULT_SHARDING_PATTERN);
            fail();
        } catch (IllegalArgumentException e) {
            // pass
        }

        try {
            new IBatisNamespaceShardingRule(DEFAULT_TYPE_PATTEN, "", DEFAULT_SHARDING_PATTERN);
            fail();
        } catch (IllegalArgumentException e) {
            // pass
        }
    }
View Full Code Here

        List<String> shards = rule.action();
        assertTrue(CollectionUtils.isNotEmpty(shards));
        assertEquals(1, shards.size());
        assertEquals("shard1,shard2", shards.get(0));

        rule = new IBatisNamespaceShardingRule(DEFAULT_TYPE_PATTEN, "shard1;shard2",
                DEFAULT_SHARDING_PATTERN);
        rule.setActionPatternSeparator(";");
        shards = null;
        shards = rule.action();
        assertTrue(CollectionUtils.isNotEmpty(shards));
View Full Code Here

            // pass
        }

        // construction abnormally
        try {
            rule = new IBatisNamespaceShardingRule(null, "shard1,shard2", DEFAULT_SHARDING_PATTERN);
            fail();
        } catch (IllegalArgumentException e) {
            // pass
        }
        try {
            rule = new IBatisNamespaceShardingRule("", "shard1,shard2", DEFAULT_SHARDING_PATTERN);
            fail();
        } catch (IllegalArgumentException e) {
            // pass
        }
    }
View Full Code Here

    }

    public void testRuleShardingPatternMatchingAbnormally() {
        try {
            new IBatisNamespaceShardingRule(DEFAULT_TYPE_PATTEN, "shard1,shard2", null);
            fail();
        } catch (IllegalArgumentException e) {
            // pass
        }

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

        }
    }

    public void testRuleShardingPatternWithCustomFunctions() throws Exception {
        String shardingExpression = "mod.apply(id)==3";
        IBatisNamespaceShardingRule r = new IBatisNamespaceShardingRule(DEFAULT_TYPE_PATTEN,
                StringUtils.join(DEFAULT_SHARDS, ","), shardingExpression);
        Map<String, Object> functions = new HashMap<String, Object>();
        functions.put("mod", new ModFunction(18L));
        r.setFunctionMap(functions);

        Tweet t = new Tweet();
        t.setId(3L);
        t.setTweet("anything");
        IBatisRoutingFact fact = new IBatisRoutingFact(
                "com.alibaba.cobar.client.entity.Tweet.create", t);
        assertTrue(r.isDefinedAt(fact));
    }
View Full Code Here

        assertTrue(r.isDefinedAt(fact));
    }
   
    public void testRuleExpressionEvaluationWithSimpleTypeRoutingFact()
    {
        IBatisNamespaceShardingRule r = new IBatisNamespaceShardingRule(DEFAULT_TYPE_PATTEN,
                "shard2", "$ROOT.startsWith(\"A\")");
       
        IBatisRoutingFact fact = new IBatisRoutingFact(
                "com.alibaba.cobar.client.entity.Tweet.create", "Arron");
        assertTrue(r.isDefinedAt(fact));
       
        r = new IBatisNamespaceShardingRule(DEFAULT_TYPE_PATTEN,
                "shard2", "startsWith(\"A\")");
        assertTrue(r.isDefinedAt(fact));
       
        fact = new IBatisRoutingFact(
                "com.alibaba.cobar.client.entity.Tweet.create", "Donald");
        assertFalse(r.isDefinedAt(fact));
    }
View Full Code Here

TOP

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

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.