Search in sources :

Example 1 with DatabaseCategory

use of com.ctrip.framework.dal.cluster.client.database.DatabaseCategory in project dal by ctripcorp.

the class DefaultClusterTest method getDatabaseCategoryTest.

@Test
public void getDatabaseCategoryTest() {
    final DatabaseCategory databaseCategory = cluster.getDatabaseCategory();
    Assert.assertEquals(MYSQL, databaseCategory);
}
Also used : DatabaseCategory(com.ctrip.framework.dal.cluster.client.database.DatabaseCategory) Test(org.junit.Test)

Example 2 with DatabaseCategory

use of com.ctrip.framework.dal.cluster.client.database.DatabaseCategory in project dal by ctripcorp.

the class ClusterConfigXMLParser method parseCluster.

private ClusterConfig parseCluster(Node clusterNode, DalConfigCustomizedOption customizedOption) throws IOException {
    String name = getAttribute(clusterNode, NAME);
    if (StringUtils.isEmpty(name))
        throw new ClusterConfigException("cluster name undefined");
    ClusterType clusterType = ClusterType.NORMAL;
    String clusterTypeText = getAttribute(clusterNode, TYPE);
    if (!StringUtils.isEmpty(clusterTypeText))
        clusterType = ClusterType.parse(clusterTypeText);
    DatabaseCategory dbCategory = DatabaseCategory.parse(getAttribute(clusterNode, DB_CATEGORY));
    int version = Integer.parseInt(getAttribute(clusterNode, VERSION));
    ClusterConfigImpl clusterConfig = new ClusterConfigImpl(name, clusterType, dbCategory, version);
    clusterConfig.setCustomizedOption(customizedOption);
    Node databaseShardsNode = getChildNode(clusterNode, DATABASE_SHARDS);
    if (databaseShardsNode != null) {
        List<Node> databaseShardNodes = getChildNodes(databaseShardsNode, DATABASE_SHARD);
        for (Node databaseShardNode : databaseShardNodes) parseDatabaseShard(clusterConfig, databaseShardNode);
    }
    Node shardStrategiesNode = getChildNode(clusterNode, SHARD_STRATEGIES);
    if (shardStrategiesNode != null)
        parseShardStrategies(clusterConfig, shardStrategiesNode);
    Node idGeneratorsNode = getChildNode(clusterNode, ID_GENERATORS);
    if (idGeneratorsNode != null)
        parseIdGenerators(clusterConfig, idGeneratorsNode);
    Node routeStrategiesNode = getChildNode(clusterNode, ROUTE_STRATEGIES);
    if (!StringUtils.isEmpty(customizedOption.getRouteStrategy())) {
        initRouteStrategy(clusterConfig, customizedOption);
    } else if (routeStrategiesNode != null)
        parseRouteStrategies(clusterConfig, routeStrategiesNode);
    else
        initRouteStrategy(clusterConfig);
    parseDrcConfig(clusterConfig, clusterNode);
    return clusterConfig;
}
Also used : ClusterConfigException(com.ctrip.framework.dal.cluster.client.exception.ClusterConfigException) DatabaseCategory(com.ctrip.framework.dal.cluster.client.database.DatabaseCategory) ClusterType(com.ctrip.framework.dal.cluster.client.cluster.ClusterType)

Aggregations

DatabaseCategory (com.ctrip.framework.dal.cluster.client.database.DatabaseCategory)2 ClusterType (com.ctrip.framework.dal.cluster.client.cluster.ClusterType)1 ClusterConfigException (com.ctrip.framework.dal.cluster.client.exception.ClusterConfigException)1 Test (org.junit.Test)1