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