Skip to content

DATAJDBC-234 - Support properties file based query declaration #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

mcisnerosb57
Copy link
Contributor

@mcisnerosb57 mcisnerosb57 commented Mar 21, 2019

the name parameter has been created for Query.class.The NamedQuery interface is used to extract from the properties file called jdbc-named-queries.properties.Test jUnit created. modified: spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/Query.java, modified: spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcQueryLookupStrategy.java, modified: spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcQueryMethod.java , modified: spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/support/JdbcQueryMethodUnitTests.java

@pivotal-issuemaster
Copy link

@mcisnerosb57 Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@mcisnerosb57 Thank you for signing the Contributor License Agreement!

@schauder schauder changed the title the name parameter has been created for Query.class.The NamedQuery in… DATAJDBC-234 - Support properties file based query declaration Mar 25, 2019
Copy link
Contributor

@schauder schauder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have at least one integration test demonstrating this feature.

I also pointed out some issues in additional comments.

@mcisnerosb57
Copy link
Contributor Author

We should have at least one integration test demonstrating this feature.

I also pointed out some issues in additional comments.
Done . thanks!

@mcisnerosb57
Copy link
Contributor Author

Deberíamos tener al menos una prueba de integración que demuestre esta característica.

También señalé algunas cuestiones en comentarios adicionales.

Do you need anything else?. thank you very much.

@schauder
Copy link
Contributor

schauder commented Apr 5, 2019

Nothing but some more time. I'll look at this PR probably somewhere next week.

@mcisnerosb57
Copy link
Contributor Author

Nada más que un poco más de tiempo. Voy a ver este PR probablemente en algún lugar la próxima semana.

@mcisnerosb57
Copy link
Contributor Author

sorry im close the issue by error.

@mcisnerosb57 mcisnerosb57 reopened this Apr 5, 2019
@mcisnerosb57
Copy link
Contributor Author

thanks very much for your comment.

Copy link
Contributor

@schauder schauder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integration tests in the context of this project are those that are named *IntegrationTests and actually interact with a database.

You could add two test methods to JdbcRepositoryIntegrationTests one for a named query based on the method name and one based on a `@Query(name =...) annotation.

* @return May be {@code null}.
*/
@Nullable
public String getValueNamedQuery() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getNamedQuery is probably a better name.

*/
@Nullable
public String getValueNamedQuery() {
String annotatedName = getMergedAnnotationAttribute("name");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it seems I wasn't clear here.

If no name is specified, the method name should be used a the name for the named query.

@mcisnerosb57
Copy link
Contributor Author

Hi, i ve problems with de spring-data-jdbc . i cant realize mvn install , and when i cant import project because the libraly kotlin-maven-plugin:

No marketplace entries found to handle Execution compile, in /spring-data-jdbc/pom.xml in Eclipse. Please see Help for more information.

[ERROR] Failures:
[ERROR] JdbcRepositoryQueryUnitTests.publishesAsManyEventsAsReturnedAggregates:185
Wanted but not invoked:
applicationEventPublisher.publishEvent(

);
-> at org.springframework.data.jdbc.repository.support.JdbcRepositoryQueryUnitTests.publishesAsManyEventsAsReturnedAggregates(JdbcRepositoryQueryUnitTests.java:185)
Actually, there were zero interactions with this mock.

[ERROR] JdbcRepositoryQueryUnitTests.publishesSingleEventWhenQueryReturnsSingleAggregate:169
Wanted but not invoked:
applicationEventPublisher.publishEvent(

);
-> at org.springframework.data.jdbc.repository.support.JdbcRepositoryQueryUnitTests.publishesSingleEventWhenQueryReturnsSingleAggregate(JdbcRepositoryQueryUnitTests.java:169)
Actually, there were zero interactions with this mock.

[INFO]
[ERROR] Tests run: 287, Failures: 2, Errors: 0, Skipped: 1

@schauder
Copy link
Contributor

Great to see you are still working on this.

You are hinting at three different problems:
a) not being able to execute maven install
b) not being able to import the project into Eclipse
c) some tests failing.

I'm not sure I'll be able to help with b) since I don't use that IDE.
But let's start with a) for now.
What is the exact out put you get when you checkout the master branch and run
./mvnw clean install?

@mcisnerosb57
Copy link
Contributor Author

MVN install error:
[ERROR] Failures:
[ERROR] JdbcRepositoryQueryUnitTests.publishesAsManyEventsAsReturnedAggregates:185
Wanted but not invoked:
applicationEventPublisher.publishEvent(

);
-> at org.springframework.data.jdbc.repository.support.JdbcRepositoryQueryUnitTests.publishesAsManyEventsAsReturnedAggregates(JdbcRepositoryQueryUnitTests.java:185)
Actually, there were zero interactions with this mock.

[ERROR] JdbcRepositoryQueryUnitTests.publishesSingleEventWhenQueryReturnsSingleAggregate:169
Wanted but not invoked:
applicationEventPublisher.publishEvent(

);
-> at org.springframework.data.jdbc.repository.support.JdbcRepositoryQueryUnitTests.publishesSingleEventWhenQueryReturnsSingleAggregate(JdbcRepositoryQueryUnitTests.java:169)
Actually, there were zero interactions with this mock.

[INFO]
[ERROR] Tests run: 287, Failures: 2, Errors: 0, Skipped: 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:56 min
[INFO] Finished at: 2019-05-10T14:30:03+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project spring-data-jdbc: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\m.cisneros.bernardo\moises\spring-data-jdbc\spring-data-jdbc\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Thanks very much

@schauder
Copy link
Contributor

Is this with the latest version of the master branch? Because it looks like an issue that we had some time ago when we updated Mockito. Please make sure to pull the latest changes and run with -U to make sure you get all the latest snapshots.

@mcisnerosb57
Copy link
Contributor Author

Integration tests in the context of this project are those that are named *IntegrationTests and actually interact with a database.

You could add two test methods to JdbcRepositoryIntegrationTests one for a named query based on the method name and one based on a `@query(name =...) annotation.

the following things is happening in the integration test:
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [findById]; nested exception is java.sql.SQLSyntaxErrorException: unexpected token: FINDBYID
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:93)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1442)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:632)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:668)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:693)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:747)
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:235)
at org.springframework.data.jdbc.repository.support.JdbcRepositoryQuery.lambda$4(JdbcRepositoryQuery.java:173)
at org.springframework.data.jdbc.repository.support.JdbcRepositoryQuery.lambda$0(JdbcRepositoryQuery.java:130)
at org.springframework.data.jdbc.repository.support.JdbcRepositoryQuery.execute(JdbcRepositoryQuery.java:119)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:602)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:592)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:592)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.repository.core.support.MethodInvocationValidator.invoke(MethodInvocationValidator.java:99)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at org.springframework.data.jdbc.repository.$Proxy41.findById(Unknown Source)
at org.springframework.data.jdbc.repository.JdbcRepositoryIntegrationTests.findByIdReturnsEmptyWhenNoneFound(JdbcRepositoryIntegrationTests.java:87)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.RunPrepareTestInstanceCallbacks.evaluate(RunPrepareTestInstanceCallbacks.java:64)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.springframework.test.context.junit4.statements.SpringFailOnTimeout.evaluate(SpringFailOnTimeout.java:87)
at org.springframework.test.context.junit4.statements.ProfileValueChecker.evaluate(ProfileValueChecker.java:103)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.springframework.test.context.junit4.statements.ProfileValueChecker.evaluate(ProfileValueChecker.java:103)
at org.springframework.test.context.junit4.rules.SpringClassRule$TestContextManagerCacheEvictor.evaluate(SpringClassRule.java:190)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207)
Caused by: java.sql.SQLSyntaxErrorException: unexpected token: FINDBYID
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.(Unknown Source)
at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:237)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:614)
... 56 more
Caused by: org.hsqldb.HsqlException: unexpected token: FINDBYID
at org.hsqldb.error.Error.parseError(Unknown Source)
at org.hsqldb.ParserBase.unexpectedToken(Unknown Source)
at org.hsqldb.ParserCommand.compilePart(Unknown Source)
at org.hsqldb.ParserCommand.compileStatement(Unknown Source)
at org.hsqldb.Session.compileStatement(Unknown Source)
at org.hsqldb.StatementManager.compile(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 60 more

private static DummyEntity createDummyEntity() {

	DummyEntity entity = new DummyEntity();
	entity.setName("Entity Name");
	return entity;
}
interface DummyEntityRepository extends CrudRepository<DummyEntity, Long> {
	@Query(name= "dummyentity.findbyId")
	public Optional<DummyEntity> findById(@Param("id") Long id);

// @query(name= "dummyentity.findbyId")
// public Optional findbyIdNamedQuery(@param("id") Long id);
}

@Data
static class DummyEntity {
	String name;
	@Id private Long idProp;
}

@schauder
Copy link
Contributor

Have you been able to fix your development environment problems? The PR builds ok for me.

@@ -122,14 +122,31 @@
<version>${mybatis.version}</version>
<optional>true</optional>
</dependency>

<dependency>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not add additional dependencies.

<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>${hsqldb.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially not Hibernate.

@@ -0,0 +1,117 @@
package org.springframework.data.jdbc.repository;

import static org.junit.Assert.assertEquals;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer AssertJ assertions.

import java.util.stream.Stream;

@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:application-context.xml")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look how other intergration-tests are setup and construct any new tests the same way.
But really you can just add tests to existing integration-tests. JdbcRepositoryIntegrationTests is a good candidate.

@@ -50,6 +71,9 @@
@Transactional
public class JdbcRepositoryIntegrationTests {

Logger logger = LoggerFactory.getLogger(JdbcRepositoryIntegrationTests.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed.

@@ -255,11 +255,11 @@ public void executeCustomModifyingQueryWithReturnTypeVoid() {
assertThat(repository.findByNameAsEntity("Spring Data JDBC")).isNotNull();
}

@Test // DATAJDBC-175
/*@Test // DATAJDBC-175
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not remove tests.

import lombok.Data;
import org.springframework.data.annotation.Id;

import javax.persistence.GeneratedValue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use javax.persistence

import javax.persistence.GeneratedValue;

@Data
public class DummyEntity {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create test entities as static inner classes.


import java.util.stream.Stream;

@Repository
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need an @Repository annotation on an interface extending @CrudRepository

import java.util.stream.Stream;

@Repository
public interface DummyEntityRepository extends CrudRepository<DummyEntity, Long> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as entities for testing, please use static inner interfaces for repositories used in tests.

@mcisnerosb57
Copy link
Contributor Author

I need to be able to pull the code to update it.
If it does not appear that I have changed 150 files in my pull request.
Can you give me permissions on spring-data-jdbc to create the branch issue / DATAJDBC-234 branch or can you also create it in the repository and give me permissions on that branch from master.

Thank you!

@schauder
Copy link
Contributor

You don't need more than reading access to the repository.
All you need to do is:

  • undo the merge with master
  • update your master branch to be identically with the one from this repository.
  • rebase your DATAJDBC-234 branch on your updated master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants