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+
18+ import jakarta .enterprise .event .Observes ;
19+ import jakarta .enterprise .inject .spi .AfterBeanDiscovery ;
20+ import jakarta .enterprise .inject .spi .Extension ;
21+ import org .eclipse .jnosql .mapping .metadata .ClassScanner ;
22+
23+ import java .util .Set ;
24+ import java .util .logging .Logger ;
25+
26+ /**
27+ * CDI extension for Cassandra integration.
28+ */
29+ public class Neo4JExtension implements Extension {
30+
31+ private static final Logger LOGGER = Logger .getLogger (Neo4JExtension .class .getName ());
32+
33+ /**
34+ * Observes the AfterBeanDiscovery event to add Cassandra repository beans.
35+ *
36+ * @param afterBeanDiscovery the AfterBeanDiscovery event
37+ */
38+ void onAfterBeanDiscovery (@ Observes final AfterBeanDiscovery afterBeanDiscovery ) {
39+ ClassScanner scanner = ClassScanner .load ();
40+ Set <Class <?>> crudTypes = scanner .repositories (Neo4JRepository .class );
41+
42+ LOGGER .info ("Starting the onAfterBeanDiscovery with elements number: " + crudTypes .size ());
43+
44+ crudTypes .forEach (type -> afterBeanDiscovery .addBean (new Neo4JRepositoryBean <>(type )));
45+
46+ LOGGER .info ("Finished the onAfterBeanDiscovery" );
47+ }
48+ }
0 commit comments