org.eclipse.jnosql.mapping.keyvalue.spi.KeyValueExtension Maven / Gradle / Ivy
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*
* Contributors:
*
* Otavio Santana
*/
package org.eclipse.jnosql.mapping.keyvalue.spi;
import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.spi.AfterBeanDiscovery;
import jakarta.enterprise.inject.spi.Extension;
import jakarta.enterprise.inject.spi.ProcessProducer;
import org.eclipse.jnosql.communication.keyvalue.BucketManager;
import org.eclipse.jnosql.mapping.DatabaseMetadata;
import org.eclipse.jnosql.mapping.Databases;
import org.eclipse.jnosql.mapping.keyvalue.query.RepositoryKeyValueBean;
import org.eclipse.jnosql.mapping.metadata.ClassScanner;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;
import static org.eclipse.jnosql.mapping.DatabaseType.KEY_VALUE;
public class KeyValueExtension implements Extension {
private static final Logger LOGGER = Logger.getLogger(KeyValueExtension.class.getName());
private final Set databases = new HashSet<>();
void observes(@Observes final ProcessProducer pp) {
Databases.addDatabase(pp, KEY_VALUE, databases);
}
void onAfterBeanDiscovery(@Observes final AfterBeanDiscovery afterBeanDiscovery) {
ClassScanner scanner = ClassScanner.load();
Set> crudTypes = scanner.repositoriesStandard();
Set> customRepositories = scanner.customRepositories();
LOGGER.info(String.format("Processing Key-Value extension: %d databases crud %d found",
databases.size(), crudTypes.size()));
LOGGER.info("Processing repositories as a Key-Value implementation: " + crudTypes);
LOGGER.info("Ignoring custom repositories as a Key-Value implementation: " + customRepositories);
databases.forEach(type -> {
final TemplateBean bean = new TemplateBean(type.getProvider());
afterBeanDiscovery.addBean(bean);
});
crudTypes.forEach(type -> {
if (!databases.contains(DatabaseMetadata.DEFAULT_KEY_VALUE)) {
afterBeanDiscovery.addBean(new RepositoryKeyValueBean<>(type, ""));
}
databases.forEach(database -> afterBeanDiscovery
.addBean(new RepositoryKeyValueBean<>(type, database.getProvider())));
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy