16
16
package org .springframework .data .ldap .repository .support ;
17
17
18
18
import static org .springframework .data .querydsl .QuerydslUtils .*;
19
+ import static org .springframework .data .repository .core .support .RepositoryComposition .*;
19
20
20
21
import java .lang .reflect .Constructor ;
21
22
import java .lang .reflect .Method ;
22
23
import java .util .Optional ;
23
24
25
+ import org .springframework .dao .InvalidDataAccessApiUsageException ;
24
26
import org .springframework .data .ldap .core .mapping .LdapMappingContext ;
25
27
import org .springframework .data .ldap .repository .query .AnnotatedLdapRepositoryQuery ;
26
28
import org .springframework .data .ldap .repository .query .LdapQueryMethod ;
@@ -94,9 +96,9 @@ public LdapRepositoryFactory(LdapOperations ldapOperations) {
94
96
* @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getEntityInformation(java.lang.Class)
95
97
*/
96
98
@ Override
97
- @ SuppressWarnings ("unchecked" )
99
+ @ SuppressWarnings ({ "unchecked" , "rawtypes" } )
98
100
public <T , ID > EntityInformation <T , ID > getEntityInformation (Class <T > domainClass ) {
99
- return new LdapEntityInformation (domainClass );
101
+ return new LdapEntityInformation (domainClass , ldapOperations . getObjectDirectoryMapper () );
100
102
}
101
103
102
104
/*
@@ -105,11 +107,46 @@ public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClas
105
107
*/
106
108
@ Override
107
109
protected Class <?> getRepositoryBaseClass (RepositoryMetadata metadata ) {
110
+ return SimpleLdapRepository .class ;
111
+ }
112
+
113
+ /*
114
+ * (non-Javadoc)
115
+ * @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getRepositoryFragments(org.springframework.data.repository.core.RepositoryMetadata)
116
+ */
117
+ @ Override
118
+ protected RepositoryFragments getRepositoryFragments (RepositoryMetadata metadata ) {
119
+ return getRepositoryFragments (metadata , this .ldapOperations );
120
+ }
121
+
122
+ /**
123
+ * Creates {@link RepositoryFragments} based on {@link RepositoryMetadata} to add LDAP-specific extensions. Typically,
124
+ * adds a {@link QuerydslLdapPredicateExecutor} if the repository interface uses Querydsl.
125
+ * <p>
126
+ * Can be overridden by subclasses to customize {@link RepositoryFragments}.
127
+ *
128
+ * @param metadata repository metadata.
129
+ * @param operations the LDAP operations manager.
130
+ * @return
131
+ * @since 2.6
132
+ */
133
+ protected RepositoryFragments getRepositoryFragments (RepositoryMetadata metadata , LdapOperations operations ) {
108
134
109
135
boolean isQueryDslRepository = QUERY_DSL_PRESENT
110
136
&& QuerydslPredicateExecutor .class .isAssignableFrom (metadata .getRepositoryInterface ());
111
137
112
- return isQueryDslRepository ? QuerydslLdapRepository .class : SimpleLdapRepository .class ;
138
+ if (isQueryDslRepository ) {
139
+
140
+ if (metadata .isReactiveRepository ()) {
141
+ throw new InvalidDataAccessApiUsageException (
142
+ "Cannot combine Querydsl and reactive repository support in a single interface" );
143
+ }
144
+
145
+ return RepositoryFragments .just (new QuerydslLdapPredicateExecutor <>(
146
+ getEntityInformation (metadata .getDomainType ()), getProjectionFactory (), operations , mappingContext ));
147
+ }
148
+
149
+ return RepositoryFragments .empty ();
113
150
}
114
151
115
152
/*
0 commit comments