Swipe to navigate through the chapters of this book
It’s time we started looking at how we actually access data. Spring has multiple ways of accessing data; here, we’re going to look at JdbcTemplate, a facade that provides trivial access to common operations, and we’re going to address some of Chapter 7’s other issues with data access.
Please log in to get access to this content
HikariCP is one of many decent JDBC connection pools available for Java and can be found at https://github.com/brettwooldridge/HikariCP .
The statement that Lombok generates “standard methods” is a little wrong – in general, Lombok will generate better methods than most programmers will. We’ll take a look at what Lombok generates for a simple Artist.java in a page or so. It’s a little verbose, but by golly, it’s generally “more correct” than what your authors would have written on their own for such a simple class.
I wonder if anyone’s ever scanned a crowd, looking for people with sore thumbs, to see if they actually are easy to detect. When my thumb is sore, I don’t wave it about making sure people know it.
Just in case you’re interested, “a,” “an,” and “the” are in fact all of the articles in English. “A” and “an” are called “indefinite articles,” because they refer to one of a set of objects without specifying which one of the set is being referred to, while “the” is called a “definite article” because it’s specifying a particular object.
Worth mentioning: James Moore was a giant help in creating this section.
Cyclomatic complexity is, well, way out of scope for this book, but now that we’ve mentioned it, it’s a way of calculating the number of independent paths through a method, by looking at the control flow. Basically, every nested difference in control flow adds to the complexity of a method. The streamed version of findArtistByName(String, boolean) looks complex because it’s got some nested method calls and it’s a less familiar set of operations for many programmers, but it’s actually simpler because there are fewer branches in the code; thus it gets a lower real complexity score. With that said, the goal of programming is to get something done, as opposed to a mandate to use streams or whatever – so you should feel free to do what makes sense to you and what you are able to make work.
This chapter will finish what we started in Chapter 7. Our prior chapter added a web interface for parts of a music service, but didn’t include all of our requirements because it wasn’t the right place to bring up transactions. After this section, you could write a rich client to interact with the services and have a functioning application.
- Spring Data Access with JdbcTemplate
Joseph B. Ottinger
- Sequence number
- Chapter number
- Chapter 8