Beispiel #1
0
 /* (non-Javadoc)
  * @see mx.com.bbva.bancomer.commons.business.BbvaIBusinessObject#createCommand(mx.com.bbva.bancomer.commons.model.dto.BbvaAbstractDataTransferObject)
  */
 @Override
 public <T extends BbvaAbstractDataTransferObject> T createCommand(
     T bbvaAbstractDataTransferObject) {
   logger.debug("Entrada createCommand          -- OK");
   logger.debug("Datos de Entrada createCommand -- " + bbvaAbstractDataTransferObject.toString());
   UsuarioVO usuarioVO = ((UsuarioDTO) bbvaAbstractDataTransferObject).getUsuarioVO();
   String userName = usuarioVO.getNombreUsuario();
   int idPerfil = usuarioVO.getIdPerfil();
   int idEstatus = usuarioVO.getEstatusUsuario();
   usuarioVO = readCommand(usuarioVO);
   ((UsuarioDTO) bbvaAbstractDataTransferObject).getUsuarioVO().setIdPerfil(idPerfil);
   ((UsuarioDTO) bbvaAbstractDataTransferObject).getUsuarioVO().setNombreUsuario(userName);
   ((UsuarioDTO) bbvaAbstractDataTransferObject).getUsuarioVO().setEstatusUsuario(idEstatus);
   if (usuarioVO == null) {
     SqlSession session = MapeadorSessionFactory.getSqlSessionFactory().openSession();
     MapUsuario mapUsuario = session.getMapper(MapUsuario.class);
     try {
       mapUsuario.crearUsuario(((UsuarioDTO) bbvaAbstractDataTransferObject).getUsuarioVO());
       session.commit();
     } catch (Exception ex) {
       session.rollback();
       ex.printStackTrace();
       bbvaAbstractDataTransferObject.setErrorCode("SQL-001");
       bbvaAbstractDataTransferObject.setErrorDescription(ex.getMessage());
     } finally {
       session.close();
     }
     logger.debug("Datos de Salida invoke -- " + bbvaAbstractDataTransferObject.toString());
     logger.debug("Salida invoke          -- OK");
   } else {
     bbvaAbstractDataTransferObject.setErrorCode("0001");
     bbvaAbstractDataTransferObject.setErrorDescription("El usuario ya existe");
   }
   return bbvaAbstractDataTransferObject;
 }
Beispiel #2
0
  /**
   * 新增資費佣金資料
   *
   * @return int 筆數
   * @throws Exception
   */
  public boolean insert(TeleratesVo vo) throws Exception {
    SqlSession session = null;
    boolean status = false;
    int cnt = 0;
    try {
      session = getSession(false);
      cnt = session.insert("teleRates.insert", vo);
      session.commit();
      if (cnt > 0) {
        status = true;
      }

      //			StoreMonitorService.notifyCustomerQualifyTagChange();
      StoreMonitorService.notifyDataTagChange();
      StoreMonitorService.notifyVoiceTagChange();
    } catch (Exception e) {
      e.printStackTrace();
      logger.error(e.getMessage());
      session.rollback();
      throw e;
    } finally {
      closeCoonnection(session);
    }

    return status;
  }
  @Override
  public UserProfile checkAuthenticationDB(String username, String password) throws Exception {

    SqlSession session = SqlMapConfig.getSqlSession(false);

    try {

      // Run command ----------------------------------------------------
      Map<String, Object> map = new HashMap<String, Object>();

      map.put("username", username);
      map.put("password", password);

      UserProfile userProfile = session.selectOne("UserProfile.getUserProfile", map);

      session.commit();

      return userProfile;

    } catch (Exception e) {

      session.rollback();

      throw e;

    } finally {

      session.clearCache();
      session.close();
      session = null;
    }
  }
Beispiel #4
0
  @Test
  public void should_insert_using_existing_session() throws Exception {
    setupData("insert");

    ResourceDto file1 =
        new ResourceDto()
            .setUuid("ABCD")
            .setKey("org.struts:struts:/src/main/java/org/struts/Action.java")
            .setDeprecatedKey("org.struts:struts:org.struts.Action")
            .setScope(Scopes.FILE)
            .setQualifier(Qualifiers.FILE)
            .setLanguage("java")
            .setName("Action")
            .setLongName("org.struts.Action");
    ResourceDto file2 =
        new ResourceDto()
            .setUuid("BCDE")
            .setKey("org.struts:struts:/src/main/java/org/struts/Filter.java")
            .setDeprecatedKey("org.struts:struts:org.struts.Filter")
            .setScope(Scopes.FILE)
            .setQualifier(Qualifiers.FILE)
            .setLanguage("java")
            .setName("Filter")
            .setLongName("org.struts.Filter");

    SqlSession session = getMyBatis().openSession();

    dao.insertUsingExistingSession(file1, session);
    dao.insertUsingExistingSession(file2, session);

    session.rollback();

    assertEmptyTables("projects");
  }
Beispiel #5
0
  /** USE THIS INSTEAD OF THE BATGEN DELETE It also deletes associated events of the object.s */
  public int delete(Long key) throws BoException {
    SqlSession session = null;
    int result = 0;
    String where = "KEY='" + key + "' ";
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("where", where);

    // first delete all events associated with this object
    EventBo.getInstance().deleteEventsOf(ItemType.SOFTWARE, key);

    try {
      session = SessionFactory.getSession();
      SoftwareDao mapper = session.getMapper(SoftwareDao.class);
      result = mapper.delete(map);
      session.commit();

    } catch (Exception e) {
      session.rollback();
      throw new BoException(e);

    } finally {
      if (session != null) session.close();
    }

    return result;
  }
  @Override
  public int sell(Map<Integer, Integer> sells, Date date, String bz, String uId, int shopId)
      throws Exception {
    int ret = 0;
    SqlSession sqlSession = null;

    try {
      sqlSession = SessionUtils.getSession();

      SellMapper sellMapper = sqlSession.getMapper(SellMapper.class);
      SellDetailMapper sellDetailMapper = sqlSession.getMapper(SellDetailMapper.class);
      StockMapper stockMapper = sqlSession.getMapper(StockMapper.class);

      Sell sell = new Sell();
      sell.setsBz(bz);
      sell.setsDate(date);
      sell.setShopId(shopId);
      sell.setuId(uId);

      sellMapper.insert(sell);

      Iterator<Integer> iterator = sells.keySet().iterator();
      List<Stock> stocks = stockMapper.selectAll();

      while (iterator.hasNext()) {
        SellDetail sellDetail = new SellDetail();
        sellDetail.setSellId(sell.getsId());
        sellDetail.setpId(iterator.next());
        sellDetail.setsNum(sells.get(sellDetail.getpId()));
        sellDetailMapper.insert(sellDetail);

        for (Stock stock : stocks) {
          if (stock.getShopId() == shopId && stock.getpId() == sellDetail.getpId()) {
            if (stock.getsNum() >= sellDetail.getsNum()) {
              stock.setsNum(stock.getsNum() - sellDetail.getsNum());
              stockMapper.updateByPrimaryKey(stock);
            } else {
              throw new Exception();
            }
          }
        }
      }

      sqlSession.commit();
      ret = 1;
    } catch (Exception e) {
      sqlSession.rollback();
      throw e;
    } finally {
      SessionUtils.closeSession(sqlSession);
    }

    return ret;
  }
 public List<ServerInfo> queryListById(int serverId) {
   String smtpId = "ServerInfo.queryById";
   List<ServerInfo> list = null;
   try {
     session = sessionFactory.openSession();
     list = session.selectList(smtpId, serverId);
     session.close();
   } catch (Exception e) {
     session.rollback();
     e.printStackTrace();
   }
   return list;
 }
 public void createStudentWithMap(Map<String, Object> studentDataMap) {
   SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
   try {
     StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
     mapper.insertStudentWithMap(studentDataMap);
     sqlSession.commit();
   } catch (Exception e) {
     sqlSession.rollback();
     e.printStackTrace();
     throw new RuntimeException(e.getCause());
   } finally {
     sqlSession.close();
   }
 }
 public Student updateStudent(Student student) {
   SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
   try {
     StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
     mapper.updateStudent(student);
     sqlSession.commit();
     return student;
   } catch (Exception e) {
     sqlSession.rollback();
     e.printStackTrace();
     throw new RuntimeException(e.getCause());
   } finally {
     sqlSession.close();
   }
 }
Beispiel #10
0
 @Test
 public void noParameterMApperMethod() {
   SqlSession session = MyBatisTestUtil.getSession();
   EntityMapper mapper = session.getMapper(EntityMapper.class);
   try {
     mapper.deleteAll();
     session.commit();
   } catch (Exception e) {
     e.printStackTrace();
     Assert.assertTrue(false);
     session.rollback();
   } finally {
     session.close();
   }
 }
 public boolean deleteStudent(int id) {
   SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
   try {
     StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
     int count = mapper.deleteStudent(id);
     sqlSession.commit();
     return count > 0;
   } catch (Exception e) {
     sqlSession.rollback();
     e.printStackTrace();
     throw new RuntimeException(e.getCause());
   } finally {
     sqlSession.close();
   }
 }
  @Test
  public void test() throws Exception {

    SqlSession session = SessionFactory.getSession();
    AgileListDao agileListDao = session.getMapper(AgileListDao.class);

    try {

      AgileList agileList = TestAgileListDao.createAgileList();
      String where = "KEY='" + agileList.getKey() + "' ";
      Map<String, Object> map = new HashMap<String, Object>();
      map.put("where", where);

      int count = agileListDao.create(agileList);
      assertEquals(1, count);
      assertNotNull(agileList.getKey());

      AgileList readRecord = agileListDao.read(map);
      assertNotNull(readRecord.getKey());

      compareRecords(agileList, readRecord);

      List<AgileList> list1 = agileListDao.getListByStoryId(agileList.getStoryId());
      assertEquals(1, list1.size());
      compareRecords(agileList, list1.get(0));

      modifyRecord(agileList);
      count = agileListDao.update(agileList);
      assertEquals(1, count);

      readRecord = agileListDao.read(map);
      assertNotNull(readRecord.getKey());

      compareRecords(agileList, readRecord);

      count = agileListDao.delete(map);
      assertEquals(1, count);

      readRecord = agileListDao.read(map);
      assertNull(readRecord);

    } finally {
      if (session != null) {
        session.rollback();
        session.close();
      }
    }
  }
Beispiel #13
0
  @Override
  public int editNotice(Notice notice) {

    SqlSession session = factory.openSession();

    int result = 0;

    try {
      result = session.update("com.fantastic.web.dao.NoticeDao.editNotice", notice);
      session.commit();
    } finally {
      session.rollback();
      session.close();
    }
    return result;
  }
Beispiel #14
0
  /**
   * 新增專案
   *
   * @return boolean
   * @throws Exception
   */
  public boolean insertNewProjectAndAttribut(ProjectVo vo, List<Projects_attributeJsonVo> avo)
      throws Exception {
    SqlSession session = null;
    boolean status = false;
    int cnt = 0;
    int cntAvo = 0;
    String json = "";
    try {
      logger.debug("insertNewProjectAndAttribut entry ======");

      session = getSession(false);
      // insert a new major project
      cnt = session.insert("project.insertProject", vo);

      // setting the project id to attributes
      for (Projects_attributeJsonVo d : avo) {
        d.setPid(vo.getId());
      }

      // transfer the attributes to its JsonVo
      ProjectJsonVo pvo = new ProjectJsonVo();
      pvo.setMajorPrjAttributes(avo);

      // to Json
      Gson gson = new Gson();
      json = gson.toJson(pvo);

      DB_jsonMappingVo dbMapVo = new DB_jsonMappingVo();
      dbMapVo.setId(vo.getId());
      dbMapVo.setJson(json);
      cnt = session.update("project.updateProjectAttribute", dbMapVo);

      if (cnt > 0) {
        status = true;
      }
      session.commit();
    } catch (Exception e) {
      e.printStackTrace();
      logger.error(e.getMessage());
      session.rollback();
      throw e;
    } finally {
      closeCoonnection(session);
    }

    return status;
  }
Beispiel #15
0
  /**
   * 根據id刪除主專案
   *
   * @return boolean 成功或失敗
   */
  public boolean deletePrjInfo(long id) {
    SqlSession session = null;
    boolean status = false;
    int cnt = 0;
    try {
      session = getSession(false);

      Project_subsetVo psVo = new Project_subsetVo();
      ProjectSubsetDao psDao = new ProjectSubsetDao(getDataSourceEnvironment());
      List<Project_subsetVo> psList = null;
      // 根據主專案id先取得所屬子專案資料
      psList = psDao.findByPrjId(id);

      Project_aggregateVo paVo = new Project_aggregateVo();
      ProjectAggregateDao paDao = new ProjectAggregateDao(getDataSourceEnvironment());

      if (!NullTK.isNull(psList)) {
        for (Project_subsetVo d : psList) {
          List<Project_aggregateVo> paList = null;
          View_project_aggregateVo rvo = new View_project_aggregateVo();
          // 根據子專案id取得所屬銷售組合之資料
          paList = paDao.findBySubsetId(d.getId());
          for (Project_aggregateVo dd : paList) {
            // 根據銷售組合資料刪除所屬的費率與佣金資料
            cnt = session.delete("rates.deleteById", dd.getRateid());
            cnt = session.delete("commission.deleteById", dd.getComissionid());
          }
          // 根據子專案id刪除所屬隻銷售組合資料
          cnt = session.delete("projectAggregate.deleteBySubsetId", d.getId());
        }
        cnt = session.delete("projectSubset.deleteByPrjId", id);
      }
      cnt = session.delete("project.deleteById", id);

      session.commit();
      if (cnt > 0) {
        status = true;
      }
    } catch (Exception e) {
      e.printStackTrace();
      logger.error(e.getMessage());
      session.rollback();
    } finally {
      closeCoonnection(session);
    }
    return status;
  }
Beispiel #16
0
  @Override
  public int removeNotice(String code) {
    // TODO Auto-generated method stub

    SqlSession session = factory.openSession();

    int result = 0;

    try {
      result = session.delete("com.fantastic.web.dao.NoticeDao.removeNotice", code);
      session.commit();
    } finally {
      session.rollback();
      session.close();
    }
    return result;
  }
Beispiel #17
0
  @Override
  public int addNotice(Notice notice) {
    // TODO Auto-generated method stub

    SqlSession session = factory.openSession();

    int result = 0;

    try {
      result = session.insert("com.fantastic.web.dao.NoticeDao.addNotice", notice);
      session.commit();
    } finally {
      session.rollback();
      session.close();
    }
    return result;
  }
Beispiel #18
0
  private static boolean showMessage(WebMessage pWebMessage) {

    boolean lBlnResult = false;

    mLog.debug("Start showMessage(WebMessage)");

    SqlSessionFactory lSqlSessionFactory =
        SqlSessionFactoryManager.getInstance().getSqlSessionFactoryBibisco();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {

      MessagesMapper lMessagesMapper = lSqlSession.getMapper(MessagesMapper.class);
      Messages lMessages = lMessagesMapper.selectByPrimaryKey(pWebMessage.getIdMessage());

      if (lMessages != null) {
        // message already read: check if i can show another time
        if (lMessages.getNumberOfViews() < pWebMessage.getNumberOfViewsAllowed()) {
          lMessages.setNumberOfViews(lMessages.getNumberOfViews() + 1);
          lMessagesMapper.updateByPrimaryKey(lMessages);
          lBlnResult = true;
        } else {
          lBlnResult = false;
        }
      } else {
        // message not read
        lMessages = new Messages();
        lMessages.setIdMessage(pWebMessage.getIdMessage());
        lMessages.setNumberOfViews(1);
        lMessagesMapper.insert(lMessages);
        lBlnResult = true;
      }

      lSqlSession.commit();

    } catch (Throwable t) {
      mLog.error(t);
      lSqlSession.rollback();
      throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION);
    } finally {
      lSqlSession.close();
    }

    mLog.debug("End showMessage(WebMessage)");

    return lBlnResult;
  }
Beispiel #19
0
  /**
   * Deletes all data (rows) from SOFTWARE
   *
   * @throws BoException
   */
  public void deleteAll() throws BoException {
    SqlSession session = null;

    try {
      session = SessionFactory.getSession();
      SoftwareDao mapper = session.getMapper(SoftwareDao.class);
      mapper.deleteAll();
      session.commit();

    } catch (Exception e) {
      session.rollback();
      throw new BoException(e);

    } finally {
      if (session != null) session.close();
    }
  }
  public StreamServer getStreamServerById(long id) {
    StreamServer s = null;
    SqlSession sql =
        StreamManager.getSqlSessionFactory().openSession(TransactionIsolationLevel.SERIALIZABLE);

    try {
      StreamServerDao dao = sql.getMapper(StreamServerDao.class);
      s = dao.getStreamServerById(id);
      sql.commit();
    } catch (Exception e) {
      sql.rollback();
      e.printStackTrace();
    } finally {
      sql.close();
    }

    return s;
  }
  public List<StreamServer> getAllStreamServers() {
    List<StreamServer> svlist = null;
    SqlSession sql =
        StreamManager.getSqlSessionFactory().openSession(TransactionIsolationLevel.SERIALIZABLE);

    try {
      StreamServerDao dao = sql.getMapper(StreamServerDao.class);
      svlist = dao.getAllStreamServers();
      sql.commit();
    } catch (Exception e) {
      sql.rollback();
      e.printStackTrace();
    } finally {
      sql.close();
    }

    return svlist;
  }
Beispiel #22
0
  /**
   * 批量新增
   *
   * @param vo MemberVo
   * @return boolean 成功或失敗
   */
  public void batchInsert(List<MemberVo> list) {
    SqlSession session = null;
    try {
      session = getSession(false);
      // vo.setStatus(STAUS_ENABLE);
      for (MemberVo v : list) {
        session.update("member.insert", v);
      }

      session.commit();
    } catch (Exception e) {
      e.printStackTrace();
      logger.error(e.getMessage());
      session.rollback();
    } finally {
      closeCoonnection(session);
    }
  }
Beispiel #23
0
  /**
   * 批量新增
   *
   * @param vo Goods_costVo
   * @return boolean 成功或失敗
   * @throws Exception
   */
  public void batchUpdate(List<ProjectVo> list) throws Exception {
    SqlSession session = null;
    try {
      session = getSession(false);
      for (ProjectVo v : list) {
        session.update("project.update2", v);
      }

      session.commit();
    } catch (Exception e) {
      e.printStackTrace();
      logger.error(e.getMessage());
      session.rollback();
      throw e;
    } finally {
      closeCoonnection(session);
    }
  }
Beispiel #24
0
  /**
   * Executes the specified action on the action.service() service.
   *
   * @param action the action to be executed.
   * @return the response.
   * @throws SerializationException the serialization exception
   */
  public HasResponse execute(HasService action) throws SerializationException {

    HasResponse response = null;
    LOG.debug("\n\nRazorServer execute " + action.getClass().getName() + "\naction " + action);
    String classname = action.service().classname();

    try {
      Class<?> c = Class.forName(classname); // say AccountService
      Method[] allMethods = c.getDeclaredMethods(); // can be static
      for (Method m : allMethods) {
        String mname = m.getName();
        if (mname.equals("execute")) {
          Type[] pType = m.getGenericParameterTypes();
          if (pType[1].toString().equals("class " + action.getClass().getName())) {
            SqlSession sqlSession = openSession();
            try {
              m.setAccessible(true);
              Object t = getService(action.service());
              response = (HasResponse) m.invoke(t, sqlSession, action);
              sqlSession.commit();
            } catch (IllegalAccessException x) {
              LOG.error(
                  "IllegalAccessException " + action.getClass().getName() + "\n" + x.getMessage());
            } catch (InvocationTargetException x) {
              LOG.error(
                  "InvocationTargetException exception "
                      + action.getClass().getName()
                      + "\n"
                      + x.getMessage());
            } catch (Throwable x) {
              sqlSession.rollback();
              MonitorService.log(x);
            } finally {
              sqlSession.close();
            }
          }
        }
      }
    } catch (ClassNotFoundException x) {
      MonitorService.log(x);
      LOG.error("ClassNotFoundException " + action.getClass().getName() + "\n" + x.getMessage());
    }
    return response;
  }
  @Test
  public void test() throws Exception {

    SqlSession session = SessionFactory.getSession();
    EventDao eventDao = session.getMapper(EventDao.class);

    try {

      Event event = TestEventDao.createEvent();
      String where = "KEY='" + event.getKey() + "' ";
      Map<String, Object> map = new HashMap<String, Object>();
      map.put("where", where);

      int count = eventDao.create(event);
      assertEquals(1, count);
      assertNotNull(event.getKey());

      Event readRecord = eventDao.read(map);
      assertNotNull(readRecord.getKey());

      compareRecords(event, readRecord);

      modifyRecord(event);
      count = eventDao.update(event);
      assertEquals(1, count);

      readRecord = eventDao.read(map);
      assertNotNull(readRecord.getKey());

      compareRecords(event, readRecord);

      count = eventDao.delete(map);
      assertEquals(1, count);

      readRecord = eventDao.read(map);
      assertNull(readRecord);

    } finally {
      if (session != null) {
        session.rollback();
        session.close();
      }
    }
  }
Beispiel #26
0
  public int delete(int no) throws Exception {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
      sqlSession.delete("net.bitacademy.java41.dao.ProjectMapper.deleteProjectMember", no);
      sqlSession.delete("net.bitacademy.java41.dao.ProjectMapper.delete", no);

      sqlSession.commit();
      return 1;
    } catch (Exception e) {
      sqlSession.rollback();
      throw e;

    } finally {
      try {
        sqlSession.close();
      } catch (Exception e) {
      }
    }
  }
  public boolean deleteStreamServer(long id) {
    boolean ok = true;
    SqlSession sql =
        StreamManager.getSqlSessionFactory().openSession(TransactionIsolationLevel.SERIALIZABLE);

    try {
      StreamServerDao dao = sql.getMapper(StreamServerDao.class);
      dao.deleteStreamServer(id);
      sql.commit();
    } catch (Exception e) {
      ok = false;
      sql.rollback();
      e.printStackTrace();
    } finally {
      sql.close();
    }

    return ok;
  }
  @Override
  public Requirement readRequirement(Requirement requirement) {

    SqlSession sqlSession = getSqlSessionFactory().openSession();
    try {

      RequirementMapper requirementMapper = sqlSession.getMapper(RequirementMapper.class);
      if (requirementMapper.checkIfExistingRequirement(requirement) > 0) {
        return requirementMapper.selectRequirement(requirement);
      }

    } catch (Exception e) {
      e.printStackTrace();
      sqlSession.rollback();
    } finally {
      sqlSession.close();
    }
    return null;
  }
Beispiel #29
0
 /**
  * 根據id刪除主專案
  *
  * @return boolean 成功或失敗
  */
 public boolean delete(long id) {
   SqlSession session = null;
   boolean status = false;
   try {
     session = getSession(false);
     int cnt = session.delete("project.deleteById", id);
     session.commit();
     if (cnt > 0) {
       status = true;
     }
   } catch (Exception e) {
     e.printStackTrace();
     logger.error(e.getMessage());
     session.rollback();
   } finally {
     closeCoonnection(session);
   }
   return status;
 }
Beispiel #30
0
  /**
   * Get a list of software objects between (inclusive) the dates start and end.
   *
   * @param start
   * @param end
   * @return
   * @throws BoException
   */
  public List<Software> getListByPurchaseRange(Date start, Date end) throws BoException {
    SqlSession session = null;
    List<Software> list;

    try {
      session = SessionFactory.getSession();
      SoftwareDao mapper = session.getMapper(SoftwareDao.class);
      list = mapper.getListByPurchaseRange(start, end);
      session.commit();

    } catch (Exception e) {
      session.rollback();
      throw new BoException(e);
    } finally {
      if (session != null) session.close();
    }

    return list;
  }