Skip to content

Commit 7cd29d0

Browse files
committed
Merge remote-tracking branch 'remotes/origin/dev'
2 parents 75c7c94 + 1510853 commit 7cd29d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1125
-1072
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,31 @@ Conditions on frameworks which I choose for consideration:
4343
4. The framework must be mature enough for "enterprise level" use
4444

4545
#### Subjective pros/cons of each framework
46+
> Reference:[java-persistence-frameworks-comparison](https://github.com/bwajtr/java-persistence-frameworks-comparison)
47+
4648
**Hibernate/JPA**
4749
* [Compare to JPA](http://ebean-orm.github.io/architecture/compare-jpa)
4850

51+
**JDBC Template**
52+
* Pros
53+
* Feels like you are very close to JDBC itself
54+
* Implemented all of the scenarios without bigger issues - there were no hidden surprises
55+
* Very easy batch operations
56+
* Easy setup
57+
* Cons
58+
* Methods in JDBCDataRepositoryImpl are not much readable - that's because you have to inline SQL in Java code. It would have been better if Java supported multiline strings.
59+
* Debug logging could be better
60+
61+
**jOOQ**
62+
* Pros
63+
* Very fluent, very easy to write new queries, code is very readable
64+
* Once setup it's very easy to use, excellent for simple queries
65+
* Awesome logger debug output
66+
* Cons
67+
* Paid license for certain databases - it'll be difficult to persuade managers that it's worth it :)
68+
* Not so much usable for big queries - it's better to use native SQL (see scenario 9.)
69+
* Weird syntax of batch operations (in case that you do not use UpdatableRecord). But it's not a big deal...
70+
4971
**MyBatis**
5072
* Pros
5173
* Writing SQL statements in XML mapper file feels good - it's easy to work with parameters

README_zh.md

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@
2525
* 支持MySQL、Oracle、SQL Server、H2、PostgreSQL等数据库
2626

2727
#### 实现的场景 ####
28-
1. Fetch single entity based on primary key
29-
2. Fetch list of entities based on condition
30-
3. Save new single entity and return primary key
31-
4. Batch insert multiple entities of the same type and return generated keys
32-
5. Update single existing entity - update all fields of entity at once
33-
6. Fetch many-to-one relation (Company for Department)
34-
7. Fetch one-to-many relation (Departments for Company)
35-
8. Update entities one-to-many relation (Departments in Company) - add two items, update two items and delete one item - all at once
36-
9. Complex select - construct select where conditions based on some boolean conditions + throw in some JOINs
37-
10. Execute query using JDBC simple Statement (not PreparedStatement)
38-
11. Remove single entity based on primary key
28+
29+
1. 基于主键获取单个实体
30+
2. 根据条件获取实体的列表
31+
3. 保存新的单个实体并返回主键
32+
4. 批量插入相同类型的多个实体并返回生成的主键列表
33+
5. 更新单个现有实体——同时更新所有的实体字段
34+
6. 获取多对一关系(部门的所属公司)
35+
7. 获取一对多关系(公司的部门)
36+
8. 更新实体一对多的关系(公司的部门)-增加两个项目,更新两个项目和删除一个项目-所有只需一句代码/一次操作
37+
9. 复杂的选择-构造选择的条件基于一些布尔条件+加入一些连接
38+
10. 使用JDBC简单语句(非PreparedStatement)执行查询
39+
11. 基于主键移除单个实体
3940

4041
## 为什么选择[Ebean ORM](https://ebean-orm.github.io)
4142

@@ -49,10 +50,32 @@
4950
4. 足够成熟以应对企业级应用(Ebean和Hibernate同时期作品,资格老,而且持续更新以满足更高需求)
5051

5152
#### 框架优缺点比较
53+
> 参考:[java-persistence-frameworks-comparison](https://github.com/bwajtr/java-persistence-frameworks-comparison)
54+
5255
**Hibernate/JPA**
5356
* [Compare to JPA](http://ebean-orm.github.io/architecture/compare-jpa)
5457
* 反正比Hibernate/JPA好
5558

59+
**JDBC Template**
60+
* 优点
61+
* 感觉自己非常接近JDBC本身
62+
* 实现了所有的场景而没有更大的问题-没有隐藏的惊喜
63+
* 非常容易的批量操作
64+
* 设置简单
65+
* 缺点
66+
* 在Java代码中内联SQL使得实现仓储接口的可读性不强。如果Java支持多行字符串,那就更好了
67+
* 调试日志可以更好
68+
69+
**jOOQ**
70+
* 优点
71+
* 非常流畅,很容易编写新的查询,代码非常易读
72+
* 一旦设置好,就很容易使用,非常适合简单的查询
73+
* 很棒的日志记录器调试输出
74+
* 缺点
75+
* 某些数据库的付费许可证——很难说服经理们相信它是值得的:)
76+
* 对于大的查询来说没有那么多的实用性——最好使用原生SQL(参见场景9)
77+
* 批量操作的怪异语法(如果您不使用UpdatableRecord)。但这没什么大不了的……
78+
5679
**MyBatis**
5780
* 优点
5881
* 在XML映射文件里写SQL语句很爽
@@ -72,7 +95,7 @@
7295

7396
## 快速开始 ##
7497

75-
建立maven项目,建议使用spring boot建立web项目
98+
建立maven项目,建议使用spring boot和[spring-data-ebean-spring-boot](https://github.com/hexagonframework/spring-data-ebean-spring-boot.git)建立web项目
7699

77100
实例:[spring-boot-data-ebean-samples](https://github.com/hexagonframework/spring-boot-data-ebean-samples)
78101

@@ -150,7 +173,7 @@ public interface UserRepository extends EbeanRepository<User, Long> {
150173
int deleteUserByEmailAddress(@Param("emailAddress") String emailAddress);
151174
152175
/**
153-
* 命名ORM查询
176+
* 命名ORM/SQL查询
154177
*/
155178
@Query(name = "withManagerById")
156179
List<User> findByLastnameNamedOql(@Param("lastname") String lastname);

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.hexagonframework.data</groupId>
88
<artifactId>spring-data-ebean</artifactId>
9-
<version>1.3.0.RELEASE</version>
9+
<version>1.3.1.RELEASE</version>
1010
<packaging>jar</packaging>
1111

1212
<name>Spring Data Ebean</name>

src/main/java/org/springframework/data/ebean/annotation/Modifying.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616

1717
package org.springframework.data.ebean.annotation;
1818

19-
import java.lang.annotation.*;
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
2024

2125
/**
2226
* Indicates a method should be regarded as Update{@link io.ebean.UpdateQuery} or SqlUpdate {@link io.ebean.SqlUpdate}.

src/main/java/org/springframework/data/ebean/annotation/Procedure.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616

1717
package org.springframework.data.ebean.annotation;
1818

19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
1924
import org.springframework.data.annotation.QueryAnnotation;
2025

21-
import java.lang.annotation.*;
22-
2326
/**
2427
* Annotation to declare stored procedure mappings directly on repository methods.
2528
*

src/main/java/org/springframework/data/ebean/annotation/Query.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616

1717
package org.springframework.data.ebean.annotation;
1818

19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
1924
import org.springframework.data.annotation.QueryAnnotation;
2025

21-
import java.lang.annotation.*;
22-
2326
/**
2427
* Annotation to declare finder queries directly on repository methods.
2528
*

src/main/java/org/springframework/data/ebean/domain/AbstractAggregateRoot.java

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616

1717
package org.springframework.data.ebean.domain;
1818

19-
import org.springframework.data.domain.AfterDomainEventPublication;
20-
import org.springframework.data.domain.DomainEvents;
21-
import org.springframework.util.Assert;
22-
23-
import javax.persistence.MappedSuperclass;
24-
import javax.persistence.Transient;
2519
import java.util.ArrayList;
2620
import java.util.Collection;
2721
import java.util.Collections;
2822
import java.util.List;
23+
import javax.persistence.MappedSuperclass;
24+
import javax.persistence.Transient;
25+
import org.springframework.data.domain.AfterDomainEventPublication;
26+
import org.springframework.data.domain.DomainEvents;
27+
import org.springframework.util.Assert;
2928

3029
/**
3130
* Abstract base class for aggregate root, aggregate extends {@link AbstractEntity} and add
@@ -35,37 +34,37 @@
3534
*/
3635
@MappedSuperclass
3736
public abstract class AbstractAggregateRoot extends AbstractEntity {
38-
@Transient
39-
private transient final List<DomainEvent> domainEvents = new ArrayList<>();
37+
@Transient
38+
private transient final List<DomainEvent> domainEvents = new ArrayList<>();
4039

41-
/**
42-
* Registers the given event object for publication on a call to a Spring Data repository's save methods.
43-
*
44-
* @param event must not be {@literal null}.
45-
* @return the event that has been added.
46-
*/
47-
protected <T extends DomainEvent> T registerEvent(T event) {
48-
Assert.notNull(event, "Domain event must not be null!");
40+
/**
41+
* Registers the given event object for publication on a call to a Spring Data repository's save methods.
42+
*
43+
* @param event must not be {@literal null}.
44+
* @return the event that has been added.
45+
*/
46+
protected <T extends DomainEvent> T registerEvent(T event) {
47+
Assert.notNull(event, "Domain event must not be null!");
4948

50-
this.domainEvents.add(event);
51-
return event;
52-
}
49+
this.domainEvents.add(event);
50+
return event;
51+
}
5352

54-
/**
55-
* Clears all domain events currently held. Usually invoked by the infrastructure in place in Spring Data
56-
* repositories.
57-
*/
58-
@AfterDomainEventPublication
59-
protected void clearDomainEvents() {
60-
this.domainEvents.clear();
61-
}
53+
/**
54+
* Clears all domain events currently held. Usually invoked by the infrastructure in place in Spring Data
55+
* repositories.
56+
*/
57+
@AfterDomainEventPublication
58+
protected void clearDomainEvents() {
59+
this.domainEvents.clear();
60+
}
6261

63-
/**
64-
* All domain events currently captured by the aggregate.
65-
*/
66-
@DomainEvents
67-
protected Collection<DomainEvent> domainEvents() {
68-
return Collections.unmodifiableList(domainEvents);
69-
}
62+
/**
63+
* All domain events currently captured by the aggregate.
64+
*/
65+
@DomainEvents
66+
protected Collection<DomainEvent> domainEvents() {
67+
return Collections.unmodifiableList(domainEvents);
68+
}
7069

7170
}

0 commit comments

Comments
 (0)