Skip to content

Commit b25cdcf

Browse files
committed
feat: update param
Signed-off-by: Otavio Santana <[email protected]>
1 parent 6d554ea commit b25cdcf

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2022 Contributors to the Eclipse Foundation
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.databases.couchbase.mapping;
16+
17+
18+
import com.couchbase.client.java.json.JsonObject;
19+
import jakarta.data.repository.Param;
20+
21+
import java.lang.annotation.Annotation;
22+
import java.lang.reflect.Method;
23+
import java.util.Optional;
24+
import java.util.stream.Stream;
25+
26+
final class JsonObjectUtil {
27+
28+
private JsonObjectUtil() {
29+
}
30+
31+
static JsonObject getParams(Object[] args, Method method) {
32+
33+
JsonObject jsonObject = JsonObject.create();
34+
Annotation[][] annotations = method.getParameterAnnotations();
35+
36+
for (int index = 0; index < annotations.length; index++) {
37+
38+
final Object arg = args[index];
39+
40+
Optional<Param> param = Stream.of(annotations[index])
41+
.filter(Param.class::isInstance)
42+
.map(Param.class::cast)
43+
.findFirst();
44+
param.ifPresent(p -> jsonObject.put(p.value(), arg));
45+
46+
}
47+
48+
return jsonObject;
49+
}
50+
}

jnosql-couchbase/src/test/java/org/eclipse/jnosql/databases/couchbase/mapping/CouchbaseDocumentRepositoryProxyTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.eclipse.jnosql.databases.couchbase.mapping;
1616

1717
import com.couchbase.client.java.json.JsonObject;
18+
import jakarta.data.repository.Param;
1819
import jakarta.inject.Inject;
1920
import org.eclipse.jnosql.mapping.core.Converters;
2021
import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension;
@@ -133,6 +134,6 @@ interface HumanRepository extends CouchbaseRepository<Human, String> {
133134
List<Human> findAllQuery();
134135

135136
@N1QL("select * from Person where name = $name")
136-
List<Human> findByName(String name);
137+
List<Human> findByName(@Param("name") String name);
137138
}
138139
}

0 commit comments

Comments
 (0)