Skip to content
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

#315 - Add example for Spring Data JDBC usage with jOOQ #385

Closed

Conversation

florianluediger
Copy link
Contributor

This sample shows the concurrent usage of Spring Data JDBC wit jOOQ.

I am not particularly happy with the fact that there is a Category class for both Spring Data JDBC and jOOQ and that I have to map them onto each other in the JooqMethods class. If you have any suggestions on how to improve this, feel free to give me a heads up.

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.

About the duplicated classes. This might help: https://www.jooq.org/doc/3.9/manual/sql-execution/fetching/pojos/

@@ -0,0 +1,60 @@
/*
* This file is generated by jOOQ.
Copy link
Contributor

Choose a reason for hiding this comment

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

Generated files shouldn't be checked into version control. Obviously applies to all generated files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have used this example as a reference, so I included the generated sources. I will remove these because I also think it makes no sense to include them.

<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.11.0</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid putting versions directly into dependencies.

Ideally remove them completely.
They might be already defined by an upstream pom.xml.

If they aren't extract them into a property.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

@Bean
public ApplicationListener<BeforeSaveEvent> timeStampingSaveTime() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove all code not essential for this example. Simplify the model if necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


List<Category> getCategoriesWithAgeGroup(AgeGroup ageGroup) {
Result<Record> res = this.dslContext.select().from(CATEGORY).where(CATEGORY.AGE_GROUP.equal(ageGroup.name())).fetch();
List<Category> categoryList = new ArrayList<Category>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can and I think it's a very elegant solution - done

* @author Florian Lüdiger
*/
@Component
public class JooqMethods {
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be an arbitrary component but a custom implementation for a repository method. See https://docs.spring.io/spring-data/jdbc/docs/1.0.0.RC1/reference/html/#repositories.custom-implementations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really like that approach, it works really well!

To rerun the code generator, just execute the following commands:
[indent=0]
----
$ rm -rf gensrc
Copy link
Contributor

Choose a reason for hiding this comment

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

is the rm really necessary? that really should be done by the clean of the mvn call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mvn clean does not actually delete the generated sources. However these get ovewritten by the mvn generate-sources command, so I guess this step is not really necessary.

@florianluediger
Copy link
Contributor Author

Thank you @schauder for your detailed review, it really is a lot of fun to work on this issue and I think I'm learning a lot! I have fixed the things you pointed out and hope that everything is okay now. If not, feel free to hit me up again.

schauder pushed a commit that referenced this pull request Aug 2, 2018
Demonstrating how to use jOOQ as the basis for an implementation of custom repository methods.

Original pull request: #385.
schauder added a commit that referenced this pull request Aug 2, 2018
Used default directory for code generation.
Formatting.
Simplified asserts with some AssertJ trickery.

Original pull request: #385.
@schauder
Copy link
Contributor

schauder commented Aug 2, 2018

Thanks for the work. I squashed, polished and merged.

@schauder schauder closed this Aug 2, 2018
@dashirov-fl
Copy link

Where is example.springdata.jdbc.basics.simpleentity.domain.tables.Category.CATEGORY coming from? Can't find it anywhere in any branches.

@schauder
Copy link
Contributor

@dashirov-fl this is generated by JOOQ.

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