Skip to content

Commit

Permalink
Improve code style (#660)
Browse files Browse the repository at this point in the history
* Improve code style

* Fix license position
  • Loading branch information
fh-ms authored Oct 5, 2023
1 parent 9cb0e73 commit d75049e
Show file tree
Hide file tree
Showing 70 changed files with 611 additions and 585 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
* #L%
*/

import javax.enterprise.inject.Alternative;
import javax.enterprise.inject.Stereotype;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.enterprise.inject.Alternative;
import javax.enterprise.inject.Stereotype;


/**
* The Storage class in MicroStream indicates a class as a root instance.
Expand All @@ -47,4 +48,5 @@
@Alternative
public @interface Storage
{
// marker annotation
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import javax.cache.integration.CacheWriter;
import javax.enterprise.inject.Instance;

import one.microstream.cache.types.CacheStore;
import org.eclipse.microprofile.config.Config;

import one.microstream.cache.types.CacheStore;
import one.microstream.storage.types.StorageManager;


Expand Down Expand Up @@ -145,8 +145,8 @@ public MutableConfiguration<K, V> get()
if(this.storage)
{
LOGGER.log(Level.FINE, "Using the storage option to this cache, so it will enable write and read through");
StorageManager storageManager = this.storageManager.get();
CacheStore<K, V> cacheStore = CacheStore.New(cacheProperty.getName(),storageManager);
final StorageManager storageManager = this.storageManager.get();
final CacheStore<K, V> cacheStore = CacheStore.New(this.cacheProperty.getName(),storageManager);
configuration.setCacheLoaderFactory(() -> cacheStore);
configuration.setCacheWriterFactory(() -> cacheStore);
configuration.setWriteThrough(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ CacheManager getManager()
return this.cacheManager;
}

@SuppressWarnings("resource")
@Produces
@StorageCache
public <K, V> Cache<K, V> producer(final InjectionPoint injectionPoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,24 @@
* #L%
*/

import one.microstream.integrations.cdi.types.ConfigurationCoreProperties;
import one.microstream.integrations.cdi.types.extension.StorageExtension;
import one.microstream.storage.embedded.configuration.types.EmbeddedStorageConfigurationBuilder;
import one.microstream.storage.embedded.types.EmbeddedStorageFoundation;
import one.microstream.storage.embedded.types.EmbeddedStorageManager;
import one.microstream.storage.types.StorageManager;
import org.eclipse.microprofile.config.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import java.util.Map;

import org.eclipse.microprofile.config.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import one.microstream.integrations.cdi.types.ConfigurationCoreProperties;
import one.microstream.integrations.cdi.types.extension.StorageExtension;
import one.microstream.storage.embedded.configuration.types.EmbeddedStorageConfigurationBuilder;
import one.microstream.storage.embedded.types.EmbeddedStorageFoundation;
import one.microstream.storage.embedded.types.EmbeddedStorageManager;
import one.microstream.storage.types.StorageManager;


@ApplicationScoped
Expand Down Expand Up @@ -64,22 +66,20 @@ public StorageManager getStorageManager()
if (this.storageExtension.getStorageManagerConfigInjectionNames()
.isEmpty())
{
return storageManagerFromProperties();
}
else
{
// StorageManager through StorageManagerConverter
String configName = storageExtension.getStorageManagerConfigInjectionNames()
.iterator()
.next();
LOGGER.info(
"Loading StorageManager from file indicated by MicroProfile Config key : "
+ configName
);

// This will succeed since it is already validated during deployment of the application.
return config.getValue(configName, StorageManager.class);
return this.storageManagerFromProperties();
}

// StorageManager through StorageManagerConverter
final String configName = this.storageExtension.getStorageManagerConfigInjectionNames()
.iterator()
.next();
LOGGER.info(
"Loading StorageManager from file indicated by MicroProfile Config key : "
+ configName
);

// This will succeed since it is already validated during deployment of the application.
return this.config.getValue(configName, StorageManager.class);
}

private EmbeddedStorageManager storageManagerFromProperties()
Expand All @@ -95,32 +95,32 @@ private EmbeddedStorageManager storageManagerFromProperties()
{
builder.set(entry.getKey(), entry.getValue());
}
EmbeddedStorageFoundation<?> foundation = builder.createEmbeddedStorageFoundation();
final EmbeddedStorageFoundation<?> foundation = builder.createEmbeddedStorageFoundation();
foundation.setDataBaseName("Generic");

customizers.stream()
this.customizers.stream()
.forEach(customizer -> customizer.customize(foundation));

EmbeddedStorageManager storageManager = foundation
final EmbeddedStorageManager storageManager = foundation
.createEmbeddedStorageManager();

if (isAutoStart(properties))
if (this.isAutoStart(properties))
{
storageManager.start();
}

if (!storageExtension.hasStorageRoot())
if (!this.storageExtension.hasStorageRoot())
{
// Only execute at this point when no storage root bean has defined with @Storage
// Initializers are called from StorageBean.create if user has defined @Storage and root is read.
initializers.stream()
this.initializers.stream()
.forEach(initializer -> initializer.initialize(storageManager));
}

return storageManager;
}

private boolean isAutoStart(Map<String, String> properties)
private boolean isAutoStart(final Map<String, String> properties)
{
return Boolean.parseBoolean(properties.getOrDefault("autoStart", "true"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
* #L%
*/

import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.Set;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.AnnotatedType;
Expand All @@ -29,9 +33,6 @@
import javax.enterprise.inject.spi.CDI;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.PassivationCapable;
import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.Set;


/**
Expand All @@ -55,6 +56,7 @@ protected <B> B getInstance(final Class<B> clazz)
return CDI.current().select(clazz).get();
}

@SuppressWarnings("unchecked")
protected void injectDependencies(final T root)
{
final AnnotatedType<T> type = (AnnotatedType<T>) this.beanManager.createAnnotatedType(root.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@
* #L%
*/

import one.microstream.integrations.cdi.exceptions.CDIExceptionStorage;
import one.microstream.integrations.cdi.types.Storage;
import one.microstream.integrations.cdi.types.config.StorageManagerInitializer;
import one.microstream.reflect.XReflect;
import one.microstream.storage.types.StorageManager;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.InjectionPoint;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import one.microstream.integrations.cdi.exceptions.CDIExceptionStorage;
import one.microstream.integrations.cdi.types.Storage;
import one.microstream.integrations.cdi.types.config.StorageManagerInitializer;
import one.microstream.reflect.XReflect;
import one.microstream.storage.types.StorageManager;


/**
Expand Down Expand Up @@ -99,7 +100,7 @@ public T create(final CreationalContext<T> context)
final Set<Bean<?>> initializerBeans = this.beanManager.getBeans(StorageManagerInitializer.class);
for (final Bean<?> initializerBean : initializerBeans)
{
StorageManagerInitializer initializer = (StorageManagerInitializer) beanManager.getReference(initializerBean
final StorageManagerInitializer initializer = (StorageManagerInitializer) this.beanManager.getReference(initializerBean
, initializerBean.getBeanClass()
, this.beanManager.createCreationalContext(initializerBean));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
* #L%
*/

import one.microstream.integrations.cdi.types.Storage;
import one.microstream.storage.types.StorageManager;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
Expand All @@ -35,13 +39,11 @@
import javax.enterprise.inject.spi.ProcessAnnotatedType;
import javax.enterprise.inject.spi.ProcessInjectionPoint;
import javax.enterprise.inject.spi.WithAnnotations;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;

import org.eclipse.microprofile.config.inject.ConfigProperty;

import one.microstream.integrations.cdi.types.Storage;
import one.microstream.storage.types.StorageManager;


/**
Expand Down Expand Up @@ -85,9 +87,9 @@ void collectInjectionsFromStorageBean(@Observes final ProcessInjectionPoint<?, ?
.add(ip);
}
// Is @Inject @ConfigProperty on StorageManager?
if (isStorageManagerFromConfig(ip))
if (this.isStorageManagerFromConfig(ip))
{
this.storageManagerConfigInjectionNames.add(getConfigPropertyValueOf(ip));
this.storageManagerConfigInjectionNames.add(this.getConfigPropertyValueOf(ip));

}
}
Expand Down Expand Up @@ -146,7 +148,7 @@ public Set<String> getStorageManagerConfigInjectionNames()

public boolean hasStorageRoot()
{
return !storageRoot.isEmpty();
return !this.storageRoot.isEmpty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

package one.microstream.integrations.cdi.types;

/*-
/*-w
* #%L
* microstream-integrations-cdi3
* %%
Expand All @@ -21,13 +21,14 @@
* #L%
*/

import jakarta.enterprise.inject.Alternative;
import jakarta.enterprise.inject.Stereotype;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.enterprise.inject.Alternative;
import jakarta.enterprise.inject.Stereotype;


/**
* The Storage class in MicroStream indicates a class as a root instance.
Expand All @@ -47,4 +48,5 @@
@Alternative
public @interface Storage
{
// marker annotation
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
import javax.cache.expiry.ExpiryPolicy;
import javax.cache.integration.CacheLoader;
import javax.cache.integration.CacheWriter;
import jakarta.enterprise.inject.Instance;

import one.microstream.cache.types.CacheStore;
import org.eclipse.microprofile.config.Config;

import jakarta.enterprise.inject.Instance;
import one.microstream.cache.types.CacheStore;
import one.microstream.storage.types.StorageManager;


Expand Down Expand Up @@ -145,8 +145,8 @@ public MutableConfiguration<K, V> get()
if(this.storage)
{
LOGGER.log(Level.FINE, "Using the storage option to this cache, so it will enable write and read through");
StorageManager storageManager = this.storageManager.get();
CacheStore<K, V> cacheStore = CacheStore.New(cacheProperty.getName(),storageManager);
final StorageManager storageManager = this.storageManager.get();
final CacheStore<K, V> cacheStore = CacheStore.New(this.cacheProperty.getName(),storageManager);
configuration.setCacheLoaderFactory(() -> cacheStore);
configuration.setCacheWriterFactory(() -> cacheStore);
configuration.setWriteThrough(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
import java.util.Objects;
import java.util.logging.Logger;

import jakarta.annotation.PostConstruct;
import javax.cache.Cache;
import javax.cache.CacheManager;
import javax.cache.Caching;
import javax.cache.configuration.MutableConfiguration;
import javax.cache.spi.CachingProvider;

import org.eclipse.microprofile.config.Config;

import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Disposes;
import jakarta.enterprise.inject.Instance;
import jakarta.enterprise.inject.Produces;
import jakarta.enterprise.inject.spi.InjectionPoint;
import jakarta.inject.Inject;

import org.eclipse.microprofile.config.Config;

import one.microstream.storage.types.StorageManager;


Expand Down Expand Up @@ -82,6 +82,7 @@ CacheManager getManager()
return this.cacheManager;
}

@SuppressWarnings("resource")
@Produces
@StorageCache
public <K, V> Cache<K, V> producer(final InjectionPoint injectionPoint)
Expand Down
Loading

0 comments on commit d75049e

Please sign in to comment.