Java tutorial
/* Copyright (C) 2012 NTT DATA Corporation This program is free software; you can redistribute it and/or Modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ package com.clustercontrol.notify.monitor.util; import java.util.List; import javax.persistence.TypedQuery; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.clustercontrol.accesscontrol.bean.PrivilegeConstant.ObjectPrivilegeMode; import com.clustercontrol.bean.PriorityConstant; import com.clustercontrol.commons.util.HinemosEntityManager; import com.clustercontrol.commons.util.JpaTransactionManager; import com.clustercontrol.fault.EventLogNotFound; import com.clustercontrol.fault.InvalidRole; import com.clustercontrol.fault.MonitorNotFound; import com.clustercontrol.fault.ObjectPrivilege_InvalidRole; import com.clustercontrol.monitor.bean.ConfirmConstant; import com.clustercontrol.notify.monitor.model.EventLogEntity; import com.clustercontrol.notify.monitor.model.EventLogEntityPK; import com.clustercontrol.notify.monitor.model.StatusInfoEntity; import com.clustercontrol.notify.monitor.model.StatusInfoEntityPK; public class QueryUtil { /** ? */ private static Log m_log = LogFactory.getLog(QueryUtil.class); public static StatusInfoEntity getStatusInfoPK(StatusInfoEntityPK pk) throws MonitorNotFound, InvalidRole { return getStatusInfoPK(pk, ObjectPrivilegeMode.READ); } public static StatusInfoEntity getStatusInfoPK(StatusInfoEntityPK pk, ObjectPrivilegeMode mode) throws MonitorNotFound, InvalidRole { HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); StatusInfoEntity entity = null; try { entity = em.find(StatusInfoEntity.class, pk, mode); if (entity == null) { MonitorNotFound e = new MonitorNotFound("StatusInfoEntity.findByPrimaryKey" + pk.toString()); m_log.info("getStatusInfoPK() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); throw e; } } catch (ObjectPrivilege_InvalidRole e) { m_log.info("getStatusInfoPK() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); throw new InvalidRole(e.getMessage(), e); } return entity; } public static StatusInfoEntity getStatusInfoPK(String facilityId, String monitorId, String monitorDetailId, String pluginId) throws MonitorNotFound, InvalidRole { return getStatusInfoPK(new StatusInfoEntityPK(facilityId, monitorId, monitorDetailId, pluginId)); } public static StatusInfoEntity getStatusInfoPK(String facilityId, String monitorId, String monitorDetailId, String pluginId, ObjectPrivilegeMode mode) throws MonitorNotFound, InvalidRole { return getStatusInfoPK(new StatusInfoEntityPK(facilityId, monitorId, monitorDetailId, pluginId), mode); } public static List<StatusInfoEntity> getStatusInfoByExpirationStatus(Long expirationDate) { HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); List<StatusInfoEntity> list = em .createNamedQuery("StatusInfoEntity.findExpirationStatus", StatusInfoEntity.class) .setParameter("expirationDate", expirationDate).getResultList(); return list; } public static EventLogEntity getEventLogPK(EventLogEntityPK pk) throws EventLogNotFound, InvalidRole { return getEventLogPK(pk, ObjectPrivilegeMode.READ); } public static EventLogEntity getEventLogPK(EventLogEntityPK pk, ObjectPrivilegeMode mode) throws EventLogNotFound, InvalidRole { HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); EventLogEntity entity = null; try { entity = em.find(EventLogEntity.class, pk, mode); if (entity == null) { EventLogNotFound e = new EventLogNotFound("EventLogEntity.findByPrimaryKey" + pk.toString()); m_log.info("getEventLogPK() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); throw e; } } catch (ObjectPrivilege_InvalidRole e) { m_log.info("getEventLogPK() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); throw new InvalidRole(e.getMessage(), e); } return entity; } public static EventLogEntity getEventLogPK(String monitorId, String monitorDetailId, String pluginId, Long outputDate, String facilityId) throws EventLogNotFound, InvalidRole { return getEventLogPK(new EventLogEntityPK(monitorId, monitorDetailId, pluginId, outputDate, facilityId)); } public static EventLogEntity getEventLogPK(String monitorId, String monitorDetailId, String pluginId, Long outputDate, String facilityId, ObjectPrivilegeMode mode) throws EventLogNotFound, InvalidRole { return getEventLogPK(new EventLogEntityPK(monitorId, monitorDetailId, pluginId, outputDate, facilityId), mode); } public static int updateEventLogFlgByFilter(String[] facilityIds, Integer[] priorityList, Long outputFromDate, Long outputToDate, Long generationFromDate, Long generationToDate, String monitorId, String monitorDetailId, String application, String message, Integer confirmFlg, String confirmUser, String comment, String commentUser, Integer confirmType, Long confirmDate, Boolean collectGraphFlg) { HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); // ?????????? String notInclude = "NOT:"; // ??????? Integer selectConfirmFlg = null; if (confirmType == ConfirmConstant.TYPE_CONFIRMED) { selectConfirmFlg = ConfirmConstant.TYPE_UNCONFIRMED; } else if (confirmType == ConfirmConstant.TYPE_UNCONFIRMED) { selectConfirmFlg = ConfirmConstant.TYPE_CONFIRMED; } // SQL? StringBuffer sbJpql = new StringBuffer(); sbJpql.append( "UPDATE EventLogEntity a SET a.confirmFlg = :confirmFlg, a.confirmDate = :confirmDate, a.confirmUser = :confirmUser"); sbJpql.append(" WHERE true = true"); // ID if (facilityIds != null && facilityIds.length > 0) { sbJpql.append(" AND a.id.facilityId IN (" + HinemosEntityManager.getParamNameString("facilityId", facilityIds) + ")"); } // ?? if (priorityList != null && priorityList.length > 0 && priorityList.length != PriorityConstant.PRIORITY_LIST.length) { sbJpql.append(" AND a.priority IN (" + HinemosEntityManager.getParamNameString("priority", new String[priorityList.length]) + ")"); } // ? if (outputFromDate != null) { sbJpql.append(" AND a.id.outputDate >= :outputFromDate"); } // ? if (outputToDate != null) { sbJpql.append(" AND a.id.outputDate <= :outputToDate "); } // if (generationFromDate != null) { sbJpql.append(" AND a.generationDate >= :generationFromDate "); } // if (generationToDate != null) { sbJpql.append(" AND a.generationDate <= :generationToDate "); } // ID if (monitorId != null && !"".equals(monitorId)) { if (!monitorId.startsWith(notInclude)) { sbJpql.append(" AND a.id.monitorId like :monitorId"); } else { sbJpql.append(" AND a.id.monitorId not like :monitorId"); } } // if (monitorDetailId != null && !"".equals(monitorDetailId)) { if (!monitorDetailId.startsWith(notInclude)) { sbJpql.append(" AND a.id.monitorDetailId like :monitorDetailId"); } else { sbJpql.append(" AND a.id.monitorDetailId not like :monitorDetailId"); } } // if (application != null && !"".equals(application)) { if (!application.startsWith(notInclude)) { sbJpql.append(" AND a.application like :application"); } else { sbJpql.append(" AND a.application not like :application"); } } // if (message != null && !"".equals(message)) { if (!message.startsWith(notInclude)) { sbJpql.append(" AND a.message like :message"); } else { sbJpql.append(" AND a.message not like :message"); } } // if (comment != null && !"".equals(comment)) { if (!comment.startsWith(notInclude)) { sbJpql.append(" AND a.comment like :comment"); } else { sbJpql.append(" AND a.comment not like :comment"); } } // if (commentUser != null && !"".equals(commentUser)) { if (!commentUser.startsWith(notInclude)) { sbJpql.append(" AND a.commentUser like :commentUser"); } else { sbJpql.append(" AND a.commentUser not like :commentUser"); } } // ? if (selectConfirmFlg != null) { sbJpql.append(" AND a.confirmFlg = :selectConfirmFlg "); } TypedQuery<Integer> query = em .createQuery(sbJpql.toString(), Integer.class, EventLogEntity.class, ObjectPrivilegeMode.MODIFY) .setParameter("confirmFlg", confirmFlg).setParameter("confirmDate", confirmDate) .setParameter("confirmUser", confirmUser); // ID if (facilityIds != null && facilityIds.length > 0) { query = HinemosEntityManager.appendParam(query, "facilityId", facilityIds); } // ?? if (priorityList != null && priorityList.length > 0 && priorityList.length != PriorityConstant.PRIORITY_LIST.length) { int count = priorityList.length; if (count > 0) { for (int i = 0; i < count; i++) { query = query.setParameter("priority" + i, priorityList[i]); } } } // ? if (outputFromDate != null) { query.setParameter("outputFromDate", outputFromDate); } // ? if (outputToDate != null) { query.setParameter("outputToDate", outputToDate); } // if (generationFromDate != null) { query.setParameter("generationFromDate", generationFromDate); } // if (generationToDate != null) { query.setParameter("generationToDate", generationToDate); } // ID if (monitorId != null && !"".equals(monitorId)) { if (!monitorId.startsWith(notInclude)) { query = query.setParameter("monitorId", monitorId); } else { query = query.setParameter("monitorId", monitorId.substring(notInclude.length())); } } // if (monitorDetailId != null && !"".equals(monitorDetailId)) { if (!monitorDetailId.startsWith(notInclude)) { query = query.setParameter("monitorDetailId", monitorDetailId); } else { query = query.setParameter("monitorDetailId", monitorDetailId.substring(notInclude.length())); } } // if (application != null && !"".equals(application)) { if (!application.startsWith(notInclude)) { query = query.setParameter("application", application); } else { query = query.setParameter("application", application.substring(notInclude.length())); } } // if (message != null && !"".equals(message)) { if (!message.startsWith(notInclude)) { query = query.setParameter("message", message); } else { query = query.setParameter("message", message.substring(notInclude.length())); } } // if (comment != null && !"".equals(comment)) { if (!comment.startsWith(notInclude)) { query = query.setParameter("comment", comment); } else { query = query.setParameter("comment", comment.substring(notInclude.length())); } } // if (commentUser != null && !"".equals(commentUser)) { if (!commentUser.startsWith(notInclude)) { query = query.setParameter("commentUser", commentUser); } else { query = query.setParameter("commentUser", commentUser.substring(notInclude.length())); } } // ? if (selectConfirmFlg != null) { query.setParameter("selectConfirmFlg", selectConfirmFlg); } // if (collectGraphFlg != null) { query.setParameter("collectGraphFlg", collectGraphFlg); } return query.executeUpdate(); } // TODO // updateEventLogFlgByFilter?getEventLogByFilter?????????? public static List<EventLogEntity> getEventLogByFilter(String[] facilityIds, Integer[] priorityList, Long outputFromDate, Long outputToDate, Long generationFromDate, Long generationToDate, String monitorId, String monitorDetailId, String application, String message, Integer confirmFlg, String confirmUser, String comment, String commentUser, Boolean collectGraphFlg, String ownerRoleId, Boolean orderByFlg, Integer limit) { HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); // ?????????? String notInclude = "NOT:"; StringBuffer sbJpql = new StringBuffer(); sbJpql.append("SELECT a FROM EventLogEntity a WHERE true = true"); // ID if (facilityIds != null && facilityIds.length > 0) { sbJpql.append(" AND a.id.facilityId IN (" + HinemosEntityManager.getParamNameString("facilityId", facilityIds) + ")"); } // ?? if (priorityList != null && priorityList.length > 0 && priorityList.length != PriorityConstant.PRIORITY_LIST.length) { sbJpql.append(" AND a.priority IN (" + HinemosEntityManager.getParamNameString("priority", new String[priorityList.length]) + ")"); } // ? if (outputFromDate != null) { sbJpql.append(" AND a.id.outputDate >= :outputFromDate"); } // ? if (outputToDate != null) { sbJpql.append(" AND a.id.outputDate <= :outputToDate"); } // if (generationFromDate != null) { sbJpql.append(" AND a.generationDate >= :generationFromDate"); } // if (generationToDate != null) { sbJpql.append(" AND a.generationDate <= :generationToDate"); } // ID if (monitorId != null && !"".equals(monitorId)) { if (!monitorId.startsWith(notInclude)) { sbJpql.append(" AND a.id.monitorId like :monitorId"); } else { sbJpql.append(" AND a.id.monitorId not like :monitorId"); } } // if (monitorDetailId != null && !"".equals(monitorDetailId)) { if (!monitorDetailId.startsWith(notInclude)) { sbJpql.append(" AND a.id.monitorDetailId like :monitorDetailId"); } else { sbJpql.append(" AND a.id.monitorDetailId not like :monitorDetailId"); } } // if (application != null && !"".equals(application)) { if (!application.startsWith(notInclude)) { sbJpql.append(" AND a.application like :application"); } else { sbJpql.append(" AND a.application not like :application"); } } // if (message != null && !"".equals(message)) { if (!message.startsWith(notInclude)) { sbJpql.append(" AND a.message like :message"); } else { sbJpql.append(" AND a.message not like :message"); } } // ? if (confirmFlg != null) { sbJpql.append(" AND a.confirmFlg = :confirmFlg"); } // ? if (confirmUser != null && !"".equals(confirmUser)) { if (!confirmUser.startsWith(notInclude)) { sbJpql.append(" AND a.confirmUser like :confirmUser"); } else { sbJpql.append(" AND a.confirmUser not like :confirmUser"); } } // if (comment != null && !"".equals(comment)) { if (!comment.startsWith(notInclude)) { sbJpql.append(" AND a.comment like :comment"); } else { sbJpql.append(" AND a.comment not like :comment"); } } // if (commentUser != null && !"".equals(commentUser)) { if (!commentUser.startsWith(notInclude)) { sbJpql.append(" AND a.commentUser like :commentUser"); } else { sbJpql.append(" AND a.commentUser not like :commentUser"); } } // if (collectGraphFlg != null) { sbJpql.append(" AND a.collectGraphFlg = :collectGraphFlg"); } //ID if (ownerRoleId != null && !"".equals(ownerRoleId)) { if (!ownerRoleId.startsWith(notInclude)) { sbJpql.append(" AND a.ownerRoleId like :ownerRoleId"); } else { sbJpql.append(" AND a.ownerRoleId not like :ownerRoleId"); } } // if (orderByFlg) { sbJpql.append(" ORDER BY a.id.outputDate"); } else { sbJpql.append(" ORDER BY a.id.outputDate DESC"); } TypedQuery<EventLogEntity> typedQuery = em.createQuery(sbJpql.toString(), EventLogEntity.class); // ID if (facilityIds != null && facilityIds.length > 0) { typedQuery = HinemosEntityManager.appendParam(typedQuery, "facilityId", facilityIds); } // ?? if (priorityList != null && priorityList.length > 0 && priorityList.length != PriorityConstant.PRIORITY_LIST.length) { int count = priorityList.length; if (count > 0) { for (int i = 0; i < count; i++) { typedQuery = typedQuery.setParameter("priority" + i, priorityList[i]); } } } // ? if (outputFromDate != null) { typedQuery = typedQuery.setParameter("outputFromDate", outputFromDate); } // ? if (outputToDate != null) { typedQuery = typedQuery.setParameter("outputToDate", outputToDate); } // if (generationFromDate != null) { typedQuery = typedQuery.setParameter("generationFromDate", generationFromDate); } // if (generationToDate != null) { typedQuery = typedQuery.setParameter("generationToDate", generationToDate); } // ID if (monitorId != null && !"".equals(monitorId)) { if (!monitorId.startsWith(notInclude)) { typedQuery = typedQuery.setParameter("monitorId", monitorId); } else { typedQuery = typedQuery.setParameter("monitorId", monitorId.substring(notInclude.length())); } } // if (monitorDetailId != null && !"".equals(monitorDetailId)) { if (!monitorDetailId.startsWith(notInclude)) { typedQuery = typedQuery.setParameter("monitorDetailId", monitorDetailId); } else { typedQuery = typedQuery.setParameter("monitorDetailId", monitorDetailId.substring(notInclude.length())); } } // if (application != null && !"".equals(application)) { if (!application.startsWith(notInclude)) { typedQuery = typedQuery.setParameter("application", application); } else { typedQuery = typedQuery.setParameter("application", application.substring(notInclude.length())); } } // if (message != null && !"".equals(message)) { if (!message.startsWith(notInclude)) { typedQuery = typedQuery.setParameter("message", message); } else { typedQuery = typedQuery.setParameter("message", message.substring(notInclude.length())); } } // ? if (confirmFlg != null) { typedQuery = typedQuery.setParameter("confirmFlg", confirmFlg); } // ? if (confirmUser != null && !"".equals(confirmUser)) { if (!confirmUser.startsWith(notInclude)) { typedQuery = typedQuery.setParameter("confirmUser", confirmUser); } else { typedQuery = typedQuery.setParameter("confirmUser", confirmUser.substring(notInclude.length())); } } // if (comment != null && !"".equals(comment)) { if (!comment.startsWith(notInclude)) { typedQuery = typedQuery.setParameter("comment", comment); } else { typedQuery = typedQuery.setParameter("comment", comment.substring(notInclude.length())); } } // if (commentUser != null && !"".equals(commentUser)) { if (!commentUser.startsWith(notInclude)) { typedQuery = typedQuery.setParameter("commentUser", commentUser); } else { typedQuery = typedQuery.setParameter("commentUser", commentUser.substring(notInclude.length())); } } // if (collectGraphFlg != null) { typedQuery = typedQuery.setParameter("collectGraphFlg", collectGraphFlg); } //ID if (ownerRoleId != null && !"".equals(ownerRoleId)) { if (!ownerRoleId.startsWith(notInclude)) { typedQuery = typedQuery.setParameter("ownerRoleId", ownerRoleId); } else { typedQuery = typedQuery.setParameter("ownerRoleId", ownerRoleId.substring(notInclude.length())); } } if (limit != null) { typedQuery = typedQuery.setMaxResults(limit); } return typedQuery.getResultList(); } public static List<EventLogEntity> getEventLogByHighPriorityFilter(String[] facilityIds, Integer priority, Long outputFromDate, Long outputToDate, Long generationFromDate, Long generationToDate, String application, String message, Integer confirmFlg, String confirmUser, Boolean orderByFlg) { HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); StringBuffer sbJpql = new StringBuffer(); sbJpql.append("SELECT a FROM EventLogEntity a WHERE true = true"); // ID if (facilityIds != null && facilityIds.length > 0) { sbJpql.append(" AND a.id.facilityId IN (" + HinemosEntityManager.getParamNameString("facilityId", facilityIds) + ")"); } // ?? if (priority != null) { sbJpql.append(" AND a.priority = :priority"); } // ? if (outputFromDate != null) { sbJpql.append(" AND a.id.outputDate >= :outputFromDate"); } // ? if (outputToDate != null) { sbJpql.append(" AND a.id.outputDate <= :outputToDate"); } // if (generationFromDate != null) { sbJpql.append(" AND a.generationDate >= :generationFromDate"); } // if (generationToDate != null) { sbJpql.append(" AND a.generationDate <= :generationToDate"); } // if (application != null && !"".equals(application)) { sbJpql.append(" AND a.application like :application"); } // if (message != null && !"".equals(message)) { sbJpql.append(" AND a.message like :message"); } // ? if (confirmFlg != null) { sbJpql.append(" AND a.confirmFlg = :confirmFlg"); } // ? if (confirmUser != null) { sbJpql.append(" AND a.confirmUser = :confirmUser"); } // if (orderByFlg) { sbJpql.append(" ORDER BY a.id.outputDate DESC"); } TypedQuery<EventLogEntity> typedQuery = em.createQuery(sbJpql.toString(), EventLogEntity.class); // ID if (facilityIds != null && facilityIds.length > 0) { typedQuery = HinemosEntityManager.appendParam(typedQuery, "facilityId", facilityIds); } // ?? if (priority != null) { typedQuery = typedQuery.setParameter("priority", priority); } // ? if (outputFromDate != null) { typedQuery = typedQuery.setParameter("outputFromDate", outputFromDate); } // ? if (outputToDate != null) { typedQuery = typedQuery.setParameter("outputToDate", outputToDate); } // if (generationFromDate != null) { typedQuery = typedQuery.setParameter("generationFromDate", generationFromDate); } // if (generationToDate != null) { typedQuery = typedQuery.setParameter("generationToDate", generationToDate); } // if (application != null && !"".equals(application)) { typedQuery = typedQuery.setParameter("application", application); } // if (message != null && !"".equals(message)) { typedQuery = typedQuery.setParameter("message", message); } // ? if (confirmFlg != null) { typedQuery = typedQuery.setParameter("confirmFlg", confirmFlg); } // ? if (confirmUser != null) { typedQuery = typedQuery.setParameter("confirmUser", confirmUser); } typedQuery = typedQuery.setMaxResults(1); return typedQuery.getResultList(); } public static List<StatusInfoEntity> getStatusInfoByFilter(String[] facilityIds, Integer[] priorityList, Long outputFromDate, Long outputToDate, Long generationFromDate, Long generationToDate, String monitorId, String monitorDetailId, String application, String message, String ownerRoleId) { HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); // ?????????? String notInclude = "NOT:"; StringBuffer sbJpql = new StringBuffer(); sbJpql.append("SELECT a FROM StatusInfoEntity a WHERE true = true"); // ID if (facilityIds != null && facilityIds.length > 0) { sbJpql.append(" AND a.id.facilityId IN (" + HinemosEntityManager.getParamNameString("facilityId", facilityIds) + ")"); } // ?? if (priorityList != null && priorityList.length > 0 && priorityList.length != PriorityConstant.PRIORITY_LIST.length) { sbJpql.append(" AND a.priority IN (" + HinemosEntityManager.getParamNameString("priority", new String[priorityList.length]) + ")"); } // ? if (outputFromDate != null) { sbJpql.append(" AND a.outputDate >= :outputFromDate"); } // ? if (outputToDate != null) { sbJpql.append(" AND a.outputDate <= :outputToDate"); } // if (generationFromDate != null) { sbJpql.append(" AND a.generationDate >= :generationFromDate"); } // if (generationToDate != null) { sbJpql.append(" AND a.generationDate <= :generationToDate"); } // ID if (monitorId != null && !"".equals(monitorId)) { if (!monitorId.startsWith(notInclude)) { sbJpql.append(" AND a.id.monitorId like :monitorId"); } else { sbJpql.append(" AND a.id.monitorId not like :monitorId"); } } // if (monitorDetailId != null && !"".equals(monitorDetailId)) { if (!monitorDetailId.startsWith(notInclude)) { sbJpql.append(" AND a.id.monitorDetailId like :monitorDetailId"); } else { sbJpql.append(" AND a.id.monitorDetailId not like :monitorDetailId"); } } // if (application != null && !"".equals(application)) { if (!application.startsWith(notInclude)) { sbJpql.append(" AND a.application like :application"); } else { sbJpql.append(" AND a.application not like :application"); } } // if (message != null && !"".equals(message)) { if (!message.startsWith(notInclude)) { sbJpql.append(" AND a.message like :message"); } else { sbJpql.append(" AND a.message not like :message"); } } //ID if (ownerRoleId != null && !"".equals(ownerRoleId)) { if (!ownerRoleId.startsWith(notInclude)) { sbJpql.append(" AND a.ownerRoleId like :ownerRoleId"); } else { sbJpql.append(" AND a.ownerRoleId not like :ownerRoleId"); } } TypedQuery<StatusInfoEntity> typedQuery = em.createQuery(sbJpql.toString(), StatusInfoEntity.class); // ID if (facilityIds != null && facilityIds.length > 0) { typedQuery = HinemosEntityManager.appendParam(typedQuery, "facilityId", facilityIds); } // ?? if (priorityList != null && priorityList.length > 0 && priorityList.length != PriorityConstant.PRIORITY_LIST.length) { int count = priorityList.length; if (count > 0) { for (int i = 0; i < count; i++) { typedQuery = typedQuery.setParameter("priority" + i, priorityList[i]); } } } // ? if (outputFromDate != null) { typedQuery = typedQuery.setParameter("outputFromDate", outputFromDate); } // ? if (outputToDate != null) { typedQuery = typedQuery.setParameter("outputToDate", outputToDate); } // if (generationFromDate != null) { typedQuery = typedQuery.setParameter("generationFromDate", generationFromDate); } // if (generationToDate != null) { typedQuery = typedQuery.setParameter("generationToDate", generationToDate); } // ID if (monitorId != null && !"".equals(monitorId)) { if (!monitorId.startsWith(notInclude)) { typedQuery = typedQuery.setParameter("monitorId", monitorId); } else { typedQuery = typedQuery.setParameter("monitorId", monitorId.substring(notInclude.length())); } } // if (monitorDetailId != null && !"".equals(monitorDetailId)) { if (!monitorDetailId.startsWith(notInclude)) { typedQuery = typedQuery.setParameter("monitorDetailId", monitorDetailId); } else { typedQuery = typedQuery.setParameter("monitorDetailId", monitorDetailId.substring(notInclude.length())); } } // if (application != null && !"".equals(application)) { if (!application.startsWith(notInclude)) { typedQuery = typedQuery.setParameter("application", application); } else { typedQuery = typedQuery.setParameter("application", application.substring(notInclude.length())); } } // if (message != null && !"".equals(message)) { if (!message.startsWith(notInclude)) { typedQuery = typedQuery.setParameter("message", message); } else { typedQuery = typedQuery.setParameter("message", message.substring(notInclude.length())); } } //ID if (ownerRoleId != null && !"".equals(ownerRoleId)) { if (!ownerRoleId.startsWith(notInclude)) { typedQuery = typedQuery.setParameter("ownerRoleId", ownerRoleId); } else { typedQuery = typedQuery.setParameter("ownerRoleId", ownerRoleId.substring(notInclude.length())); } } return typedQuery.getResultList(); } public static List<StatusInfoEntity> getStatusInfoByHighPriorityFilter(String[] facilityIds, Long outputFromDate, Long outputToDate, Long generationFromDate, Long generationToDate, String application, String message, String ownerRoleId, boolean orderFlg) { HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); StringBuffer sbJpql = new StringBuffer(); sbJpql.append("SELECT a FROM StatusInfoEntity a WHERE true = true"); // ID if (facilityIds != null && facilityIds.length > 0) { sbJpql.append(" AND a.id.facilityId IN (" + HinemosEntityManager.getParamNameString("facilityId", facilityIds) + ")"); } // ? if (outputFromDate != null) { sbJpql.append(" AND a.outputDate >= :outputFromDate"); } // ? if (outputToDate != null) { sbJpql.append(" AND a.outputDate <= :outputToDate"); } // if (generationFromDate != null) { sbJpql.append(" AND a.generationDate >= :generationFromDate"); } // if (generationToDate != null) { sbJpql.append(" AND a.generationDate <= :generationToDate"); } // if (application != null && !"".equals(application)) { sbJpql.append(" AND a.application like :application"); } // if (message != null && !"".equals(message)) { sbJpql.append(" AND a.message like :message"); } // ID if (ownerRoleId != null && !"".equals(ownerRoleId)) { sbJpql.append(" AND a.ownerRoleId = :ownerRoleId"); } if (orderFlg) { sbJpql.append(" ORDER BY a.priority, a.outputDate DESC"); } else { sbJpql.append(" ORDER BY a.priority"); } TypedQuery<StatusInfoEntity> typedQuery = em.createQuery(sbJpql.toString(), StatusInfoEntity.class); // ID if (facilityIds != null && facilityIds.length > 0) { typedQuery = HinemosEntityManager.appendParam(typedQuery, "facilityId", facilityIds); } // ? if (outputFromDate != null) { typedQuery = typedQuery.setParameter("outputFromDate", outputFromDate); } // ? if (outputToDate != null) { typedQuery = typedQuery.setParameter("outputToDate", outputToDate); } // if (generationFromDate != null) { typedQuery = typedQuery.setParameter("generationFromDate", generationFromDate); } // if (generationToDate != null) { typedQuery = typedQuery.setParameter("generationToDate", generationToDate); } // if (application != null && !"".equals(application)) { typedQuery = typedQuery.setParameter("application", application); } // if (message != null && !"".equals(message)) { typedQuery = typedQuery.setParameter("message", message); } // ID if (ownerRoleId != null && !"".equals(ownerRoleId)) { typedQuery = typedQuery.setParameter("ownerRoleId", ownerRoleId); } typedQuery = typedQuery.setMaxResults(1); return typedQuery.getResultList(); } }