Creating objects that contain objects

What's the best practice for creating an object from a table that contains a list of objects from another table? For example, say I have an employees table:
EMPLOYEES
id    name
1     Derek Epperson
2     Judy Johnsonand I also have an equipment table that contains all the equipment belonging to each employee
EQUIPMENT
id    emp_id   name
101   1        Laptop Computer
102   1        Flash Drive
103   2        Desktop Computer
104   2        Wireless RouterI want to create a Java function that will return create a List of two Employees, each with a List<Equipment> of that employee's equipment. One option is to create the Employees and then query for Equipment separately, like this:
List<Employee> employees = myDAO.getEmployees();
for (Employee employee : employees) {
  employee.setEquipment(myDAO.getEquipment(employee.getId()));
}However, that is a lot of database calls. Is there an easy way to do this in a single query?

By JOIN, you mean connect them so that a query will return something like this?
EMPLOYEES
id    name             equip_id   equip_name
1     Derek Epperson   101        Laptop Computer
1     Derek Epperson   102        Flash Drive
2     Judy Johnson     103        Desktop Computer
2     Judy Johnson     104        Wireless RouterThen I would have to check on each row whether the id had changed, a la:
rs = ps.executeQuery(getEmployeesAndEquipmentJoin);
int previousId = -1;
Employee employee
while (rs.next()) {
  if (rs.getInt("id") != previousId) {
    previousId = rs.getInt("id");
    employee = new Employee(rs);
    employees.add(employee);
  employee.getEquipment.add(new Equipment(rs));
}That seems a little awkward, but if that's the best way to do it without ORM then I can work with that.

Similar Messages

  • Create page that contains buttons

    I need to create page that contains many buttons each one is used for opening a specific page.
    Can anybody help me to give the steps?

    Hi,
    I think you need help for HTML DB.
    - Go and create page (could be HTML)
    - Then add region (form region)
    - Create buttons. Every button has ability to redirect to Page in this Application or URL. Just choose any page in the application.
    - On each step you can hit help to learn details.
    - There is a function “Create Multiple Buttons”
    Konstantin
    [email protected]

  • How can I use iWeb to create website that contains a lot of downloadable audio files?

    Hi
    How to use iWeb to create a website that contains a downloadable audio files.  I'm uloading about 15 GB of audio files.  I need to creat folders "albums" and then put the files in these folders.   Any advise?
    Thank you very much for your time to this
    W B

    The important thing is not to put the audio files directly into iWeb: if you do that then every time iWeb decides it needs to upload the entire site you will find yourself uploading all 15GB of audio files, which won't make you happy. Start by uploading the files to the server - in folders as suits you - and then link to them in iWeb.
    If you want them to download rather than play, you may be able to set up an .'htaccess' file in the folder which will force a download - it depends on whether your hosting service will allow this. The method is described here:
    http://www.wilmut.webspace.virginmedia.com/notes/missing/download.html
    Here is an example of a simple link which produces a download (without the process described the audio file would play in the browser in a blank page):
    http://rfwilmut.net/stars/dawson2.mp3
    Then all you need to do is to provide a link, designed however suits you, in your iWeb page. If your server won't allow the .htaccess file then you will have to ask visitors to control-click (Mac) or right-click (Windows) on the link and choose 'Download linked file' or equivalent - not so convenient; or otherwise zip the files first, which won't much reduce their size but will force a download (and of course the recipients will have to unzip them).
    If you want the files to play in a player in the page, you can use an html snippet to provide a player as described in this page (you will also need to upload a script to the webspace - this is provided in the page):
    http://www.wilmut.webspace.virginmedia.com/notes/qtembed.html

  • I can no longer create groups that contain subgroups??

    Folks,
    I used to be able to create a group, drag existing subgroups and individuals into that group, and send emails to all by simply typing the group name into Mail.
    I can no longer do this.
    Now, to be precise. I can create what looks like a group and by dragging existing subgroups into it -- but it no longer functions as a group. When I type the name or drag it (from Contacts) into the "To:" line of Mail, the only thing that shows up are the top-level individuals (i.e., those who I put dragged in as individuals, not those who are only in one of the subgroups that I dragged in).
    If I create a group that only has subgroups (i.e., no individuals at the top level, only individuals who are members of one or more of the included subgroups) then after I type the group name in the "To:" line of mail, the group name dissappears, and nothing appears in Mail's "To:" line.
    The actual behavior is a little more subtle than this but the bottom line is that I can no longer create groups with subgroups.
    Help!!

    Hi,
    If you list the steps you have taken to fix this it will help.
    Have you tried using the File > New Event menu item?
    Have you logged the user account out/ restarted the computer?
    Have you tried un-syncing any accounts synced to Calendar?
    Is there some change made to the computer that may have triggered this?
    Best wishes
    John M

  • How to create XSD that contains elements of array as well ?

    Hello,
    I want to create a such XSD in Jdeveloper Like
    Employee-
    -firstName string
    -lastName string
    -student array
    Student is another XSD.
    Kindly provide me the source code or good link about that.
    Thanks

    Here you go...
    <?xml version="1.0" encoding="windows-1252" ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.example.org"
    targetNamespace="http://www.example.org"
    elementFormDefault="qualified">
    <xsd:element name="Employee" type="EmployeeType">
    <xsd:annotation>
    <xsd:documentation>
    A sample element
    </xsd:documentation>
    </xsd:annotation>
    </xsd:element>
    <xsd:complexType name="EmployeeType">
    <xsd:sequence>
    <xsd:element name="firstName" type="xsd:string"/>
    <xsd:element name="lastName" type="xsd:string"/>
    <xsd:element name="student" type="xsd:string" maxOccurs="unbounded"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:schema>
    Here an Employee element will have one firstName element, one lastName element and student element. And you can see student can be 1 to many (outbounded) elements.
    Hope this helps...
    Thanks,
    N

  • Is there any object in labview that contains a list of data for the user to select (selection one at a time) or add a new data?

    Is there any object in labview that contains a list of data for the user to select (selection one at a time) or add a new data?

    List and table controls -> listbox..is that what you are thinking of?
    The listbox presents the user with a list of options, and you can set it to only accept one selection at a time...Adding new data to the list can not be done directly by the user but if you make e.g. a text control and a button you can programatically insert new objects described in the text box when the button is pressed...(see example).
    If you need more than one column you have the multicolumn listbox. If you want the users to write new entries directly yu can use a table and read selected cells using it's selection start property to read what cell has been selected.
    MTO
    Attachments:
    Listbox_example.vi ‏34 KB

  • Parsing a String object that contains the database details in jsp

    Hi All,
    In my project i have a model which is a bean that contains
    a method :-
    UserBean.java
    ....getUserData()
    //the database connection is written here.
    st.executeUpdate("insert ----------");
    In the servlet i am calling the bean,
    ControllerServlet.java
    UserBean ub=new UserBean();
    Object obj=ub.getUserData();
    session.putValue("something",obj); //Here the obj contains all the database datas that is used in insert query
    //By using RequestDispacher i am forwarding this request & the response
    to the jsp page
    ViewJsp.jsp
    String data=(String)session.getValue("something");
    //Here "data" now contains all the database contents that is stored using insert query in the bean
    From here i need to parse the "data" in order to display the contents
    stored in the string "data" in to a html table.
    Plz. do provide a solution for this.It is very Urgent at the moment.
    So that i will be very thankful to u.
    Thanx,
    contactananth

    ok, first of all, in getData, i assume you do a SELECT, not an INSERT,
    so your bean code should look like:
    ResultSet rs = st.executeQuery(...) // or somethig like that
    return rs; // it will contain the data you needand in the jsp you write:
    ResultSet rs = (ResultSet)session.getValue("something");
    instead of
    String data=(String)session.getValue("something");
    i assume you know how to work with a ResultSet

  • I know the name of an object - how do I get the name of the object that contains it?

    If I have a Movieclip, I can trace the name of the Movieclip
    that contains it using the _parent property.
    With a generic object, is there a way to trace the name of
    the object that contains it?
    Please, please tell me - this will be a huge help.
    Thanks

    Thanks for these comments - my problem isn't with MovieClips.
    I need to know if there is something which is the generic Objects
    equivalent to the MovieClips _parent property.
    Here's some code that hopefully will help explain further:
    class MyClass extends Object {
    var myObject:Object;
    function MyClass (){
    myFirstObject = new Object();
    myFirstObject.theParent = this;
    private function getNameOfParent(p_object:Object){
    // Some code to return the name of the object that contains
    p_object
    trace(p_object.__proto__); // Output: [object Object]
    trace(p_object._parent); // Output: undefined
    trace(p_object.theParent); // Output: [object Object]
    return ???
    public function doSomething(p_num:Number){
    var parentName = getNameOfParent(myObject);
    // do some more action...
    Timeline code:
    var myClass1 = new MyClass();
    myClass1.doSomething();

  • Scaling an object that contains a gradient

    I'm working in Illustrator CS3. Got a question: I'm looking to scale an object that contains a gradient, but I want the position of the gradient to remain in the same position on the page. That is, I don't want the gradient to scale along with the object. Is it possible to do this without manually rebuilding the gradient?

    Normal scaling of an object (using the Scale tool, Transform or dragging the bounding box) will always scale the gradient too, but there is a sort of workaround if you know where the gradient starts and ends in the original.
    If you haven't already marked the beginning and end of your gradient, do so by pasting a copy of it in front (Cmd-F) and expanding the gradient - then you can see its start and end points when you turn off the preview. Mark what you need with guides and delete the expanded gradient. It's useful to make a guide that follows the angle of the gradient.
    Now draw a gradient-filled rectangle behind your object and get the gradient to match the angle and position of the gradient in your object by dragging with the gradient tool according to the guides.
    Having done this, copy and scale your object and change it into a clipping mask that masks the rectangle you just drew. Alternatively you can make a masking layer of your object if you know how to do that.
    Lock the rectangle (if you are using a normal clipping mask) and then you can move the object (which is now a mask) at will and the gradient will stay put.
    This is all a bit long-winded but please get back to me if you're lost :-)

  • I have  a singleton that contains my data object. How to refresh components

    I have a singleton that contains my data object. This
    singleton data is used to populate comboboxes and datagrids across
    various custom components that are children of the main
    application. These components can manipulate the singleton. When
    these changes are made to the singleton what do I have to do to get
    this data to refresh across the componets that use its data?

    I assume that your mail app on your iPad/iPhone is Apple Mail.  You can open a MS Word/Excel document in Adobe Reader for iOS and convert it to PDF at a time.
    In Mail, long press (press & hold) an attachment icon.
    Select "Open in Adobe Reader".
    Follow the instructions shown in Adobe Reader to subscribe to a paid service called "Adobe PDF Pack" to convert the document to PDF.
    Please note that Adobe Reader for iOS itself is a free app but the subscription for the Word/Excel to PDF conversion is a paid service (i.e. not free).
    In case you have any questions about Adobe PDF Pack, here's the user forum.
    Adobe PDF Pack

  • Class that creates objects?

    Hello everyone! Im quite new to java and oop, but im enjoying using it quite a lot. I have read some books but everything is so fresh it is easy to get confused. I think this is a very basic questions but, here it goes:
    I have this simple class:
    public class Soda {
    int id;
    int sid;
    String brand;
    String flavor;
    }And now i want to fetch an URL that will return a text string for example "|1|23|Fanta|Orange". Now i want to create a Soda Object from this string (The String could have several Sodas)".... forget the parsing needed and the fectching for the text and everything else (Im using J2ME, and i have it solved)... but more basically:
    how can i make a *method that creates Soda objects*? Funny how i get confused with the simplest things.
    Thank you everyone for your comments and help!
    Alejandro

    AlexR wrote:
    while(something) {
    Soda soda=new Soda();}and each iteration of the while loop will create a different object? or overwrite over and over the created soda object?Each iteraion will create a new Soda object, and overwrite the soda variable with a reference to that object. If you want to have access to all the Soda objects after the loop exits, you need to add references to them to a collection or array.
    [http://java.sun.com/docs/books/tutorial/collections/]
    [http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html]
    Also, you can create constructors that take arguments.
    String brand = (parse brand from string);
    String flavor = (parse flavor from string);
    Soda soda = new Soda(brand, flavor);
    public class Soda {
      private final String brand;
      private final String flavor;
      public Soda(String brand, String flavor) {
        this.brand = brand;
        this.flavor = flavor;
    }

  • How to get a list of schemas that contain objects

    Hello,
    Kindly check on how to get a list of schema that contain objects.
    Regards,
    Tarman.

    Here is the oracle version info and it run under HP-UX.
    Oracle9i Enterprise Edition Release 9.2.0.5.0 - 64bit Production
    With the Partitioning and Real Application Clusters options
    JServer Release 9.2.0.5.0 - Production
    I have problem when run the query,
    SQL> select owner, count(object_name) from dba_objects where owner is not in ('S
    YS','SYSTEM','SYSMAN');
    select owner, count(object_name) from dba_objects where owner is not in ('SYS','
    SYSTEM','SYSMAN')
    ERROR at line 1:
    ORA-00908: missing NULL keyword
    Thanks.

  • ABAP OO, Creating object dynamically

    Hi everybody,
         I’m currently working on some Abap OO examples. Everything is working ok except for the following: Creating objects dynamically.
    This is what I’d like to do:
    Lets say we obtain a bunch of sales orders using a simple select statement and place them in an internal table. For each entry in our internal table, I’d like to generate a new sales order object. This salesorder object is a simple class with a constructor with an Id and some other attributes.
    When this is done, I’d like to append every object to a new object, say basket, so that this basket contains something like an internal table within each record a reference to the salesorder. Is this easy to do? I’m using the example that is described in the sap guide (create object pointer type (class_name) but it looks to me that you still have to declare the reference variables before you can create the object.
    Hmm, I think Java is better suited for a job like this.
    Hope you can help,
    Cheers and Best wishes
    Laurens Steffers
    The Netherlands.

    Hi,
    Its not all that difficult in ABAP as well. The following code is based on Chapter 5, Listing 5.20 from book ABAP Objects.
    What you need is an internal table of type <your sales object> e.g.
    DATA: BEGIN OF obj_sales_order
            sales_order_no LIKE <sales_order_no_type>,
            <...>,
            objref TYPE REF TO <SALES_ORDER_CLASS>
          END OF obj_sales_order,
          reftab LIKE SORTED TABLES OF obj_sales_order
                      WITH UNIQUE KEY sales_order_no
                                      <other key attributes>.
    Now all you need to do is to do a SELECT...ENDSELECT loop, and:
    SELECT ...
    obj_sales_order-sales_order_no = <selection result>
    obj_sales_order-<other key attr> = <selection result>
    READ TABLE reftab INTO obj_sales_order
                      FROM obj_sales_order.
    IF sy-subrc <> 0.
      CREATE OBJECT obj_sales_order-objref
             EXPORTING ...
             EXCEPTIONS ...
      IF sy-subrc <> 0.
        MESSAGE ...
        CONTINUE.
      ELSE.
        INSERT obj_sales_order INTO TABLE reftab.
      ENDIF.
    ENDIF.
    CALL METHOD obj_sales_order-objref-><method>.
    ENDSELECT.
    Hope this help.
    Regards

  • Create  object for a class in jar file

    Hi
    I am using Oracle JDeveloper 10g. I have created a main application using Swing/JClient technologies. I am facing a problem for the past one week. I let u all people know my problem and I kindly request you to send a solution if known possibly confirmed.
    Problem: I have created a main application using swing that class extends JFrame. This main application consists of two parts. One left side panel and one right side panel. Left side panel contains JTree component. Each item in that tree refers to a class file located in a separate jar file.i.e that acts as a separate application. If we are executing separately that jar file class, I am able to see that small application running. If I am selecting an item in JTree during runtime, I should place that small application from the respective jar file in the right side panel of the main application. I can locate the jar file and even I can create object to that particular class file. But I cannot execute the application even separately and also not able to place in the right side panel of the main application.
    Note: The small application from the jar file contains one class file containing main method. That class file extends JPanel and implements JUPanel. i.e., with data binding. I am trying to create an object for this class file with data binding from my main application. Navigation bar is used in the main class file.
    If possible can any provide me solution at the earliest. Waiting eagerly for the positive reply.
    Regards,
    s.senthilkumar

    Can you sure that there is only a A class in the classpath of Tomcat, I advise you to add
    some statements into the A class so that you can be sure which classloader is used
    to load the A class.

  • How can the servlet engine create objects of interfaces?help

    hello,
    I have this basic fundamental query...when using servlets i noticed that so many methods in the HttpServlet class take as arguments objects of the type "Interface"..where as basic principle in java is u cant instantiate interfaces...interfaces r mere templates which u implement by ur own custom classes.
    For example the doGet method recieves from the servlet engine(servlet container) two arguments which r HttpServletResponse object and HttpServletRequest object..and u use these further to make use of the methods of the inmterfaces..which again is a mystery to me...why?
    here is why:-
    since HttpServletResponse and HttpServletRequest r interfaces..they cant be instantiated...and now that the sevlet engine provides objects of these interfaces...how come u r able to to use the methods of these interfaces...for r they not empty methods?..
    example how r u able to make the sendRedirect() method of HttpServletResponse interface work...is this method not an empty method?
    there r several interfaces...whose objects r being used and passed in this similar fashion....(for example there r many methods that return an enumeration...which is used as if it were an ordinary class that can be instantiated..and whose methods r non empty emthods)
    please help me resolve this mystery
    sheeba

    Don't call me "u". The word is "you". Likewise "are" and not "r".
    The servlet engine creates objects of concrete classes that implement those interfaces. If you want to find the names of those classes in your particular server, you could use for examplereq.getClass().getName()

Maybe you are looking for