Permalink
Browse files

removed deprecated create by example methods

  • Loading branch information...
DirkMahler committed Jan 8, 2019
1 parent e1e4856 commit b7f804f286e1c9051e112cad07b2cbf10bcf6195
@@ -104,21 +104,6 @@
*/
CompositeObject create(Class<?> type, Class<?>... types);

/**
* Create a new {@link CompositeObject} instance using an example.
*
* @param example
* The example instance.
* @param type
* The interface the property type shall implement.
* @param types
* Additional interfaces the entity type shall implement.
* @return The {@link CompositeObject} instance.
*/
@Deprecated
CompositeObject create(Example<CompositeObject> example, Class<?> type, Class<?>... types);


/**
* Create a new property instance.
*
@@ -131,31 +116,18 @@
*/
<T> T create(Class<T> type);

/**
* Create a new property instance using an example.
*
* @param example
* The example instance.
* @param <T>
* The expected return type. Note that it must be assignable to
* at least one of the interfaces specified for the types.
* @param type
* The interface the property type shall implement.
* @return The property instance.
*/
@Deprecated
<T> T create(Example<T> example, Class<T> type);

/**
* Create a new {@link CompositeObject} instance using an example.
*
* @param type
* The interface the property type shall implement.
* @param example
* The example instance.
* @param types
* Additional interfaces the entity type shall implement.
* @return The {@link CompositeObject} instance.
*/
<T> T create(Class<T> type, Example<T> example);
<T> T create(Class<T> type, Example<T> example, Class<?>... types);

/**
* Creates an instance of a typed relation between a source and a target
@@ -177,29 +149,6 @@
*/
<S, R, T> R create(S source, Class<R> relationType, T target);

/**
* Creates an instance of a typed relation between a source and a target
* instance using an example.
*
* @param example
* The example instance.
* @param source
* The source instance.
* @param relationType
* The relation type.
* @param target
* The target instance.
* @param <S>
* The source type.
* @param <R>
* The relation type.
* @param <T>
* The target type.
* @return The created relation instance.
*/
@Deprecated
<S, R, T> R create(Example<R> example, S source, Class<R> relationType, T target);

/**
* Creates an instance of a typed relation between a source and a target
* instance using an example.
@@ -154,7 +154,7 @@ public XOTransaction currentTransaction() {
exampleProxyMethodServices.put(type, proxyMethodService);
}
InstanceInvocationHandler invocationHandler = new InstanceInvocationHandler(exampleEntity, proxyMethodService);
List<Class<?>> effectiveTypes = new ArrayList<>();
List<Class<?>> effectiveTypes = new ArrayList<>(types.length + 1);
effectiveTypes.add(type);
effectiveTypes.addAll(Arrays.asList(types));
CompositeType compositeType = CompositeTypeBuilder.create(CompositeObject.class, type, types);
@@ -224,20 +224,9 @@ public CompositeObject create(Class<?> type, Class<?>... types) {
}

@Override
public CompositeObject create(Example<CompositeObject> example, Class<?> type, Class<?>... types) {
public <T> T create(Class<T> type, Example<T> example, Class<?>... types) {
Map<PrimitivePropertyMethodMetadata<PropertyMetadata>, Object> exampleEntity = prepareExample(example, type);
return createByExample(exampleEntity, type, types);
}

@Override
public <T> T create(Example<T> example, Class<T> type) {
return create(type, example);
}

@Override
public <T> T create(Class<T> type, Example<T> example) {
Map<PrimitivePropertyMethodMetadata<PropertyMetadata>, Object> exampleEntity = prepareExample(example, type);
return createByExample(exampleEntity, type).as(type);
return createByExample(exampleEntity, type, types).as(type);
}

public <T> T create(Class<T> type) {
@@ -272,11 +261,6 @@ private CompositeObject createByExample(Map<PrimitivePropertyMethodMetadata<Prop
return createByExample(from, relationType, to, Collections.emptyMap());
}

@Override
public <S, R, T> R create(Example<R> example, S from, Class<R> relationType, T to) {
return create(from, relationType, to, example);
}

@Override
public <S, R, T> R create(S from, Class<R> relationType, T to, Example<R> example) {
Map<PrimitivePropertyMethodMetadata<PropertyMetadata>, Object> exampleRelation = prepareExample(example, relationType);
@@ -1,15 +1,5 @@
package com.buschmais.xo.neo4j.test.example;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.net.URISyntaxException;
import java.util.Collection;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import com.buschmais.xo.api.CompositeObject;
import com.buschmais.xo.api.Example;
import com.buschmais.xo.api.XOManager;
@@ -18,6 +8,14 @@
import com.buschmais.xo.neo4j.test.example.composite.A;
import com.buschmais.xo.neo4j.test.example.composite.B;
import com.buschmais.xo.neo4j.test.example.composite.Parent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Collection;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

@RunWith(Parameterized.class)
public class ByExampleTest extends AbstractNeo4jXOManagerTest {
@@ -27,7 +25,7 @@ public ByExampleTest(XOUnit xoUnit) {
}

@Parameterized.Parameters
public static Collection<Object[]> getXOUnits() throws URISyntaxException {
public static Collection<Object[]> getXOUnits() {
return xoUnits(A.class, B.class, Parent.class);
}

@@ -36,24 +34,24 @@ public void createByExample() {
XOManager xoManager = getXOManager();
xoManager.currentTransaction().begin();
// java 7: anonymous inner class
A a1 = xoManager.create(new Example<A>() {
A a1 = xoManager.create(A.class, new Example<A>() {
@Override
public void prepare(A example) {
example.setValue("A1");
example.setName("Name of A1");
}
}, A.class);
});
assertThat(a1.getValue(), equalTo("A1"));
assertThat(a1.getName(), equalTo("Name of A1"));
// java 8: lambda expression
A a2 = xoManager.create(example -> {
A a2 = xoManager.create(A.class, example -> {
example.setValue("A2");
example.setName("Name of A2");
}, A.class);
});
assertThat(a2.getValue(), equalTo("A2"));
assertThat(a2.getName(), equalTo("Name of A2"));
// Create a relation
Parent parent = xoManager.create(example -> example.setName("Name of A1->A2"), a1, Parent.class, a2);
Parent parent = xoManager.create(a1, Parent.class, a2, example -> example.setName("Name of A1->A2"));
assertThat(parent.getName(), equalTo("Name of A1->A2"));

xoManager.currentTransaction().commit();
@@ -77,14 +75,14 @@ public void findCompositeByExample() {
XOManager xoManager = getXOManager();
xoManager.currentTransaction().begin();
// java 7: anonymous inner class
CompositeObject compositeObject1 = xoManager.<CompositeObject>create(new Example<CompositeObject>() {
A compositeObject1 = xoManager.create(A.class, new Example<A>() {
@Override
public void prepare(CompositeObject example) {
example.as(A.class).setValue("A1");
public void prepare(A example) {
example.setValue("A1");
}
}, A.class, B.class);
}, B.class);
// java 8: lambda expression
xoManager.<CompositeObject>create(example -> example.as(A.class).setValue("A2"), A.class, B.class);
xoManager.create(A.class, example -> example.setValue("A2"), B.class);
// java 8: lambda expression, alternative
xoManager.create(A.class, example -> example.setValue("A3"));
xoManager.currentTransaction().commit();

0 comments on commit b7f804f

Please sign in to comment.