Formatting. Also, need to redo merge so as to avoid ValueProviderMap immutability.
This commit is contained in:
parent
a65b775faa
commit
52dab5872c
16 changed files with 449 additions and 459 deletions
|
@ -3,13 +3,15 @@ package net.helenus.core;
|
|||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
import net.helenus.mapping.value.ValueProviderMap;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
|
||||
import com.google.common.primitives.Primitives;
|
||||
|
||||
import net.helenus.core.reflect.DefaultPrimitiveTypes;
|
||||
import net.helenus.core.reflect.Drafted;
|
||||
import net.helenus.core.reflect.MapExportable;
|
||||
import net.helenus.mapping.MappingUtil;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
|
||||
public abstract class AbstractEntityDraft<E> implements Drafted<E> {
|
||||
|
||||
|
@ -38,31 +40,30 @@ public abstract class AbstractEntityDraft<E> implements Drafted<E> {
|
|||
T value = (T) backingMap.get(key);
|
||||
|
||||
if (value == null) {
|
||||
value = (T) entityMap.get(key);
|
||||
if (value == null) {
|
||||
value = (T) entityMap.get(key);
|
||||
if (value == null) {
|
||||
|
||||
if (Primitives.allPrimitiveTypes().contains(returnType)) {
|
||||
if (Primitives.allPrimitiveTypes().contains(returnType)) {
|
||||
|
||||
DefaultPrimitiveTypes type = DefaultPrimitiveTypes.lookup(returnType);
|
||||
if (type == null) {
|
||||
throw new RuntimeException("unknown primitive type " + returnType);
|
||||
}
|
||||
DefaultPrimitiveTypes type = DefaultPrimitiveTypes.lookup(returnType);
|
||||
if (type == null) {
|
||||
throw new RuntimeException("unknown primitive type " + returnType);
|
||||
}
|
||||
|
||||
return (T) type.getDefaultValue();
|
||||
}
|
||||
} else {
|
||||
// Collections fetched from the entityMap
|
||||
if (value instanceof Collection) {
|
||||
try {
|
||||
value = MappingUtil.<T>clone(value);
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
//TODO(gburd): deep?shallow? copy of List, Map, Set to a mutable collection.
|
||||
value = (T)SerializationUtils.<Serializable>clone((Serializable)value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (T) type.getDefaultValue();
|
||||
}
|
||||
} else {
|
||||
// Collections fetched from the entityMap
|
||||
if (value instanceof Collection) {
|
||||
try {
|
||||
value = MappingUtil.<T>clone(value);
|
||||
} catch (CloneNotSupportedException e) {
|
||||
// TODO(gburd): deep?shallow? copy of List, Map, Set to a mutable collection.
|
||||
value = (T) SerializationUtils.<Serializable>clone((Serializable) value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ public abstract class AbstractUnitOfWork<E extends Exception> implements UnitOfW
|
|||
@Override
|
||||
public synchronized UnitOfWork<E> begin() {
|
||||
elapsedTime = Stopwatch.createStarted();
|
||||
// log.recordCacheAndDatabaseOperationCount(txn::start)
|
||||
// log.record(txn::start)
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -306,7 +306,7 @@ public abstract class AbstractUnitOfWork<E extends Exception> implements UnitOfW
|
|||
uow.committed = false;
|
||||
uow.aborted = true;
|
||||
});
|
||||
// log.recordCacheAndDatabaseOperationCount(txn::abort)
|
||||
// log.record(txn::abort)
|
||||
// cache.invalidateSince(txn::start time)
|
||||
if (!hasAborted()) {
|
||||
elapsedTime.stop();
|
||||
|
|
|
@ -23,23 +23,20 @@ import java.lang.reflect.Constructor;
|
|||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.helenus.core.cache.SessionCache;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.datastax.driver.core.*;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.Table;
|
||||
|
||||
import brave.Tracer;
|
||||
import net.helenus.core.cache.CacheUtil;
|
||||
import net.helenus.core.cache.Facet;
|
||||
import net.helenus.core.cache.SessionCache;
|
||||
import net.helenus.core.cache.UnboundFacet;
|
||||
import net.helenus.core.operation.*;
|
||||
import net.helenus.core.reflect.Drafted;
|
||||
|
@ -80,8 +77,8 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
HelenusSession(Session session, String usingKeyspace, CodecRegistry registry, boolean showCql,
|
||||
PrintStream printStream, SessionRepositoryBuilder sessionRepositoryBuilder, Executor executor,
|
||||
boolean dropSchemaOnClose, ConsistencyLevel consistencyLevel, boolean defaultQueryIdempotency,
|
||||
Class<? extends UnitOfWork> unitOfWorkClass, SessionCache sessionCache,
|
||||
MetricRegistry metricRegistry, Tracer tracer) {
|
||||
Class<? extends UnitOfWork> unitOfWorkClass, SessionCache sessionCache, MetricRegistry metricRegistry,
|
||||
Tracer tracer) {
|
||||
this.session = session;
|
||||
this.registry = registry == null ? CodecRegistry.DEFAULT_INSTANCE : registry;
|
||||
this.usingKeyspace = Objects.requireNonNull(usingKeyspace,
|
||||
|
@ -98,10 +95,10 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
this.zipkinTracer = tracer;
|
||||
|
||||
if (sessionCache == null) {
|
||||
this.sessionCache = SessionCache.<String, Object>defaultCache();
|
||||
} else {
|
||||
this.sessionCache = sessionCache;
|
||||
}
|
||||
this.sessionCache = SessionCache.<String, Object>defaultCache();
|
||||
} else {
|
||||
this.sessionCache = sessionCache;
|
||||
}
|
||||
|
||||
this.valueProvider = new RowColumnValueProvider(this.sessionRepository);
|
||||
this.valuePreparer = new StatementColumnValuePreparer(this.sessionRepository);
|
||||
|
@ -242,48 +239,49 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
|
||||
@Override
|
||||
public void mergeCache(Table<String, String, Either<Object, List<Facet>>> uowCache) {
|
||||
List<Object> items = uowCache.values().stream().filter(Either::isLeft).map(Either::getLeft).distinct().collect(Collectors.toList());
|
||||
List<Object> items = uowCache.values().stream().filter(Either::isLeft).map(Either::getLeft).distinct()
|
||||
.collect(Collectors.toList());
|
||||
for (Object pojo : items) {
|
||||
HelenusEntity entity = Helenus.resolve(MappingUtil.getMappingInterface(pojo));
|
||||
Map<String, Object> valueMap = pojo instanceof MapExportable ? ((MapExportable) pojo).toMap() : null;
|
||||
if (entity.isCacheable()) {
|
||||
List<Facet> boundFacets = new ArrayList<>();
|
||||
for (Facet facet : entity.getFacets()) {
|
||||
if (facet instanceof UnboundFacet) {
|
||||
UnboundFacet unboundFacet = (UnboundFacet) facet;
|
||||
UnboundFacet.Binder binder = unboundFacet.binder();
|
||||
unboundFacet.getProperties().forEach(prop -> {
|
||||
if (valueMap == null) {
|
||||
Object value = BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop);
|
||||
binder.setValueForProperty(prop, value.toString());
|
||||
} else {
|
||||
binder.setValueForProperty(prop, valueMap.get(prop.getPropertyName()).toString());
|
||||
}
|
||||
});
|
||||
if (binder.isBound()) {
|
||||
boundFacets.add(binder.bind());
|
||||
}
|
||||
} else {
|
||||
boundFacets.add(facet);
|
||||
}
|
||||
}
|
||||
// NOTE: should equal `String tableName = CacheUtil.schemaName(facets);`
|
||||
List<String[]> facetCombinations = CacheUtil.flattenFacets(boundFacets);
|
||||
String tableName = CacheUtil.schemaName(boundFacets);
|
||||
mergeAndUpdateCacheValues(pojo, tableName, facetCombinations);
|
||||
}
|
||||
}
|
||||
HelenusEntity entity = Helenus.resolve(MappingUtil.getMappingInterface(pojo));
|
||||
Map<String, Object> valueMap = pojo instanceof MapExportable ? ((MapExportable) pojo).toMap() : null;
|
||||
if (entity.isCacheable()) {
|
||||
List<Facet> boundFacets = new ArrayList<>();
|
||||
for (Facet facet : entity.getFacets()) {
|
||||
if (facet instanceof UnboundFacet) {
|
||||
UnboundFacet unboundFacet = (UnboundFacet) facet;
|
||||
UnboundFacet.Binder binder = unboundFacet.binder();
|
||||
unboundFacet.getProperties().forEach(prop -> {
|
||||
if (valueMap == null) {
|
||||
Object value = BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop);
|
||||
binder.setValueForProperty(prop, value.toString());
|
||||
} else {
|
||||
binder.setValueForProperty(prop, valueMap.get(prop.getPropertyName()).toString());
|
||||
}
|
||||
});
|
||||
if (binder.isBound()) {
|
||||
boundFacets.add(binder.bind());
|
||||
}
|
||||
} else {
|
||||
boundFacets.add(facet);
|
||||
}
|
||||
}
|
||||
// NOTE: should equal `String tableName = CacheUtil.schemaName(facets);`
|
||||
List<String[]> facetCombinations = CacheUtil.flattenFacets(boundFacets);
|
||||
String tableName = CacheUtil.schemaName(boundFacets);
|
||||
mergeAndUpdateCacheValues(pojo, tableName, facetCombinations);
|
||||
}
|
||||
}
|
||||
|
||||
List<List<Facet>> deletedFacetSets = uowCache.values().stream().filter(Either::isRight).map(Either::getRight).collect(
|
||||
Collectors.toList());
|
||||
for (List<Facet> facets : deletedFacetSets) {
|
||||
String tableName = CacheUtil.schemaName(facets);
|
||||
List<String[]> combinations = CacheUtil.flattenFacets(facets);
|
||||
for (String[] combination : combinations) {
|
||||
String cacheKey = tableName + "." + Arrays.toString(combination);
|
||||
sessionCache.invalidate(cacheKey);
|
||||
}
|
||||
}
|
||||
List<List<Facet>> deletedFacetSets = uowCache.values().stream().filter(Either::isRight).map(Either::getRight)
|
||||
.collect(Collectors.toList());
|
||||
for (List<Facet> facets : deletedFacetSets) {
|
||||
String tableName = CacheUtil.schemaName(facets);
|
||||
List<String[]> combinations = CacheUtil.flattenFacets(facets);
|
||||
for (String[] combination : combinations) {
|
||||
String cacheKey = tableName + "." + Arrays.toString(combination);
|
||||
sessionCache.invalidate(cacheKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void mergeAndUpdateCacheValues(Object pojo, String tableName, List<String[]> facetCombinations) {
|
||||
|
@ -505,20 +503,20 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
}
|
||||
|
||||
public <E> UpdateOperation<E> update(Object pojo) {
|
||||
if (pojo instanceof MapExportable == false) {
|
||||
throw new HelenusMappingException(
|
||||
"update of objects that don't implement MapExportable is not yet supported");
|
||||
}
|
||||
return new UpdateOperation<E>(this, pojo);
|
||||
}
|
||||
if (pojo instanceof MapExportable == false) {
|
||||
throw new HelenusMappingException(
|
||||
"update of objects that don't implement MapExportable is not yet supported");
|
||||
}
|
||||
return new UpdateOperation<E>(this, pojo);
|
||||
}
|
||||
|
||||
public <E> UpdateOperation<E> update(Drafted<E> drafted) {
|
||||
if (drafted instanceof AbstractEntityDraft == false) {
|
||||
throw new HelenusMappingException(
|
||||
"update of draft objects that don't inherit from AbstractEntityDraft is not yet supported");
|
||||
}
|
||||
if (drafted instanceof AbstractEntityDraft == false) {
|
||||
throw new HelenusMappingException(
|
||||
"update of draft objects that don't inherit from AbstractEntityDraft is not yet supported");
|
||||
}
|
||||
AbstractEntityDraft<E> draft = (AbstractEntityDraft<E>) drafted;
|
||||
UpdateOperation update = new UpdateOperation<E>(this, draft);
|
||||
UpdateOperation update = new UpdateOperation<E>(this, draft);
|
||||
Map<String, Object> map = draft.toMap();
|
||||
Set<String> mutatedProperties = draft.mutated();
|
||||
HelenusEntity entity = Helenus.entity(draft.getEntityClass());
|
||||
|
|
|
@ -126,9 +126,9 @@ public final class SessionInitializer extends AbstractSessionOperations {
|
|||
}
|
||||
|
||||
public SessionInitializer setSessionCache(SessionCache sessionCache) {
|
||||
this.sessionCache = sessionCache;
|
||||
return this;
|
||||
}
|
||||
this.sessionCache = sessionCache;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConsistencyLevel getDefaultConsistencyLevel() {
|
||||
return consistencyLevel;
|
||||
|
@ -251,7 +251,7 @@ public final class SessionInitializer extends AbstractSessionOperations {
|
|||
initialize();
|
||||
return new HelenusSession(session, usingKeyspace, registry, showCql, printStream, sessionRepository, executor,
|
||||
autoDdl == AutoDdl.CREATE_DROP, consistencyLevel, idempotent, unitOfWorkClass, sessionCache,
|
||||
metricRegistry, zipkinTracer);
|
||||
metricRegistry, zipkinTracer);
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
|
|
|
@ -25,10 +25,10 @@ public class BoundFacet extends Facet<String> {
|
|||
private final Map<HelenusProperty, Object> properties;
|
||||
|
||||
public BoundFacet(HelenusProperty property, Object value) {
|
||||
super(property.getPropertyName(), value == null ? null : value.toString());
|
||||
this.properties = new HashMap<HelenusProperty, Object>(1);
|
||||
this.properties.put(property, value);
|
||||
}
|
||||
super(property.getPropertyName(), value == null ? null : value.toString());
|
||||
this.properties = new HashMap<HelenusProperty, Object>(1);
|
||||
this.properties.put(property, value);
|
||||
}
|
||||
|
||||
public BoundFacet(String name, Map<HelenusProperty, Object> properties) {
|
||||
super(name,
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
package net.helenus.core.cache;
|
||||
|
||||
import net.helenus.core.Helenus;
|
||||
import net.helenus.core.reflect.MapExportable;
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
import net.helenus.mapping.MappingUtil;
|
||||
import net.helenus.mapping.value.BeanColumnValueProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.helenus.core.reflect.MapExportable;
|
||||
|
||||
public class CacheUtil {
|
||||
|
||||
public static List<String[]> combinations(List<String> items) {
|
||||
|
@ -45,22 +41,25 @@ public class CacheUtil {
|
|||
}
|
||||
|
||||
public static Object merge(Object to, Object from) {
|
||||
if (to == from) {
|
||||
return to;
|
||||
if (to == from) {
|
||||
return to;
|
||||
} else {
|
||||
return from;
|
||||
}
|
||||
/*
|
||||
// TODO(gburd): take ttl and writeTime into account when merging.
|
||||
Map<String, Object> toValueMap = to instanceof MapExportable ? ((MapExportable) to).toMap() : null;
|
||||
Map<String, Object> fromValueMap = to instanceof MapExportable ? ((MapExportable) from).toMap() : null;
|
||||
|
||||
//TODO(gburd): take ttl and writeTime into account when merging.
|
||||
Map<String, Object> toValueMap = to instanceof MapExportable ? ((MapExportable) to).toMap() : null;
|
||||
Map<String, Object> fromValueMap = to instanceof MapExportable ? ((MapExportable) from).toMap() : null;
|
||||
|
||||
if (toValueMap != null && fromValueMap != null) {
|
||||
for (String key : fromValueMap.keySet()) {
|
||||
if (toValueMap.containsKey(key) && toValueMap.get(key) != fromValueMap.get(key)) {
|
||||
toValueMap.put(key, fromValueMap.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toValueMap != null && fromValueMap != null) {
|
||||
for (String key : fromValueMap.keySet()) {
|
||||
if (toValueMap.containsKey(key) && toValueMap.get(key) != fromValueMap.get(key)) {
|
||||
toValueMap.put(key, fromValueMap.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
return to;
|
||||
*/
|
||||
}
|
||||
|
||||
public static String schemaName(List<Facet> facets) {
|
||||
|
|
|
@ -20,25 +20,25 @@ import com.google.common.cache.Cache;
|
|||
|
||||
public class GuavaCache<K, V> implements SessionCache<K, V> {
|
||||
|
||||
final Cache<K, V> cache;
|
||||
final Cache<K, V> cache;
|
||||
|
||||
GuavaCache(Cache<K, V> cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
GuavaCache(Cache<K, V> cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate(K key) {
|
||||
cache.invalidate(key);
|
||||
}
|
||||
@Override
|
||||
public void invalidate(K key) {
|
||||
cache.invalidate(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(K key) {
|
||||
return cache.getIfPresent(key);
|
||||
}
|
||||
@Override
|
||||
public V get(K key) {
|
||||
return cache.getIfPresent(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(K key, V value) {
|
||||
cache.put(key, value);
|
||||
}
|
||||
@Override
|
||||
public void put(K key, V value) {
|
||||
cache.put(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,21 +16,21 @@
|
|||
|
||||
package net.helenus.core.cache;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
||||
public interface SessionCache<K, V> {
|
||||
|
||||
static <K, V> SessionCache<K, V> defaultCache() {
|
||||
int MAX_CACHE_SIZE = 10000;
|
||||
int MAX_CACHE_EXPIRE_SECONDS = 600;
|
||||
return new GuavaCache<K, V>(CacheBuilder.newBuilder().maximumSize(MAX_CACHE_SIZE)
|
||||
.expireAfterAccess(MAX_CACHE_EXPIRE_SECONDS, TimeUnit.SECONDS)
|
||||
.expireAfterWrite(MAX_CACHE_EXPIRE_SECONDS, TimeUnit.SECONDS).recordStats().build());
|
||||
}
|
||||
static <K, V> SessionCache<K, V> defaultCache() {
|
||||
int MAX_CACHE_SIZE = 10000;
|
||||
int MAX_CACHE_EXPIRE_SECONDS = 600;
|
||||
return new GuavaCache<K, V>(CacheBuilder.newBuilder().maximumSize(MAX_CACHE_SIZE)
|
||||
.expireAfterAccess(MAX_CACHE_EXPIRE_SECONDS, TimeUnit.SECONDS)
|
||||
.expireAfterWrite(MAX_CACHE_EXPIRE_SECONDS, TimeUnit.SECONDS).recordStats().build());
|
||||
}
|
||||
|
||||
void invalidate(K key);
|
||||
V get(K key);
|
||||
void put(K key, V value);
|
||||
void invalidate(K key);
|
||||
V get(K key);
|
||||
void put(K key, V value);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import java.util.*;
|
|||
import net.helenus.core.*;
|
||||
import net.helenus.core.cache.Facet;
|
||||
import net.helenus.core.cache.UnboundFacet;
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
import net.helenus.mapping.HelenusProperty;
|
||||
|
||||
public abstract class AbstractFilterOperation<E, O extends AbstractFilterOperation<E, O>>
|
||||
|
@ -111,38 +110,38 @@ public abstract class AbstractFilterOperation<E, O extends AbstractFilterOperati
|
|||
ifFilters.add(filter);
|
||||
}
|
||||
|
||||
protected List<Facet> bindFacetValues(List<Facet> facets) {
|
||||
if (facets == null) {
|
||||
return new ArrayList<Facet>();
|
||||
}
|
||||
List<Facet> boundFacets = new ArrayList<>();
|
||||
Map<HelenusProperty, Filter> filterMap = new HashMap<>(filters.size());
|
||||
filters.forEach(f -> filterMap.put(f.getNode().getProperty(), f));
|
||||
protected List<Facet> bindFacetValues(List<Facet> facets) {
|
||||
if (facets == null) {
|
||||
return new ArrayList<Facet>();
|
||||
}
|
||||
List<Facet> boundFacets = new ArrayList<>();
|
||||
Map<HelenusProperty, Filter> filterMap = new HashMap<>(filters.size());
|
||||
filters.forEach(f -> filterMap.put(f.getNode().getProperty(), f));
|
||||
|
||||
for (Facet facet : facets) {
|
||||
if (facet instanceof UnboundFacet) {
|
||||
UnboundFacet unboundFacet = (UnboundFacet) facet;
|
||||
UnboundFacet.Binder binder = unboundFacet.binder();
|
||||
if (filters != null) {
|
||||
for (HelenusProperty prop : unboundFacet.getProperties()) {
|
||||
for (Facet facet : facets) {
|
||||
if (facet instanceof UnboundFacet) {
|
||||
UnboundFacet unboundFacet = (UnboundFacet) facet;
|
||||
UnboundFacet.Binder binder = unboundFacet.binder();
|
||||
if (filters != null) {
|
||||
for (HelenusProperty prop : unboundFacet.getProperties()) {
|
||||
|
||||
Filter filter = filterMap.get(prop);
|
||||
if (filter != null) {
|
||||
Object[] postulates = filter.postulateValues();
|
||||
for (Object p : postulates) {
|
||||
binder.setValueForProperty(prop, p.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Filter filter = filterMap.get(prop);
|
||||
if (filter != null) {
|
||||
Object[] postulates = filter.postulateValues();
|
||||
for (Object p : postulates) {
|
||||
binder.setValueForProperty(prop, p.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (binder.isBound()) {
|
||||
boundFacets.add(binder.bind());
|
||||
}
|
||||
} else {
|
||||
boundFacets.add(facet);
|
||||
}
|
||||
}
|
||||
return boundFacets;
|
||||
}
|
||||
}
|
||||
if (binder.isBound()) {
|
||||
boundFacets.add(binder.bind());
|
||||
}
|
||||
} else {
|
||||
boundFacets.add(facet);
|
||||
}
|
||||
}
|
||||
return boundFacets;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -333,10 +333,10 @@ public abstract class AbstractStatementOperation<E, O extends AbstractStatementO
|
|||
List<Facet> facets = new ArrayList<>();
|
||||
Map<String, Object> valueMap = pojo instanceof MapExportable ? ((MapExportable) pojo).toMap() : null;
|
||||
|
||||
for (Facet facet : identifyingFacets) {
|
||||
if (facet instanceof UnboundFacet) {
|
||||
UnboundFacet unboundFacet = (UnboundFacet) facet;
|
||||
UnboundFacet.Binder binder = unboundFacet.binder();
|
||||
for (Facet facet : identifyingFacets) {
|
||||
if (facet instanceof UnboundFacet) {
|
||||
UnboundFacet unboundFacet = (UnboundFacet) facet;
|
||||
UnboundFacet.Binder binder = unboundFacet.binder();
|
||||
for (HelenusProperty prop : unboundFacet.getProperties()) {
|
||||
Object value;
|
||||
if (valueMap == null) {
|
||||
|
|
|
@ -15,10 +15,7 @@
|
|||
*/
|
||||
package net.helenus.core.operation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
|
@ -31,10 +28,8 @@ import net.helenus.core.AbstractSessionOperations;
|
|||
import net.helenus.core.Filter;
|
||||
import net.helenus.core.UnitOfWork;
|
||||
import net.helenus.core.cache.Facet;
|
||||
import net.helenus.core.cache.UnboundFacet;
|
||||
import net.helenus.core.reflect.HelenusPropertyNode;
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
import net.helenus.mapping.HelenusProperty;
|
||||
import net.helenus.support.HelenusMappingException;
|
||||
|
||||
public final class DeleteOperation extends AbstractFilterOperation<ResultSet, DeleteOperation> {
|
||||
|
@ -134,8 +129,8 @@ public final class DeleteOperation extends AbstractFilterOperation<ResultSet, De
|
|||
}
|
||||
|
||||
public List<Facet> bindFacetValues() {
|
||||
return bindFacetValues(getFacets());
|
||||
}
|
||||
return bindFacetValues(getFacets());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet sync() throws TimeoutException {
|
||||
|
@ -156,9 +151,9 @@ public final class DeleteOperation extends AbstractFilterOperation<ResultSet, De
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Facet> getFacets() {
|
||||
return entity.getFacets();
|
||||
}
|
||||
@Override
|
||||
public List<Facet> getFacets() {
|
||||
return entity.getFacets();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public final class InsertOperation<T> extends AbstractOperation<T, InsertOperati
|
|||
|
||||
private final List<Fun.Tuple2<HelenusPropertyNode, Object>> values = new ArrayList<Fun.Tuple2<HelenusPropertyNode, Object>>();
|
||||
private final T pojo;
|
||||
private final Class<?> resultType;
|
||||
private final Class<?> resultType;
|
||||
private HelenusEntity entity;
|
||||
private boolean ifNotExists;
|
||||
|
||||
|
@ -56,7 +56,7 @@ public final class InsertOperation<T> extends AbstractOperation<T, InsertOperati
|
|||
|
||||
this.ifNotExists = ifNotExists;
|
||||
this.pojo = null;
|
||||
this.resultType = ResultSet.class;
|
||||
this.resultType = ResultSet.class;
|
||||
}
|
||||
|
||||
public InsertOperation(AbstractSessionOperations sessionOperations, Class<?> resultType, boolean ifNotExists) {
|
||||
|
@ -251,14 +251,14 @@ public final class InsertOperation<T> extends AbstractOperation<T, InsertOperati
|
|||
return sync();
|
||||
}
|
||||
T result = super.sync(uow);
|
||||
Class<?> iface = entity.getMappingInterface();
|
||||
if (resultType == iface) {
|
||||
Class<?> iface = entity.getMappingInterface();
|
||||
if (resultType == iface) {
|
||||
cacheUpdate(uow, result, entity.getFacets());
|
||||
} else {
|
||||
if (entity.isCacheable()) {
|
||||
sessionOps.cacheEvict(bindFacetValues());
|
||||
}
|
||||
}
|
||||
if (entity.isCacheable()) {
|
||||
sessionOps.cacheEvict(bindFacetValues());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -207,7 +207,7 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
|||
if (facet instanceof UnboundFacet) {
|
||||
UnboundFacet unboundFacet = (UnboundFacet) facet;
|
||||
UnboundFacet.Binder binder = unboundFacet.binder();
|
||||
for (HelenusProperty prop : unboundFacet.getProperties()) {
|
||||
for (HelenusProperty prop : unboundFacet.getProperties()) {
|
||||
if (filters != null) {
|
||||
Filter filter = filters.get(prop);
|
||||
if (filter != null) {
|
||||
|
|
|
@ -29,7 +29,6 @@ import com.datastax.driver.core.querybuilder.Update;
|
|||
import net.helenus.core.*;
|
||||
import net.helenus.core.cache.BoundFacet;
|
||||
import net.helenus.core.cache.Facet;
|
||||
import net.helenus.core.cache.UnboundFacet;
|
||||
import net.helenus.core.reflect.HelenusPropertyNode;
|
||||
import net.helenus.core.reflect.MapExportable;
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
|
@ -62,26 +61,26 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
this.draftMap = draft.toMap();
|
||||
}
|
||||
|
||||
public UpdateOperation(AbstractSessionOperations sessionOperations, Object pojo) {
|
||||
super(sessionOperations);
|
||||
this.draft = null;
|
||||
this.draftMap = null;
|
||||
this.pojo = pojo;
|
||||
this.entity = Helenus.resolve(MappingUtil.getMappingInterface(pojo));
|
||||
}
|
||||
public UpdateOperation(AbstractSessionOperations sessionOperations, Object pojo) {
|
||||
super(sessionOperations);
|
||||
this.draft = null;
|
||||
this.draftMap = null;
|
||||
this.pojo = pojo;
|
||||
this.entity = Helenus.resolve(MappingUtil.getMappingInterface(pojo));
|
||||
}
|
||||
|
||||
public UpdateOperation(AbstractSessionOperations sessionOperations, HelenusPropertyNode p, Object v) {
|
||||
super(sessionOperations);
|
||||
this.draft = null;
|
||||
this.draftMap = null;
|
||||
public UpdateOperation(AbstractSessionOperations sessionOperations, HelenusPropertyNode p, Object v) {
|
||||
super(sessionOperations);
|
||||
this.draft = null;
|
||||
this.draftMap = null;
|
||||
|
||||
Object value = sessionOps.getValuePreparer().prepareColumnValue(v, p.getProperty());
|
||||
assignments.put(QueryBuilder.set(p.getColumnName(), value), new BoundFacet(p.getProperty(), v));
|
||||
Object value = sessionOps.getValuePreparer().prepareColumnValue(v, p.getProperty());
|
||||
assignments.put(QueryBuilder.set(p.getColumnName(), value), new BoundFacet(p.getProperty(), v));
|
||||
|
||||
addPropertyNode(p);
|
||||
}
|
||||
addPropertyNode(p);
|
||||
}
|
||||
|
||||
public <V> UpdateOperation<E> set(Getter<V> getter, V v) {
|
||||
public <V> UpdateOperation<E> set(Getter<V> getter, V v) {
|
||||
Objects.requireNonNull(getter, "getter is empty");
|
||||
|
||||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(getter);
|
||||
|
@ -91,23 +90,23 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
assignments.put(QueryBuilder.set(p.getColumnName(), value), new BoundFacet(prop, value));
|
||||
|
||||
if (draft != null) {
|
||||
String key = prop.getPropertyName();
|
||||
if (draft.get(key, value.getClass()) != value) {
|
||||
draft.set(key, value);
|
||||
}
|
||||
}
|
||||
String key = prop.getPropertyName();
|
||||
if (draft.get(key, value.getClass()) != value) {
|
||||
draft.set(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
if (entity != null) {
|
||||
if (entity.isCacheable() && pojo != null && pojo instanceof MapExportable) {
|
||||
String key = prop.getPropertyName();
|
||||
Map<String, Object> map = ((MapExportable) pojo).toMap();
|
||||
if (!(map instanceof ValueProviderMap)) {
|
||||
if (map.get(key) != value) {
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (entity != null) {
|
||||
if (entity.isCacheable() && pojo != null && pojo instanceof MapExportable) {
|
||||
String key = prop.getPropertyName();
|
||||
Map<String, Object> map = ((MapExportable) pojo).toMap();
|
||||
if (!(map instanceof ValueProviderMap)) {
|
||||
if (map.get(key) != value) {
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addPropertyNode(p);
|
||||
|
||||
|
@ -132,15 +131,15 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
|
||||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(counterGetter);
|
||||
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
Long value = (Long)BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop);
|
||||
facet = new BoundFacet(prop, value + delta);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
draftMap.put(key, (Long) draftMap.get(key) + delta);
|
||||
}
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
Long value = (Long) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop);
|
||||
facet = new BoundFacet(prop, value + delta);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
draftMap.put(key, (Long) draftMap.get(key) + delta);
|
||||
}
|
||||
|
||||
assignments.put(QueryBuilder.incr(p.getColumnName(), delta), facet);
|
||||
|
||||
|
@ -159,17 +158,17 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
|
||||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(counterGetter);
|
||||
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
Long value = (Long) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop);
|
||||
facet = new BoundFacet(prop, value - delta);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
draftMap.put(key, (Long) draftMap.get(key) - delta);
|
||||
}
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
Long value = (Long) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop);
|
||||
facet = new BoundFacet(prop, value - delta);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
draftMap.put(key, (Long) draftMap.get(key) - delta);
|
||||
}
|
||||
|
||||
assignments.put(QueryBuilder.decr(p.getColumnName(), delta), facet);
|
||||
assignments.put(QueryBuilder.decr(p.getColumnName(), delta), facet);
|
||||
|
||||
addPropertyNode(p);
|
||||
|
||||
|
@ -191,19 +190,19 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(listGetter);
|
||||
Object valueObj = prepareSingleListValue(p, value);
|
||||
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
List<V> list = new ArrayList<V>((List<V>)BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
list.add(0, value);
|
||||
facet = new BoundFacet(prop, list);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
List<V> list = (List<V>) draftMap.get(key);
|
||||
list.add(0, value);
|
||||
}
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
List<V> list = new ArrayList<V>((List<V>) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
list.add(0, value);
|
||||
facet = new BoundFacet(prop, list);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
List<V> list = (List<V>) draftMap.get(key);
|
||||
list.add(0, value);
|
||||
}
|
||||
|
||||
assignments.put(QueryBuilder.prepend(p.getColumnName(), valueObj), facet);
|
||||
assignments.put(QueryBuilder.prepend(p.getColumnName(), valueObj), facet);
|
||||
|
||||
addPropertyNode(p);
|
||||
|
||||
|
@ -218,19 +217,19 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(listGetter);
|
||||
List valueObj = prepareListValue(p, value);
|
||||
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
List<V> list = new ArrayList<V>((List<V>)BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
list.addAll(0, value);
|
||||
facet = new BoundFacet(prop, list);
|
||||
} else if (draft != null && value.size() > 0) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
List<V> list = (List<V>) draftMap.get(key);
|
||||
list.addAll(0, value);
|
||||
}
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
List<V> list = new ArrayList<V>((List<V>) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
list.addAll(0, value);
|
||||
facet = new BoundFacet(prop, list);
|
||||
} else if (draft != null && value.size() > 0) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
List<V> list = (List<V>) draftMap.get(key);
|
||||
list.addAll(0, value);
|
||||
}
|
||||
|
||||
assignments.put(QueryBuilder.prependAll(p.getColumnName(), valueObj), facet);
|
||||
assignments.put(QueryBuilder.prependAll(p.getColumnName(), valueObj), facet);
|
||||
|
||||
addPropertyNode(p);
|
||||
|
||||
|
@ -245,28 +244,28 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(listGetter);
|
||||
Object valueObj = prepareSingleListValue(p, value);
|
||||
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null || draft != null) {
|
||||
List<V> list;
|
||||
HelenusProperty prop = p.getProperty();
|
||||
if (pojo != null) {
|
||||
list = new ArrayList<V>((List<V>) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
} else {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
list = (List<V>) draftMap.get(key);
|
||||
}
|
||||
if (idx < 0) {
|
||||
list.add(0, value);
|
||||
} else if (idx > list.size()) {
|
||||
list.add(list.size(), value);
|
||||
} else {
|
||||
list.add(idx, value);
|
||||
}
|
||||
list.add(0, value);
|
||||
facet = new BoundFacet(prop, list);
|
||||
}
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null || draft != null) {
|
||||
List<V> list;
|
||||
HelenusProperty prop = p.getProperty();
|
||||
if (pojo != null) {
|
||||
list = new ArrayList<V>((List<V>) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
} else {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
list = (List<V>) draftMap.get(key);
|
||||
}
|
||||
if (idx < 0) {
|
||||
list.add(0, value);
|
||||
} else if (idx > list.size()) {
|
||||
list.add(list.size(), value);
|
||||
} else {
|
||||
list.add(idx, value);
|
||||
}
|
||||
list.add(0, value);
|
||||
facet = new BoundFacet(prop, list);
|
||||
}
|
||||
|
||||
assignments.put(QueryBuilder.setIdx(p.getColumnName(), idx, valueObj), facet);
|
||||
assignments.put(QueryBuilder.setIdx(p.getColumnName(), idx, valueObj), facet);
|
||||
|
||||
addPropertyNode(p);
|
||||
|
||||
|
@ -281,18 +280,18 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(listGetter);
|
||||
Object valueObj = prepareSingleListValue(p, value);
|
||||
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
List<V> list = new ArrayList<V>((List<V>)BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
list.add(value);
|
||||
facet = new BoundFacet(prop, list);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
List<V> list = (List<V>) draftMap.get(key);
|
||||
list.add(value);
|
||||
}
|
||||
assignments.put(QueryBuilder.append(p.getColumnName(), valueObj), facet);
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
List<V> list = new ArrayList<V>((List<V>) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
list.add(value);
|
||||
facet = new BoundFacet(prop, list);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
List<V> list = (List<V>) draftMap.get(key);
|
||||
list.add(value);
|
||||
}
|
||||
assignments.put(QueryBuilder.append(p.getColumnName(), valueObj), facet);
|
||||
|
||||
addPropertyNode(p);
|
||||
|
||||
|
@ -307,18 +306,18 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(listGetter);
|
||||
List valueObj = prepareListValue(p, value);
|
||||
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
List<V> list = new ArrayList<V>((List<V>)BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
list.addAll(value);
|
||||
facet = new BoundFacet(prop, list);
|
||||
} else if (draft != null && value.size() > 0) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
List<V> list = (List<V>) draftMap.get(key);
|
||||
list.addAll(value);
|
||||
}
|
||||
assignments.put(QueryBuilder.appendAll(p.getColumnName(), valueObj), facet);
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
List<V> list = new ArrayList<V>((List<V>) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
list.addAll(value);
|
||||
facet = new BoundFacet(prop, list);
|
||||
} else if (draft != null && value.size() > 0) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
List<V> list = (List<V>) draftMap.get(key);
|
||||
list.addAll(value);
|
||||
}
|
||||
assignments.put(QueryBuilder.appendAll(p.getColumnName(), valueObj), facet);
|
||||
|
||||
addPropertyNode(p);
|
||||
|
||||
|
@ -333,18 +332,18 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(listGetter);
|
||||
Object valueObj = prepareSingleListValue(p, value);
|
||||
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
List<V> list = new ArrayList<V>((List<V>)BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
list.remove(value);
|
||||
facet = new BoundFacet(prop, list);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
List<V> list = (List<V>) draftMap.get(key);
|
||||
list.remove(value);
|
||||
}
|
||||
assignments.put(QueryBuilder.discard(p.getColumnName(), valueObj), facet);
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
List<V> list = new ArrayList<V>((List<V>) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
list.remove(value);
|
||||
facet = new BoundFacet(prop, list);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
List<V> list = (List<V>) draftMap.get(key);
|
||||
list.remove(value);
|
||||
}
|
||||
assignments.put(QueryBuilder.discard(p.getColumnName(), valueObj), facet);
|
||||
|
||||
addPropertyNode(p);
|
||||
|
||||
|
@ -359,18 +358,18 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(listGetter);
|
||||
List valueObj = prepareListValue(p, value);
|
||||
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
List<V> list = new ArrayList<V>((List<V>)BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
list.removeAll(value);
|
||||
facet = new BoundFacet(prop, list);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
List<V> list = (List<V>) draftMap.get(key);
|
||||
list.removeAll(value);
|
||||
}
|
||||
assignments.put(QueryBuilder.discardAll(p.getColumnName(), valueObj), facet);
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
List<V> list = new ArrayList<V>((List<V>) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
list.removeAll(value);
|
||||
facet = new BoundFacet(prop, list);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
List<V> list = (List<V>) draftMap.get(key);
|
||||
list.removeAll(value);
|
||||
}
|
||||
assignments.put(QueryBuilder.discardAll(p.getColumnName(), valueObj), facet);
|
||||
|
||||
addPropertyNode(p);
|
||||
|
||||
|
@ -421,18 +420,18 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(setGetter);
|
||||
Object valueObj = prepareSingleSetValue(p, value);
|
||||
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
Set<V> set = new HashSet<V>((Set<V>)BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
set.add(value);
|
||||
facet = new BoundFacet(prop, set);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
Set<V> set = (Set<V>) draftMap.get(key);
|
||||
set.add(value);
|
||||
}
|
||||
assignments.put(QueryBuilder.add(p.getColumnName(), valueObj), facet);
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
Set<V> set = new HashSet<V>((Set<V>) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
set.add(value);
|
||||
facet = new BoundFacet(prop, set);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
Set<V> set = (Set<V>) draftMap.get(key);
|
||||
set.add(value);
|
||||
}
|
||||
assignments.put(QueryBuilder.add(p.getColumnName(), valueObj), facet);
|
||||
|
||||
addPropertyNode(p);
|
||||
|
||||
|
@ -447,17 +446,17 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(setGetter);
|
||||
Set valueObj = prepareSetValue(p, value);
|
||||
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
Set<V> set = new HashSet<V>((Set<V>)BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
set.addAll(value);
|
||||
facet = new BoundFacet(prop, set);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
Set<V> set = (Set<V>) draftMap.get(key);
|
||||
set.addAll(value);
|
||||
}
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
Set<V> set = new HashSet<V>((Set<V>) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
set.addAll(value);
|
||||
facet = new BoundFacet(prop, set);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
Set<V> set = (Set<V>) draftMap.get(key);
|
||||
set.addAll(value);
|
||||
}
|
||||
assignments.put(QueryBuilder.addAll(p.getColumnName(), valueObj), facet);
|
||||
|
||||
addPropertyNode(p);
|
||||
|
@ -473,17 +472,17 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(setGetter);
|
||||
Object valueObj = prepareSingleSetValue(p, value);
|
||||
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
Set<V> set = new HashSet<V>((Set<V>)BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
set.remove(value);
|
||||
facet = new BoundFacet(prop, set);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
Set<V> set = (Set<V>) draftMap.get(key);
|
||||
set.remove(value);
|
||||
}
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
Set<V> set = new HashSet<V>((Set<V>) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
set.remove(value);
|
||||
facet = new BoundFacet(prop, set);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
Set<V> set = (Set<V>) draftMap.get(key);
|
||||
set.remove(value);
|
||||
}
|
||||
assignments.put(QueryBuilder.remove(p.getColumnName(), valueObj), facet);
|
||||
|
||||
addPropertyNode(p);
|
||||
|
@ -499,17 +498,17 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(setGetter);
|
||||
Set valueObj = prepareSetValue(p, value);
|
||||
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
Set<V> set = new HashSet<V>((Set<V>)BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
set.removeAll(value);
|
||||
facet = new BoundFacet(prop, set);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
Set<V> set = (Set<V>) draftMap.get(key);
|
||||
set.removeAll(value);
|
||||
}
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
HelenusProperty prop = p.getProperty();
|
||||
Set<V> set = new HashSet<V>((Set<V>) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
set.removeAll(value);
|
||||
facet = new BoundFacet(prop, set);
|
||||
} else if (draft != null) {
|
||||
String key = p.getProperty().getPropertyName();
|
||||
Set<V> set = (Set<V>) draftMap.get(key);
|
||||
set.removeAll(value);
|
||||
}
|
||||
assignments.put(QueryBuilder.removeAll(p.getColumnName(), valueObj), facet);
|
||||
|
||||
addPropertyNode(p);
|
||||
|
@ -560,14 +559,15 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(mapGetter);
|
||||
HelenusProperty prop = p.getProperty();
|
||||
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
Map<K, V> map = new HashMap<K, V>((Map<K, V>)BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
map.put(key, value);
|
||||
facet = new BoundFacet(prop, map);
|
||||
} else if (draft != null) {
|
||||
((Map<K, V>) draftMap.get(prop.getPropertyName())).put(key, value);
|
||||
}
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
Map<K, V> map = new HashMap<K, V>(
|
||||
(Map<K, V>) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
map.put(key, value);
|
||||
facet = new BoundFacet(prop, map);
|
||||
} else if (draft != null) {
|
||||
((Map<K, V>) draftMap.get(prop.getPropertyName())).put(key, value);
|
||||
}
|
||||
|
||||
Optional<Function<Object, Object>> converter = prop.getWriteConverter(sessionOps.getSessionRepository());
|
||||
if (converter.isPresent()) {
|
||||
|
@ -593,14 +593,15 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(mapGetter);
|
||||
HelenusProperty prop = p.getProperty();
|
||||
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
Map<K, V> newMap = new HashMap<K, V>((Map<K, V>)BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
newMap.putAll(map);
|
||||
facet = new BoundFacet(prop, newMap);
|
||||
} else if (draft != null) {
|
||||
((Map<K, V>) draftMap.get(prop.getPropertyName())).putAll(map);
|
||||
}
|
||||
BoundFacet facet = null;
|
||||
if (pojo != null) {
|
||||
Map<K, V> newMap = new HashMap<K, V>(
|
||||
(Map<K, V>) BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop));
|
||||
newMap.putAll(map);
|
||||
facet = new BoundFacet(prop, newMap);
|
||||
} else if (draft != null) {
|
||||
((Map<K, V>) draftMap.get(prop.getPropertyName())).putAll(map);
|
||||
}
|
||||
|
||||
Optional<Function<Object, Object>> converter = prop.getWriteConverter(sessionOps.getSessionRepository());
|
||||
if (converter.isPresent()) {
|
||||
|
@ -687,13 +688,13 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
public E sync() throws TimeoutException {
|
||||
E result = super.sync();
|
||||
if (entity.isCacheable()) {
|
||||
if (draft != null) {
|
||||
sessionOps.updateCache(draft, bindFacetValues());
|
||||
} else if (pojo != null) {
|
||||
sessionOps.updateCache(pojo, bindFacetValues());
|
||||
} else {
|
||||
sessionOps.cacheEvict(bindFacetValues());
|
||||
}
|
||||
if (draft != null) {
|
||||
sessionOps.updateCache(draft, bindFacetValues());
|
||||
} else if (pojo != null) {
|
||||
sessionOps.updateCache(pojo, bindFacetValues());
|
||||
} else {
|
||||
sessionOps.cacheEvict(bindFacetValues());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -705,21 +706,21 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
}
|
||||
E result = super.sync(uow);
|
||||
if (draft != null) {
|
||||
cacheUpdate(uow, result, bindFacetValues());
|
||||
} else if (pojo != null) {
|
||||
cacheUpdate(uow, (E)pojo, bindFacetValues());
|
||||
}
|
||||
cacheUpdate(uow, result, bindFacetValues());
|
||||
} else if (pojo != null) {
|
||||
cacheUpdate(uow, (E) pojo, bindFacetValues());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Facet> bindFacetValues() {
|
||||
List<Facet> facets = bindFacetValues(entity.getFacets());
|
||||
facets.addAll(assignments.values().stream().distinct().filter(o -> o != null).collect(Collectors.toList()));
|
||||
return facets;
|
||||
}
|
||||
@Override
|
||||
public List<Facet> bindFacetValues() {
|
||||
List<Facet> facets = bindFacetValues(entity.getFacets());
|
||||
facets.addAll(assignments.values().stream().distinct().filter(o -> o != null).collect(Collectors.toList()));
|
||||
return facets;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public List<Facet> getFacets() {
|
||||
if (entity != null) {
|
||||
return entity.getFacets();
|
||||
|
|
|
@ -21,7 +21,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.Map;
|
||||
|
||||
import net.helenus.core.Helenus;
|
||||
|
@ -102,8 +101,8 @@ public class MapperInvocationHandler<E> implements InvocationHandler, Serializab
|
|||
}
|
||||
|
||||
if (MapExportable.TO_MAP_METHOD.equals(methodName)) {
|
||||
//return Collections.unmodifiableMap(src);
|
||||
return src;
|
||||
// return Collections.unmodifiableMap(src);
|
||||
return src;
|
||||
}
|
||||
|
||||
Object value = src.get(methodName);
|
||||
|
|
|
@ -285,41 +285,39 @@ public final class MappingUtil {
|
|||
}
|
||||
|
||||
// https://stackoverflow.com/a/4882306/366692
|
||||
public static <T> T clone(T object)
|
||||
throws CloneNotSupportedException {
|
||||
Object clone = null;
|
||||
public static <T> T clone(T object) throws CloneNotSupportedException {
|
||||
Object clone = null;
|
||||
|
||||
// Use reflection, because there is no other way
|
||||
try {
|
||||
Method method = object.getClass().getMethod("clone");
|
||||
clone = method.invoke(object);
|
||||
} catch (InvocationTargetException e) {
|
||||
rethrow(e.getCause());
|
||||
} catch (Exception cause) {
|
||||
rethrow(cause);
|
||||
}
|
||||
if (object.getClass().isInstance(clone)) {
|
||||
@SuppressWarnings("unchecked") // clone class <= object class <= T
|
||||
T t = (T) clone;
|
||||
return t;
|
||||
} else {
|
||||
throw new ClassCastException(clone.getClass().getName());
|
||||
}
|
||||
}
|
||||
// Use reflection, because there is no other way
|
||||
try {
|
||||
Method method = object.getClass().getMethod("clone");
|
||||
clone = method.invoke(object);
|
||||
} catch (InvocationTargetException e) {
|
||||
rethrow(e.getCause());
|
||||
} catch (Exception cause) {
|
||||
rethrow(cause);
|
||||
}
|
||||
if (object.getClass().isInstance(clone)) {
|
||||
@SuppressWarnings("unchecked") // clone class <= object class <= T
|
||||
T t = (T) clone;
|
||||
return t;
|
||||
} else {
|
||||
throw new ClassCastException(clone.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
private static void rethrow(Throwable cause)
|
||||
throws CloneNotSupportedException {
|
||||
if (cause instanceof RuntimeException) {
|
||||
throw (RuntimeException) cause;
|
||||
}
|
||||
if (cause instanceof Error) {
|
||||
throw (Error) cause;
|
||||
}
|
||||
if (cause instanceof CloneNotSupportedException) {
|
||||
throw (CloneNotSupportedException) cause;
|
||||
}
|
||||
CloneNotSupportedException e = new CloneNotSupportedException();
|
||||
e.initCause(cause);
|
||||
throw e;
|
||||
}
|
||||
private static void rethrow(Throwable cause) throws CloneNotSupportedException {
|
||||
if (cause instanceof RuntimeException) {
|
||||
throw (RuntimeException) cause;
|
||||
}
|
||||
if (cause instanceof Error) {
|
||||
throw (Error) cause;
|
||||
}
|
||||
if (cause instanceof CloneNotSupportedException) {
|
||||
throw (CloneNotSupportedException) cause;
|
||||
}
|
||||
CloneNotSupportedException e = new CloneNotSupportedException();
|
||||
e.initCause(cause);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue