Thread: Entity Objects

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    7
    Rep Power
    0

    Entity Objects


    Ok, I'm writing a Content Management System for an upcoming website, and I am currently working on writing classes for doing database access, more specifically, loading and saving user information.

    What i have now is a class User, which contains a users username, password, and userid.

    3 different constructors allow it to be instantiated using a username, userid, or a blank object for creating a new user. Also passed into the constructor is a Connection object, which is the database connection being used for the Entity Object. This allows the objects save and load methods to access the database without actually setting up the connection within the class.

    My biggest question is, is that a good way of doing this? I think it will make the code in my jsp pages and servlets much easier to read, as well as cut down on redundant code, because all the mundane and messy operations which are used alot are kept hidden for the most part.
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    That doesn't sound too bad.

    Have you looked into connection pooling at all? It's way more efficient, and kind of takes care of what you're trying to accomplish. Some app servers can set up connection pools for you (more efficient that way), or you can create them yourself. Basically, this gives you a single class that manages all your connections, then you just grab a connection when you need it, and return it to the pool when you're done. It removes the overhead of making a fresh connection each time, plus it allows for multiple connections (you decide how many), to be made simultaneously. Your app will be faster for multiple users that way.
    -james
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    7
    Rep Power
    0
    Oooh, That sounds cool, dyou have a link to a tutorial for setting that up?
  6. #4
  7. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Well, if you're going to write your own, you can try this: http://builder.com.com/article.jhtml...11212kev02.htm

    If you're using tomcat 4.1 here's some help on using the built-in functionality. You should be able to set everything up through the admin utility, though.
    http://jakarta.apache.org/tomcat/tom...les-howto.html
    -james

IMN logo majestic logo threadwatch logo seochat tools logo