Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Database link tables to model

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Database link tables to model

    Suppose you have an application that stores images in categories. Images can be uploaded, deleted, viewed, ... by users that were given right to view, upload, delete, ... Categories can be nested, and the rights can be set on every level.

    Database:

    Table category: id, name
    Table user: id, name
    Table user_category: id, user_id, category_id, view, delete, upload


    Should I create a UserCategory object that has a User and a Category object + the view, delete & upload rights?
    Fetching the categories for a user will thus result in a List<UserCategory>.
    Category.countImages() -> results in a full count of all images in the category
    UserCategory.countImages() -> counts images in the categories where the user has right to
    Is this a good approach?


  2. #2
    Member
    Join Date
    Apr 2012
    Location
    Superior, CO, USA
    Posts
    80
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default Re: Database link tables to model

    That sounds reasonable. From a database perspective you've got a many to many relationship between a Category and a User with permissions tied to this relationship.

    Realize that there are some potential performance issues with this approach. Say I'm 50 levels deep trying to determine if a User has permission to do something. Presumably you want to deny permission if some parent up the chain doesn't allow the operation that the User is trying. You now need to walk up the tree examining each parent node to determine if you should grant the permission. Now have it 50,000 levels deep. That may not be your use case so this may not be a big issue.
    Need Java help? Check out the HotJoe Java Help forums!

Similar Threads

  1. Unstructured Data Model
    By richip in forum Object Oriented Programming
    Replies: 1
    Last Post: March 17th, 2011, 10:25 AM
  2. How to update 2 tables in database using JDBC
    By nrao in forum JDBC & Databases
    Replies: 0
    Last Post: November 11th, 2010, 07:05 PM
  3. Java Swing Tables ( JTable Models ) to connect to Database
    By javaprogrammer in forum JDBC & Databases
    Replies: 0
    Last Post: January 26th, 2010, 04:13 PM
  4. Replies: 0
    Last Post: January 26th, 2010, 04:10 PM
  5. the problems of psx model ripping
    By wolfgar in forum Java Theory & Questions
    Replies: 4
    Last Post: November 4th, 2009, 07:31 PM