• Post Reply Bookmark Topic Watch Topic
  • New Topic

Design :: How to expose API for adding new object to a list  RSS feed

 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I have a swt client and a stateless facade that expose the server API to the client.

Suppose that I have two objects - Company the contain list of workers

I want to write a generic API to the client that create,add,update,delete objects.

Some objects, like worker need to be created in a parent context.
I mean that in order to create new worker we need to have the company that the worker belongs.
So, I thought about the following API:

Object public createObj(parentId,parentType,obj);

The function will add the worker to the list of workers in company and will return the new Worker object (with the ID).

There are some issues here:
1. In order to save the new worker I need to get the workers list in company than add the new worker and save the company.
The problem is that in case that there are thousands of workers we will need to load all the workers for only save one worker.
2. JPA required to save the company object in order to save the worker (there are OneToMany), so the persist return Company object but i want to return to the client the new Worker that has been created.
I don't want to run on all the thousands of workers in order to search this worker.

How you overcome the problem that I mention above?

Thank you
 
Rajesh Agarwal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Based on the company ID you should build the company object. The company object should have a method to addEmployee() which would take an instance of a Worker object. This would ass this Worker to the existing list of employees of the company and may or maynot return a Collection of Employees in the company.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!