Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / March 2005

Tip: Looking for answers? Try searching our database.

Newbie: Data Objects and Associated DAOs

Thread view: 
DartmanX - 29 Mar 2005 17:58 GMT
I'm a relative newbie at this, but I'm looking for an easier way. I'm
using the 1.4.2 SDK (can't upgrade to 1.5).

When I create an object, I always create the object and an associated
DAO to go with it. Here's a quick example:

public class User {
  private int userid;
  private String username;
  private String password;

  public int getUserid() {
     return this.userid;
  }

  // remainder of setter and getter functions
}

public class UserDAO extends GenericDatabaseAccess {

   public void addItem(User u) {
       // Adds a new user to the backend database
   }

   public void delItem(int key) {
       // Delete from the database based on the key
   {

   public void editItem(User u) {
       // Edits an existing record by replacing the existing record
with
       // information in the object passed
    }

   public User getItem(int key) {
       // Return a User object based on the key
    }

    public java.util.LinkedList getAllItems() {
        // Return all of the items from the database as a Linked List
of
        // User objects
    }

}

Since what I've been writing usually has several object types, I'm
interested in finding a quicker way to do the grunt work of creating
the DAOs. And since I'm a newb, I don't know much except basic JDBC and
a free pooled database connection package I've been using.

Any advice, hints, tricks, etc are appreciated.

Jason
CodeFutures - 30 Mar 2005 09:48 GMT
> Since what I've been writing usually has several object types, I'm
> interested in finding a quicker way to do the grunt work of creating
[quoted text clipped - 4 lines]
>
> Jason

Hello Jason,

The best shortcut is to generate the Java code for DAOs rather than
write them by hand.

FireStorm/DAO is a Java Code Generator that can import existing
database schemas (from a SQL script or from a live JDBC connection) and
can then generate a complete DAO persistence tier.

Check out:

http://www.codefutures.com/products/firestorm/

Regards
PJ Murray
CodeFutures Software - Java Code Generation for Data Persistence
http://www.codefutures.com
frebe - 30 Mar 2005 17:53 GMT
> Since what I've been writing usually has several object types, I'm
> interested in finding a quicker way to do the grunt work of creating
> the DAOs. And since I'm a newb, I don't know much except basic JDBC and
> a free pooled database connection package I've been using.

Look at http://butler.sourceforge.net. It has a generator that will
generate java classes based on the tables in your schema.

/Fredrik


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.