Hi Jitendara
I highly appreciate your time for helping.
Quote:
What is the primary key on deviceTypeRole class. Is it being modified anywhere ?
The primary key on deviceTypeRole class is ID. It also has device_type_Id and Role_Id. Here is the structure
Code:
SQL> desc device_type_role
Name Null? Type
----------------------------------------- -------- -----------
ID NOT NULL NUMBER(10)
DEV_TYPE_ID NOT NULL NUMBER(10)
ROLE_ID NOT NULL NUMBER(10)
CHANGE_USER NOT NULL NUMBER(10)
CHANGE_DATE NOT NULL DATE
The primary key on deviceTypeRole class (i.e. ID) isn't modified anywhere as explained below
Step 1
We have dropdown to perform CRUD. The dropdrown has DeviceTypeID values. Whenever user picks a value from dropdown (i.e. onChange event) I am loading DeviceType object (i.e. Parent class), which has set of associated objects i.e. DeviceTypeRoles
Code:
deviceType=deviceTypeManager.getDeviceType(selectedDeviceType);
this.deviceTypeRoles = new ArrayList (deviceType.getDeviceTypeRoles());
Step 2
From deviceTypeRoles object , i extract the roleId and roleName and add it ArrayList so as to render it on the User Interface.
private List deviceRoles = = new ArrayList();
this.deviceRoles.add(new SelectItem(roleId.toString(),role.getName()));
Please note the ArrayList deviceRoles has value binding with user inetrface and will have latest set of roles added/removed by the user on user interface
As the ArrayList deviceRoles has latest set of roles, i pass that as argument to my update method in the JSF Backing Bean
Step 3
deviceTypeManager.updateDeviceType(deviceType, getDeviceTypeRolesSet());
public Set getDeviceTypeRolesSet()
{
Set deviceTypeRoleSet = new HashSet();
deviceTypeRole = new DeviceTypeRole(); //creating new instance of pojo i.e. association class
for (Iterator iter = deviceRoles.iterator(); iter.hasNext();) {
SelectItem selectItem = (SelectItem) iter.next();
String roleId = (String)selectItem.getValue();
deviceTypeRole = deviceTypeManager.getDeviceTypeRoleByRoleId(Long.valueOf(roleId));// For each role on the user interface load the DeviceTypeRole object
deviceTypeRole.setDeviceType(deviceType);
deviceTypeRoleSet.add(deviceTypeRole);
}
return deviceTypeRoleSet;
}
Quote:
What about the set, is it being reset after being loaded?
As shown in Step3 the set is being reset with the latest set of roles added/removed from the user interface
Step 4
In the business layer i.e. Spring , here is the snippet for update
Code:
public void updateDeviceType(DeviceType deviceType, Set<DeviceTypeRole> deviceTypeRoles) {
System.out.println("In updateDeviceType Manager method");
deviceType.addAll(deviceTypeRoles);
this.deviceTypeDao.update(deviceType);
}
Step 5
In the DeviceType POJO , here is the snippet for addAll called from update method of business layer
Code:
public void addAll (Set aDeviceTypeRoles) {
this.getDeviceTypeRoles().clear();
for (Object o: aDeviceTypeRoles) {
DeviceTypeRole dtRole = (DeviceTypeRole) o;
System.out.println("Name="+dtRole.getNamsRole().getName());
add(dtRole);
}
public void add (DeviceTypeRole dtr) {
this.deviceTypeRoles.add(dtr);
dtr.setDeviceType(this);
}
Thanks again for helping