1
1
/*
2
- * Copyright 2013-2014 the original author or authors.
2
+ * Copyright 2013-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
15
15
*/
16
16
package org .springframework .data .repository .core .support ;
17
17
18
+ import static java .util .Arrays .*;
18
19
import static org .springframework .util .ClassUtils .*;
19
20
import static org .springframework .util .ReflectionUtils .*;
20
21
21
22
import java .io .Serializable ;
22
23
import java .lang .reflect .Method ;
23
- import java .util .Arrays ;
24
24
25
25
import org .springframework .data .domain .Pageable ;
26
26
import org .springframework .data .domain .Sort ;
@@ -72,7 +72,7 @@ public DefaultCrudMethods(RepositoryMetadata metadata) {
72
72
* The most suitable save method is selected as follows: We prefer
73
73
* <ol>
74
74
* <li>a {@link RepositoryMetadata#getDomainType()} as first parameter over</li>
75
- * <li>an {@link Object} as first parameter</li>
75
+ * <li>an {@link Object} as first parameter. </li>
76
76
* </ol>
77
77
*
78
78
* @param metadata must not be {@literal null}.
@@ -81,8 +81,10 @@ public DefaultCrudMethods(RepositoryMetadata metadata) {
81
81
@ SuppressWarnings ("unchecked" )
82
82
private Method selectMostSuitableSaveMethod (RepositoryMetadata metadata ) {
83
83
84
- for (Class <?> type : Arrays .asList (metadata .getDomainType (), Object .class )) {
84
+ for (Class <?> type : asList (metadata .getDomainType (), Object .class )) {
85
+
85
86
Method saveMethodCandidate = findMethod (metadata .getRepositoryInterface (), SAVE , type );
87
+
86
88
if (saveMethodCandidate != null ) {
87
89
return getMostSpecificMethod (saveMethodCandidate , metadata .getRepositoryInterface ());
88
90
}
@@ -106,9 +108,10 @@ private Method selectMostSuitableSaveMethod(RepositoryMetadata metadata) {
106
108
@ SuppressWarnings ("unchecked" )
107
109
private Method selectMostSuitableDeleteMethod (RepositoryMetadata metadata ) {
108
110
109
- for (Class <?> type : Arrays . asList (metadata .getDomainType (), metadata .getIdType (), Serializable .class ,
110
- Iterable . class )) {
111
+ for (Class <?> type : asList (metadata .getDomainType (), metadata .getIdType (), Serializable .class , Iterable . class )) {
112
+
111
113
Method candidate = findMethod (metadata .getRepositoryInterface (), DELETE , type );
114
+
112
115
if (candidate != null ) {
113
116
return getMostSpecificMethod (candidate , metadata .getRepositoryInterface ());
114
117
}
@@ -122,7 +125,7 @@ private Method selectMostSuitableDeleteMethod(RepositoryMetadata metadata) {
122
125
* <ol>
123
126
* <li>a {@link Pageable} as first parameter over</li>
124
127
* <li>a {@link Sort} as first parameter over</li>
125
- * <li>no parameters</li>
128
+ * <li>no parameters. </li>
126
129
* </ol>
127
130
*
128
131
* @param metadata must not be {@literal null}.
@@ -131,9 +134,12 @@ private Method selectMostSuitableDeleteMethod(RepositoryMetadata metadata) {
131
134
@ SuppressWarnings ("unchecked" )
132
135
private Method selectMostSuitableFindAllMethod (RepositoryMetadata metadata ) {
133
136
134
- for (Class <?> type : Arrays .asList (Pageable .class , Sort .class )) {
137
+ for (Class <?> type : asList (Pageable .class , Sort .class )) {
138
+
135
139
if (hasMethod (metadata .getRepositoryInterface (), FIND_ALL , type )) {
140
+
136
141
Method candidate = findMethod (PagingAndSortingRepository .class , FIND_ALL , type );
142
+
137
143
if (candidate != null ) {
138
144
return getMostSpecificMethod (candidate , metadata .getRepositoryInterface ());
139
145
}
@@ -160,8 +166,10 @@ private Method selectMostSuitableFindAllMethod(RepositoryMetadata metadata) {
160
166
@ SuppressWarnings ("unchecked" )
161
167
private Method selectMostSuitableFindOneMethod (RepositoryMetadata metadata ) {
162
168
163
- for (Class <?> type : Arrays .asList (metadata .getIdType (), Serializable .class )) {
169
+ for (Class <?> type : asList (metadata .getIdType (), Serializable .class )) {
170
+
164
171
Method candidate = findMethod (metadata .getRepositoryInterface (), FIND_ONE , type );
172
+
165
173
if (candidate != null ) {
166
174
return getMostSpecificMethod (candidate , metadata .getRepositoryInterface ());
167
175
}
0 commit comments