Unverified Commit 37da1390 authored by 张亮's avatar 张亮 Committed by GitHub
Browse files

Merge pull request #913 from cherrylzhao/dev

modify swarding-proxy userGroup thread model.
parents 8386510b fbc46a23
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@
        <guava-retrying.version>2.0.0</guava-retrying.version>
        <quartz.version>2.3.0</quartz.version>
        <opentracing.version>0.30.0</opentracing.version>
        <atomikos.version>4.0.4</atomikos.version>
        <javax.transaction.version>1.1</javax.transaction.version>

        <maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
        <maven-assembly-plugin.version>3.1.0</maven-assembly-plugin.version>
@@ -315,6 +317,26 @@
                <version>${opentracing.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.atomikos</groupId>
                <artifactId>transactions</artifactId>
                <version>${atomikos.version}</version>
            </dependency>
            <dependency>
                <groupId>com.atomikos</groupId>
                <artifactId>transactions-jta</artifactId>
                <version>${atomikos.version}</version>
            </dependency>
            <dependency>
                <groupId>com.atomikos</groupId>
                <artifactId>transactions-jdbc</artifactId>
                <version>${atomikos.version}</version>
            </dependency>
            <dependency>
                <groupId>javax.transaction</groupId>
                <artifactId>jta</artifactId>
                <version>${javax.transaction.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
+63 −0
Original line number Diff line number Diff line
/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </p>
 */

package io.shardingsphere.core.constant;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * TransactionType Enum.
 *
 * @author zhaojun
 */
@RequiredArgsConstructor
@Getter
public enum TransactionType {
    
    /**
     * default local transaction.
     */
    NONE(""),
    
    /**
     * XA distribute transaction provided by RDBMS vendor.
     */
    XA("XA"),
    
    /**
     * TCC (Try-Confirm-Cancel) distribute transaction mode.
     */
    TCC("TCC");
    
    private final String type;
    
    /**
     * Find enum by type value.
     *
     * @param type property type
     * @return value enum, return {@code NONE} if not found
     */
    public static TransactionType findByValue(final String type) {
        for (TransactionType each : TransactionType.values()) {
            if (each.getType().equals(type)) {
                return each;
            }
        }
        return NONE;
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import java.util.Map;
 *
 * @author zhangyonglun
 * @author panjuan
 * @author zhaojun
 */
@Getter
@Setter
@@ -55,6 +56,8 @@ public class YamlProxyConfiguration {
   
    private YamlShardingRuleConfiguration shardingRule = new YamlShardingRuleConfiguration();
    
    private String transactionMode;
    
    /**
     * Unmarshal yaml sharding configuration from yaml file.
     * 
+17 −0
Original line number Diff line number Diff line
@@ -47,6 +47,23 @@
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>com.atomikos</groupId>
            <artifactId>transactions</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atomikos</groupId>
            <artifactId>transactions-jta</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atomikos</groupId>
            <artifactId>transactions-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
+57 −0
Original line number Diff line number Diff line
/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </p>
 */

package io.shardingsphere.proxy.config;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import io.shardingsphere.core.yaml.sharding.DataSourceParameter;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

/**
 * Create default proxy raw datasource using {@code HikariDataSource}.
 *
 * @author zhaojun
 */
public class DefaultProxyRawDataSource extends ProxyRawDataSource {
    
    public DefaultProxyRawDataSource(final Map<String, DataSourceParameter> dataSourceParameters) {
        super(dataSourceParameters);
    }
    
    @Override
    protected Map<String, DataSource> buildInternal(final String key, final DataSourceParameter dataSourceParameter) {
        final Map<String, DataSource> result = new HashMap<>(128, 1);
        HikariConfig config = new HikariConfig();
        config.setDriverClassName("com.mysql.jdbc.Driver");
        config.setJdbcUrl(dataSourceParameter.getUrl());
        config.setUsername(dataSourceParameter.getUsername());
        config.setPassword(dataSourceParameter.getPassword());
        config.setAutoCommit(dataSourceParameter.getAutoCommit());
        config.setConnectionTimeout(dataSourceParameter.getConnectionTimeout());
        config.setIdleTimeout(dataSourceParameter.getIdleTimeout());
        config.setMaxLifetime(dataSourceParameter.getMaxLifetime());
        config.setMaximumPoolSize(dataSourceParameter.getMaximumPoolSize());
        config.addDataSourceProperty("useServerPrepStmts", "true");
        config.addDataSourceProperty("cachePrepStmts", "true");
        result.put(key, new HikariDataSource(config));
        return result;
    }
}
Loading