コード例 #1
0
  /**
   * 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());
    }
  }
コード例 #2
0
  /**
   * Method is used to get Presenter material based on presenter code
   *
   * @param presenterCode
   * @return PresenterMaterial object
   */
  public PresenterMaterial getPresenterMaterial(int presenterCode) {
    log.log(Level.INFO, "PresenterMaintenance ---> getPresenterMaterial ");
    Session session = null;
    PresenterMaterial mat = null;
    try {
      session = HibernateFactory.openSession();
      Query selectQ =
          session.createQuery(
              "select materialName,material from PresenterMaterial where presenterCode = "
                  + presenterCode
                  + " and fieldName = 'filename2'");
      List list = selectQ.list();

      if (list != null && list.size() > 0) {
        mat = new PresenterMaterial();
        Object[] objectDoc = (Object[]) list.get(0);
        mat.setMaterialName((String) objectDoc[0]);
        mat.setMaterial((byte[]) objectDoc[1]);
      } else {
        log.log(Level.INFO, "PresenterMaintenance ---> getPresenterMaterial : No Material Found ");
      }

    } catch (Exception e) {
      log.log(Level.SEVERE, e.getMessage());
      e.printStackTrace();
    } finally {
      try {
        HibernateFactory.close(session);

      } catch (Exception e) {
        log.log(Level.SEVERE, e.getMessage());
        e.printStackTrace();
      }
    }
    return mat;
  }