DATAJPA-461 - Polishing of binding implementation for StringQueries.
We now always create a ParameterBinding for all parameters to simplify the client code so that it can safely always lookup bindings and apply them. Changed the setup of the regular expression to work with the keywords provided by the binding types to ease future extensions. Added integration test to quickly verify the EclipseLink bug we're running into now for further reference. Original pull request: #56.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.infrastructure;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
@@ -25,4 +27,13 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
@ContextConfiguration("classpath:eclipselink.xml")
|
||||
public class EclipseLinkMetamodelIntegrationTests extends MetamodelIntegrationTests {
|
||||
|
||||
/**
|
||||
* TODO: Remove, once https://bugs.eclipse.org/bugs/show_bug.cgi?id=427892 is fixed.
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
@Override
|
||||
public void canAccessParametersByIndexForNativeQueries() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Path;
|
||||
@@ -42,8 +43,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration({ "classpath:infrastructure.xml" })
|
||||
public class MetamodelIntegrationTests {
|
||||
|
||||
@PersistenceContext
|
||||
EntityManager em;
|
||||
@PersistenceContext EntityManager em;
|
||||
|
||||
@Test
|
||||
public void considersOneToOneAttributeAnAssociation() {
|
||||
@@ -66,4 +66,12 @@ public class MetamodelIntegrationTests {
|
||||
|
||||
assertThat(path.getModel().getBindableType(), is(BindableType.ENTITY_TYPE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canAccessParametersByIndexForNativeQueries() {
|
||||
|
||||
Query query = em.createNativeQuery("SELECT u from User u where u.lastname = ?1");
|
||||
|
||||
assertThat(query.getParameter(1), is(notNullValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,7 +23,10 @@ import org.springframework.data.jpa.repository.query.StringQuery.LikeParameterBi
|
||||
import org.springframework.data.repository.query.parser.Part.Type;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link LikeParameterBinding}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public class LikeBindingUnitTests {
|
||||
|
||||
|
||||
@@ -124,10 +124,11 @@ public class StringQueryUnitTests {
|
||||
assertThat(query.getQueryString(), is(queryString));
|
||||
|
||||
List<ParameterBinding> bindings = query.getParameterBindings();
|
||||
assertThat(bindings, hasSize(2));
|
||||
assertThat(bindings, hasSize(3));
|
||||
|
||||
assertNamedBinding(InParameterBinding.class, "ids", bindings.get(0));
|
||||
assertNamedBinding(InParameterBinding.class, "names", bindings.get(1));
|
||||
assertNamedBinding(ParameterBinding.class, "bar", bindings.get(2));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,10 +162,11 @@ public class StringQueryUnitTests {
|
||||
assertThat(query.getQueryString(), is(queryString));
|
||||
|
||||
List<ParameterBinding> bindings = query.getParameterBindings();
|
||||
assertThat(bindings, hasSize(2));
|
||||
assertThat(bindings, hasSize(3));
|
||||
|
||||
assertPositionalBinding(InParameterBinding.class, 1, bindings.get(0));
|
||||
assertPositionalBinding(InParameterBinding.class, 2, bindings.get(1));
|
||||
assertPositionalBinding(ParameterBinding.class, 3, bindings.get(2));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user