Skip to content

Commit 65d848a

Browse files
committed
feat: neo4j repository
Signed-off-by: Otavio Santana <[email protected]>
1 parent e4ecb9a commit 65d848a

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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.neo4j.mapping;
16+
17+
import jakarta.enterprise.context.spi.CreationalContext;
18+
import jakarta.enterprise.inject.Default;
19+
import jakarta.enterprise.util.AnnotationLiteral;
20+
import org.eclipse.jnosql.mapping.core.Converters;
21+
import org.eclipse.jnosql.mapping.core.spi.AbstractBean;
22+
import org.eclipse.jnosql.mapping.metadata.EntitiesMetadata;
23+
24+
import java.lang.annotation.Annotation;
25+
import java.lang.reflect.Proxy;
26+
import java.lang.reflect.Type;
27+
import java.util.Collections;
28+
import java.util.Set;
29+
30+
31+
class Neo4JRepositoryBean<T, K> extends AbstractBean<Neo4JRepository<T, K>> {
32+
33+
private final Class<T> type;
34+
35+
private final Set<Type> types;
36+
37+
private final Set<Annotation> qualifiers = Collections.singleton(new AnnotationLiteral<Default>() {
38+
});
39+
40+
Neo4JRepositoryBean(Class<T> type) {
41+
this.type = type;
42+
this.types = Collections.singleton(type);
43+
}
44+
45+
@Override
46+
public Class<?> getBeanClass() {
47+
return type;
48+
}
49+
50+
@SuppressWarnings("unchecked")
51+
@Override
52+
public Neo4JRepository<T, K> create(CreationalContext<Neo4JRepository<T, K>> creationalContext) {
53+
Neo4JTemplate template = getInstance(Neo4JTemplate.class);
54+
Converters converters = getInstance(Converters.class);
55+
EntitiesMetadata entitiesMetadata = getInstance(EntitiesMetadata.class);
56+
Neo4JRepositoryProxy<T, K> handler = new Neo4JRepositoryProxy<>(template, type,
57+
converters, entitiesMetadata);
58+
return (Neo4JRepository<T, K>) Proxy.newProxyInstance(type.getClassLoader(),
59+
new Class[]{type},
60+
handler);
61+
}
62+
63+
64+
@Override
65+
public Set<Type> getTypes() {
66+
return types;
67+
}
68+
69+
@Override
70+
public Set<Annotation> getQualifiers() {
71+
return qualifiers;
72+
}
73+
74+
@Override
75+
public String getId() {
76+
return type.getName() + "@neo4j";
77+
}
78+
79+
}

0 commit comments

Comments
 (0)