Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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

Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
    Bookmark Topic Watch Topic
  • New Topic