Formatting.

This commit is contained in:
Greg Burd 2017-11-01 16:19:07 -04:00
parent 13eaa7e7ea
commit 2ee300e420
4 changed files with 42 additions and 49 deletions

View file

@ -286,8 +286,8 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab
private void replaceCachedFacetValues(Object pojo, String tableName, List<String[]> facetCombinations) { private void replaceCachedFacetValues(Object pojo, String tableName, List<String[]> facetCombinations) {
for (String[] combination : facetCombinations) { for (String[] combination : facetCombinations) {
String cacheKey = tableName + "." + Arrays.toString(combination); String cacheKey = tableName + "." + Arrays.toString(combination);
sessionCache.invalidate(cacheKey); sessionCache.invalidate(cacheKey);
sessionCache.put(cacheKey, pojo); sessionCache.put(cacheKey, pojo);
} }
} }
@ -306,22 +306,21 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab
UnitOfWork uow = ctor.newInstance(this, parent); UnitOfWork uow = ctor.newInstance(this, parent);
if (LOG.isInfoEnabled() && uow.getPurpose() == null) { if (LOG.isInfoEnabled() && uow.getPurpose() == null) {
StringBuilder purpose = null; StringBuilder purpose = null;
int frame = 0; int frame = 0;
StackTraceElement[] trace = Thread.currentThread().getStackTrace(); StackTraceElement[] trace = Thread.currentThread().getStackTrace();
String targetClassName = HelenusSession.class.getName(); String targetClassName = HelenusSession.class.getName();
do { frame++; } while (!trace[frame].getClassName().equals(targetClassName) && frame < trace.length); do {
do { frame++; } while (trace[frame].getClassName().equals(targetClassName) && frame < trace.length); frame++;
if (frame < trace.length) { } while (!trace[frame].getClassName().equals(targetClassName) && frame < trace.length);
purpose = new StringBuilder().append(trace[frame].getClassName()) do {
.append(".") frame++;
.append(trace[frame].getMethodName()) } while (trace[frame].getClassName().equals(targetClassName) && frame < trace.length);
.append("(") if (frame < trace.length) {
.append(trace[frame].getFileName()) purpose = new StringBuilder().append(trace[frame].getClassName()).append(".")
.append(":") .append(trace[frame].getMethodName()).append("(").append(trace[frame].getFileName())
.append(trace[frame].getLineNumber()) .append(":").append(trace[frame].getLineNumber()).append(")");
.append(")"); uow.setPurpose(purpose.toString());
uow.setPurpose(purpose.toString()); }
}
} }
if (parent != null) { if (parent != null) {
parent.addNestedUnitOfWork(uow); parent.addNestedUnitOfWork(uow);
@ -329,7 +328,8 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab
return uow.begin(); return uow.begin();
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException } catch (NoSuchMethodException | InvocationTargetException | InstantiationException
| IllegalAccessException e) { | 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); execute(SchemaUtil.dropUserType(entity), true);
break; break;
default: default :
throw new HelenusException("Unknown entity type."); throw new HelenusException("Unknown entity type.");
} }
} }

View file

@ -18,11 +18,12 @@ package net.helenus.core.cache;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.RemovalListener; import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification; import com.google.common.cache.RemovalNotification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public interface SessionCache<K, V> { public interface SessionCache<K, V> {
@ -30,23 +31,18 @@ public interface SessionCache<K, V> {
static <K, V> SessionCache<K, V> defaultCache() { static <K, V> SessionCache<K, V> defaultCache() {
GuavaCache<K, V> cache; GuavaCache<K, V> cache;
RemovalListener<K, V> listener = RemovalListener<K, V> listener = new RemovalListener<K, V>() {
new RemovalListener<K, V>() { @Override
@Override public void onRemoval(RemovalNotification<K, V> n) {
public void onRemoval(RemovalNotification<K, V> n) { if (n.wasEvicted()) {
if (n.wasEvicted()) { String cause = n.getCause().name();
String cause = n.getCause().name(); LOG.info(cause);
LOG.info(cause); }
} }
} };
};
cache = new GuavaCache<K, V>(CacheBuilder.newBuilder() cache = new GuavaCache<K, V>(CacheBuilder.newBuilder().maximumSize(25_000)
.maximumSize(25_000) .expireAfterAccess(5, TimeUnit.MINUTES).softValues().removalListener(listener).build());
.expireAfterAccess(5, TimeUnit.MINUTES)
.softValues()
.removalListener(listener)
.build());
return cache; return cache;
} }

View file

@ -24,7 +24,6 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -126,7 +125,7 @@ public class MapperInvocationHandler<E> implements InvocationHandler, Serializab
} }
if (MapExportable.TO_MAP_METHOD.equals(methodName)) { if (MapExportable.TO_MAP_METHOD.equals(methodName)) {
return src; //Collections.unmodifiableMap(src); return src; // Collections.unmodifiableMap(src);
} }
Object value = src.get(methodName); Object value = src.get(methodName);

View file

@ -39,6 +39,11 @@ public final class ValueProviderMap implements Map<String, Object> {
this.immutable = entity.getMappingInterface().isAssignableFrom(Drafted.class); 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 @Override
public Object get(Object key) { public Object get(Object key) {
if (key instanceof String) { if (key instanceof String) {
@ -111,17 +116,10 @@ public final class ValueProviderMap implements Map<String, Object> {
@Override @Override
public Set<java.util.Map.Entry<String, Object>> entrySet() { public Set<java.util.Map.Entry<String, Object>> entrySet() {
return entity.getOrderedProperties() return entity.getOrderedProperties().stream().map(p -> {
.stream() return new ValueProviderMap.Entry<String, Object>(p.getPropertyName(),
.map(p -> { valueProvider.getColumnValue(source, -1, p, immutable));
return new ValueProviderMap.Entry<String, Object>(p.getPropertyName(), }).collect(Collectors.toSet());
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));
} }
@Override @Override