Example #1
0
	public void processSelection(NodeSelectedEvent event) {
		try {
			HtmlTree tree = (HtmlTree) event.getComponent();
			Department bean = (Department) tree.getRowData();
			ID_ = bean.getID_();
			selectRecordById(String.valueOf(ID_));
			orgId = bean.getOrgId();
			parentId = bean.getParentId();
			orgName = bean.getOrgName();
			parentName = bean.getParentName();
			if (FunctionLib.isNum(getMySession().getTempStr().get("Department.move.id"))) {
				Query query = getSession().getNamedQuery("core.department.moverecordbyid");
				query.setParameter("mId", 0);
				query.setParameter("orgId", orgId);
				query.setParameter("parentId", ID_);
				query.setParameter("id", getMySession().getTempStr().get("Department.move.id"));
				query.executeUpdate();
				query = null;
				getMySession().getTempStr().put("Department.move.id", "");

				query = getSession().createSQLQuery("CALL of_update_group(:id)");
				query.setParameter("id", getMySession().getTempStr().get("Department.move.id"));
				query.executeUpdate();

				FunctionLib.refresh();
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
  public void deleteById(Serializable id) {
    Session session = getSessionFactory().getCurrentSession();
    Transaction transaction = session.beginTransaction();

    // ɾ³ý²É¹ºÑ¯¼ÛÃ÷ϸ
    String hql = "delete from BuyOrderList where order.id=:orderId";
    Query query = session.createQuery(hql);
    query.setParameter("orderId", id);
    query.executeUpdate();

    // ɾ³ý¸½¼þ
    hql = "delete from Accessory where sort=:sort and dataId=:dataId";
    query = session.createQuery(hql);
    query.setParameter("sort", OrderState.CGGL_WLCG);
    query.setParameter("dataId", id);
    query.executeUpdate();

    // ÉóºË¼Ç¼
    hql = "delete from AuditMind where sort=:sort and dataId=:dataId";
    query = session.createQuery(hql);
    query.setParameter("sort", OrderState.CGGL_WLCG);
    query.setParameter("dataId", id);
    query.executeUpdate();

    // ɾ³ýÎïÁϲɹºµ¥
    hql = "delete from BuyOrder where id=:id";
    query = session.createQuery(hql);
    query.setParameter("id", id);
    query.executeUpdate();

    transaction.commit();
  }
Example #3
0
 public void deleteUser(WkTUser user) {
   // 首先删除用户角色关系
   Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
   session.beginTransaction();
   String deleteUserRole = "delete WkTUserole as u_r where u_r.id.kuId=?";
   Query dUserRole = session.createQuery(deleteUserRole);
   dUserRole.setLong(0, user.getKuId());
   dUserRole.executeUpdate();
   // 还需要删除用户发布信息、消息等
   String deleteNR = "delete XyNUrd as xnurd where xnurd.id.kuId=?";
   Query updateNRQ = session.createQuery(deleteNR);
   updateNRQ.setLong(0, user.getKuId());
   updateNRQ.executeUpdate();
   String deleteM = "delete XyMReceiver as xmr where xmr.id.kuId=?";
   Query updateM = session.createQuery(deleteM);
   updateM.setLong(0, user.getKuId());
   updateM.executeUpdate();
   String deleteN = "delete XyMessage as xm where xm.kuId=?";
   Query updateN = session.createQuery(deleteN);
   updateN.setLong(0, user.getKuId());
   updateN.executeUpdate();
   session.getTransaction().commit();
   // 删除用户
   getHibernateTemplate().delete(user);
 }
Example #4
0
	/**
	 * 更新一条记录
	 */
	public void updateRecordById() {
		try {
			Map<?, ?> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
			String orgId = (String) params.get("orgId");
			String parentId = (String) params.get("parentId");
			String id = (String) params.get("id");
			if (!FunctionLib.isNum(orgId) || !FunctionLib.isNum(parentId) || !FunctionLib.isNum(id))
				return;
			if ("".equals(depaName)) {
				String msg = getLang().getProp().get(getMySession().getL()).get("name") + getLang().getProp().get(getMySession().getL()).get("cannotbenull");
				getMySession().setMsg(msg, 2);
				return;
			}
			Query query = getSession().getNamedQuery("core.department.updaterecordbyid");
			query.setParameter("mId", 0);
			query.setParameter("depaName", depaName);
			query.setParameter("depaDesc", depaDesc);
			query.setParameter("sequence", sequence);
			query.setParameter("id", id);
			query.executeUpdate();
			query = null;

			query = getSession().getNamedQuery("core.department.of.update");
			query.setParameter("id", id);
			query.executeUpdate();

			String msg = getLang().getProp().get(getMySession().getL()).get("success");
			getMySession().setMsg(msg, 1);
		} catch (Exception ex) {
			String msg = getLang().getProp().get(getMySession().getL()).get("faield");
			getMySession().setMsg(msg, 2);
			ex.printStackTrace();
		}
	}
Example #5
0
  public static String returnItem(String recordId) {
    System.out.println("what happened");

    String record = DBQuerrier.getRecord(recordId);
    if (record.equals("[]")) return "[0]";

    String[] paras = record.split(",");
    // if(!("0".equals(paras[paras.length-2])))
    // return "[0]";

    int borrowCount = 0;
    try {
      borrowCount =
          Integer.parseInt(
              (paras[paras.length - 1].substring(0, paras[paras.length - 1].length() - 1)));
    } catch (Exception e) {
      // TODO: handle exception
    }
    System.out.println("woca" + borrowCount);
    Session session = sessionStart();
    Transaction tx = session.beginTransaction();
    String hql = "update Borrowrecord br set br.returnDate = ? where br.recordId = ?";
    Query query = ((SharedSessionContract) session).createQuery(hql);

    int recordIdInt = 0;

    try {
      recordIdInt = Integer.parseInt(recordId);
    } catch (Exception e) {
      // TODO: handle exception
      return "[0]";
    }
    Date currenTimeDate = new Date();
    query.setTimestamp(0, currenTimeDate);
    query.setInteger(1, recordIdInt);

    int resInt = query.executeUpdate();
    tx.commit();
    session.close();

    // return done , update count
    if (!("".equals(paras[3]))) {
      session = sessionStart();
      tx = session.beginTransaction();
      hql = "update Iteminfo ii set ii.leftcount = ii.leftcount + ? where ii.id = ?";
      query = ((SharedSessionContract) session).createQuery(hql);
      query.setInteger(0, borrowCount);
      int itemIdInt = 0;
      itemIdInt = Integer.parseInt(paras[3]);
      query.setInteger(1, itemIdInt);
      query.executeUpdate();
      tx.commit();
      session.close();
    }

    return "[" + resInt + "]";
  }
 private void deleteContent() {
   Session session = sessionFactory.openSession();
   Transaction tr = session.beginTransaction();
   Query query = session.createQuery("delete from Simple");
   query.executeUpdate();
   query = session.createQuery("delete from SimpleBase");
   query.executeUpdate();
   tr.commit();
   session.close();
 }
Example #7
0
  /** 解密文件 */
  public void notlockFile(String notfileId, String notlick_password) {

    int id = Integer.parseInt(notfileId);

    String sqlL = "update File f set f.isLock=0 where f.id=" + id;
    Query qL = sessionFactory.getCurrentSession().createQuery(sqlL);
    qL.executeUpdate();

    String sqlp = "update File f set f.password ='' where f.id=" + id;
    Query qp = sessionFactory.getCurrentSession().createQuery(sqlp);
    qp.executeUpdate();
  }
Example #8
0
  /** 分享文件 */
  public void shareFile(String path, File file, User user, HttpSession httpSession) {
    // 分享时间
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    String createDate = df.format(new Date());
    // 文件的location
    String location = path + "\\" + file.getName();
    // 文件的类型type
    String type = file.getType();
    // 文件的描述
    User u = (User) httpSession.getAttribute("u");
    String description = u.getStuNo() + "分享给我的文件";

    File fileShare = new File();
    fileShare.setUser(user);
    fileShare.setSize(file.getSize());
    fileShare.setPath(path);
    fileShare.setName(file.getName());
    fileShare.setType(type);
    fileShare.setPassword("");
    fileShare.setIsLock(0);
    fileShare.setIsShare(0);
    fileShare.setShareDownload(0);
    fileShare.setDescription(description);
    fileShare.setLocation(location);
    fileShare.setShareUrl("");
    fileShare.setCreateDate(createDate);

    sessionFactory.getCurrentSession().save(fileShare);

    // 更改被分享的文件属性,是否被分享
    String sql = "update File f set f.isShare=1 where f.id=" + file.getId();
    Query q = sessionFactory.getCurrentSession().createQuery(sql);
    q.executeUpdate();

    // 更改被分享的文件属性,被分享次数
    int shareNun = file.getShareDownload() + 1;
    String sqlS = "update File f set f.shareDownload=" + shareNun + "  where f.id=" + file.getId();
    Query qS = sessionFactory.getCurrentSession().createQuery(sqlS);
    qS.executeUpdate();

    // 分享文件后,网盘中的分享文件数量要更改
    // 得到网盘中的分享文件数量
    String sqlN = "select count(*) from File f where f.user.id=" + u.getId() + " and f.isShare=1";
    Query qN = sessionFactory.getCurrentSession().createQuery(sqlN);
    long shareNumL = (Long) qN.uniqueResult();
    int shareNum = (int) shareNumL;

    // 更新网盘分享文件的数量
    String sqlSD = "update Disk d set d.shareNumber=" + shareNum + " where d.user.id=" + u.getId();
    Query qSD = sessionFactory.getCurrentSession().createQuery(sqlSD);
    qSD.executeUpdate();
  }
 public int deleteDeptPsn(SalDeptPsn sdp) {
   StringBuilder sb = new StringBuilder();
   sb.append("delete SalDeptPsn sdp where sdp.id = :id");
   Query q = getSession().createQuery(sb.toString());
   q.setParameter("id", sdp.getId());
   return q.executeUpdate();
 }
 public void deleteDonViTinhTen(String dvtTen) {
   session.beginTransaction();
   String sql = "update DonViTinh set daXoa = 1 where dvtTen = '" + dvtTen + "'";
   Query query = session.createQuery(sql);
   query.executeUpdate();
   session.getTransaction().commit();
 }
Example #11
0
  public int updateAppointment(
      Appointment appointment,
      Date appointmentDate,
      int appointmentId,
      int timeSlot,
      int doctorId) {
    initializeTransaction();
    String hql;
    int result = 0;
    hql =
        "UPDATE APPOINTMENT SET time_slot = :timeSlot, "
            + ",appointment_date = :appointmentDate"
            + ",booked_date = :currentDate"
            + " , doctor_id = :doctorId"
            + " , room_id = :roomId"
            + "WHERE appointment_id = :appointmentId";
    try {
      Query query = session.createQuery(hql);

      query.setParameter(":timeSlot", 60);
      query.setParameter(":appointmentDate", appointmentDate);
      query.setParameter(":currentDate", (new java.util.Date()).toString());
      query.setParameter(":doctorId", doctorId);
      query.setParameter(":roomId", 5);
      query.setParameter(":appointmentId", appointmentId);

      result = query.executeUpdate();

    } catch (Exception e) {
      e.printStackTrace();
    }

    session.save(appointment);
    return result;
  }
Example #12
0
 public Long deleteUser(Long userId) {
   Session session = sessionFactory.getCurrentSession();
   Query query = session.createQuery("delete User where id = :ID");
   query.setParameter("ID", new Long(userId));
   Long result = (long) query.executeUpdate();
   return result;
 }
Example #13
0
 @SuppressWarnings("unchecked")
 @Override
 public Users checkUsers(Users users) {
   // TODO Auto-generated method stub
   try {
     String queryString = "from Users as model where model.account= ? and model.password= ?";
     Query queryObject = getCurrentSession().createQuery(queryString);
     queryObject.setParameter(0, users.getAccount());
     queryObject.setParameter(1, users.getPassword());
     List<Users> results = queryObject.list();
     if (results.size() > 0) {
       Timestamp tt = new Timestamp(System.currentTimeMillis());
       queryString = "update Users as model set model.logintime= ? where model.account= ?";
       Query query = this.getCurrentSession().createQuery(queryString);
       query.setParameter(0, tt);
       query.setParameter(1, users.getAccount());
       query.executeUpdate();
       return (Users) results.get(0);
     } else {
       return null;
     }
   } catch (Exception e) {
     System.out.println("getusers error:" + e.getMessage());
     return null;
   }
 }
  /**
   * Method is used to save presenter material details in db
   *
   * @param session
   * @param pCode presenter code
   * @param op (INSERT/UPDATE)
   * @param HttpServletRequest requestParameters
   * @param pCode
   * @param byteSession
   * @param field_name
   */
  public void storeMaterialToDB(
      Session session,
      int pCode,
      String op,
      HttpServletRequest requestParameters,
      String byteSession,
      String file_name,
      String field_name) {

    try {

      if (op.equals("UPDATE")) {
        Query deleteQ =
            session.createQuery(
                "delete PresenterMaterial where presenterCode =:presenterCode and fieldName =:fieldName");
        deleteQ.setParameter("presenterCode", pCode);
        deleteQ.setParameter("fieldName", field_name);
        deleteQ.executeUpdate();
      }
      PresenterMaterial preMat = null;
      byte[] bytearray = (byte[]) requestParameters.getSession().getAttribute(byteSession);
      if (pCode > 0) {
        preMat = new PresenterMaterial();
        preMat.setPresenterCode(pCode);
        preMat.setMaterialName(file_name);
        preMat.setFieldName(field_name);
        preMat.setMaterial(bytearray);
        session.save(preMat);
      }
      log.log(Level.INFO, "---PresenterMaintenance Upload Material  Done---");
    } catch (Exception e) {
      e.printStackTrace();
      log.log(Level.SEVERE, e.getMessage());
    }
  }
Example #15
0
 public void execute(final String statement, Object... values) {
   Query query = getSession().createQuery(statement);
   for (int position = 0; position < values.length; position++) {
     query.setParameter(position, values[position]);
   }
   query.executeUpdate();
 }
Example #16
0
 public void execute(final String statement, final Map paraMap) {
   Query query = getSession().createQuery(statement);
   if (paraMap != null) {
     query.setProperties(paraMap);
   }
   query.executeUpdate();
 }
Example #17
0
 public boolean delOsunitHasSByUnitID(Integer UnitID) {
   Query query = null;
   query = this.getSession().createSQLQuery("delete from OSUnitHasS where UnitID = ?");
   query.setParameter(0, UnitID);
   query.executeUpdate();
   return true;
 }
 @Override
 @Transactional
 public String updateDomainApplicationPlanMappingDetails(
     DomainApplicationPlanMapping domainApplicationPlanMapping, Long subscriptionId)
     throws Exception {
   String result = null;
   try {
     Query query =
         sessionFactory
             .getCurrentSession()
             .createQuery(
                 "update DomainApplicationPlanMapping set PLAN_START_DATE=:startDate,PLAN_EXPIRY_DATE=:endDate,UPDATED_DATE=:updatedDate,"
                     + "UPDATED_BY=:updatedBy where SUBSCRIPTION_ID=:subId");
     query.setParameter("startDate", domainApplicationPlanMapping.getPlanStartDate());
     query.setParameter("endDate", domainApplicationPlanMapping.getPlanExpiryDate());
     query.setParameter("updatedDate", domainApplicationPlanMapping.getUpdatedDate());
     query.setParameter("updatedBy", domainApplicationPlanMapping.getUpdatedBy());
     query.setParameter("subId", subscriptionId);
     query.executeUpdate();
   } catch (Exception e) {
     result = e.getMessage();
     e.printStackTrace();
     throw e;
   }
   return result;
 }
Example #19
0
 public void deleteMessage(int fromId, long messageId) {
   String sql = "delete from Message where fromid=? and id=?";
   Query query = this.getQuery(sql);
   query.setParameter(0, fromId);
   query.setParameter(1, messageId);
   query.executeUpdate();
 }
Example #20
0
 @Override
 public void deleteOrderBoards(Order order) {
   Query query = getSession().getNamedQuery("deleteOrderBoardsByOrder");
   query.setEntity("order", order);
   query.setString("status", StoreElementStatus.order.name());
   query.executeUpdate();
 }
  @RequestMapping(value = "convert")
  @Transactional(propagation = Propagation.REQUIRES_NEW)
  public String validateImages() throws Exception {
    final Session session = sessionFactory.getCurrentSession();
    final Query query =
        session.createQuery(
            "select id, name from billiongoods.server.warehouse.impl.HibernateCategory");
    final List list = query.list();
    for (Object o : list) {
      final Object[] v = (Object[]) o;

      final Integer id = (Integer) v[0];
      final String name = (String) v[1];

      final String s = symbolicConverter.generateSymbolic(name);

      final Query query1 =
          session.createQuery(
              "update billiongoods.server.warehouse.impl.HibernateCategory set symbolic=:n where id=:id");
      query1.setParameter("id", id);
      query1.setParameter("n", s);
      query1.executeUpdate();
    }
    return "/content/maintain/main";
  }
Example #22
0
  public void removePlayerFromLeague(League league, Player player) {
    //		List<PlayerLeague> playerLeagues = hibernateTemplate.find(getPlayerLeagueQuery("", "where
    // playerleague.player.id=? and playerleague.league.id=?"),
    //				new Object[] {player.getId(), league.getId()});
    //		if (!playerLeagues.isEmpty())
    //		{
    //		 hibernateTemplate.delete(playerLeagues.iterator().next());
    //		}
    //		if (!playerLeagues.isEmpty())
    //		{
    //			dao.delete(playerLeagues.iterator().next());
    //		}

    Query query =
        getQuery(
            getPlayerLeagueQuery(
                "", "where playerleague.player.id=? and playerleague.league.id=?"));
    query.setParameter(0, player.getId());
    query.setParameter(1, league.getId());

    List<PlayerLeague> playerLeagues = query.list();

    for (PlayerLeague playerLeague : playerLeagues) {
      Query query2 = getQuery("delete from playerLeague where id = ?");
      query2.setParameter(0, playerLeague.getId());

      query2.executeUpdate();
    }
  }
Example #23
0
 @Override
 public void deleteSubscription(int userId, int forumId) {
   // TODO Auto-generated method stub
   Session session = this.sessionFactory.openSession();
   Transaction tx = null;
   try {
     tx = session.beginTransaction();
     Query query =
         session.createQuery(
             "delete from Subscription where userId = :userId and forumId = :forumId");
     query.setParameter("userId", userId);
     query.setParameter("forumId", forumId);
     int result = query.executeUpdate();
     System.out.println("Execute query..");
     if (result > 0) {
       tx.commit();
       // System.out.println("Subscription Removed..");
     } else {
       // System.out.println("Subscription does not exist");
       tx.rollback();
     }
   } catch (HibernateException e) {
     if (tx != null) {
       tx.rollback();
       e.printStackTrace();
     }
   } finally {
     session.close();
   }
 }
Example #24
0
  @Override
  public boolean deleteUser(Integer id) throws Exception {
    dLog.info("Entering method deleteUser | User ID:" + id);
    boolean result = false;
    Session session = null;

    try {
      session = getSession();
      String hql = "delete from User where id = " + id.toString();
      Query query = session.createQuery(hql);
      int row = query.executeUpdate();

      if (row > 0) {
        result = true;
      }
    } catch (Exception e) {
      dLog.error("Exception in deleteUser", e);
    } finally {
      // ensure that session is close regardless of the errors in try/catch
      if (session != null) {
        session.close();
      }
    }

    return result;
  }
Example #25
0
  /** 加密文件 */
  public void lockFile(String fileId, String lick_password) {

    int id = Integer.parseInt(fileId);

    String sqlL = "update File f set f.isLock=1 where f.id=" + id;
    Query qL = sessionFactory.getCurrentSession().createQuery(sqlL);
    qL.executeUpdate();

    String sqlp =
        "update File f set f.password = '******' where f.id="
            + id;
    Query qp = sessionFactory.getCurrentSession().createQuery(sqlp);
    qp.executeUpdate();
  }
 public int anonymizeHelperAddresses() {
   SessionHolder sessionHolder = SessionManager.getInstance().registerSession(this, null);
   try {
     sessionHolder.beginTransaction();
     Query qry =
         sessionHolder.createQuery(
             "UPDATE "
                 + Helper.class.getSimpleName()
                 + " SET "
                 + Helper.ATTR_MAIL_ADDRESS
                 + " = :address WHERE "
                 + Helper.ATTR_MAIL_ADDRESS
                 + " IS NOT NULL AND "
                 + Helper.ATTR_MAIL_ADDRESS
                 + " <> ''");
     qry.setParameter(
         "address",
         AppConfiguration.getInstance()
             .getConfigurationValue(AppConfigurationValues.PROCESS_TEST_MAIL));
     int rows = qry.executeUpdate();
     sessionHolder.commitTransaction();
     return rows;
   } catch (Exception e) {
     sessionHolder.rollbackTransaction();
     ;
     throw new ResourcePlanningException(
         "helper addresses could not be anonymized : " + e.getMessage());
   } finally {
     SessionManager.getInstance().unregisterSession(sessionHolder);
   }
 }
 public void deleteDonViTinh(int dvtId) {
   session.beginTransaction();
   String sql = "update DonViTinh set daXoa = 1 where dvtId = " + dvtId;
   Query query = session.createQuery(sql);
   query.executeUpdate();
   session.getTransaction().commit();
 }
Example #28
0
  @Override
  public void deleteByTransID(String transID) {

    Session session = null;
    Transaction tx = null;
    String hql = null;
    // SystemUser user = null;
    try {
      session = HibernateUtil.getSession();

      tx = session.beginTransaction();

      hql = "delete from CheckPlan where trans_id=?";
      Query query = session.createQuery(hql);
      query.setString(0, transID);

      query.executeUpdate();

      tx.commit();
    } catch (RuntimeException re) {
      throw re;
    } finally {
      if (null != session) {
        session.close();
      }
    }
  }
 @Override
 public void update_PictureLog(Sys_Picture picture) {
   // TODO Auto-generated method stub
   Query query = getSession().createQuery("update Sys_Picture  t set t.flag = '" + 0 + "' ");
   query.executeUpdate();
   this.getSession().update(picture);
 }
Example #30
0
  /*
   * (non-Javadoc)
   *
   * @see cn.tinder.fuego.dao.CheckPlanDao#delete(cn.tinder.fuego.domain.po.CheckPlan )
   */
  @Override
  public void delete(CheckPlan plan) {
    // TODO Auto-generated method stub
    log.debug("[DAO] Delete the CheckPlan:" + plan.toString());

    Session session = null;
    Transaction tx = null;
    String hql = null;
    // SystemUser user = null;
    try {
      session = HibernateUtil.getSession();

      tx = session.beginTransaction();

      hql = "delete from CheckPlan where trans_id=? and dept_id=? ";
      Query query = session.createQuery(hql);
      query.setString(0, plan.getTransID());
      query.setString(1, plan.getDeptID());

      query.executeUpdate();

      tx.commit();
    } catch (RuntimeException re) {
      throw re;
    } finally {
      if (null != session) {
        session.close();
      }
    }

    log.debug("[DAO] Success!Delete the CheckPlan:" + plan.toString());
  }