Skip to main content
  • 1012 Accesses

Abstract

Software applications usually handle sets of data that must be stored in an organized manner so they can be easily accessed, managed, and updated. The fact that data can be persisted means that it is available even when the application is down. So storage is decoupled from the rest of the application. The most common way of organizing data for storage is a database. Any storage setup that allows data to be organized in such a way that it can be queried and updated represents a database. The most widely known and used databases nowadays are relational databases (such as MySQL, PostgreSQL, and Oracle) and non-relational databases, also known as NoSQL. XML files can be used as a database as well, but only for small applications, because using XML files for data storage implies that all data must be loaded into memory to be managed.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 79.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 99.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    MyBatis was previously known as iBatis, before Apache dropped it. More information on the new official site: http://blog.mybatis.org/

  2. 2.

    Take a look at the code of the JdbcTemplate class: https://github.com/spring-projects/spring-framework/blob/master/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java

  3. 3.

    More information on the official Spring Reference page: https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html#jdbc-packages.

  4. 4.

    Other Spring classes to access a different type of resource follow the same pattern: JmsTemplate, RestTemplate, and so forth.

  5. 5.

    Data Definition Language

  6. 6.

    Data Manipulation Language

  7. 7.

    If you want to learn more about the template method behavioral design pattern, here’s a useful link: https://www.oodesign.com/template-method-pattern.html

  8. 8.

    Fortunately, a working module configuration is provided which you can inspect and learn from.

  9. 9.

    Polymorphism is one of the object-oriented programming principles. The term is of Greek etymology and means one name, many forms. Polymorphism manifests itself in software by having multiple methods all with the same name but slightly different functionalities.

  10. 10.

    Also publicly available on GitHub: https://github.com/spring-projects/spring-framework/blob/master/spring-jdbc/src/main/java/org/springframework/jdbc/core/RowCallbackHandler.java

  11. 11.

    Also publicly available on GitHub: https://github.com/spring-projects/spring-framework/blob/master/spring-jdbc/src/main/java/org/springframework/jdbc/core/ResultSetExtractor.java

  12. 12.

    This approach of providing parameters is used by JPA and Hibernate as well.

  13. 13.

    Code accessible on GitHub: https://github.com/spring-projects/spring-framework/blob/master/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java, or in IntelliJ IDEA, click the class name and press the Control (Command in macOS) key, and the sources will be opened for you.

  14. 14.

    Its many signatures and recommended uses can be inspected in the official JavaDoc available online http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jdbc/core/JdbcTemplate.html.

  15. 15.

    This kind of approach leaves an application sensitive to SQL Injection attacks, which is why in enterprise applications, the tables are never created by executing DDL scripts in the code with parameter values provided by the user.

  16. 16.

    Class org.springframework.dao.DataAccessException is an abstract class, parent of all the family of Spring Data Access exceptions.

  17. 17.

    An exception to this rule would be if the server catches fire or gets really wet.

  18. 18.

    You can find more about Atomikos on their official site: https://www.atomikos.com/.

  19. 19.

    Well, if you have two databases with person tables that is.

  20. 20.

    Savepoints are used to roll back transactions to a specified point. In the other words, this lets you roll back part of the transaction; in this case, the part corresponding the nested transaction, instead of the entire transaction.

  21. 21.

    A very good article on nested transactions in case you are curious: http://www.intstrings.com/ramivemula/articles/nested-sql-transactions-explained/

  22. 22.

    Official Javadoc: https://docs.spring.io/spring-framework/docs/current/javadoc-api/index.html?org/springframework/test/context/jdbc/SqlGroup.html

  23. 23.

    The most popular programmers’ social network https://stackoverflow.com

  24. 24.

    You might have noticed that modules of this project depends on each other, code is not duplicated unless there is no choice to do so. This is done for two reasons: reducing code duplication makes the code more easy to navigate and promotes good coding practices and also provides us the opportunity to practice java modules configuration.

  25. 25.

    The previous code is a simplified version written with lambda expressions. If you are curious about the expanded version, just take a look at this repository https://github.com/Apress/pivotal-certified-pro-spring-dev-exam that contains sources for the previous edition of this book.

  26. 26.

    The most popular article about Spring distributed transactions has since 2009 been David Sayer’s https://www.javaworld.com/article/2077963/open-source-tools/distributed-transactions-in-spring--with-and-without-xa.html.

  27. 27.

    A complete list of steps showing how to configure and use the Atomikos JTA provider is available on the Spring official blog: https://spring.io/blog/2011/08/15/configuring-spring-and-jta-without-full-java-ee/.

  28. 28.

    Hibernate OGM provides Java Persistence (JPA) support for NoSQL solutions. It reuses Hibernate ORM’s engine but persists entities into a NoSQL datastore instead of a relational database. Read more about it on the official site: http://hibernate.org/ogm/.

  29. 29.

    Support for Hibernate 3 & 4 has been dropped completely in Spring 5.

  30. 30.

    You can read more about the project on their GitHub page https://github.com/brettwooldridge/HikariCP.

  31. 31.

    Since explaining database relationships and JPA is not a topic of this book, if you want a quick tutorial on how many-to-many relationships are configured correctly with Hibernate, take a look at this small repository I created https://github.com/iuliana/many-to-many

  32. 32.

    The EntityManager instance annotated with @PersistenceContext cannot be accessed from a constructor, since it cannot be created and associated with the persistence context in the constructor. The reason for this is the definition of the @PersistenceContext. This annotation has the following meta-annotation defined: @Target(value=TYPE,METHOD,FIELD). Full JavaDoc API here: http://docs.oracle.com/javaee/7/api/javax/persistence/PersistenceContext.html.

  33. 33.

    The implementation is not really optimal and absolutely unnecessary, but bear with it for the sake of the example.

  34. 34.

    Project official page: https://spring.io/projects/spring-data

  35. 35.

    Spring Boot property list: https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

  36. 36.

    You can read about them here: http://nosql-database.org/.

  37. 37.

    Official site here: https://www.mongodb.com/community.

  38. 38.

    Javadoc API here: https://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/MongoTransactionManager.html

  39. 39.

    Documentation reference: https://docs.mongodb.com/manual/core/transactions/

  40. 40.

    GitHub page for the embedded database library: https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2020 Iuliana Cosmina

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Cosmina, I. (2020). Data Access. In: Pivotal Certified Professional Core Spring 5 Developer Exam. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-5136-2_5

Download citation

Publish with us

Policies and ethics