Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
2dfa55fc
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2dfa55fc
编写于
9月 22, 2017
作者:
H
haocao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor sharding-jdbc-spring examples 7th.
上级
f2d81ab2
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
102 addition
and
47 deletion
+102
-47
sharding-jdbc-raw-jdbc-example/sharding-jdbc-raw-jdbc-java-example/src/main/resources/logback.xml
...jdbc-raw-jdbc-java-example/src/main/resources/logback.xml
+1
-1
sharding-jdbc-raw-jdbc-example/sharding-jdbc-raw-jdbc-yaml-example/src/main/resources/logback.xml
...jdbc-raw-jdbc-yaml-example/src/main/resources/logback.xml
+1
-1
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-jpa-example/src/main/java/io/shardingjdbc/example/jpa/SpringJpaShardingDatabaseAndTableMain.java
...bc/example/jpa/SpringJpaShardingDatabaseAndTableMain.java
+33
-0
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-jpa-example/src/main/java/io/shardingjdbc/example/jpa/repository/OrderRepository.java
.../shardingjdbc/example/jpa/repository/OrderRepository.java
+2
-2
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-jpa-example/src/main/java/io/shardingjdbc/example/jpa/repository/OrderRepositoryImpl.java
...rdingjdbc/example/jpa/repository/OrderRepositoryImpl.java
+3
-2
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-jpa-example/src/main/java/io/shardingjdbc/example/jpa/service/OrderService.java
...ava/io/shardingjdbc/example/jpa/service/OrderService.java
+33
-0
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-jpa-example/src/main/resources/META-INF/jpa/jpaShardingDatabaseAndTable.xml
...in/resources/META-INF/jpa/jpaShardingDatabaseAndTable.xml
+27
-1
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-jpa-example/src/main/resources/META-INF/jpa/mysql/jpaContext.xml
...mple/src/main/resources/META-INF/jpa/mysql/jpaContext.xml
+0
-38
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-jpa-example/src/main/resources/logback.xml
...ring-namespace-jpa-example/src/main/resources/logback.xml
+1
-1
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-mybatis-example/src/main/resources/logback.xml
...-namespace-mybatis-example/src/main/resources/logback.xml
+1
-1
未找到文件。
sharding-jdbc-raw-jdbc-example/sharding-jdbc-raw-jdbc-java-example/src/main/resources/logback.xml
浏览文件 @
2dfa55fc
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property
name=
"log.context.name"
value=
"sharding-jdbc-
example-jdbc
"
/>
<property
name=
"log.context.name"
value=
"sharding-jdbc-
raw-jdbc-java-example
"
/>
<property
name=
"log.charset"
value=
"UTF-8"
/>
<property
name=
"log.pattern"
value=
"[%-5level] %date --%thread-- [%logger] %msg %n"
/>
...
...
sharding-jdbc-raw-jdbc-example/sharding-jdbc-raw-jdbc-yaml-example/src/main/resources/logback.xml
浏览文件 @
2dfa55fc
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property
name=
"log.context.name"
value=
"sharding-jdbc-
example-config-yaml
"
/>
<property
name=
"log.context.name"
value=
"sharding-jdbc-
raw-jdbc-yaml-example
"
/>
<property
name=
"log.charset"
value=
"UTF-8"
/>
<property
name=
"log.pattern"
value=
"[%-5level] %date --%thread-- [%logger] %msg %n"
/>
...
...
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-jpa-example/src/main/java/io/shardingjdbc/example/jpa/Main.java
→
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-jpa-example/src/main/java/io/shardingjdbc/example/jpa/
SpringJpaShardingDatabaseAndTable
Main.java
浏览文件 @
2dfa55fc
...
...
@@ -17,32 +17,17 @@
package
io.shardingjdbc.example.jpa
;
import
io.shardingjdbc.example.jpa.
entity.Order
;
import
io.shardingjdbc.example.jpa.repository.OrderRepository
;
import
io.shardingjdbc.example.jpa.
service.OrderService
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
import
java.util.ArrayList
;
import
java.util.List
;
public
final
class
Main
{
public
final
class
SpringJpaShardingDatabaseAndTableMain
{
// CHECKSTYLE:OFF
public
static
void
main
(
final
String
[]
args
)
{
// CHECKSTYLE:ON
ClassPathXmlApplicationContext
applicationContext
=
new
ClassPathXmlApplicationContext
(
"META-INF/jpa/mysql/jpaContext.xml"
);
OrderRepository
orderRepository
=
applicationContext
.
getBean
(
OrderRepository
.
class
);
List
<
Long
>
orderIds
=
new
ArrayList
<>(
10
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
Order
order
=
new
Order
();
order
.
setUserId
(
51
);
order
.
setStatus
(
"INSERT_TEST"
);
orderRepository
.
insert
(
order
);
}
System
.
out
.
println
(
orderRepository
.
selectAll
());
System
.
out
.
println
(
"--------------"
);
for
(
Long
each
:
orderIds
)
{
orderRepository
.
delete
(
each
);
}
applicationContext
.
close
();
ApplicationContext
applicationContext
=
new
ClassPathXmlApplicationContext
(
"META-INF/jpa/jpaShardingDatabaseAndTable.xml"
);
OrderService
orderService
=
applicationContext
.
getBean
(
OrderService
.
class
);
orderService
.
testAll
();
}
}
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-jpa-example/src/main/java/io/shardingjdbc/example/jpa/repository/OrderRepository.java
浏览文件 @
2dfa55fc
...
...
@@ -23,9 +23,9 @@ import java.util.List;
public
interface
OrderRepository
{
void
insert
(
Order
order
);
Long
insert
(
Order
order
);
void
delete
(
l
ong
orderId
);
void
delete
(
L
ong
orderId
);
List
<
Order
>
selectAll
();
}
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-jpa-example/src/main/java/io/shardingjdbc/example/jpa/repository/OrderRepositoryImpl.java
浏览文件 @
2dfa55fc
...
...
@@ -34,12 +34,13 @@ public class OrderRepositoryImpl implements OrderRepository {
private
EntityManager
entityManager
;
@Override
public
void
insert
(
final
Order
order
)
{
public
Long
insert
(
final
Order
order
)
{
entityManager
.
persist
(
order
);
return
order
.
getOrderId
();
}
@Override
public
void
delete
(
final
l
ong
orderId
)
{
public
void
delete
(
final
L
ong
orderId
)
{
Query
query
=
entityManager
.
createQuery
(
"DELETE FROM Order o WHERE o.orderId = ?1 AND o.userId = 51"
);
query
.
setParameter
(
1
,
orderId
);
query
.
executeUpdate
();
...
...
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-jpa-example/src/main/java/io/shardingjdbc/example/jpa/service/OrderService.java
0 → 100644
浏览文件 @
2dfa55fc
package
io.shardingjdbc.example.jpa.service
;
import
io.shardingjdbc.example.jpa.entity.Order
;
import
io.shardingjdbc.example.jpa.repository.OrderRepository
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
@Service
public
class
OrderService
{
@Resource
private
OrderRepository
orderRepository
;
public
void
testAll
()
{
List
<
Long
>
orderIds
=
new
ArrayList
<>(
10
);
System
.
out
.
println
(
"1.Insert--------------"
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
Order
order
=
new
Order
();
order
.
setUserId
(
51
);
order
.
setStatus
(
"INSERT_TEST"
);
orderIds
.
add
(
orderRepository
.
insert
(
order
));
}
System
.
out
.
println
(
orderRepository
.
selectAll
());
System
.
out
.
println
(
"2.Delete--------------"
);
for
(
Long
each
:
orderIds
)
{
orderRepository
.
delete
(
each
);
}
System
.
out
.
println
(
orderRepository
.
selectAll
());
}
}
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-jpa-example/src/main/resources/META-INF/jpa/
mysql/shardingContext
.xml
→
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-jpa-example/src/main/resources/META-INF/jpa/
jpaShardingDatabaseAndTable
.xml
浏览文件 @
2dfa55fc
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:p=
"http://www.springframework.org/schema/p"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:tx=
"http://www.springframework.org/schema/tx"
xmlns:sharding=
"http://shardingjdbc.io/schema/shardingjdbc/sharding"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://shardingjdbc.io/schema/shardingjdbc/sharding
http://shardingjdbc.io/schema/shardingjdbc/sharding/sharding.xsd"
>
http://shardingjdbc.io/schema/shardingjdbc/sharding/sharding.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"
>
<context:annotation-config
/>
<context:component-scan
base-package=
"io.shardingjdbc.example.jpa"
/>
<bean
id=
"entityManagerFactory"
class=
"org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
>
<property
name=
"dataSource"
ref=
"shardingDataSource"
/>
<property
name=
"jpaVendorAdapter"
>
<bean
class=
"org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:database=
"MYSQL"
/>
</property>
<property
name=
"packagesToScan"
value=
"io.shardingjdbc.example.jpa.entity"
/>
<property
name=
"jpaProperties"
>
<props>
<prop
key=
"hibernate.dialect"
>
org.hibernate.dialect.MySQLDialect
</prop>
<prop
key=
"hibernate.hbm2ddl.auto"
>
create
</prop>
</props>
</property>
</bean>
<bean
id=
"transactionManager"
class=
"org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref=
"entityManagerFactory"
/>
<tx:annotation-driven/>
<bean
id=
"demo_ds_0"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/demo_ds_0"
/>
...
...
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-jpa-example/src/main/resources/META-INF/jpa/mysql/jpaContext.xml
已删除
100644 → 0
浏览文件 @
f2d81ab2
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:p=
"http://www.springframework.org/schema/p"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:tx=
"http://www.springframework.org/schema/tx"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"
>
<import
resource=
"shardingContext.xml"
/>
<context:annotation-config
/>
<context:component-scan
base-package=
"io.shardingjdbc.example.jpa"
/>
<bean
id=
"entityManagerFactory"
class=
"org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
>
<property
name=
"dataSource"
ref=
"shardingDataSource"
/>
<property
name=
"jpaVendorAdapter"
>
<bean
class=
"org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:database=
"MYSQL"
/>
</property>
<property
name=
"packagesToScan"
value=
"io.shardingjdbc.example.jpa.entity"
/>
<property
name=
"jpaProperties"
>
<props>
<prop
key=
"hibernate.dialect"
>
org.hibernate.dialect.MySQLDialect
</prop>
<prop
key=
"hibernate.max_fetch_depth"
>
10
</prop>
<prop
key=
"hibernate.jdbc.fetch_size"
>
100
</prop>
<prop
key=
"hibernate.jdbc.batch_size"
>
10
</prop>
<prop
key=
"hibernate.hbm2ddl.auto"
>
create
</prop>
<prop
key=
"hibernate.show_sql"
>
true
</prop>
<prop
key=
"hibernate.format_sql"
>
true
</prop>
<prop
key=
"javax.persistence.validation.mode"
>
none
</prop>
</props>
</property>
</bean>
<bean
id=
"transactionManager"
class=
"org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref=
"entityManagerFactory"
/>
<tx:annotation-driven/>
</beans>
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-jpa-example/src/main/resources/logback.xml
浏览文件 @
2dfa55fc
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property
name=
"log.context.name"
value=
"sharding-jdbc-
example-jpa
"
/>
<property
name=
"log.context.name"
value=
"sharding-jdbc-
spring-namespace-jpa-example
"
/>
<property
name=
"log.charset"
value=
"UTF-8"
/>
<property
name=
"log.pattern"
value=
"[%-5level] %date --%thread-- [%logger] %msg %n"
/>
...
...
sharding-jdbc-spring-namespace-example/sharding-jdbc-spring-namespace-mybatis-example/src/main/resources/logback.xml
浏览文件 @
2dfa55fc
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property
name=
"log.context.name"
value=
"sharding-jdbc-
example-mybatis
"
/>
<property
name=
"log.context.name"
value=
"sharding-jdbc-
spring-namespace-mybatis-example
"
/>
<property
name=
"log.charset"
value=
"UTF-8"
/>
<property
name=
"log.pattern"
value=
"[%-5level] %date --%thread-- [%logger] %msg %n"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录