Added check for mutated set so that the backingMap could contain all object values. The other option was to auto-refresh the instance's backing map when a getter is invoked for a valid property that isn't included in the backing map (which still may be handy/required for caching to work).

This commit is contained in:
Greg Burd 2017-08-09 16:20:38 -04:00
parent 871c8d0c90
commit a126607c09
3 changed files with 95 additions and 92 deletions

View file

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.helenus</groupId>
<artifactId>helenus-core</artifactId>
<version>2.0.13-SNAPSHOT</version>
<version>2.0.14-SNAPSHOT</version>
<packaging>jar</packaging>
<name>helenus</name>

View file

@ -15,21 +15,14 @@
*/
package net.helenus.core.operation;
import java.util.*;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.querybuilder.BuiltStatement;
import com.datastax.driver.core.querybuilder.Insert;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.google.common.base.Predicates;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.helenus.core.AbstractSessionOperations;
import net.helenus.core.Getter;
import net.helenus.core.reflect.HelenusPropertyNode;
import net.helenus.core.reflect.MapExportable;
import net.helenus.mapping.ColumnType;
import net.helenus.mapping.HelenusEntity;
import net.helenus.mapping.HelenusProperty;
import net.helenus.mapping.MappingUtil;
@ -37,6 +30,8 @@ import net.helenus.mapping.value.BeanColumnValueProvider;
import net.helenus.support.Fun;
import net.helenus.support.HelenusMappingException;
import java.util.*;
public final class InsertOperation extends AbstractOperation<ResultSet, InsertOperation> {
private HelenusEntity entity;
@ -59,13 +54,18 @@ public final class InsertOperation extends AbstractOperation<ResultSet, InsertOp
this.entity = entity;
this.ifNotExists = ifNotExists;
Set<String> keys = (pojo instanceof MapExportable) ? ((MapExportable)pojo).toMap().keySet() : null;
Collection<HelenusProperty> properties = entity.getOrderedProperties();
Set<String> keys = null;
if (pojo instanceof MapExportable) {
keys = ((MapExportable) pojo).mutated();
if (keys == null) {
keys = ((MapExportable) pojo).toMap().keySet();
}
}
for (HelenusProperty prop : properties) {
// Skip properties that are not in the map of the pojo we're storing. This creates a path
// for entity instances to be {in,up}serted without including all columns in the INSERT statement.
if (keys == null || keys.contains(prop.getPropertyName())) {
Object value = BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop);

View file

@ -16,6 +16,7 @@
package net.helenus.core.reflect;
import java.util.Map;
import java.util.Set;
public interface MapExportable {
@ -23,4 +24,6 @@ public interface MapExportable {
Map<String, Object> toMap();
default Set<String> mutated() { return null; }
}