log.debug("ID="+roleVO.getId()+" || "+roleVO.getRoleName());
rset = pStmt.executeQuery();
if( rset.next() ){
if(rset.getInt(1)>0){
DAOException daox = new DAOException ("Database Error");
daox.setMessageKey(IErrorMessageKeys.KEY_ERROR_DUPLICATE_ROLE);
throw daox;
}
}
sql = qManager.getUpdateRole(dbType);
log.debug(sql);
pStmt = con.prepareStatement( sql );
pStmt.setString( 1, roleVO.getRoleName() );
pStmt.setString( 2, roleVO.getRoleDesc() );
pStmt.setString( 3, roleVO.getId());
pStmt.executeUpdate();
this.createSearchContent(con, dbType, roleVO, "TBL_ROLE", "ROLE_ID" ) ;
//first delete old groups
sql = qManager.getDeleteRoleGroupQuery(dbType);
pStmt = con.prepareStatement( sql );
pStmt.setString( 1, roleVO.getId());
pStmt.executeUpdate();
String[] groupIds = EEMSUtil.convertToArray(roleVO.getGroupNames(),IConstants.EEMS_DELIMITER);
if(groupIds!=null)
{
sql = qManager.getFetchRoleGroupQuery(dbType);
pStmt = con.prepareStatement( sql );
log.debug(sql);
for (int i=0; i<groupIds.length;i++)
{
if(groupIds[i]!= null)
{
log.debug("GROUPSID " + groupIds[i]);
log.debug("role id "+roleVO.getId());
pStmt.setString( 1, groupIds[i].trim() );
pStmt.setString( 2, roleVO.getId() );
pStmt.executeUpdate();
log.debug("ROLE-GROUP added" + i);
}
}
}
//first delete old privilege
sql = qManager.getDelRolePrivilegeQuery(dbType);
pStmt = con.prepareStatement( sql );
pStmt.setString( 1, roleVO.getId());
pStmt.executeUpdate();
/* Privilege */
String[] privilegeIds = EEMSUtil.convertToArray(roleVO.getPrivilegeNames(),IConstants.EEMS_DELIMITER);
if(groupIds!=null)
{
sql = qManager.getRolePrivilegeQuery(dbType);
pStmt = con.prepareStatement( sql );
log.debug(sql);
for (int i=0; i<privilegeIds.length;i++)
{
if(privilegeIds[i]!= null)
{
log.debug("privilegeID " + privilegeIds[i]);
log.debug("role id "+roleVO.getId());
pStmt.setString( 1, roleVO.getId() );
pStmt.setString( 2, privilegeIds[i].trim() );
pStmt.executeUpdate();
log.debug("ROLE-privilege added" + i);
}
}
}
/* Privilege */
log.debug("inserted...and updated");
con.commit();
}
catch(SQLException ex)
{
try
{
con.rollback();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
DAOException daox = new DAOException ("Database Error");
daox.setMessageKey(IErrorMessageKeys.KEY_DATABASE_ERROR);
throw daox;
}
finally
{
try
{
super.cleanUp(rset, pStmt);
this.releaseConnection(con);
}
catch (DAOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
DAOException daox = new DAOException ("FATAL Error");
daox.setMessageKey(IErrorMessageKeys.KEY_FATAL_ERROR);
throw daox;
}
}