/** * Delete all messages that do not involve users other than the one specified (no other users as sender o recipient) * @param userProfile the receiver/sender of the message */ @Modifying @Transactional(readOnly = false) public void deleteBelongingTo(YadaUserProfile userProfile) { // Messages that have the user as sender or recipient, and nobody else involved, or // where the user is both sender and recipient List <YadaUserMessage> toDelete = YadaSql.instance().selectFrom("select yum from YadaUserMessage yum") .where("(sender=:userProfile and recipient=null)").or() .where("(sender=null and recipient=:userProfile)").or() .where("(sender=:userProfile and recipient=:userProfile)") .setParameter("userProfile", userProfile) .query(em, YadaUserMessage.class).getResultList(); // Need to fetch them all then delete them, in order to cascade deletes to "created" and "attachment" for (YadaUserMessage yadaUserMessage : toDelete) { em.remove(yadaUserMessage); } }
/** * Updates counts of test run. * @param id Test run id. * @param totalCases Total test case count. * @param failedCases Total failed test cases count. */ @Modifying @Transactional @Query("UPDATE TestRun tr SET tr.exampleCount = COALESCE(tr.exampleCount, 0) + :totalCases, " + "tr.failureCount = COALESCE(tr.failureCount, 0) + :failedCases, " + "tr.duration = COALESCE(tr.duration, 0) + :duration " + "WHERE tr.id = :id") void updateCounts(@Param("id") Long id, @Param("totalCases") int totalCases, @Param("failedCases") int failedCases, @Param("duration") double duration);
@Modifying @Query(QueryProperties.updateStaffProfileByEmpId) int updateStaffProfile(@Param("employeeFirstName") String employeeFirstName, @Param("employeeLastName") String employeeLastName, @Param("employeeTitle") String employeeTitle, @Param("employeePhone") String employeePhone, @Param("employeeId") long employeeId);
/** * Opens a new ticket * @param type * @param title * @param messageText initial ticket message * @param sender User opening the ticket * @param severity * @return the newly created ticket */ @Modifying @Transactional(readOnly = false) public YadaTicket addTicket(YadaLocalEnum<?> type, String title, String messageText, YadaUserProfile sender, int severity) { List<YadaTicketMessage> yadaTicketMessages = new ArrayList<>(); YadaTicket yadaTicket = new YadaTicket(); yadaTicket.setStatus(YadaTicketStatus.OPEN); yadaTicket.setPriority(severity); yadaTicket.setType(type); yadaTicket.setOwner(sender); yadaTicket.setTitle(title); YadaTicketMessage yadaTicketMessage = new YadaTicketMessage(); yadaTicketMessage.setTitle(title); yadaTicketMessage.setMessage(messageText); yadaTicketMessage.setSender(sender); // When a ticket is added, no recipient has been chosen yet for the message // yadaTicketMessage.setRecipient(); yadaTicketMessage.setStackable(false); // Same-content messages will never be stacked yadaTicketMessage.setPriority(severity); // message priority is the same as ticket priority yadaTicket.setMessages(yadaTicketMessages); yadaTicketMessage.setYadaTicket(yadaTicket); yadaTicketMessages.add(yadaTicketMessage); em.persist(yadaTicket); // Cascade save return yadaTicket; }
/** * Send a reply to a ticket. * @param yadaTicket * @param messageText * @param replySender the user replying to the previous message, could be either the support staff or the original user * @param supportStaffReply true if this reply is an answer to the user who opened the ticket, false if it is the user answer to the support staff * @param closeTicket true if the replyer has closed the ticket on this reply * @return the new message added to the ticket */ @Modifying @Transactional(readOnly = false) public YadaTicketMessage replyTicket(Long yadaTicketId, String messageText, YadaUserProfile replySender, boolean supportStaffReply, boolean closeTicket) { YadaTicket yadaTicket = em.find(YadaTicket.class, yadaTicketId); // Altrimenti si prende "could not initialize proxy - no Session" alla getMessages() YadaTicketMessage yadaTicketMessage = new YadaTicketMessage(); yadaTicket.getMessages().add(yadaTicketMessage); yadaTicketMessage.setYadaTicket(yadaTicket); yadaTicketMessage.setMessage(messageText); yadaTicketMessage.setTitle(yadaTicket.getTitle()); yadaTicketMessage.setSender(replySender); if (supportStaffReply) { yadaTicketMessage.setRecipient(yadaTicket.getOwner()); } else { yadaTicketMessage.setRecipient(yadaTicket.getAssigned()); // Could be null, but it's ok } yadaTicketMessage.setStackable(false); // Same-content messages will never be stacked yadaTicketMessage.setPriority(yadaTicket.getPriority()); // message priority is the same as ticket priority if (closeTicket) { yadaTicket.setStatus(YadaTicketStatus.CLOSED); } else { // When the owner replies without closing, the ticket becomes OPEN // When the staff replies an open ticket, the status becomes ANSWERED yadaTicket.setStatus(supportStaffReply && yadaTicket.isOpen() ? YadaTicketStatus.ANSWERED : YadaTicketStatus.OPEN); } return yadaTicketMessage; }
@Modifying @Transactional(readOnly = false) @Query("delete from #{#entityName} e where e.expiration is not null and e.expiration < NOW()") void deleteExpired();
@Modifying @Transactional @Query("delete from BotCamera bc where bc.timeTaken < ?1") void deleteOlderThan(Date timeTaken);
@Modifying @Query(value = "delete from user where id = ?", nativeQuery = true) public void deleteUserById(String id);
@Modifying @Query("update Notification n set n.isRead = true where n.touser = ?1") void updateByIsRead(User user);
@Modifying(clearAutomatically = true) @Transactional @Query(nativeQuery = true, value = "DELETE FROM ARTICLE_CATE_LABEL WHERE ARTICLE_ID=:articleId") int deleteArticleCateLabel(@Param("articleId") Long articleId);
@Modifying(clearAutomatically = true) @Transactional @Query(nativeQuery = true, value = "DELETE FROM ARTICLE_CATE_LABEL WHERE ARTICLE_ID=:articleId AND CATE_LABEL_ID NOT IN:cateLabelId") int deleteArticleCateLabel(@Param("articleId") Long articleId, @Param("cateLabelId") List<Long> cateLabelIds);
@Modifying(clearAutomatically = true) @Transactional @Query(nativeQuery = true, value = "UPDATE MEMO_REMIND SET STATUS=:status WHERE ID =:id") int updateStatus(@Param("id") Long id, @Param("status") Integer status);
@Modifying @Transactional @Query(value="DELETE FROM cms_page WHERE bo_type_id = :boTypeId", nativeQuery=true) void deleteByBoTypeId(@Param(value="boTypeId") long boTypeId);
@Modifying @Query("delete from InstanceConfig where ConfigAppId=?1 and ConfigClusterName=?2 and ConfigNamespaceName = ?3") int batchDelete(String appId, String clusterName, String namespaceName);
@Modifying @Transactional(readOnly = false) @Query("delete from #{#entityName} e where e.yadaUserCredentials = :userCredentials and e.type = :facebookType") void deleteByYadaUserCredentialsAndType(@Param("userCredentials") YadaUserCredentials userCredentials, @Param("facebookType") int facebookType);
@Modifying @Query("select p.time,p.psJVM from TomcatResultEntity p where p.tomcatId=(?1) order by p.time asc ") List<TomcatResultEntity> seletctJvmByTomcatId(String id);
@Modifying @Transactional @Query(value="DELETE FROM #{#entityName} t WHERE t.boTypeId = :boTypeId") void deleteByBoTypeId(@Param(value="boTypeId") long boTypeId);
@Modifying @Query("select p from ManagerTomcatEntity p where p.id in (?1)") List<ManagerTomcatEntity> selectByIds(String[] ids);
@Transactional @Modifying @Query("delete from User where id = ?1") void deleteByUserId(Long id);
@Modifying(clearAutomatically = true) @Query(value = "DELETE FROM history_points WHERE seat_id = (:seat_id);", nativeQuery = true) void deleteBy(@Param("seat_id") String idSeat);
@Modifying @Query("select p from TomcatSessionResultEntity p where p.id in (?1)") List<TomcatSessionResultEntity> selectByIds(String[] ids);
@Modifying @Query("select p.time,p.sessionCount from TomcatSessionResultEntity p where p.tomcatId=(?1) order by p.time asc ") List<TomcatSessionResultEntity> seletctSessionByTomcatId(String id);
@Modifying @Query("delete from #{#entityName} m where m.userId = ?1 order by m.dateTime desc limit 1") void deleteUserLastMeal(Long userId);
@Modifying @Query("delete from VerificationToken t where t.expiryDate <= ?1") void deleteAllExpiredSince(Date now);
@Modifying @Transactional @Query(value="UPDATE core_menu SET is_visible=(SELECT t.is_visible FROM (SELECT is_visible FROM core_menu WHERE id = :id) as t) WHERE id IN (:parentIds)", nativeQuery=true) void syncParentsVisible(@Param("id") long id, @Param("parentIds") List<Long> parentIds);
/** * Save a message. If the message is stackable, only increment the counter of an existing message with identical * content and same recipient and same sender and same data, if not older than one day * @param m */ @Modifying @Transactional(readOnly = false) public void createOrIncrement(YadaUserMessage<?> m) { log.debug("YadaUserMessage to {} from {}: [{}] '{}' - {} (data={})", m.getReceiverName()!=null?m.getReceiverName():"-", m.getSender()!=null?m.getSenderName():"-", m.getPriority(), m.getTitle(), m.getMessage(), m.getData()); if (m.getId()!=null) { throw new YadaInvalidUsageException("Message already exists with id=" + m.getId()); } /* Recipient can be null. For example in a ticket. if (m.getRecipient()==null) { throw new YadaInvalidUsageException("Message with no recipient - title=" + m.getTitle()); }*/ if (!m.isStackable()) { em.persist(m); return; } // Need to update an existing row counter if it exists, or insert a new one. // Not using "insert ... on duplicate key update" because of the time window // TODO the time window could be a (configured) parameter Date oldestStackTime = yadaUtil.daysAgo(1); // Time window: one day ago m.computeHash(); // Needed List<YadaUserMessage> existingList = YadaSql.instance().selectFrom("select m from YadaUserMessage m") //YadaTicketMessage? .where("m.contentHash=:contentHash").and() .where("m.modified > :oldestStackTime").and() .where("m.recipient = :recipient").and() .where(m.getSender()!=null, "m.sender = :sender").and() .where(m.getData()!=null, "m.data = :data").and() .orderBy("m.modified desc") .setParameter("contentHash", m.getContentHash()) .setParameter("oldestStackTime", oldestStackTime) .setParameter("recipient", m.getRecipient()) .setParameter("sender", m.getSender()) .setParameter("data", m.getData()) .query(em, YadaUserMessage.class).setMaxResults(1).getResultList(); if (existingList.isEmpty()) { em.persist(m); } else { m = existingList.get(0); m.incrementStack(); m.setReadByRecipient(false); m.setModified(new Date()); } }
@Modifying @Query("update Item set isdeleted=1,DataChange_LastModifiedBy = ?2 where namespaceId = ?1") int deleteByNamespaceId(long namespaceId, String operator);
/** * Here we demonstrate the use of SecurityContext information in dynamic SpEL parameters in a JPQL update statement. */ @Modifying @Query("update BusinessObject b set b.data = upper(b.data), b.lastModifiedBy = :#{#security.principal}, b.lastModifiedDate = :#{new java.util.Date()}") void modifiyDataWithRecordingSecurityContext();
@Modifying @Query("update Commit set isdeleted=1,DataChange_LastModifiedBy = ?4 where appId=?1 and clusterName=?2 and namespaceName = ?3") int batchDelete(String appId, String clusterName, String namespaceName, String operator);
@Modifying @Query(value = "update movie m set m.likes = ?1 where m.id = ?2", nativeQuery = true) void modifyMovieLikesById(long likes, long movieId);
@Modifying @Query(value = "update order_record o set o.partner_id = ?2 where o.id = ?1" , nativeQuery = true) void modifyOrderRecordWithPartnerId(long id, long parnetId);
@Modifying @Query(value = "update order_record o set o.status = ?2 where o.id = ?1" , nativeQuery = true) void modifyOrderRecordWithStatus(long id, int status);
@Modifying @Query(value = "update ticket t set t.status = ?1 where t.id = ?2", nativeQuery = true) void modifyTicketStatusById(int status, long ticketTd);
@Modifying @Query(value = "update ticket t set t.message = ?1 where t.id = ?2", nativeQuery = true) void modifyTicketMessageById(String message, long ticketTd);
@Modifying @Query(value = "delete from RolePrivilege bean where role_id = ?1 and privilege_id = ?2") void deletePrivilegeByRoleId(Long roleId, Long privilegeId);
@Modifying @Query(value = "delete from RolePrivilege bean where role_id = ?1 and privilege_id in ?2") void deletePrivilegesByRoleId(Long roleId, List<Long> privilegeIds);
@Modifying @Query(value="delete from UserPrivilege bean where user_id = ?1", nativeQuery = false) void deleteByUser_id(Long userId);
@Modifying @Query(value="delete from UserPrivilege bean where user_id = ?1 and privilege_id = ?2", nativeQuery = false) void deletePrivilegeByUserId(Long userId, long privilegeId);
@Modifying @Query(value = "delete from UserPrivilege bean where user_id = ?1 and privilege_id in ?2") void deletePrivilegesByUserId(Long userId, List<Long> privilegeIds);
@Modifying @Query(value = "delete from UserPrivilege bean where privilege_id = ?1") void deleteByPrivilegeId(Long privilegeId);