Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaRanch SimpleTable  RSS feed

 
Joseph Smithern
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reference JavaRanch Ben Souther's SimpleTable example: SimpleTable\WEB-INF\classes\us\souther\simpletable

It is excellent!! I am now using it for my MVC architecture to work with Oracle.

My question is does it use DAO (Data Access Object) pattern or what is the term for how you are passing database objects in SimpleTable?

Here is the AddressBook class:

Servlet:


JSP:

[ February 23, 2008: Message edited by: Joseph Smithern ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37180
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joseph,
AddressRowBean looks like a DTO (data transfer object). The AddressBook class itself is a DAO because it access the database via JDBC. AddressRowBean is a simple object. It does not access the database - meaning it can't be a DAO. It's whole purpose appears to be storing the data to send to another layer. Which is the definition of a DTO.
 
Joseph Smithern
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne,

I have read many articles and the SimpleTable and your explanation is by far the best explanation in helping me understand DTO and DAO.
[ February 23, 2008: Message edited by: Joseph Smithern ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't know I published that one.
I know I wrote it but I don't think I've ever linked to it.
Where did you find out about it, here?

Anyway, if you're using this in a real project, you should also consider using the command pattern or front controller pattern so you don't need to write separate servlets for every operation your app will perform. These days I use Bear Bibeault's FrontMan controller.

Also for large projects, it's a good idea to make a clean separation between your DAO layer and your business objects. In this case, AddressBook does so little, it serves as both. If it were to grow I would want to break it into a class that does nothing but pull data from the database (DAO) and another object that contains business rules like validation, access control, etc. This way, if you decide to change databases, you don't need to re-work the classes that contain your rules.

The important thing is that the business objects (AddressBook in this case) don't know or care that they're being used by a web app (or a command line app, or a Swing app, etc...) and that your web app has no idea that AddressBook stores and retrieves its data from a relational database.
 
Joseph Smithern
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
I didn't know I published that one.
I know I wrote it but I don't think I've ever linked to it.
Where did you find out about it, here?


You mentioned it in this posting: http://www.coderanch.com/t/292801/JSP/java/MVC-example-or-tutorial
There must be others out there who also found it very helpful.

Can you maybe include it in your Simple Servlet examples (http://simple.souther.us/)?

Thanks again!
[ February 26, 2008: Message edited by: Joseph Smithern ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!