package com.eforce.baby.auth.dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import org.apache.log4j.Logger;
import com.eforce.baby.auth.vo.MenuVO;
import com.eforce.baby.common.dao.BaseDAO;
import com.eforce.baby.common.dao.DAOException;
import com.eforce.baby.common.dao.QueryManager;
public class MenuDAO extends BaseDAO
{
private Logger log = Logger.getLogger(this.getClass().getName());
public ArrayList findMenuItemsForUser(String dsName, String dbType, String userId) throws DAOException
{
log.debug("findMenuItemsForUser() : ENTER");
String sql = QueryManager.getInstance().getFindMenuItemsForUserQuery(dbType);
ArrayList menuList = new ArrayList();
Connection con = null;
PreparedStatement stmt = null;
ResultSet rset = null;
ResultSetMetaData rsmd = null;
try
{
con = super.createConnection(dsName);
stmt = con.prepareStatement(sql);
stmt.setString(1, userId);
rset = stmt.executeQuery();
MenuVO menu = null;
while(rset.next())
{
menu = new MenuVO();
menu.setMenuId((rset.getString(1)) == null ? "" : rset.getString(1));
menu.setMenuName((rset.getString(2)) == null ? "" : rset.getString(2));
menu.setQuickMenuName((rset.getString(3)) == null ? "" : rset.getString(3));
menu.setParentMenuId((rset.getString(4)) == null ? "" : rset.getString(4));
menu.setLeaf((rset.getString(5)) == null ? "" : rset.getString(5));
menu.setTarget((rset.getString(6)) == null ? "" : rset.getString(6));
menu.setHyperlink((rset.getString(7)) == null ? "" : rset.getString(7));
menu.setTagName((rset.getString(8)) == null ? "" : rset.getString(8));
menu.setPrivilegeId((rset.getString(9)) == null ? "" : rset.getString(9));
menu.setPopup((rset.getString(10)) == null ? "" : rset.getString(10));
menu.setPrivilegeName((rset.getString(11)) == null ? "" : rset.getString(11));
menu.setEnabled("Y");
//add each menu to the menuList
menuList.add(menu);
}
}
catch(SQLException se)
{
throw new DAOException(se.getMessage());
}
finally
{
super.releaseConnection(con);
super.cleanUp(rset, stmt);
}
log.debug("Total Menu Items: " + menuList.size());
log.debug("findMenuItemsForUser() : EXIT");
return menuList;
}
public ArrayList findAllMenuItemsForUser(String dsName, String dbType, String userId) throws DAOException
{
log.debug("findAllMenuItemsForUser() : ENTER");
String sql = QueryManager.getInstance().getFindAllMenuItemsForUserQuery(dbType);
ArrayList menuList = new ArrayList();
Connection con = null;
PreparedStatement stmt = null;
ResultSet rset = null;
ResultSetMetaData rsmd = null;
try
{
con = super.createConnection(dsName);
stmt = con.prepareStatement(sql);
stmt.setString(1, userId);
rset = stmt.executeQuery();
MenuVO menu = null;
while(rset.next())
{
menu = new MenuVO();
menu.setMenuId((rset.getString(1)) == null ? "" : rset.getString(1));
menu.setMenuName((rset.getString(2)) == null ? "" : rset.getString(2));
menu.setQuickMenuName((rset.getString(3)) == null ? "" : rset.getString(3));
menu.setParentMenuId((rset.getString(4)) == null ? "" : rset.getString(4));
menu.setLeaf((rset.getString(5)) == null ? "" : rset.getString(5));
menu.setTarget((rset.getString(6)) == null ? "" : rset.getString(6));
menu.setHyperlink((rset.getString(7)) == null ? "" : rset.getString(7));
menu.setTagName((rset.getString(8)) == null ? "" : rset.getString(8));
menu.setPrivilegeId((rset.getString(9)) == null ? "" : rset.getString(9));
menu.setPopup((rset.getString(10)) == null ? "" : rset.getString(10));
menu.setPrivilegeName((rset.getString(11)) == null ? "" : rset.getString(11));
menu.setEnabled((rset.getString(12)) == null ? "Y" : rset.getString(12));
//add each menu to the menuList
menuList.add(menu);
}
}
catch(SQLException se)
{
throw new DAOException(se.getMessage());
}
finally
{
super.releaseConnection(con);
super.cleanUp(rset, stmt);
}
log.debug("Total Menu Items: " + menuList.size());
log.debug("findAllMenuItemsForUser() : EXIT");
return menuList;
}
public int enableMenuItems(String dsName, String dbType, String userId, String menuList) throws DAOException
{
log.debug("enableMenuItems() : ENTER");
int rowCount = 0;
String sql = QueryManager.getInstance().getEnableMenuItemsForUserQuery(dbType);
sql = sql.replaceAll("#", menuList);
log.debug("sql: " + sql);
Connection con = null;
PreparedStatement stmt = null;
try
{
con = super.createConnection(dsName);
stmt = con.prepareStatement(sql);
stmt.setString(1, userId);
rowCount = stmt.executeUpdate();
log.debug("rowCount: " + rowCount);
}
catch(SQLException se)
{
throw new DAOException(se.getMessage());
}
finally
{
super.releaseConnection(con);
super.cleanUp(null, stmt);
}
log.debug("enableMenuItems() : EXIT");
return rowCount;
}
public int disableMenuItems(String dsName, String dbType, String userId, String menuId) throws DAOException
{
log.debug("disableMenuItems() : ENTER");
int rowCount = 0;
log.debug("dsName: [" + dsName + "]");
log.debug("dbType: [" + dbType + "]");
log.debug("userId: [" + userId + "]");
log.debug("menuId: [" + menuId + "]");
String sql = QueryManager.getInstance().getDisableMenuItemsForUserQuery(dbType);
Connection con = null;
PreparedStatement stmt = null;
try
{
con = super.createConnection(dsName);
stmt = con.prepareStatement(sql);
stmt.setString(1, userId);
stmt.setString(2, menuId);
rowCount = stmt.executeUpdate();
log.debug("rowCount: " + rowCount);
}
catch(SQLException se)
{
throw new DAOException(se.getMessage());
}
finally
{
super.releaseConnection(con);
super.cleanUp(null, stmt);
}
log.debug("disableMenuItems() : EXIT");
return rowCount;
}
public void setDefaultPage(String dsName, String dbType, String profileId, String page) throws DAOException
{
log.debug("setDefaultPage() : ENTER");
log.debug("dsName: [" + dsName + "]");
log.debug("dbType: [" + dbType + "]");
log.debug("profileId: [" + profileId + "]");
log.debug("page: [" + page + "]");
String sql = QueryManager.getInstance().getSetDefaultMenuQuery(dbType);
Connection con = null;
PreparedStatement stmt = null;
try
{
con = super.createConnection(dsName);
stmt = con.prepareStatement(sql);
stmt.setString(1, page);
stmt.setString(2, profileId);
stmt.executeUpdate();
}
catch(SQLException se)
{
throw new DAOException(se.getMessage());
}
finally
{
super.releaseConnection(con);
super.cleanUp(null, stmt);
}
log.debug("setDefaultPage() : EXIT");
}
public void setDefaultMenu(String dsName, String dbType, String profileId, String menuType) throws DAOException
{
log.debug("setDefaultMenu() : ENTER");
log.debug("dsName: [" + dsName + "]");
log.debug("dbType: [" + dbType + "]");
log.debug("profileId: [" + profileId + "]");
log.debug("menuType: [" + menuType + "]");
String sql = QueryManager.getInstance().getSetDefaultMenuTypeQuery(dbType);
Connection con = null;
PreparedStatement stmt = null;
try
{
con = super.createConnection(dsName);
stmt = con.prepareStatement(sql);
stmt.setString(1, menuType);
stmt.setString(2, profileId);
stmt.executeUpdate();
}
catch(SQLException se)
{
throw new DAOException(se.getMessage());
}
finally
{
super.releaseConnection(con);
super.cleanUp(null, stmt);
}
log.debug("setDefaultMenu() : EXIT");
}
}