Skip to content

Commit

Permalink
Merge pull request baihui212#7 from threezhang/jiuru
Browse files Browse the repository at this point in the history
Thank threezhang([email protected]) for fix the jar dependency problem.
  • Loading branch information
baihui212 authored Jul 14, 2016
2 parents 1670e97 + 6bf3f63 commit 35c5406
Show file tree
Hide file tree
Showing 57 changed files with 1,493 additions and 729 deletions.
35 changes: 35 additions & 0 deletions tsharding-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# maven ignore
target/
*.jar
*.war
*.zip
*.tar
*.tar.gz

# eclipse ignore
.metadata/
.settings/
.project
.classpath
.springBeans

# idea ignore
.idea/
*.ipr
*.iml
*.iws

# temp ignore
logs/
*.log
*.cache
*.diff
*.patch
*.tmp
*.swp

# system ignore
.DS_Store
Thumbs.db

/bin/
16 changes: 4 additions & 12 deletions tsharding-client/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
交易分库分表组件TSharding

1.0.0-SNAPSHOT

##2015-09-08
##版本1.0.0-SNAPSHOT
new features:
com.mogujie.trade.tsharding.route.orm.MapperEnhancer#enhanceMapperClass //增加注解信息和注解内容,以支持mybatis mapper类的动态绑定

##2015-09-18
##版本1.0.0
已经支持交易订单分库分表完整需求,灰度完成100%发布上线。发布tsharding稳定版.
####
1.测试用例入口 com.mogujie.service.tsharding.test#TShardingTest
2.默认走Master库的前缀命名 com.mogujie.trade.tsharding.route.orm.base.ReadWriteSplittingContextInitializer.DEFAULT_WRITE_METHOD_NAMES
3.SQL增强 com.mogujie.trade.tsharding.route.orm.MapperResourceEnhancer.enhancedShardingSQL

##版本1.0.1.1
优化orm元数据增强扩展时的内存消耗
##版本1.0.2
增加XDItemOrderEx表sharding支持。
110 changes: 76 additions & 34 deletions tsharding-client/pom.xml
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mogujie.trade</groupId>
<artifactId>tsharding</artifactId>
<version>1.0.0</version>
</parent>

<groupId>com.mogujie.trade</groupId>
<artifactId>tsharding-client</artifactId>
<version>1.0.2</version>
<version>1.0.0</version>
<name>tsharding client</name>

<properties>
<mybatis.version>3.2.8</mybatis.version>
<mybatis-spring.version>1.2.2</mybatis-spring.version>
<spring.version>4.0.6.RELEASE</spring.version>
<junit.version>4.10</junit.version>
<javassist.version>3.19.0-GA</javassist.version>
<fastjson.version>1.2.7</fastjson.version>
<slf4j-api.version>1.7.21</slf4j-api.version>
<druid.version>1.0.18</druid.version>
<mysql.version>5.1.38</mysql.version>
<aspectj.version>1.8.8</aspectj.version>
</properties>

<dependencies>
<dependency>
<groupId>com.mogujie.trade</groupId>
<artifactId>trade.switch</artifactId>
<version>1.0.2.1111switch</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
Expand All @@ -49,59 +48,102 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.19.0-GA</version>
<version>${javassist.version}</version>
</dependency>

<dependency>
<groupId>com.mogujie.tesla</groupId>
<artifactId>tesla-support</artifactId>
<version>${tesla.support.version}</version>
<type>pom</type>
<exclusions>
<exclusion>
<groupId>com.mogujie.tesla</groupId>
<artifactId>tesla-dal-db-orm</artifactId>
</exclusion>
</exclusions>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>

<dependency>
<groupId>com.mogujie.tesla</groupId>
<artifactId>tesla-dal-db</artifactId>
<version>1.0.11-SNAPSHOT</version>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>

<dependency>
<groupId>com.mogujie.trade</groupId>
<artifactId>trade.switch</artifactId>
<version>1.0.2</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-api.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>

<dependency>
<groupId>com.mogujie.service</groupId>
<artifactId>trade.service.base</artifactId>
<version>1.0.6</version>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<skipTests>false</skipTests>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.mogujie.trade.db;

/**
* @author by jiuru on 16/7/14.
*/
public class DataSourceConfig {

static final int DEFAULT_MIN_POOL_SIZE = 0;
static final int DEFAULT_MAX_POOL_SIZE = 10;
static final int DEFAULT_INI_POOL_SIZE = 0;

private String url;

private String username;

private String password;

private int minPoolSize;

private int maxPoolSize;

private int initialPoolSize;

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public int getMinPoolSize() {
return minPoolSize;
}

public void setMinPoolSize(int minPoolSize) {
this.minPoolSize = minPoolSize;
}

public int getMaxPoolSize() {
return maxPoolSize;
}

public void setMaxPoolSize(int maxPoolSize) {
this.maxPoolSize = maxPoolSize;
}

public int getInitialPoolSize() {
return initialPoolSize;
}

public void setInitialPoolSize(int initialPoolSize) {
this.initialPoolSize = initialPoolSize;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mogujie.trade.db;

import javax.sql.DataSource;
import java.sql.SQLException;

/**
* @author by jiuru on 16/7/14.
*/
public interface DataSourceFactory<T extends DataSource> {

T getDataSource(DataSourceConfig config) throws SQLException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.mogujie.trade.db;

import java.io.Closeable;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;

/**
* @author by jiuru on 16/7/14.
*/
public class DataSourceLookup implements Closeable {

private final Map<String, ReadWriteSplittingDataSource> dataSources;

public DataSourceLookup(Map<String, ReadWriteSplittingDataSource> dataSources) {
this.dataSources = Collections.unmodifiableMap(dataSources);
}

/**
* @param name
* @return
*/
public ReadWriteSplittingDataSource get(String name) {
return this.dataSources.get(name);
}

public Map<String, ReadWriteSplittingDataSource> getMapping() {
return this.dataSources;
}

@Override
public void close() throws IOException {
for (ReadWriteSplittingDataSource dataSource : dataSources.values()) {
dataSource.close();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.mogujie.trade.db;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @author by jiuru on 16/7/14.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface DataSourceRouting {
/**
* 静态绑定该Mapper对应的数据源
*
* @return 绑定的数据源的名称
*/
String value() default "";

/**
* 指定运行时路由处理的Handler,动态指定对应的数据源。<b>注意:此方式不能支持事务!</b>
*
* @return
*/
Class<? extends DataSourceRoutingHandler> handler() default EmptyDataSourceRoutingHandler.class;

}
Loading

0 comments on commit 35c5406

Please sign in to comment.