throws Exception {
// TODO Auto-generated method stub
RoleMapping rm = RoleMapping.create();
IDAO roleUser = null;
if ( getRoleId() != null ) {
if ( getGroupId() != null ){
roleUser = GenericDAO.createDAOImpl(
DefaultConnectionFactory.create(),
"select R.EMPCODE from EMPTABLE E, PARTTABLE P, ROLEUSERTABLE R where E.ISDELETED='0' and P.PARTCODE = ?groupCode and E.PARTCODE=P.PARTCODE and R.ROLECODE = ?roleCode and R.EMPCODE = E.EMPCODE ",
IDAO.class
);
roleUser.set("roleCode", getRoleId());
roleUser.set("groupCode", getGroupId());
roleUser.select();
} else if ( getReferenceRole() != null && getReferenceRole().getMapping(instance) != null ) {
roleUser = GenericDAO.createDAOImpl(
DefaultConnectionFactory.create(),
"select R.EMPCODE from EMPTABLE E, (select PARTCODE, EMPCODE from EMPTABLE where EMPCODE= ?empCode) T, ROLEUSERTABLE R where E.ISDELETED='0' and E.PARTCODE = T.PARTCODE and R.ROLECODE = ?roleCode and R.EMPCODE = E.EMPCODE ",
IDAO.class
);
roleUser.set("empCode", getReferenceRole().getMapping(instance).getEndpoint());
roleUser.set("roleCode", getRoleId());
roleUser.select();
} else {
roleUser = GenericDAO.createDAOImpl(
DefaultConnectionFactory.create(),
"select empCode from roleUserTable where roleCode = ?roleCode",
IDAO.class
);
roleUser.set("roleCode", getRoleId());
roleUser.select();
}
} else {
if ( getGroupId() != null ){
roleUser = GenericDAO.createDAOImpl(
DefaultConnectionFactory.create(),
"select EMPCODE from EMPTABLE where ISDELETED='0' and PARTCODE = ?PARTCODE ",
IDAO.class
);
roleUser.set("PARTCODE", getGroupId());
roleUser.select();
} else if ( getReferenceRole() != null && getReferenceRole().getMapping(instance) != null ) {
roleUser = GenericDAO.createDAOImpl(
DefaultConnectionFactory.create(),
"select E.EMPCODE from EMPTABLE E, (select PARTCODE, EMPCODE from EMPTABLE where EMPCODE= ?empCode) T where E.ISDELETED='0' and E.PARTCODE = T.PARTCODE",
IDAO.class
);
roleUser.set("empCode", getReferenceRole().getMapping(instance).getEndpoint());
roleUser.select();
} else {
}
}
if(roleUser != null)
{
while(roleUser.next()){
String endpoint = roleUser.getString("empCode");
rm.setEndpoint(endpoint);
rm.fill(instance);
rm.moveToAdd();
}