Skip to content

Commit

Permalink
Merge pull request #210 from eclipse/add_config_configuration
Browse files Browse the repository at this point in the history
 Support to Eclipse Config #203
  • Loading branch information
otaviojava authored Oct 3, 2019
2 parents 0c13797 + 45d48c6 commit 09a14f6
Show file tree
Hide file tree
Showing 149 changed files with 3,678 additions and 5,211 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2019 Otávio Santana and others
* 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.artemis.column.configuration;

import jakarta.nosql.column.ColumnConfiguration;
import jakarta.nosql.column.ColumnFamilyManagerAsync;
import jakarta.nosql.column.ColumnFamilyManagerAsyncFactory;
import org.eclipse.jnosql.artemis.configuration.SettingsConverter;
import org.eclipse.jnosql.artemis.util.BeanManagers;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.Converter;

/**
* Converter the {@link String} to {@link ColumnFamilyManagerAsync} it will use the {@link SettingsConverter} and
* find by the provider that should be an implementation of {@link ColumnConfiguration}
*/
public class ColumnFamilyManagerAsyncConverter implements Converter<ColumnFamilyManagerAsync> {

@Override
public ColumnFamilyManagerAsync convert(String value) {
Config config = BeanManagers.getInstance(Config.class);
final ColumnFamilyManagerAsyncFactory managerFactory = config.getValue(value, ColumnFamilyManagerAsyncFactory.class);
final String database = value + ".database";
final String entity = config.getValue(database, String.class);
return managerFactory.getAsync(entity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2019 Otávio Santana and others
* 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.artemis.column.configuration;

import jakarta.nosql.Settings;
import jakarta.nosql.column.ColumnConfigurationAsync;
import jakarta.nosql.column.ColumnFamilyManagerAsyncFactory;
import jakarta.nosql.mapping.reflection.Reflections;
import org.eclipse.jnosql.artemis.configuration.ConfigurationException;
import org.eclipse.jnosql.artemis.configuration.SettingsConverter;
import org.eclipse.jnosql.artemis.util.BeanManagers;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.Converter;

/**
* Converter the {@link String} to {@link ColumnFamilyManagerAsyncFactory} it will use the {@link SettingsConverter} and
* find by the provider that should be an implementation of {@link ColumnConfigurationAsync}
*/
public class ColumnFamilyManagerAsyncFactoryConverter implements Converter<ColumnFamilyManagerAsyncFactory> {

@Override
public ColumnFamilyManagerAsyncFactory convert(String value) {
final SettingsConverter settingsConverter = BeanManagers.getInstance(SettingsConverter.class);
Config config = BeanManagers.getInstance(Config.class);
final Settings settings = settingsConverter.convert(value);
String provider = value + ".provider";
final Class<?> configurationClass = config.getValue(provider, Class.class);
if (ColumnConfigurationAsync.class.isAssignableFrom(configurationClass)) {
final Reflections reflections = BeanManagers.getInstance(Reflections.class);
final ColumnConfigurationAsync configuration = (ColumnConfigurationAsync) reflections.newInstance(configurationClass);
return configuration.get(settings);

}
throw new ConfigurationException("The class " + configurationClass + " is not valid to " + ColumnConfigurationAsync.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2019 Otávio Santana and others
* 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.artemis.column.configuration;

import jakarta.nosql.column.ColumnConfiguration;
import jakarta.nosql.column.ColumnFamilyManager;
import jakarta.nosql.column.ColumnFamilyManagerFactory;
import org.eclipse.jnosql.artemis.configuration.SettingsConverter;
import org.eclipse.jnosql.artemis.util.BeanManagers;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.Converter;

/**
* Converter the {@link String} to {@link ColumnFamilyManager} it will use the {@link SettingsConverter} and
* find by the provider that should be an implementation of {@link ColumnConfiguration}
*/
public class ColumnFamilyManagerConverter implements Converter<ColumnFamilyManager> {

@Override
public ColumnFamilyManager convert(String value) {
Config config = BeanManagers.getInstance(Config.class);
final ColumnFamilyManagerFactory managerFactory = config.getValue(value, ColumnFamilyManagerFactory.class);
final String database = value + ".database";
final String entity = config.getValue(database, String.class);
return managerFactory.get(entity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2019 Otávio Santana and others
* 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.artemis.column.configuration;

import jakarta.nosql.Settings;
import jakarta.nosql.column.ColumnConfiguration;
import jakarta.nosql.column.ColumnFamilyManagerFactory;
import jakarta.nosql.mapping.reflection.Reflections;
import org.eclipse.jnosql.artemis.configuration.ConfigurationException;
import org.eclipse.jnosql.artemis.configuration.SettingsConverter;
import org.eclipse.jnosql.artemis.util.BeanManagers;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.Converter;

/**
* Converter the {@link String} to {@link ColumnFamilyManagerFactory} it will use the {@link SettingsConverter} and
* find by the provider that should be an implementation of {@link ColumnConfiguration}
*/
public class ColumnFamilyManagerFactoryConverter implements Converter<ColumnFamilyManagerFactory> {

@Override
public ColumnFamilyManagerFactory convert(String value) {
final SettingsConverter settingsConverter = BeanManagers.getInstance(SettingsConverter.class);
Config config = BeanManagers.getInstance(Config.class);
final Settings settings = settingsConverter.convert(value);
String provider = value + ".provider";
final Class<?> configurationClass = config.getValue(provider, Class.class);
if (ColumnConfiguration.class.isAssignableFrom(configurationClass)) {
final Reflections reflections = BeanManagers.getInstance(Reflections.class);
final ColumnConfiguration configuration = (ColumnConfiguration) reflections.newInstance(configurationClass);
return configuration.get(settings);

}
throw new ConfigurationException("The class " + configurationClass + " is not valid to " + ColumnConfiguration.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2019 Otávio Santana and others
* 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.artemis.column.configuration;

import jakarta.nosql.column.ColumnFamilyManagerAsync;
import jakarta.nosql.mapping.column.ColumnTemplateAsync;
import jakarta.nosql.mapping.column.ColumnTemplateAsyncProducer;
import org.eclipse.jnosql.artemis.configuration.SettingsConverter;
import org.eclipse.jnosql.artemis.util.BeanManagers;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.Converter;

/**
* Converter the {@link String} to {@link ColumnTemplateAsync} it will use the {@link SettingsConverter} and
* find by the provider that should be an implementation of {@link jakarta.nosql.column.ColumnConfigurationAsync}
*/
public class ColumnTemplateAsyncConverter implements Converter<ColumnTemplateAsync> {

@Override
public ColumnTemplateAsync convert(String value) {
Config config = BeanManagers.getInstance(Config.class);
final ColumnFamilyManagerAsync manager = config.getValue(value, ColumnFamilyManagerAsync.class);
ColumnTemplateAsyncProducer producer = BeanManagers.getInstance(ColumnTemplateAsyncProducer.class);

return producer.get(manager);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2019 Otávio Santana and others
* 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.artemis.column.configuration;

import jakarta.nosql.column.ColumnFamilyManager;
import jakarta.nosql.mapping.column.ColumnTemplate;
import jakarta.nosql.mapping.column.ColumnTemplateProducer;
import org.eclipse.jnosql.artemis.configuration.SettingsConverter;
import org.eclipse.jnosql.artemis.util.BeanManagers;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.Converter;

/**
* Converter the {@link String} to {@link ColumnTemplate} it will use the {@link SettingsConverter} and
* find by the provider that should be an implementation of {@link jakarta.nosql.column.ColumnConfiguration}
*/
public class ColumnTemplateConverter implements Converter<ColumnTemplate> {

@Override
public ColumnTemplate convert(String value) {
Config config = BeanManagers.getInstance(Config.class);
final ColumnFamilyManager manager = config.getValue(value, ColumnFamilyManager.class);
ColumnTemplateProducer producer = BeanManagers.getInstance(ColumnTemplateProducer.class);

return producer.get(manager);
}
}

This file was deleted.

Loading

0 comments on commit 09a14f6

Please sign in to comment.