Skip to content

Commit

Permalink
Don't merge collection property default value with graph value
Browse files Browse the repository at this point in the history
  • Loading branch information
frant-hartm committed Aug 15, 2017
1 parent 89e60c1 commit c38608c
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ o Update Neo4j to version 3.2.3 in 3.2 profile
o Update Neo4j to version 3.3.0-alpha05 in 3.3 profile
o Update java driver version to 1.4.3
o Test against java driver 1.5-alpha1 in driver-1.5 profile
o Don't merge collection property default value with graph value

3.0.0-RC1
o Add verifyConnection configuration property for bolt and http driver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,12 @@ private void writeProperty(ClassInfo classInfo, Object instance, Property<?, ?>
if (writer.type().isArray() || Iterable.class.isAssignableFrom(writer.type())) {
FieldInfo reader = classInfo.getFieldInfo(property.getKey().toString());
if (reader != null) {
Object currentValue = reader.readProperty(instance);
Class<?> paramType = writer.type();
Class elementType = underlyingElementType(classInfo, property.getKey().toString());
if (paramType.isArray()) {
value = EntityAccessManager.merge(paramType, value, (Object[]) currentValue, elementType);
value = EntityAccessManager.merge(paramType, value, new Object[]{} , elementType);
} else {
value = EntityAccessManager.merge(paramType, value, (Collection) currentValue, elementType);
value = EntityAccessManager.merge(paramType, value, Collections.emptyList(), elementType);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
* You may not use this product except in compliance with the License.
*
* This product may include a number of subcomponents with
* separate copyright notices and license terms. Your use of the source
* code for these subcomponents is subject to the terms and
* conditions of the subcomponent's license, as noted in the LICENSE file.
*/

package org.neo4j.ogm.persistence.examples.numbers;

import java.util.List;

import org.neo4j.ogm.annotation.NodeEntity;

import static com.google.common.collect.Lists.newArrayList;

/**
* @author Frantisek Hartman
*/
@NodeEntity
public class Bucket {

Long id;

// collection with default value
List<Integer> numbers = newArrayList(1, 2, 3);

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public List<Integer> getNumbers() {
return numbers;
}

public void setNumbers(List<Integer> numbers) {
this.numbers = numbers;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
* You may not use this product except in compliance with the License.
*
* This product may include a number of subcomponents with
* separate copyright notices and license terms. Your use of the source
* code for these subcomponents is subject to the terms and
* conditions of the subcomponent's license, as noted in the LICENSE file.
*/

package org.neo4j.ogm.persistence.examples.numbers;

import java.io.IOException;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
import org.neo4j.ogm.testutil.MultiDriverTestClass;

import static java.util.Collections.emptyList;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Frantisek Hartman
*/
public class BucketIntegrationTest extends MultiDriverTestClass {

private static SessionFactory sessionFactory;

private Session session;

@BeforeClass
public static void oneTimeSetUp() {
sessionFactory = new SessionFactory(driver, "org.neo4j.ogm.persistence.examples.numbers");
}

@Before
public void init() throws IOException {
session = sessionFactory.openSession();
session.purgeDatabase();
}

@Test
public void savedBucketShouldHaveDefaultValue() throws Exception {
Bucket bucket = new Bucket();
session.save(bucket);
session.clear();

Bucket loaded = session.load(Bucket.class, bucket.getId());
assertThat(loaded.getNumbers()).containsOnly(1, 2, 3);
}

@Test
public void emptiedBucketShouldBeEmptyAfterReload() throws Exception {
Bucket bucket = new Bucket();
bucket.setNumbers(emptyList());
session.save(bucket);
session.clear();

Bucket loaded = session.load(Bucket.class, bucket.getId());
assertThat(loaded.getNumbers()).isEmpty();
}
}

0 comments on commit c38608c

Please sign in to comment.