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) {
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.");
}
}

View file

@ -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<K, V> {
@ -30,23 +31,18 @@ public interface SessionCache<K, V> {
static <K, V> SessionCache<K, V> defaultCache() {
GuavaCache<K, V> cache;
RemovalListener<K, V> listener =
new RemovalListener<K, V>() {
@Override
public void onRemoval(RemovalNotification<K, V> n) {
if (n.wasEvicted()) {
String cause = n.getCause().name();
LOG.info(cause);
}
}
};
RemovalListener<K, V> listener = new RemovalListener<K, V>() {
@Override
public void onRemoval(RemovalNotification<K, V> n) {
if (n.wasEvicted()) {
String cause = n.getCause().name();
LOG.info(cause);
}
}
};
cache = new GuavaCache<K, V>(CacheBuilder.newBuilder()
.maximumSize(25_000)
.expireAfterAccess(5, TimeUnit.MINUTES)
.softValues()
.removalListener(listener)
.build());
cache = new GuavaCache<K, V>(CacheBuilder.newBuilder().maximumSize(25_000)
.expireAfterAccess(5, TimeUnit.MINUTES).softValues().removalListener(listener).build());
return cache;
}

View file

@ -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<E> 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);

View file

@ -39,6 +39,11 @@ public final class ValueProviderMap implements Map<String, Object> {
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<String, Object> {
@Override
public Set<java.util.Map.Entry<String, Object>> entrySet() {
return entity.getOrderedProperties()
.stream()
.map(p -> {
return new ValueProviderMap.Entry<String, Object>(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<String, Object>(p.getPropertyName(),
valueProvider.getColumnValue(source, -1, p, immutable));
}).collect(Collectors.toSet());
}
@Override