Skip to content

Conversation

@ericharmeling
Copy link
Contributor

@ericharmeling ericharmeling commented Jun 10, 2020

Fixes #7737.
Fixes #6040.
Related to #6046.

This PR includes:

  • A simple tutorial on developing a basic Spring Boot application on CRDB with MyBatis-Spring-Boot-Starter.

The code referenced by this tutorial is located here: https://github.com/jeffgbutler/mybatis-cockroach-demo/tree/master/src.

I made a couple minor changes to the application that are reflected in the .java files in this PR and in the tutorial:

Those changes are reflected in a fork of the repo: https://github.com/ericharmeling/mybatis-cockroach-demo/tree/transaction-retries.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@ericharmeling ericharmeling changed the title MyBatis Hello World tutorial Spring MyBatis Hello World tutorial Jun 10, 2020
@ericharmeling ericharmeling force-pushed the spring-mybatis-hello-world branch from 374b17c to 629acd6 Compare June 11, 2020 17:49
@ericharmeling ericharmeling force-pushed the spring-mybatis-hello-world branch from 629acd6 to d724c56 Compare June 16, 2020 15:30
@ericharmeling ericharmeling force-pushed the spring-mybatis-hello-world branch from d724c56 to 449c1ee Compare June 16, 2020 19:01
@ericharmeling ericharmeling force-pushed the spring-mybatis-hello-world branch from 449c1ee to c076104 Compare June 17, 2020 15:40
@ericharmeling
Copy link
Contributor Author

@jeffgbutler
Would you mind looking over this PR before we publish the tutorial to our public docs site? If you plan to move the code samples to a different repo, please let us know so I can update the links.

Cheers!

@vy-ton vy-ton linked an issue Jul 15, 2020 that may be closed by this pull request
@jeffgbutler
Copy link

I think this looks really good. Couple of things to think about:

  1. Do you want to say anything about the tests that use TestContainers? The tests in this example will run immediately without any further command line setup for an external Cockroach instance - which I think is cool.
  2. JDBC batch can get complex, so it might not be worth mentioning this. But the batch methods in this example do intermediate commits - that's why there is weird logic around the batch size of 128. If you don't want to do intermediate commits it can be simplified substantially. But I also think I remember reading somewhere that Cockroach likes batch sizes that are powers of 2?
  3. I just can't bring myself to put this example code in the MyBatis official repo (sorry about that). Everything else in our repo uses Maven, not Gradle, and this isn't really setup to use our parent POM, fit into the overall project build system, etc. It's easier for me to maintain if I just leave it where it is. Hope that doesn't cause too much anguish.

@ericharmeling
Copy link
Contributor Author

ericharmeling commented Jul 16, 2020

TFTR, @jeffgbutler!

  1. Do you want to say anything about the tests that use TestContainers? The tests in this example will run immediately without any further command line setup for an external Cockroach instance - which I think is cool.

Although TestContainers does have a module for Cockroach, we can't officially claim beta support with TestContainers at the moment (we're looking into it in the upcoming quarter). So, we probably want to avoid recommending the tool in our docs. Also, in the interest of simplifying things, it's a good idea to avoid introducing additional tooling where possible. Perhaps we should leave it out of the tutorial, but keep it in the repo?

  1. JDBC batch can get complex, so it might not be worth mentioning this. But the batch methods in this example do intermediate commits - that's why there is weird logic around the batch size of 128. If you don't want to do intermediate commits it can be simplified substantially. But I also think I remember reading somewhere that Cockroach likes batch sizes that are powers of 2?

Batching reads/writes does add more complexity to the sample... but we do call out using batch writes as a best practice in our docs. And we implement batch inserts in the other Java examples (e.g., https://www.cockroachlabs.com/docs/v20.1/build-a-java-app-with-cockroachdb.html). And, as you noted, we have a performance recommendation to use batch sizes of 128 (e.g., https://www.cockroachlabs.com/docs/v20.1/build-a-java-app-with-cockroachdb.html#use-a-batch-size-of-128), with some sample logic that is functionally similar to what you have in MyBatisAccountService.java. I can definitely clarify your sample's batch logic with some prose in the tutorial.

  1. I just can't bring myself to put this example code in the MyBatis official repo (sorry about that). Everything else in our repo uses Maven, not Gradle, and this isn't really setup to use our parent POM, fit into the overall project build system, etc. It's easier for me to maintain if I just leave it where it is. Hope that doesn't cause too much anguish.

No worries! Makes total sense. :)

@jeffgbutler
Copy link

@ericharmeling makes sense about TestContainers. I'll definitely leave it in the repo.

@ericharmeling
Copy link
Contributor Author

@ericharmeling makes sense about TestContainers. I'll definitely leave it in the repo.

Sounds good!

@ericharmeling ericharmeling force-pushed the spring-mybatis-hello-world branch from c076104 to 687012f Compare July 20, 2020 15:08
@ericharmeling
Copy link
Contributor Author

@jeffgbutler After looking into this more, I believe I was wrong about the batch size recommendation extending beyond our JDBC compatibility to other ORMs.

If you don't want to do intermediate commits it can be simplified substantially.

I think that's a good idea. Please see jeffgbutler/mybatis-cockroach-demo#2 for my attempt at simplifying things.

@lnhsingh
These code changes won't affect the docs.

@ericharmeling ericharmeling merged commit 41a0914 into master Aug 3, 2020
@ericharmeling ericharmeling deleted the spring-mybatis-hello-world branch August 24, 2020 16:42
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.

Add Spring + MyBatis tutorial [Docs] MyBatis Tutorial

4 participants