Notifications
Clear all

[Solved] DAO classes vs MDS or SqlService

2 Posts
2 Users
0 Reactions
944 Views
0
Topic starter

When to use Dao classes like DaoFilterCriteria, ShipmentHeaderRow etc
and when to use Model data service?
For example,

DaoFilterCriteria filter = new DaoFilterCriteria();
List<ShipmentHeaderRow> shipmentLegs = getDaoAccessor().getRows(ShipmentHeaderRow.class, filter);

fetches ShipmentHeaderRows,
whereas

ModelDataService mds = Services.get(ModelDataService.class)
List<Shipment> shipments = mds.read(Shipment.class, context, params, modelQueryComponentArray)

fetches Shipments.
What is the difference between using ShipmentHeaderRow and Shipment?
Also what is the difference between using ( MDS or SqlService ) and Dao/DaoFilterCriteria etc classes?

1 Answer
0

Don't use DAO for any new code. It's deprecated.

As far as MDL versus SqlService, here's what you should think about:

Characteristics of SqlService:

  1. Doesn't apply permissions (can be a good or bad thing for you depending on the situation)
  2. Can select just one or two fields
  3. Can do arbitrary joins, basically execute any SQL
  4. Returns loosely typed "SqlRow" objects

Characteristics of ModelDataService:

  1. Applies permissions
  2. Automatically selects all fields
  3. Can do arbitrary joins in where clause, but not in select
  4. Returns strongly typed Model objects

In general, I would think you would want to use ModelDataService in cases where we used DAO in the past. One key difference is, the default behavior of MDS is to return a level plus all its child levels. This is expensive for Shipments with many Lines. Consult the MDS javadocs to see how you can ask it to return the header only.

Swaroop Bhupathiraju Topic starter 2013-11-21 10:11:00

Thanks @Greg Merrill for mentioning about filtering what levels to retrieve.