Skip to content

Commit f578a85

Browse files
committed
feat: create suppleir by collection supplier in redis
Signed-off-by: Otavio Santana <[email protected]>
1 parent 0693efa commit f578a85

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2023 Eclipse Contribuitor
3+
* All rights reserved. This program and the accompanying materials
4+
* and Apache License v2.0 which accompanies this distribution.
5+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
6+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
7+
* You may elect to redistribute this code under either of these licenses.
8+
*/
9+
package org.eclipse.jnosql.databases.redis.mapping;
10+
11+
import jakarta.data.exceptions.MappingException;
12+
import jakarta.enterprise.context.ApplicationScoped;
13+
import jakarta.enterprise.inject.Produces;
14+
import jakarta.enterprise.inject.spi.InjectionPoint;
15+
import jakarta.inject.Inject;
16+
import org.eclipse.jnosql.databases.redis.communication.Counter;
17+
import org.eclipse.jnosql.databases.redis.communication.RedisBucketManagerFactory;
18+
import org.eclipse.jnosql.databases.redis.communication.SortedSet;
19+
import org.eclipse.jnosql.mapping.keyvalue.KeyValueDatabase;
20+
21+
import java.lang.reflect.ParameterizedType;
22+
import java.lang.reflect.Type;
23+
import java.util.Set;
24+
25+
@ApplicationScoped
26+
class CollectionSupplier {
27+
28+
29+
@Inject
30+
private RedisBucketManagerFactory factory;
31+
32+
33+
@Produces
34+
@KeyValueDatabase("")
35+
public Counter getSet(InjectionPoint injectionPoint) {
36+
return factory.getCounter(bucketName(injectionPoint));
37+
}
38+
39+
@Produces
40+
@KeyValueDatabase("")
41+
public SortedSet getRanking(InjectionPoint injectionPoint) {
42+
return factory.getSortedSet(bucketName(injectionPoint));
43+
}
44+
45+
46+
private static String bucketName(InjectionPoint injectionPoint) {
47+
48+
KeyValueDatabase keyValue = injectionPoint.getQualifiers()
49+
.stream().filter(KeyValueDatabase.class::isInstance)
50+
.map(KeyValueDatabase.class::cast)
51+
.findFirst().orElseThrow(() -> new MappingException("There is an issue to load " +
52+
"a Collection from the database"));
53+
return keyValue.value();
54+
}
55+
}

0 commit comments

Comments
 (0)