• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
Bartenders:
  • Himai Minh
  • Carey Brown
  • Frits Walraven

Do I have this right? (Spring data access & transactions)

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm preparing a write up on Spring for my team and managers. I'm not asking for editing. I'm just trying to see if my own knowledge is adequate or if I need to go back to the books.


==============



Spring handles connections and exception handling for the developer. This removes a great deal of code out of the method so reading the code and troubleshooting is much easier. Spring can also perform domain object queries that maps the ResultSet to the object. When making a query, Spring locks the row during the transaction to help with data consistency. By default any runtime exception or thrown error will trigger a rollback.

Spring also examines the metadata of the connection and uses a DataAccessException and its various subs to produce more meaningful errors than provided by a SQLException (Hibernate uses these as well).

Spring uses a wrapper around the data source to act as a proxy. For smaller applications, the developer then uses the TransactionTemplate and/or PlatformTransactionManager to directly and programmatically manage the transactions. With larger applications, developers will use Spring�s declarative transaction management by using an @Transactional annotation to identify to Spring what class elements are transactional and what transaction attributes they have (e.g. read-only, timeouts). When the transaction is created, Spring checks for existing transaction before deciding to create a new one. Since creating connections is expensive and Spring does all the connection management, the improves the application performance.

Spring also employs Object/Relational Mapping (ORM) to allow queries to be performed on the java object and eliminating the need to know the database schema once it has been mapped. Spring�s ORM also provides caching that can be performed after each unit of work and at the SessionFactory to improve performance.
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Alan,

I've worked with Spring on a few projects and I really liked it, because Spring made me write less code and better code than before. I'll give 3 examples why.

If you want execute SQL:
-Spring can get connections them(and close them als well).
-Spring has classes to execute SQL very easily, als for reading resultsets.
-even in small projects it's already handy to define transactions instead of having to code them. You won't need EJB's for that.
-Spring wraps SQLExceptions in a RuntimeExceptions: no more try/catch/finally code.
-if you want to use an ORM-tool, you can useSpring as a wrapper for that.

The dependency-injection part of Spring makes testing more easy. Classes depend on each other by interface (not by concrete class).
Example: if you service-layer depends on the dao-layer, you can write a stub for the dao-layer, and give it to your service layer.

If you're tired of copy/paste the same logging lines over and over: the Aspect Oriented part of Spring makes it for easy to write those lines once, and configure where and when you want to use them.


Herman
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic