-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Conversation
There was a problem hiding this 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
jdbc/jooq/pom.xml
Outdated
<dependency> | ||
<groupId>org.jooq</groupId> | ||
<artifactId>jooq</artifactId> | ||
<version>3.11.0</version> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use this for the conversion? https://www.jooq.org/javadoc/3.9.x/org/jooq/Result.html#into-java.lang.Class-
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
jdbc/jooq/README.adoc
Outdated
To rerun the code generator, just execute the following commands: | ||
[indent=0] | ||
---- | ||
$ rm -rf gensrc |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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. |
Demonstrating how to use jOOQ as the basis for an implementation of custom repository methods. Original pull request: #385.
Used default directory for code generation. Formatting. Simplified asserts with some AssertJ trickery. Original pull request: #385.
Thanks for the work. I squashed, polished and merged. |
Where is example.springdata.jdbc.basics.simpleentity.domain.tables.Category.CATEGORY coming from? Can't find it anywhere in any branches. |
@dashirov-fl this is generated by JOOQ. |
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 theJooqMethods
class. If you have any suggestions on how to improve this, feel free to give me a heads up.