From 2ee300e4207ca3aee24779d5a922c5bc9b399aa5 Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Wed, 1 Nov 2017 16:19:07 -0400 Subject: [PATCH] Formatting. --- .../java/net/helenus/core/HelenusSession.java | 36 +++++++++---------- .../net/helenus/core/cache/SessionCache.java | 32 ++++++++--------- .../core/reflect/MapperInvocationHandler.java | 3 +- .../mapping/value/ValueProviderMap.java | 20 +++++------ 4 files changed, 42 insertions(+), 49 deletions(-) diff --git a/src/main/java/net/helenus/core/HelenusSession.java b/src/main/java/net/helenus/core/HelenusSession.java index 78bbb98..9895342 100644 --- a/src/main/java/net/helenus/core/HelenusSession.java +++ b/src/main/java/net/helenus/core/HelenusSession.java @@ -286,8 +286,8 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab private void replaceCachedFacetValues(Object pojo, String tableName, List facetCombinations) { for (String[] combination : facetCombinations) { String cacheKey = tableName + "." + Arrays.toString(combination); - sessionCache.invalidate(cacheKey); - sessionCache.put(cacheKey, pojo); + sessionCache.invalidate(cacheKey); + sessionCache.put(cacheKey, pojo); } } @@ -306,22 +306,21 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab UnitOfWork uow = ctor.newInstance(this, parent); if (LOG.isInfoEnabled() && uow.getPurpose() == null) { StringBuilder purpose = null; - int frame = 0; + int frame = 0; StackTraceElement[] trace = Thread.currentThread().getStackTrace(); String targetClassName = HelenusSession.class.getName(); - do { frame++; } while (!trace[frame].getClassName().equals(targetClassName) && frame < trace.length); - do { frame++; } while (trace[frame].getClassName().equals(targetClassName) && frame < trace.length); - if (frame < trace.length) { - purpose = new StringBuilder().append(trace[frame].getClassName()) - .append(".") - .append(trace[frame].getMethodName()) - .append("(") - .append(trace[frame].getFileName()) - .append(":") - .append(trace[frame].getLineNumber()) - .append(")"); - uow.setPurpose(purpose.toString()); - } + do { + frame++; + } while (!trace[frame].getClassName().equals(targetClassName) && frame < trace.length); + do { + frame++; + } while (trace[frame].getClassName().equals(targetClassName) && frame < trace.length); + if (frame < trace.length) { + purpose = new StringBuilder().append(trace[frame].getClassName()).append(".") + .append(trace[frame].getMethodName()).append("(").append(trace[frame].getFileName()) + .append(":").append(trace[frame].getLineNumber()).append(")"); + uow.setPurpose(purpose.toString()); + } } if (parent != null) { parent.addNestedUnitOfWork(uow); @@ -329,7 +328,8 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab return uow.begin(); } catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) { - throw new HelenusException(String.format("Unable to instantiate %s as a UnitOfWork.", unitOfWorkClass.getSimpleName()), e); + throw new HelenusException( + String.format("Unable to instantiate %s as a UnitOfWork.", unitOfWorkClass.getSimpleName()), e); } } @@ -692,7 +692,7 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab execute(SchemaUtil.dropUserType(entity), true); break; - default: + default : throw new HelenusException("Unknown entity type."); } } diff --git a/src/main/java/net/helenus/core/cache/SessionCache.java b/src/main/java/net/helenus/core/cache/SessionCache.java index ec2d73b..f0d502c 100644 --- a/src/main/java/net/helenus/core/cache/SessionCache.java +++ b/src/main/java/net/helenus/core/cache/SessionCache.java @@ -18,11 +18,12 @@ package net.helenus.core.cache; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.google.common.cache.CacheBuilder; import com.google.common.cache.RemovalListener; import com.google.common.cache.RemovalNotification; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public interface SessionCache { @@ -30,23 +31,18 @@ public interface SessionCache { static SessionCache defaultCache() { GuavaCache cache; - RemovalListener listener = - new RemovalListener() { - @Override - public void onRemoval(RemovalNotification n) { - if (n.wasEvicted()) { - String cause = n.getCause().name(); - LOG.info(cause); - } - } - }; + RemovalListener listener = new RemovalListener() { + @Override + public void onRemoval(RemovalNotification n) { + if (n.wasEvicted()) { + String cause = n.getCause().name(); + LOG.info(cause); + } + } + }; - cache = new GuavaCache(CacheBuilder.newBuilder() - .maximumSize(25_000) - .expireAfterAccess(5, TimeUnit.MINUTES) - .softValues() - .removalListener(listener) - .build()); + cache = new GuavaCache(CacheBuilder.newBuilder().maximumSize(25_000) + .expireAfterAccess(5, TimeUnit.MINUTES).softValues().removalListener(listener).build()); return cache; } diff --git a/src/main/java/net/helenus/core/reflect/MapperInvocationHandler.java b/src/main/java/net/helenus/core/reflect/MapperInvocationHandler.java index 94f8dbd..91e5994 100644 --- a/src/main/java/net/helenus/core/reflect/MapperInvocationHandler.java +++ b/src/main/java/net/helenus/core/reflect/MapperInvocationHandler.java @@ -24,7 +24,6 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -126,7 +125,7 @@ public class MapperInvocationHandler implements InvocationHandler, Serializab } if (MapExportable.TO_MAP_METHOD.equals(methodName)) { - return src; //Collections.unmodifiableMap(src); + return src; // Collections.unmodifiableMap(src); } Object value = src.get(methodName); diff --git a/src/main/java/net/helenus/mapping/value/ValueProviderMap.java b/src/main/java/net/helenus/mapping/value/ValueProviderMap.java index fc6ad79..cafa3de 100644 --- a/src/main/java/net/helenus/mapping/value/ValueProviderMap.java +++ b/src/main/java/net/helenus/mapping/value/ValueProviderMap.java @@ -39,6 +39,11 @@ public final class ValueProviderMap implements Map { this.immutable = entity.getMappingInterface().isAssignableFrom(Drafted.class); } + private static void throwShouldNeverCall(String methodName) { + throw new HelenusMappingException(String.format( + "the method %s should never be called on an instance of a Helenus ValueProviderMap", methodName)); + } + @Override public Object get(Object key) { if (key instanceof String) { @@ -111,17 +116,10 @@ public final class ValueProviderMap implements Map { @Override public Set> entrySet() { - return entity.getOrderedProperties() - .stream() - .map(p -> { - return new ValueProviderMap.Entry(p.getPropertyName(), - valueProvider.getColumnValue(source, -1, p, immutable)); - }).collect(Collectors.toSet()); - } - - private static void throwShouldNeverCall(String methodName) { - throw new HelenusMappingException(String.format( - "the method %s should never be called on an instance of a Helenus ValueProviderMap", methodName)); + return entity.getOrderedProperties().stream().map(p -> { + return new ValueProviderMap.Entry(p.getPropertyName(), + valueProvider.getColumnValue(source, -1, p, immutable)); + }).collect(Collectors.toSet()); } @Override