-
Notifications
You must be signed in to change notification settings - Fork 54
/
AbstractLdapRepositoryQuery.java
99 lines (87 loc) · 3.08 KB
/
AbstractLdapRepositoryQuery.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Copyright 2016-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.ldap.repository.query;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.ldap.repository.Query;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.ldap.core.LdapOperations;
import org.springframework.ldap.query.LdapQuery;
import org.springframework.util.Assert;
/**
* Base class for {@link RepositoryQuery} implementations for LDAP.
*
* @author Mattias Hellborg Arthursson
* @author Mark Paluch
*/
public abstract class AbstractLdapRepositoryQuery implements RepositoryQuery {
private final LdapQueryMethod queryMethod;
private final Class<?> entityType;
private final LdapOperations ldapOperations;
/**
* Creates a new {@link AbstractLdapRepositoryQuery} instance given {@link LdapQuery}, {@link Class} and
* {@link LdapOperations}.
*
* @param queryMethod must not be {@literal null}.
* @param entityType must not be {@literal null}.
* @param ldapOperations must not be {@literal null}.
*/
public AbstractLdapRepositoryQuery(LdapQueryMethod queryMethod, Class<?> entityType, LdapOperations ldapOperations) {
Assert.notNull(queryMethod, "LdapQueryMethod must not be null!");
Assert.notNull(entityType, "Entity type must not be null!");
Assert.notNull(ldapOperations, "LdapOperations must not be null!");
this.queryMethod = queryMethod;
this.entityType = entityType;
this.ldapOperations = ldapOperations;
}
/* (non-Javadoc)
* @see org.springframework.data.repository.query.RepositoryQuery#execute(java.lang.Object[])
*/
@Override
@SuppressWarnings("ConstantConditions")
public final Object execute(Object[] parameters) {
LdapQuery query = createQuery(parameters);
if (queryMethod.isCollectionQuery()) {
return ldapOperations.find(query, entityType);
} else {
try {
return ldapOperations.findOne(query, entityType);
} catch (EmptyResultDataAccessException e) {
return null;
}
}
}
/**
* Creates a {@link Query} instance using the given {@literal parameters}.
*
* @param parameters must not be {@literal null}.
* @return
*/
protected abstract LdapQuery createQuery(Object[] parameters);
/**
* @return
*/
protected Class<?> getEntityClass() {
return entityType;
}
/* (non-Javadoc)
* @see org.springframework.data.repository.query.RepositoryQuery#getQueryMethod()
*/
@Override
public final QueryMethod getQueryMethod() {
return queryMethod;
}
}