• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

code suggestions?

 
Marshal
Posts: 16591
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you see, the repository.doSomething() api remains the same:
 
Junilu Lacar
Marshal
Posts: 16591
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recommend getting a good book on Spring. There's a lot to learn about the framework, too much to go over here.

Gotta go. will check back later.
 
Ranch Hand
Posts: 120
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I'm starting to do some refactoring, but I've come across something I'm not sure the best way to handle. I have a Bcid entity. We are using the mysql auto_increment to encode an identifier. The process for persisting a Bcid is to create the bcid with an empty identifier. Take the mysql generated id, do some encoding, and then update the Bcid record. Ideally I would like to rollback the transaction if the identifier fails to update.

In order to rollback, would I need to do everything in the BcidDao.create method?

Here's what I've got so far, but then thought that rolling back the bcid would be nice, so I don't think this will work.

 
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see any committing in your code. I believe you attempt to commit and if there is an error you rollback -- but I've added this thread to the JDBC forum, and someone there can give you a better answer.
 
Rj Ewing
Ranch Hand
Posts: 120
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The BcidDao.create method calls PreparedStatement.executeUpdate(); This is where the commit happens. I just wasn't sure if it was possible to rollback in BcidRepository or if all of my transactions would need to be done in BcidDao, thus the BcidDao.create method would also need to generate the Bcid identifier.
 
Knute Snortum
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems like you have autoCommit set -- is that right? You may have to turn that off. Also, look into transactions. That's a way to make your DB actions atomic. Are you using JDBC or something else like Hibernate? That changes what forum this should be in. This is how I did it in Hibernate:

 
Rj Ewing
Ranch Hand
Posts: 120
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya, I'm using jdbc.

I guess I was more looking for best practice in regards to if the code should go in the repository or the dao. It seems to me that since this encoding has to happen when persisting a Bcid, that it would be better to place it in the repository and not the dao.
 
Knute Snortum
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know what a repository is in this context. A DAO should take care of all CRUD actions (create, read, update, delete). Create and update deal with persistence so why not put it there?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic