Ricardo Ricardo - 1 year ago 78
Java Question

VO and DAO, How to design classes and execute query

I have a 3 tables:

Item: item_id (pk), short_description, ...
SupplierItem: item_id (fk), supplier_id (fk), vendor_product_number, ...
Supplier: item_supplier (pk), name, ...

Relation between Item and Supplier is many to many. SupplierItem is
intermediate table.

I want use VO and DAO.

How to design this in VO (Java)?

After, How can I do the following query in java code.

select i.item_id, i.short_description, s.vendor_product_number as FONUA_PRODUCT_CODE
from item i
left join supplier_item s
on i.item_id=s.item_id
where ((i.item_id=:item_id) OR :item_id IS NULL)
and i.parent_item_id is null
order by vendor_product_number DESC"

I still do not understand the concept in use VO and DAO.


Answer Source

DAO would be the java file where you define your query and get the results of the query call on the database. The results from the query will be saved by setting them as values to the properties of a particular VO.

For Example:

Your query returns ,

  • item_id, short_description, vendor_product_number

So let us say that you will have to create another java file say ItemVO.java and declare the particular properties of the ItemVO object, For Ex:

private String itemId;
private String shortDescription;
private String vendorShortNum;
/*Define your getters and setters*/

In the DAO file you will have to map the query results to the VO file's objects.

ItemVO itemVO= new ItemVO();
itemVO.setItemId(/*the particular column value from the query result*/);
itemVO.setShortDescription(/*the particular column value from the query result*/);
itemVO.setVendorShortNum(/*the particular column value from the query result*/);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download