Java tutorial
/* * Copyright 2012 Eng Kam Hon (kamhon@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.kamhon.ieagle.function.user.dao.impl; import java.util.ArrayList; import java.util.List; import net.kamhon.ieagle.dao.Jpa2Dao; import net.kamhon.ieagle.datagrid.DatagridModel; import net.kamhon.ieagle.function.user.dao.UserMenuFrameworkDao; import net.kamhon.ieagle.function.user.vo.UserMenu; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Repository; @Repository(UserMenuFrameworkDao.BEAN_NAME) public class UserMenuFrameworkDaoImpl extends Jpa2Dao<UserMenu, Long> implements UserMenuFrameworkDao { public UserMenuFrameworkDaoImpl() { super(new UserMenu(false)); } public void findUserMenuForListing(DatagridModel<UserMenu> datagridModel, Long menuId, Long menuId2, String menuName, String menuName2, Long parentMenuId, Long parentMenuId2, String parentMenuName, String parentMenuName2, String accessCode, String accessCode2, Integer treeLevel, Integer treeLevel2, String status, String status2, Long sortSeq2, String menuTarget2, String menuUrl2, String menuDesc2) { List<Object> params = new ArrayList<Object>(); String sql = " SELECT userMenu FROM userMenu IN " + UserMenu.class + " LEFT JOIN userMenu.parentMenu parentMenu " + " WHERE 1=1 "; if (menuId != null) { sql += " AND CONCAT(userMenu.menuId,'') LIKE ? "; params.add(menuId.longValue() + "%"); } if (menuId2 != null) { sql += " AND CONCAT(userMenu.menuId,'') LIKE ? "; params.add(menuId2.longValue() + "%"); } if (StringUtils.isNotBlank(menuName)) { sql += " AND userMenu.menuName LIKE ? "; params.add(menuName + "%"); } if (StringUtils.isNotBlank(menuName2)) { sql += " AND userMenu.menuName LIKE ? "; params.add(menuName2 + "%"); } if (parentMenuId != null) { sql += " AND CONCAT(parentMenu.menuId,'') LIKE ? "; params.add(parentMenuId + "%"); } if (parentMenuId2 != null) { sql += " AND CONCAT(parentMenu.menuId,'') LIKE ? "; params.add(parentMenuId2 + "%"); } if (StringUtils.isNotBlank(parentMenuName)) { sql += " AND parentMenu.menuName LIKE ? "; params.add(parentMenuName + "%"); } if (StringUtils.isNotBlank(parentMenuName2)) { sql += " AND parentMenu.menuName LIKE ? "; params.add(parentMenuName2 + "%"); } if (StringUtils.isNotBlank(accessCode)) { sql += " AND userMenu.accessCode LIKE ? "; params.add(accessCode + "%"); } if (StringUtils.isNotBlank(accessCode2)) { sql += " AND userMenu.accessCode LIKE ? "; params.add(accessCode2 + "%"); } if (treeLevel != null) { sql += " AND userMenu.treeLevel=?"; params.add(treeLevel); } if (treeLevel2 != null) { sql += " AND userMenu.treeLevel=?"; params.add(treeLevel2); } if (StringUtils.isNotBlank(status)) { sql += " AND userMenu.status = ? "; params.add(status); } if (StringUtils.isNotBlank(status2)) { sql += " AND userMenu.status = ? "; params.add(status2); } if (sortSeq2 != null) { sql += " AND CONCAT(userMenu.sortSeq,'') LIKE ? "; params.add(sortSeq2.longValue() + "%"); } if (StringUtils.isNotBlank(menuUrl2)) { sql += " AND userMenu.menuUrl LIKE ? "; params.add(menuUrl2 + "%"); } if (StringUtils.isNotBlank(menuTarget2)) { sql += " AND userMenu.menuTarget LIKE ?"; params.add(menuTarget2 + "%"); } if (StringUtils.isNotBlank(menuDesc2)) { sql += " AND userMenu.menuDesc LIKE ?"; params.add(menuDesc2 + "%"); } findForDatagrid(datagridModel, "userMenu", sql, params.toArray()); } public List<UserMenu> findUserMenuByTreeLevel(Integer treeLevel) { UserMenu example = new UserMenu(false); example.setTreeLevel(treeLevel); return findByExample(example, "menuId"); } public void updateMenuParentIdOnly(Long parentId, Long newParentId) { List<Object> params = new ArrayList<Object>(); String sql = " UPDATE " + UserMenu.class.getName() + " userMenu SET userMenu.parentId = ? WHERE userMenu.parentId=? "; params.add(newParentId); params.add(parentId); bulkUpdate(sql, params.toArray()); } public void updateMenuId(Long menuId, Long newMenuId) { List<Object> params = new ArrayList<Object>(); String sql = " UPDATE " + UserMenu.class.getName() + " userMenu SET userMenu.menuId=? WHERE userMenu.menuId = ? "; params.add(newMenuId); params.add(menuId); bulkUpdate(sql, params.toArray()); } @SuppressWarnings("unchecked") public List<Integer> findTreeLevels() { String sql = " SELECT DISTINCT userMenu.treeLevel FROM userMenu IN " + UserMenu.class + " ORDER BY userMenu.treeLevel "; return (List<Integer>) exFindQueryAsList(sql); } }