mercredi 15 juillet 2020

DAO pattern for transferring data and updating single attributes? Design question

This is a question about design practice more than about how to actually get a result I want.

I have a local database that holds product data. I want to transfer data between this and a third-party service that needs a copy of this product data. Most of the product creation and updates happen in the local database, so I mostly need to just overwrite the data that is in the third party service. I do updates this way, so the DAO objects hold all of the logic for how to actually get/update products on either side. Data retrieval and updates are handled from the service using API calls. So an update is basically:

List<Product> products = dbDAO.getProducts();
serviceDAO.update(products);

There are cases where I only want to transfer part of the data. For example the third party service creates an id when I send it a new product. I want to save this id in the database. There are other cases where I want to only update a couple attributes and not the whole product entity.

Questions:

  1. Is using a DAO pattern a standard way of handling data transfer like this, or are there more common or better designs?
  2. Should I just make an updateId method in dbDAO to update only the id (instead of all the product attributes)? Is there a better pattern for this? I'm working in Java 7 with only a handful of libraries (no Spring or Hibernate).

Aucun commentaire:

Enregistrer un commentaire