├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── README_zh.md
├── _config.yml
├── pom.xml
└── src
├── main
├── java
│ └── org
│ │ └── springframework
│ │ └── data
│ │ └── ebean
│ │ ├── annotation
│ │ ├── ExprParam.java
│ │ ├── IncludeFields.java
│ │ ├── Modifying.java
│ │ ├── Query.java
│ │ └── package-info.java
│ │ ├── domain
│ │ ├── AbstractAggregateRoot.java
│ │ ├── AbstractEntity.java
│ │ ├── DomainEvent.java
│ │ ├── DomainService.java
│ │ └── package-info.java
│ │ ├── querychannel
│ │ ├── EbeanQueryChannelService.java
│ │ ├── ExprType.java
│ │ ├── QueryChannelService.java
│ │ └── package-info.java
│ │ ├── repository
│ │ ├── EbeanRepository.java
│ │ ├── config
│ │ │ ├── EbeanRepositoriesRegistrar.java
│ │ │ ├── EbeanRepositoryConfigExtension.java
│ │ │ ├── EbeanRepositoryNameSpaceHandler.java
│ │ │ ├── EnableEbeanRepositories.java
│ │ │ └── package-info.java
│ │ ├── package-info.java
│ │ ├── query
│ │ │ ├── AbstractEbeanQuery.java
│ │ │ ├── AbstractEbeanQueryExecution.java
│ │ │ ├── AbstractStringBasedEbeanQuery.java
│ │ │ ├── EbeanQueryCreator.java
│ │ │ ├── EbeanQueryFactory.java
│ │ │ ├── EbeanQueryLookupStrategy.java
│ │ │ ├── EbeanQueryMethod.java
│ │ │ ├── EbeanQueryWrapper.java
│ │ │ ├── ExpressionBasedStringQuery.java
│ │ │ ├── InvalidEbeanQueryMethodException.java
│ │ │ ├── NamedEbeanQuery.java
│ │ │ ├── NativeEbeanQuery.java
│ │ │ ├── NativeEbeanUpdate.java
│ │ │ ├── OrmEbeanQuery.java
│ │ │ ├── OrmEbeanUpdate.java
│ │ │ ├── ParameterBinder.java
│ │ │ ├── ParameterMetadataProvider.java
│ │ │ ├── PartTreeEbeanQuery.java
│ │ │ ├── SpelExpressionStringQueryParameterBinder.java
│ │ │ ├── StringQuery.java
│ │ │ ├── StringQueryParameterBinder.java
│ │ │ └── package-info.java
│ │ └── support
│ │ │ ├── EbeanEntityInformation.java
│ │ │ ├── EbeanRepositoryFactory.java
│ │ │ ├── EbeanRepositoryFactoryBean.java
│ │ │ ├── SimpleEbeanRepository.java
│ │ │ └── package-info.java
│ │ └── util
│ │ ├── Converters.java
│ │ ├── ExampleExpressionBuilder.java
│ │ └── package-info.java
└── resources
│ ├── META-INF
│ ├── spring.factories
│ └── spring.handlers
│ └── license.txt
└── test
├── java
└── org
│ └── springframework
│ └── data
│ └── ebean
│ ├── querychannel
│ ├── EbeanQueryChannelServiceIntegrationTest.java
│ ├── UserDTO.java
│ └── UserQuery.java
│ ├── repository
│ └── UserRepositoryIntegrationTest.java
│ └── sample
│ ├── config
│ └── SampleConfig.java
│ └── domain
│ ├── Address.java
│ ├── FullName.java
│ ├── Role.java
│ ├── User.java
│ ├── UserDomainService.java
│ ├── UserEmailChangedEvent.java
│ ├── UserInfo.java
│ └── UserRepository.java
└── resources
├── application.properties
├── ebean-xml-mappings
├── UserDTOMapping.xml
├── UserInfoMapping.xml
└── UserMapping.xml
├── ebean.mf
└── logback-test.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | .idea/
3 | .settings/
4 | *.iml
5 | .project
6 | .classpath
7 | .springBeans
8 | .sonar4clipse
9 | *.sonar4clipseExternals
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
3 | jdk:
4 | - oraclejdk8
5 |
6 | env:
7 | matrix:
8 | - PROFILE=spring43
9 | - PROFILE=spring43-next
10 |
11 | cache:
12 | directories:
13 | - $HOME/.m2
14 |
15 | sudo: false
16 |
17 | install: true
18 |
19 | script: "mvn clean dependency:list test -P${PROFILE} -Dsort"
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-architect
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | 4.0.0
6 |
7 | io.github.hexagonframework.data
8 | spring-data-ebean
9 | 2.0.0.RELEASE
10 | jar
11 |
12 | Spring Data Ebean
13 | Spring Data module for Ebean repositories.
14 | https://github.com/hexagonframework/spring-data-ebean
15 | 2017
16 |
17 |
18 | Hexagon Framework
19 | https://github.com/hexagonframework
20 |
21 |
22 |
23 | xueguiyuan
24 | Xuegui Yuan
25 | yuanxuegui@163.com
26 |
27 |
28 |
29 |
30 |
31 | Apache License, Version 2.0
32 | http://www.apache.org/licenses/LICENSE-2.0.txt
33 |
34 |
35 |
36 |
37 | https://github.com/hexagonframework/spring-data-ebean.git
38 | scm:git:git://github.com/hexagonframework/spring-data-ebean.git
39 | scm:git:ssh://git@github.com/hexagonframework/spring-data-ebean.git
40 |
41 |
42 |
43 | UTF-8
44 | 1.8
45 | debug=0
46 | false
47 | false
48 | 5.1.2.RELEASE
49 | 2.1.2.RELEASE
50 | 11.21.1
51 | 11.10.4
52 | reuseReports
53 |
54 |
55 |
56 |
57 | release
58 |
59 |
60 |
61 | org.apache.maven.plugins
62 | maven-source-plugin
63 | 3.0.1
64 |
65 |
66 | package
67 |
68 | jar-no-fork
69 |
70 |
71 |
72 |
73 |
74 | org.apache.maven.plugins
75 | maven-javadoc-plugin
76 | 3.0.0
77 |
78 | ${java.version}
79 |
80 |
81 |
82 | package
83 |
84 | jar
85 |
86 |
87 |
88 |
89 |
90 | org.apache.maven.plugins
91 | maven-gpg-plugin
92 | 1.6
93 |
94 |
95 | verify
96 |
97 | sign
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | oss
107 | https://oss.sonatype.org/content/repositories/snapshots/
108 |
109 |
110 | oss
111 | https://oss.sonatype.org/service/local/staging/deploy/maven2/
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 | org.springframework.data
120 | spring-data-commons
121 | ${springdata.commons}
122 |
123 |
124 |
125 | org.springframework
126 | spring-context
127 | ${spring}
128 |
129 |
130 |
131 | org.springframework
132 | spring-jdbc
133 | ${spring}
134 |
135 |
136 |
137 | org.springframework
138 | spring-tx
139 | ${spring}
140 |
141 |
142 |
143 | org.springframework
144 | spring-core
145 | ${spring}
146 |
147 |
148 | commons-logging
149 | commons-logging
150 |
151 |
152 |
153 |
154 |
155 | io.ebean
156 | ebean
157 | ${ebean.version}
158 | true
159 |
160 |
161 |
162 | io.ebean
163 | ebean-spring-txn
164 | ${ebean-spring-txn.version}
165 |
166 |
167 |
168 | org.springframework
169 | spring-aspects
170 | ${spring}
171 | compile
172 | true
173 |
174 |
175 |
176 | org.projectlombok
177 | lombok
178 | 1.16.16
179 | true
180 |
181 |
182 |
183 | junit
184 | junit
185 | 4.12
186 | test
187 |
188 |
189 |
190 | com.h2database
191 | h2
192 | 1.4.196
193 | test
194 |
195 |
196 |
197 | org.springframework
198 | spring-test
199 | ${spring}
200 | test
201 |
202 |
203 |
204 | ch.qos.logback
205 | logback-classic
206 | 1.2.3
207 | test
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 | io.repaint.maven
216 | tiles-maven-plugin
217 | 2.10
218 | true
219 |
220 |
221 | org.avaje.tile:java-compile:1.1
222 | io.ebean.tile:enhancement:5.5
223 |
224 |
225 |
226 |
227 | org.apache.maven.plugins
228 | maven-assembly-plugin
229 | 3.0.0
230 |
231 |
232 | org.codehaus.mojo
233 | wagon-maven-plugin
234 | 2.0.0
235 |
236 |
237 | org.asciidoctor
238 | asciidoctor-maven-plugin
239 | 1.5.6
240 |
241 |
242 |
243 |
244 |
245 |
246 | spring-libs-release
247 | https://repo.spring.io/libs-release
248 |
249 |
250 |
251 |
252 |
253 | spring-plugins-release
254 | https://repo.spring.io/plugins-release
255 |
256 |
257 |
258 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/annotation/ExprParam.java:
--------------------------------------------------------------------------------
1 | package org.springframework.data.ebean.annotation;
2 |
3 | import org.springframework.data.ebean.querychannel.ExprType;
4 |
5 | import java.lang.annotation.*;
6 |
7 | /**
8 | * Expr param.
9 | *
10 | * @author XueguiYuan
11 | * @version 1.0 (created time: 2018/4/29).
12 | */
13 | @Retention(RetentionPolicy.RUNTIME)
14 | @Target(ElementType.FIELD)
15 | @Documented
16 | public @interface ExprParam {
17 |
18 | /**
19 | * Query param name.
20 | */
21 | String name() default "";
22 |
23 | /**
24 | * Query param name.
25 | */
26 | String value() default "";
27 |
28 | /**
29 | * Expr.
30 | */
31 | ExprType expr() default ExprType.DEFAULT;
32 |
33 | /**
34 | * Case insensitive.
35 | */
36 | boolean ignoreCase() default true;
37 |
38 | /**
39 | * If true, do nothing when field value is null, else and expr isNull.
40 | */
41 | boolean escapeNull() default true;
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/annotation/IncludeFields.java:
--------------------------------------------------------------------------------
1 | package org.springframework.data.ebean.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Define the fetch path string for query select and fetch.
10 | *
11 | * @author XueguiYuan
12 | * @version 1.0 (created time: 2018/4/29).
13 | */
14 | @Retention(RetentionPolicy.RUNTIME)
15 | @Target(ElementType.TYPE)
16 | public @interface IncludeFields {
17 | /**
18 | * Query fetch path string.
19 | */
20 | String value();
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/annotation/Modifying.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.data.ebean.annotation;
18 |
19 | import java.lang.annotation.*;
20 |
21 | /**
22 | * Indicates a method should be regarded as Update{@link io.ebean.UpdateQuery} or SqlUpdate{@link io.ebean.SqlUpdate}.
23 | *
24 | * @author Xuegui Yuan
25 | */
26 | @Retention(RetentionPolicy.RUNTIME)
27 | @Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
28 | @Documented
29 | public @interface Modifying {
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/annotation/Query.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.data.ebean.annotation;
18 |
19 | import org.springframework.data.annotation.QueryAnnotation;
20 |
21 | import java.lang.annotation.*;
22 |
23 | /**
24 | * Annotation to declare finder queries directly on repository methods.
25 | *
26 | * @author Xuegui Yuan
27 | */
28 | @Retention(RetentionPolicy.RUNTIME)
29 | @Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
30 | @QueryAnnotation
31 | @Documented
32 | public @interface Query {
33 |
34 | /**
35 | * Defines the Ebean query to be executed when the annotated method is called.
36 | */
37 | String value() default "";
38 |
39 | /**
40 | * Configures whether the given query is a SqlQuery. Defaults to {@literal false}.
41 | */
42 | boolean nativeQuery() default false;
43 |
44 | /**
45 | * The named query to be used. If not defined, a {@link javax.persistence.NamedQuery} with name of
46 | * {@code $ domainClass}.${queryMethodName}} will be used.
47 | */
48 | String name() default "";
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/annotation/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Annotations for Ebean specific repositories.
3 | */
4 |
5 | package org.springframework.data.ebean.annotation;
6 |
7 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/domain/AbstractAggregateRoot.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.data.ebean.domain;
18 |
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;
25 | import java.util.ArrayList;
26 | import java.util.Collection;
27 | import java.util.Collections;
28 | import java.util.List;
29 |
30 | /**
31 | * Abstract base class for aggregate root, aggregate extends {@link AbstractEntity} and add
32 | * domain event functions.
33 | *
34 | * @author XueguiYuan
35 | */
36 | @MappedSuperclass
37 | public abstract class AbstractAggregateRoot extends AbstractEntity {
38 | @Transient
39 | private transient final List domainEvents = new ArrayList<>();
40 |
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 registerEvent(T event) {
48 | Assert.notNull(event, "Domain event must not be null!");
49 |
50 | this.domainEvents.add(event);
51 | return event;
52 | }
53 |
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 | }
62 |
63 | /**
64 | * All domain events currently captured by the aggregate.
65 | */
66 | @DomainEvents
67 | protected Collection domainEvents() {
68 | return Collections.unmodifiableList(domainEvents);
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/domain/AbstractEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.data.ebean.domain;
18 |
19 | import io.ebean.annotation.CreatedTimestamp;
20 | import io.ebean.annotation.UpdatedTimestamp;
21 | import io.ebean.annotation.WhoCreated;
22 | import io.ebean.annotation.WhoModified;
23 | import org.springframework.data.domain.Auditable;
24 | import org.springframework.data.domain.Persistable;
25 | import org.springframework.util.ClassUtils;
26 |
27 | import javax.persistence.Id;
28 | import javax.persistence.MappedSuperclass;
29 | import javax.persistence.Transient;
30 | import java.time.LocalDateTime;
31 | import java.util.Optional;
32 |
33 |
34 | /**
35 | * Abstract base class for entities.
36 | * {@link #equals(Object)} and {@link #hashCode()} based on that id.
37 | *
38 | * @author Xuegui Yuan
39 | */
40 | @MappedSuperclass
41 | public abstract class AbstractEntity implements Persistable, Auditable {
42 |
43 | private static final long serialVersionUID = -5554308939380869754L;
44 |
45 | @Id
46 | protected Long id;
47 |
48 | @WhoCreated
49 | String createdBy;
50 |
51 | @CreatedTimestamp
52 | LocalDateTime createdDate;
53 |
54 | @WhoModified
55 | String lastModifiedBy;
56 |
57 | @UpdatedTimestamp
58 | LocalDateTime lastModifiedDate;
59 |
60 | @Override
61 | public Optional getCreatedBy() {
62 | return Optional.ofNullable(createdBy);
63 | }
64 |
65 | @Override
66 | public void setCreatedBy(String createdBy) {
67 | this.createdBy = createdBy;
68 | }
69 |
70 | @Override
71 | public Optional getCreatedDate() {
72 | return Optional.ofNullable(createdDate);
73 | }
74 |
75 | @Override
76 | public void setCreatedDate(LocalDateTime createdDate) {
77 | this.createdDate = createdDate;
78 | }
79 |
80 | @Override
81 | public Optional getLastModifiedBy() {
82 | return Optional.ofNullable(lastModifiedBy);
83 | }
84 |
85 | @Override
86 | public void setLastModifiedBy(String lastModifiedBy) {
87 | this.lastModifiedBy = lastModifiedBy;
88 | }
89 |
90 | @Override
91 | public Optional getLastModifiedDate() {
92 | return Optional.ofNullable(lastModifiedDate);
93 | }
94 |
95 | @Override
96 | public void setLastModifiedDate(LocalDateTime lastModifiedDate) {
97 | this.lastModifiedDate = lastModifiedDate;
98 | }
99 |
100 | @Override
101 | public int hashCode() {
102 | int hashCode = 17;
103 |
104 | hashCode += null == getId() ? 0 : getId().hashCode() * 31;
105 |
106 | return hashCode;
107 | }
108 |
109 | @Override
110 | public Long getId() {
111 | return id;
112 | }
113 |
114 | /**
115 | * Sets the id of the entity.
116 | *
117 | * @param id the id to set
118 | */
119 | public void setId(final Long id) {
120 | this.id = id;
121 | }
122 |
123 | @Transient
124 | @Override
125 | public boolean isNew() {
126 | return null == getId();
127 | }
128 |
129 | @Override
130 | public boolean equals(Object obj) {
131 | if (null == obj) {
132 | return false;
133 | }
134 |
135 | if (this == obj) {
136 | return true;
137 | }
138 |
139 | if (!getClass().equals(ClassUtils.getUserClass(obj))) {
140 | return false;
141 | }
142 |
143 | AbstractEntity that = (AbstractEntity) obj;
144 |
145 | return null != this.getId() && this.getId().equals(that.getId());
146 | }
147 |
148 | @Override
149 | public String toString() {
150 | return String.format("Entity of type %s with id: %s", this.getClass().getName(), getId());
151 | }
152 |
153 | }
154 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/domain/DomainEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.data.ebean.domain;
18 |
19 | import org.springframework.context.ApplicationEvent;
20 |
21 | /**
22 | * Domain event.
23 | *
24 | * @author Xuegui Yuan
25 | */
26 | public class DomainEvent extends ApplicationEvent {
27 |
28 | public DomainEvent(Object source) {
29 | super(source);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/domain/DomainService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.data.ebean.domain;
18 |
19 | import org.springframework.stereotype.Component;
20 |
21 | import java.lang.annotation.*;
22 |
23 | /**
24 | * Domain service use spring @Component
25 | *
26 | * @author Xuegui Yuan
27 | */
28 | @Target({ElementType.TYPE})
29 | @Retention(RetentionPolicy.RUNTIME)
30 | @Documented
31 | @Component
32 | public @interface DomainService {
33 | String value() default "";
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/domain/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Ebean specific impl classes to implement domain classes.
3 | */
4 |
5 | package org.springframework.data.ebean.domain;
6 |
7 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/querychannel/ExprType.java:
--------------------------------------------------------------------------------
1 | package org.springframework.data.ebean.querychannel;
2 |
3 | /**
4 | * Expr type.
5 | *
6 | * @author XueguiYuan
7 | * @version 1.0 (created time: 2018/4/29).
8 | */
9 | public enum ExprType {
10 | DEFAULT, EQ, NE, GT, GE, LT, LE, LIKE, STARTS_WITH, ENDS_WITH, CONTAINS, IN
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/querychannel/QueryChannelService.java:
--------------------------------------------------------------------------------
1 | package org.springframework.data.ebean.querychannel;
2 |
3 | import io.ebean.*;
4 | import org.springframework.data.domain.Pageable;
5 |
6 | import java.util.Map;
7 |
8 | /**
9 | * @author XueguiYuan
10 | * @version 1.0 (created time: 2018/4/29).
11 | */
12 | public interface QueryChannelService {
13 |
14 | Query createQuery(Class entityType, Object queryObject);
15 |
16 | Query createQuery(Class entityType, Object queryObject, Pageable pageable);
17 |
18 | Query createQuery(Class entityType);
19 |
20 | Query createQuery(Class entityType, String eql);
21 |
22 | SqlQuery createSqlQuery(String sql);
23 |
24 | Query createSqlQuery(Class entityType, String sql);
25 |
26 | Query createSqlQueryMappingColumns(Class entityType,
27 | String sql,
28 | Map columnMapping);
29 |
30 | Query createSqlQueryMappingTableAlias(Class entityType,
31 | String sql,
32 | Map tableAliasMapping);
33 |
34 | Query createNamedQuery(Class entityType, String queryName);
35 |
36 | DtoQuery createDtoQuery(Class dtoType, String sql);
37 |
38 | DtoQuery createNamedDtoQuery(Class dtoType, String namedQuery);
39 |
40 | ExampleExpression exampleOf(Object example);
41 |
42 | ExampleExpression exampleOf(Object example,
43 | boolean caseInsensitive,
44 | LikeType likeType);
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/querychannel/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * EbeanQueryWrapper channel service.
3 | */
4 |
5 | package org.springframework.data.ebean.querychannel;
6 |
7 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/repository/EbeanRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.data.ebean.repository;
18 |
19 | import io.ebean.EbeanServer;
20 | import io.ebean.SqlUpdate;
21 | import io.ebean.UpdateQuery;
22 | import org.springframework.data.domain.Example;
23 | import org.springframework.data.domain.Page;
24 | import org.springframework.data.domain.Pageable;
25 | import org.springframework.data.domain.Sort;
26 | import org.springframework.data.repository.NoRepositoryBean;
27 | import org.springframework.data.repository.PagingAndSortingRepository;
28 | import org.springframework.data.repository.query.QueryByExampleExecutor;
29 |
30 | import java.util.List;
31 | import java.util.Optional;
32 |
33 | /**
34 | * Ebean specific extension of {@link org.springframework.data.repository.Repository}.
35 | *
36 | * @author Xuegui Yuan
37 | */
38 | @NoRepositoryBean
39 | public interface EbeanRepository extends PagingAndSortingRepository, QueryByExampleExecutor {
40 |
41 | /**
42 | * Return the current EbeanServer.
43 | *
44 | * @return the current EbeanServer
45 | */
46 | EbeanServer db();
47 |
48 | /**
49 | * Set the current EbeanServer.
50 | *
51 | * @param db current EbeanServer
52 | * @return the current EbeanServer
53 | */
54 | EbeanServer db(EbeanServer db);
55 |
56 | /**
57 | * Return an UpdateQuery to perform a bulk update of many rows that match the query.
58 | *
59 | * @return the created UpdateQuery
60 | */
61 | UpdateQuery updateQuery();
62 |
63 | /**
64 | * Return a SqlUpdate for executing insert update or delete statements.
65 | *
66 | * @param sql native SQL
67 | * @return the created SqlUpdate using native SQL
68 | */
69 | SqlUpdate sqlUpdateOf(String sql);
70 |
71 | /**
72 | * Update entity which is not loaded.
73 | *
74 | * @param s entity to update
75 | * @param entity extends T
76 | * @return entity Updated entity
77 | */
78 | S update(S s);
79 |
80 | /**
81 | * Update entities which is not loaded.
82 | *
83 | * @param entities entities to update
84 | * @return entities Updated entities list
85 | */
86 | Iterable updateAll(Iterable entities);
87 |
88 | /**
89 | * Deletes the entity permanent with the given id.
90 | *
91 | * @param id must not be {@literal null}.
92 | * @throws IllegalArgumentException in case the given {@code id} is {@literal null}
93 | */
94 | void deletePermanentById(ID id);
95 |
96 | /**
97 | * Deletes a given entity permanent.
98 | *
99 | * @param entity the entity to be deleted
100 | * @throws IllegalArgumentException in case the given entity is {@literal null}.
101 | */
102 | void deletePermanent(T entity);
103 |
104 | /**
105 | * Deletes the given entities permanent.
106 | *
107 | * @param entities the entities to be deleted
108 | * @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}.
109 | */
110 | void deletePermanentAll(Iterable extends T> entities);
111 |
112 | /**
113 | * Deletes all entities permanent managed by the repository.
114 | */
115 | void deletePermanentAll();
116 |
117 | /**
118 | * Retrieves an entity by its id and select return entity properties with FetchPath string.
119 | *
120 | * @param fetchPath FetchPath string
121 | * @param id ID
122 | * @return the entity only select/fetch with FetchPath string with the given id or {@literal null} if none found
123 | */
124 | Optional findById(String fetchPath, ID id);
125 |
126 | /**
127 | * Retrieves an entity by its property name value.
128 | *
129 | * @param propertyName property name
130 | * @param propertyValue property value
131 | * @return the entity with the given property name value or {@literal null} if none found
132 | */
133 | Optional findByProperty(String propertyName, Object propertyValue);
134 |
135 | /**
136 | * Retrieves an entity by its property name value and select return entity properties with FetchPath string.
137 | *
138 | * @param fetchPath FetchPath string
139 | * @param propertyName property name
140 | * @param propertyValue property value
141 | * @return the entity only select/fetch with FetchPath string with the given property name value or {@literal null} if none found
142 | */
143 | Optional findByProperty(String fetchPath, String propertyName, Object propertyValue);
144 |
145 | /**
146 | * Retrieves an entities by its property name value.
147 | *
148 | * @param propertyName property name
149 | * @param propertyValue property value
150 | * @return the entity with the given property name value or {@literal null} if none found
151 | */
152 | List findAllByProperty(String propertyName, Object propertyValue);
153 |
154 | /**
155 | * Retrieves all entities by its property name value and select return entity properties with FetchPath string.
156 | *
157 | * @param fetchPath FetchPath string
158 | * @param propertyName property name
159 | * @param propertyValue property value
160 | * @return the entity only select/fetch with FetchPath string with the given property name value or {@literal null} if none found
161 | */
162 | List findAllByProperty(String fetchPath, String propertyName, Object propertyValue);
163 |
164 | /**
165 | * Retrieves an entity by its property name value and select return entity properties with FetchPath string.
166 | *
167 | * @param fetchPath FetchPath string.
168 | * @param propertyName property name.
169 | * @param propertyValue property value.
170 | * @param sort order by.
171 | * @return the entity only select/fetch with FetchPath string with the given property name value or {@literal null} if none found.
172 | */
173 | List findAllByProperty(String fetchPath, String propertyName, Object propertyValue, Sort sort);
174 |
175 | /**
176 | * Find all by id list.
177 | *
178 | * @param ids id list.
179 | * @return List all entities list.
180 | */
181 | @Override
182 | List findAllById(Iterable ids);
183 |
184 | /**
185 | * Find All.
186 | *
187 | * @return List all entities list.
188 | */
189 | @Override
190 | List findAll();
191 |
192 | /**
193 | * Find all order by sort config.
194 | *
195 | * @param sort order by.
196 | * @return List all entities list.
197 | */
198 | @Override
199 | List findAll(Sort sort);
200 |
201 | /**
202 | * Returns all entities and select return entity properties with FetchPath string.
203 | *
204 | * @param fetchPath FetchPath string.
205 | * @return all entities only select/fetch with FetchPath string.
206 | */
207 | List findAll(String fetchPath);
208 |
209 | /**
210 | * Returns all entities in ids and select return entity properties with FetchPath string.
211 | *
212 | * @param fetchPath FetchPath string.
213 | * @param ids ID list.
214 | * @return all entities by id in ids and select/fetch with FetchPath string.
215 | */
216 | List findAll(String fetchPath, Iterable ids);
217 |
218 | /**
219 | * Returns all entities sorted by the given options and select return entity properties with FetchPath string.
220 | *
221 | * @param fetchPath FetchPath string.
222 | * @param sort order by.
223 | * @return all entities sorted and select/fetch with FetchPath string.
224 | */
225 | List findAll(String fetchPath, Sort sort);
226 |
227 | /**
228 | * Returns a {@link Page} of entities meeting the paging restriction provided in the {@code Pageable} object.
229 | * and select return entity properties with FetchPath string.
230 | *
231 | * @param fetchPath FetchPath string.
232 | * @param pageable page request.
233 | * @return a page of entities select/fetch with FetchPath string.
234 | */
235 | Page findAll(String fetchPath, Pageable pageable);
236 |
237 | /**
238 | * Returns a {@link Page} of entities meeting the paging restriction provided in the {@code Pageable} object.
239 | * and matching the given {@link Example} and select return entity properties with FetchPath string.
240 | *
241 | * @param fetchPath FetchPath string.
242 | * @param example must not be {@literal null}.
243 | * @param pageable page request.
244 | * @return a page of entities select/fetch with FetchPath string.
245 | */
246 | Page findAll(String fetchPath, Example example, Pageable pageable);
247 |
248 | /**
249 | * Returns all entities matching the given {@link Example}. In case no match could be found an empty {@link Iterable}
250 | * is returned.
251 | *
252 | * @param example must not be {@literal null}.
253 | * @return all entities matching the given {@link Example}.
254 | */
255 | @Override
256 | List findAll(Example example);
257 |
258 | /**
259 | * Returns all entities matching the given {@link Example} applying the given {@link Sort}. In case no match could be
260 | * found an empty {@link Iterable} is returned.
261 | *
262 | * @param fetchPath FetchPath string.
263 | * @param example must not be {@literal null}.
264 | * @return all entities matching the given {@link Example}.
265 | */
266 | List findAll(String fetchPath, Example example);
267 |
268 | /**
269 | * Returns all entities matching the given {@link Example} applying the given {@link Sort}. In case no match could be
270 | * found an empty {@link Iterable} is returned.
271 | *
272 | * @param fetchPath FetchPath string.
273 | * @param example must not be {@literal null}.
274 | * @param sort the {@link Sort} specification to sort the results by, must not be {@literal null}.
275 | * @return all entities matching the given {@link Example}.
276 | */
277 | List findAll(String fetchPath, Example example, Sort sort);
278 |
279 | /**
280 | * Returns all entities matching the given {@link Example} applying the given {@link Sort}. In case no match could be
281 | * found an empty {@link Iterable} is returned.
282 | *
283 | * @param example must not be {@literal null}.
284 | * @param sort the {@link Sort} specification to sort the results by, must not be {@literal null}.
285 | * @return all entities matching the given {@link Example}.
286 | */
287 | @Override
288 | List findAll(Example example, Sort sort);
289 | }
290 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/repository/config/EbeanRepositoriesRegistrar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.data.ebean.repository.config;
18 |
19 | import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
20 | import org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport;
21 | import org.springframework.data.repository.config.RepositoryConfigurationExtension;
22 |
23 | import java.lang.annotation.Annotation;
24 |
25 | /**
26 | * {@link ImportBeanDefinitionRegistrar} to enable {@link EnableEbeanRepositories} annotation.
27 | *
28 | * @author Xuegui Yuan
29 | */
30 | class EbeanRepositoriesRegistrar extends RepositoryBeanDefinitionRegistrarSupport {
31 |
32 | /*
33 | * (non-Javadoc)
34 | * @see org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport#getAnnotation()
35 | */
36 | @Override
37 | protected Class extends Annotation> getAnnotation() {
38 | return EnableEbeanRepositories.class;
39 | }
40 |
41 | /*
42 | * (non-Javadoc)
43 | * @see org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport#getExtension()
44 | */
45 | @Override
46 | protected RepositoryConfigurationExtension getExtension() {
47 | return new EbeanRepositoryConfigExtension();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/repository/config/EbeanRepositoryConfigExtension.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.data.ebean.repository.config;
18 |
19 | import org.springframework.dao.DataAccessException;
20 | import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
21 | import org.springframework.data.ebean.repository.EbeanRepository;
22 | import org.springframework.data.ebean.repository.support.EbeanRepositoryFactoryBean;
23 | import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport;
24 |
25 | import javax.persistence.Entity;
26 | import javax.persistence.MappedSuperclass;
27 | import java.lang.annotation.Annotation;
28 | import java.util.Arrays;
29 | import java.util.Collection;
30 | import java.util.Collections;
31 | import java.util.Locale;
32 |
33 | /**
34 | * Ebean specific configuration extension parsing custom attributes from the XML namespace and
35 | * {@link EnableEbeanRepositories} annotation. Also, it registers bean definitions for a
36 | * {@link PersistenceExceptionTranslationPostProcessor} to enable exception translation of persistence specific
37 | * exceptions into Spring's {@link DataAccessException} hierarchy.
38 | *
39 | * @author Xuegui Yuan
40 | */
41 | public class EbeanRepositoryConfigExtension extends RepositoryConfigurationExtensionSupport {
42 |
43 | private static final String DEFAULT_TRANSACTION_MANAGER_BEAN_NAME = "transactionManager";
44 | private static final String ENABLE_DEFAULT_TRANSACTIONS_ATTRIBUTE = "enableDefaultTransactions";
45 |
46 | /*
47 | * (non-Javadoc)
48 | * @see org.springframework.data.repository.config.RepositoryConfigurationExtension#getRepositoryFactoryBeanClassName()
49 | */
50 | @Override
51 | public String getRepositoryFactoryBeanClassName() {
52 | return EbeanRepositoryFactoryBean.class.getName();
53 | }
54 |
55 | /*
56 | * (non-Javadoc)
57 | * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getModuleName()
58 | */
59 | @Override
60 | public String getModuleName() {
61 | return "Ebean";
62 | }
63 |
64 |
65 | /*
66 | * (non-Javadoc)
67 | * @see org.springframework.data.repository.config14.RepositoryConfigurationExtensionSupport#getModulePrefix()
68 | */
69 | @Override
70 | protected String getModulePrefix() {
71 | return getModuleName().toLowerCase(Locale.US);
72 | }
73 |
74 | /*
75 | * (non-Javadoc)
76 | * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getIdentifyingAnnotations()
77 | */
78 | @Override
79 | protected Collection> getIdentifyingAnnotations() {
80 | return Arrays.asList(Entity.class, MappedSuperclass.class);
81 | }
82 |
83 | /*
84 | * (non-Javadoc)
85 | * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getIdentifyingTypes()
86 | */
87 | @Override
88 | protected Collection> getIdentifyingTypes() {
89 | return Collections.>singleton(EbeanRepository.class);
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/repository/config/EbeanRepositoryNameSpaceHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.data.ebean.repository.config;
18 |
19 | import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
20 | import org.springframework.data.repository.config.RepositoryBeanDefinitionParser;
21 | import org.springframework.data.repository.config.RepositoryConfigurationExtension;
22 |
23 | /**
24 | * Simple namespace handler for {@literal repositories} namespace.
25 | *
26 | * @author Xuegui Yuan
27 | */
28 | public class EbeanRepositoryNameSpaceHandler extends NamespaceHandlerSupport {
29 |
30 | @Override
31 | public void init() {
32 |
33 | RepositoryConfigurationExtension extension = new EbeanRepositoryConfigExtension();
34 | RepositoryBeanDefinitionParser repositoryBeanDefinitionParser = new RepositoryBeanDefinitionParser(extension);
35 |
36 | registerBeanDefinitionParser("repositories", repositoryBeanDefinitionParser);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/repository/config/EnableEbeanRepositories.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.data.ebean.repository.config;
18 |
19 | import org.springframework.beans.factory.FactoryBean;
20 | import org.springframework.context.annotation.ComponentScan.Filter;
21 | import org.springframework.context.annotation.Import;
22 | import org.springframework.data.ebean.repository.support.EbeanRepositoryFactoryBean;
23 | import org.springframework.data.repository.config.DefaultRepositoryBaseClass;
24 | import org.springframework.data.repository.query.QueryLookupStrategy;
25 | import org.springframework.data.repository.query.QueryLookupStrategy.Key;
26 | import org.springframework.transaction.PlatformTransactionManager;
27 |
28 | import java.lang.annotation.*;
29 |
30 | /**
31 | * Annotation to enable Ebean repositories. Will scan the package of the annotated configuration class for Spring Data
32 | * repositories by default.
33 | *
34 | * @author Xuegui Yuan
35 | */
36 | @Target(ElementType.TYPE)
37 | @Retention(RetentionPolicy.RUNTIME)
38 | @Documented
39 | @Inherited
40 | @Import(EbeanRepositoriesRegistrar.class)
41 | public @interface EnableEbeanRepositories {
42 |
43 | /**
44 | * Alias for the {@link #basePackages()} attribute. Allows for more concise annotation declarations e.g.:
45 | * {@code @EnableEbeanRepositories("org.my.pkg")} instead of {@code @EnableEbeanRepositories(basePackages="org.my.pkg")}.
46 | */
47 | String[] value() default {};
48 |
49 | /**
50 | * Base packages to scan for annotated components. {@link #value()} is an alias for (and mutually exclusive with) this
51 | * attribute. Use {@link #basePackageClasses()} for a type-safe alternative to String-based package names.
52 | */
53 | String[] basePackages() default {};
54 |
55 | /**
56 | * Type-safe alternative to {@link #basePackages()} for specifying the packages to scan for annotated components. The
57 | * package of each class specified will be scanned. Consider creating a special no-op marker class or interface in
58 | * each package that serves no purpose other than being referenced by this attribute.
59 | */
60 | Class>[] basePackageClasses() default {};
61 |
62 | /**
63 | * Specifies which types are eligible for component scanning. Further narrows the set of candidate components from
64 | * everything in {@link #basePackages()} to everything in the base packages that matches the given filter or filters.
65 | */
66 | Filter[] includeFilters() default {};
67 |
68 | /**
69 | * Specifies which types are not eligible for component scanning.
70 | */
71 | Filter[] excludeFilters() default {};
72 |
73 | /**
74 | * Returns the postfix to be used when looking up custom repository implementations. Defaults to {@literal Impl}. So
75 | * for a repository named {@code PersonRepository} the corresponding implementation class will be looked up scanning
76 | * for {@code PersonRepositoryImpl}.
77 | *
78 | * @return
79 | */
80 | String repositoryImplementationPostfix() default "Impl";
81 |
82 | /**
83 | * Configures the location of where to find the Spring Data named queries properties file. Will default to
84 | * {@code META-INF/ebean-named-queries.properties}.
85 | *
86 | * @return
87 | */
88 | String namedQueriesLocation() default "";
89 |
90 | /**
91 | * Returns the key of the {@link QueryLookupStrategy} to be used for lookup queries for query methods. Defaults to
92 | * {@link Key#CREATE_IF_NOT_FOUND}.
93 | *
94 | * @return
95 | */
96 | Key queryLookupStrategy() default Key.CREATE_IF_NOT_FOUND;
97 |
98 | /**
99 | * Returns the {@link FactoryBean} class to be used for each repository instance. Defaults to
100 | * {@link EbeanRepositoryFactoryBean}.
101 | *
102 | * @return
103 | */
104 | Class> repositoryFactoryBeanClass() default EbeanRepositoryFactoryBean.class;
105 |
106 | /**
107 | * Configure the repository base class to be used to create repository proxies for this particular configuration.
108 | *
109 | * @return
110 | * @since 1.9
111 | */
112 | Class> repositoryBaseClass() default DefaultRepositoryBaseClass.class;
113 |
114 | // Ebean specific configuration
115 |
116 | /**
117 | * Configures the name of the {@link io.ebean.EbeanServer} bean definition to be used to create repositories
118 | * discovered through this annotation. Defaults to {@code ebeanServer}.
119 | *
120 | * @return
121 | */
122 | String ebeanServerRef() default "ebeanServer";
123 |
124 | /**
125 | * Configures the name of the {@link PlatformTransactionManager} bean definition to be used to create repositories
126 | * discovered through this annotation. Defaults to {@code transactionManager}.
127 | *
128 | * @return
129 | */
130 | String transactionManagerRef() default "transactionManager";
131 | }
132 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/repository/config/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Classes for Ebean namespace configuration.
3 | */
4 |
5 | package org.springframework.data.ebean.repository.config;
6 |
7 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/repository/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Interfaces and inner implementation for Ebean specific repositories.
3 | */
4 |
5 | package org.springframework.data.ebean.repository;
6 |
7 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/repository/query/AbstractEbeanQuery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.data.ebean.repository.query;
18 |
19 | import io.ebean.EbeanServer;
20 | import org.springframework.data.repository.query.DefaultParameters;
21 | import org.springframework.data.repository.query.RepositoryQuery;
22 | import org.springframework.util.Assert;
23 |
24 | import static org.springframework.data.ebean.repository.query.AbstractEbeanQueryExecution.*;
25 |
26 | /**
27 | * Abstract base class to implement {@link RepositoryQuery}.
28 | *
29 | * @author Xuegui Yuan
30 | */
31 | public abstract class AbstractEbeanQuery implements RepositoryQuery {
32 |
33 | private final EbeanQueryMethod method;
34 | private final EbeanServer ebeanServer;
35 |
36 | /**
37 | * Creates a new {@link AbstractEbeanQuery} from the given {@link EbeanQueryMethod}.
38 | *
39 | * @param method
40 | * @param ebeanServer
41 | */
42 | public AbstractEbeanQuery(EbeanQueryMethod method, EbeanServer ebeanServer) {
43 |
44 | Assert.notNull(method, "EbeanQueryMethod must not be null!");
45 | Assert.notNull(ebeanServer, "EbeanServer must not be null!");
46 |
47 | this.method = method;
48 | this.ebeanServer = ebeanServer;
49 | }
50 |
51 | /**
52 | * Returns the {@link EbeanServer}.
53 | *
54 | * @return will never be {@literal null}.
55 | */
56 | protected EbeanServer getEbeanServer() {
57 | return ebeanServer;
58 | }
59 |
60 | @Override
61 | public Object execute(Object[] parameters) {
62 | return doExecute(getExecution(), parameters);
63 | }
64 |
65 | @Override
66 | public EbeanQueryMethod getQueryMethod() {
67 | return method;
68 | }
69 |
70 | /**
71 | * @param execution
72 | * @param values
73 | * @return
74 | */
75 | private Object doExecute(AbstractEbeanQueryExecution execution, Object[] values) {
76 | Object result = execution.execute(this, values);
77 | return result;
78 | }
79 |
80 | protected AbstractEbeanQueryExecution getExecution() {
81 | if (method.isStreamQuery()) {
82 | return new StreamExecution();
83 | } else if (method.isCollectionQuery()) {
84 | return new AbstractEbeanQueryExecution.CollectionExecution();
85 | } else if (method.isSliceQuery()) {
86 | return new SlicedExecution(method.getParameters());
87 | } else if (method.isPageQuery()) {
88 | return new PagedExecution(method.getParameters());
89 | } else if (method.isModifyingQuery()) {
90 | return new UpdateExecution(method, ebeanServer);
91 | } else {
92 | return new SingleEntityExecution();
93 | }
94 | }
95 |
96 | protected ParameterBinder createBinder(Object[] values) {
97 | return new ParameterBinder((DefaultParameters) getQueryMethod().getParameters(), values);
98 | }
99 |
100 | protected EbeanQueryWrapper createQuery(Object[] values) {
101 | return doCreateQuery(values);
102 | }
103 |
104 | /**
105 | * Creates a {@link io.ebean.Query} or {@link io.ebean.SqlQuery} instance for the given values.
106 | *
107 | * @param values must not be {@literal null}.
108 | * @return
109 | */
110 | protected abstract EbeanQueryWrapper doCreateQuery(Object[] values);
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/repository/query/AbstractEbeanQueryExecution.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.data.ebean.repository.query;
18 |
19 | import io.ebean.EbeanServer;
20 | import org.springframework.dao.InvalidDataAccessApiUsageException;
21 | import org.springframework.data.domain.Slice;
22 | import org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor;
23 | import org.springframework.data.repository.query.ParameterAccessor;
24 | import org.springframework.data.repository.query.Parameters;
25 | import org.springframework.data.repository.query.ParametersParameterAccessor;
26 | import org.springframework.util.Assert;
27 |
28 | /**
29 | * Set of classes to contain query execution strategies. Depending (mostly) on the return type of a
30 | * {@link org.springframework.data.repository.query.QueryMethod} a {@link AbstractStringBasedEbeanQuery} can be executed
31 | * in various flavors.
32 | *
33 | * @author Xuegui Yuan
34 | */
35 | public abstract class AbstractEbeanQueryExecution {
36 |
37 | /**
38 | * Executes the given {@link AbstractStringBasedEbeanQuery} with the given {@link ParameterBinder}.
39 | *
40 | * @param query must not be {@literal null}.
41 | * @param values must not be {@literal null}.
42 | * @return
43 | */
44 | public Object execute(AbstractEbeanQuery query, Object[] values) {
45 | Assert.notNull(query, "AbstractEbeanQuery must not be null!");
46 | Assert.notNull(values, "Values must not be null!");
47 |
48 | return doExecute(query, values);
49 | }
50 |
51 | /**
52 | * Method to implement {@link AbstractStringBasedEbeanQuery} executions by single enum values.
53 | *
54 | * @param query
55 | * @param values
56 | * @return
57 | */
58 | protected abstract Object doExecute(AbstractEbeanQuery query, Object[] values);
59 |
60 | /**
61 | * Executes the query to return a simple collection of entities.
62 | */
63 | static class CollectionExecution extends AbstractEbeanQueryExecution {
64 |
65 | @Override
66 | protected Object doExecute(AbstractEbeanQuery repositoryQuery, Object[] values) {
67 | EbeanQueryWrapper createQuery = repositoryQuery.createQuery(values);
68 | return createQuery.findList();
69 | }
70 | }
71 |
72 | /**
73 | * Executes the query to return a {@link Slice} of entities.
74 | *
75 | * @author Xuegui Yuan
76 | */
77 | static class SlicedExecution extends AbstractEbeanQueryExecution {
78 |
79 | private final Parameters, ?> parameters;
80 |
81 | /**
82 | * Creates a new {@link SlicedExecution} using the given {@link Parameters}.
83 | *
84 | * @param parameters must not be {@literal null}.
85 | */
86 | public SlicedExecution(Parameters, ?> parameters) {
87 | this.parameters = parameters;
88 | }
89 |
90 | /*
91 | * (non-Javadoc)
92 | * @see org.springframework.data.ebean.repository.query.AbstractEbeanQueryExecution#doExecute(org.springframework.data.ebean.repository.query.AbstractEbeanQuery, java.lang.Object[])
93 | */
94 | @Override
95 | @SuppressWarnings("unchecked")
96 | protected Object doExecute(AbstractEbeanQuery query, Object[] values) {
97 | ParametersParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
98 | EbeanQueryWrapper createQuery = query.createQuery(values);
99 | return createQuery.findSlice(accessor.getPageable());
100 | }
101 | }
102 |
103 | /**
104 | * Executes the {@link AbstractStringBasedEbeanQuery} to return a {@link org.springframework.data.domain.Page} of
105 | * entities.
106 | */
107 | static class PagedExecution extends AbstractEbeanQueryExecution {
108 |
109 | private final Parameters, ?> parameters;
110 |
111 | public PagedExecution(Parameters, ?> parameters) {
112 |
113 | this.parameters = parameters;
114 | }
115 |
116 | @Override
117 | @SuppressWarnings("unchecked")
118 | protected Object doExecute(final AbstractEbeanQuery repositoryQuery, final Object[] values) {
119 | ParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
120 | EbeanQueryWrapper createQuery = repositoryQuery.createQuery(values);
121 | return createQuery.findPage(accessor.getPageable());
122 | }
123 | }
124 |
125 |
126 | /**
127 | * Executes a {@link AbstractStringBasedEbeanQuery} to return a single entity.
128 | */
129 | static class SingleEntityExecution extends AbstractEbeanQueryExecution {
130 |
131 | @Override
132 | protected Object doExecute(AbstractEbeanQuery query, Object[] values) {
133 | EbeanQueryWrapper createQuery = query.createQuery(values);
134 | return createQuery.findOne();
135 | }
136 | }
137 |
138 | /**
139 | * Executes a update query such as an update, insert or delete.
140 | */
141 | static class UpdateExecution extends AbstractEbeanQueryExecution {
142 |
143 | private final EbeanServer ebeanServer;
144 |
145 | /**
146 | * Creates an execution that automatically clears the given {@link EbeanServer} after execution if the given
147 | * {@link EbeanServer} is not {@literal null}.
148 | *
149 | * @param ebeanServer
150 | */
151 | public UpdateExecution(EbeanQueryMethod method, EbeanServer ebeanServer) {
152 |
153 | Class> returnType = method.getReturnType();
154 |
155 | boolean isVoid = void.class.equals(returnType) || Void.class.equals(returnType);
156 | boolean isInt = int.class.equals(returnType) || Integer.class.equals(returnType);
157 |
158 | Assert.isTrue(isInt || isVoid, "Modifying queries can only use void or int/Integer as return type!");
159 |
160 | this.ebeanServer = ebeanServer;
161 | }
162 |
163 | @Override
164 | protected Object doExecute(AbstractEbeanQuery query, Object[] values) {
165 | EbeanQueryWrapper createQuery = query.createQuery(values);
166 | return createQuery.update();
167 | }
168 | }
169 |
170 | /**
171 | * {@link AbstractEbeanQueryExecution} removing entities matching the query.
172 | *
173 | * @author Xuegui Yuan
174 | */
175 | static class DeleteExecution extends AbstractEbeanQueryExecution {
176 |
177 | private final EbeanServer ebeanServer;
178 |
179 | public DeleteExecution(EbeanServer ebeanServer) {
180 | this.ebeanServer = ebeanServer;
181 | }
182 |
183 | /*
184 | * (non-Javadoc)
185 | * @see org.springframework.data.ebean.repository.query.AbstractEbeanQueryExecution#doExecute(org.springframework.data.ebean.repository.query.AbstractEbeanQuery, java.lang.Object[])
186 | */
187 | @Override
188 | protected Object doExecute(AbstractEbeanQuery ebeanQuery, Object[] values) {
189 | EbeanQueryWrapper createQuery = ebeanQuery.createQuery(values);
190 | return createQuery.delete();
191 | }
192 | }
193 |
194 | /**
195 | * {@link AbstractEbeanQueryExecution} performing an exists check on the query.
196 | *
197 | * @author Xuegui Yuan
198 | */
199 | static class ExistsExecution extends AbstractEbeanQueryExecution {
200 |
201 | @Override
202 | protected Object doExecute(AbstractEbeanQuery ebeanQuery, Object[] values) {
203 | EbeanQueryWrapper createQuery = ebeanQuery.createQuery(values);
204 | return createQuery.isExists();
205 | }
206 | }
207 |
208 | /**
209 | * {@link AbstractEbeanQueryExecution} executing a Java 8 Stream.
210 | *
211 | * @author Xuegui Yuan
212 | */
213 | static class StreamExecution extends AbstractEbeanQueryExecution {
214 |
215 | private static final String NO_SURROUNDING_TRANSACTION = "You're trying to execute a streaming query method without a surrounding transaction that keeps the connection open so that the Stream can actually be consumed. Make sure the code consuming the stream uses @Transactional or any other way of declaring a (read-only) transaction.";
216 |
217 | /*
218 | * (non-Javadoc)
219 | * @see org.springframework.data.ebean.repository.query.AbstractEbeanQueryExecution#doExecute(org.springframework.data.ebean.repository.query.AbstractEbeanQuery, java.lang.Object[])
220 | */
221 | @Override
222 | protected Object doExecute(final AbstractEbeanQuery ebeanQuery, Object[] values) {
223 | if (!SurroundingTransactionDetectorMethodInterceptor.INSTANCE.isSurroundingTransactionActive()) {
224 | throw new InvalidDataAccessApiUsageException(NO_SURROUNDING_TRANSACTION);
225 | }
226 |
227 | EbeanQueryWrapper createQuery = ebeanQuery.createQuery(values);
228 | return createQuery.findStream();
229 | }
230 | }
231 | }
232 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/repository/query/AbstractStringBasedEbeanQuery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.data.ebean.repository.query;
18 |
19 | import io.ebean.EbeanServer;
20 | import org.springframework.data.repository.query.*;
21 | import org.springframework.expression.spel.standard.SpelExpressionParser;
22 | import org.springframework.util.Assert;
23 |
24 |
25 | /**
26 | * Base class for {@link String} based Ebean queries.
27 | *
28 | * @author Xuegui Yuan
29 | */
30 | abstract class AbstractStringBasedEbeanQuery extends AbstractEbeanQuery {
31 |
32 | private final StringQuery query;
33 | private final QueryMethodEvaluationContextProvider evaluationContextProvider;
34 | private final SpelExpressionParser parser;
35 |
36 | /**
37 | * Creates a new {@link AbstractStringBasedEbeanQuery} from the given {@link EbeanQueryMethod}, {@link io.ebean.EbeanServer} and
38 | * query {@link String}.
39 | *
40 | * @param method must not be {@literal null}.
41 | * @param ebeanServer must not be {@literal null}.
42 | * @param queryString must not be {@literal null}.
43 | * @param evaluationContextProvider must not be {@literal null}.
44 | * @param parser must not be {@literal null}.
45 | */
46 | public AbstractStringBasedEbeanQuery(EbeanQueryMethod method, EbeanServer ebeanServer, String queryString,
47 | QueryMethodEvaluationContextProvider evaluationContextProvider, SpelExpressionParser parser) {
48 |
49 | super(method, ebeanServer);
50 |
51 | Assert.hasText(queryString, "EbeanQueryWrapper string must not be null or empty!");
52 | Assert.notNull(evaluationContextProvider, "ExpressionEvaluationContextProvider must not be null!");
53 | Assert.notNull(parser, "Parser must not be null or empty!");
54 |
55 | this.evaluationContextProvider = evaluationContextProvider;
56 | this.query = new ExpressionBasedStringQuery(queryString, method.getEntityInformation(), parser);
57 | this.parser = parser;
58 | }
59 |
60 | /**
61 | * @return the query
62 | */
63 | public StringQuery getQuery() {
64 | return query;
65 | }
66 |
67 | /*
68 | * (non-Javadoc)
69 | * @see org.springframework.data.ebean.repository.query.AbstractEbeanQuery#doCreateQuery(java.lang.Object[])
70 | */
71 | @Override
72 | public EbeanQueryWrapper doCreateQuery(Object[] values) {
73 | ParameterAccessor accessor = new ParametersParameterAccessor(getQueryMethod().getParameters(), values);
74 |
75 | EbeanQueryWrapper query = createEbeanQuery(this.query.getQueryString());
76 |
77 | return createBinder(values).bindAndPrepare(query);
78 | }
79 |
80 | /*
81 | * (non-Javadoc)
82 | * @see org.springframework.data.ebean.repository.query.AbstractEbeanQuery#createBinder(java.lang.Object[])
83 | */
84 | @Override
85 | protected ParameterBinder createBinder(Object[] values) {
86 | return new SpelExpressionStringQueryParameterBinder((DefaultParameters) getQueryMethod().getParameters(), values, query,
87 | evaluationContextProvider, parser);
88 | }
89 |
90 | /**
91 | * Creates an appropriate Ebean query from an {@link EbeanServer} according to the current {@link AbstractEbeanQuery}
92 | * type.
93 | *
94 | * @param queryString
95 | * @return
96 | */
97 | protected EbeanQueryWrapper createEbeanQuery(String queryString) {
98 | EbeanServer ebeanServer = getEbeanServer();
99 |
100 | ResultProcessor resultFactory = getQueryMethod().getResultProcessor();
101 | ReturnedType returnedType = resultFactory.getReturnedType();
102 |
103 | return EbeanQueryWrapper.ofEbeanQuery(ebeanServer.createQuery(returnedType.getReturnedType(), queryString));
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/data/ebean/repository/query/EbeanQueryCreator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.data.ebean.repository.query;
18 |
19 | import io.ebean.Expr;
20 | import io.ebean.Expression;
21 | import io.ebean.ExpressionList;
22 | import io.ebean.Query;
23 | import org.springframework.data.domain.Sort;
24 | import org.springframework.data.mapping.PropertyPath;
25 | import org.springframework.data.repository.query.ReturnedType;
26 | import org.springframework.data.repository.query.parser.AbstractQueryCreator;
27 | import org.springframework.data.repository.query.parser.Part;
28 | import org.springframework.data.repository.query.parser.PartTree;
29 | import org.springframework.util.Assert;
30 |
31 | import java.util.Collection;
32 | import java.util.Iterator;
33 | import java.util.List;
34 |
35 | /**
36 | * EbeanQueryWrapper creator to create a {@link io.ebean.Expression} from a {@link PartTree}.
37 | *
38 | * @author Xuegui Yuan
39 | */
40 | public class EbeanQueryCreator extends AbstractQueryCreator {
41 |
42 | private final ExpressionList root;
43 | private final ParameterMetadataProvider provider;
44 | private final ReturnedType returnedType;
45 | private final PartTree tree;
46 |
47 | /**
48 | * Create a new {@link EbeanQueryCreator}.
49 | *
50 | * @param tree must not be {@literal null}.
51 | * @param type must not be {@literal null}.
52 | * @param expressionList must not be {@literal null}.
53 | * @param provider must not be {@literal null}.
54 | */
55 | public EbeanQueryCreator(PartTree tree, ReturnedType type, ExpressionList expressionList,
56 | ParameterMetadataProvider provider) {
57 | super(tree);
58 | this.tree = tree;
59 |
60 | this.root = expressionList;
61 | this.provider = provider;
62 | this.returnedType = type;
63 | }
64 |
65 | /**
66 | * Returns all {@link ParameterMetadataProvider.ParameterMetadata} created when creating the query.
67 | *
68 | * @return the parameterExpressions
69 | */
70 | public List> getParameterExpressions() {
71 | return provider.getExpressions();
72 | }
73 |
74 | /*
75 | * (non-Javadoc)
76 | * @see org.springframework.data.repository.query.parser.AbstractQueryCreator#create(org.springframework.data.repository.query.parser.Part, java.util.Iterator)
77 | */
78 | @Override
79 | protected Expression create(Part part, Iterator