Example #1
0
  @Override
  public List<BlockStatus> findAllByBlockStatusExample(
      BlockStatusExample blockStatusExample, int offset, int limit) throws DaoException {
    try {
      Connection conn = DataSourceUtils.doGetConnection(dataSource);
      Statement stmt = conn.createStatement();
      String clause =
          BlockStatusDaoImpl.buildClause(blockStatusExample) + " limit " + offset + "," + limit;

      logger.debug(
          "DB:FIND block_status[distinct="
              + blockStatusExample.isDistinct()
              + ",clause="
              + clause
              + "]");

      ResultSet rs =
          stmt.executeQuery(
              "select"
                  + (blockStatusExample.isDistinct() ? " distinct " : " ")
                  + "`id`,`id2`,`shipment_id`,`declaration_no`,`status`,`remark`,`block_date_time`,`unblock_date_time`,`company_code`,`company_type`,`user_block`,`mawb`,`hawb`,`flight_no`,`flight_date`,`user_unblock`,`modified_date_time`,`auto_block_profile_id` from block_status"
                  + clause);

      List<BlockStatus> list = new ArrayList<BlockStatus>();
      while (rs.next()) {
        list.add(BlockStatusDaoImpl.createInstanceFromResultSet(rs));
      }
      rs.close();
      stmt.close();

      return list;
    } catch (Exception e) {
      throw new DaoException(e);
    }
  }
Example #2
0
  @Override
  public int countByBlockStatusExample(BlockStatusExample blockStatusExample) throws DaoException {
    try {
      Connection conn = DataSourceUtils.doGetConnection(dataSource);
      Statement stmt = conn.createStatement();

      String clause = BlockStatusDaoImpl.buildClause(blockStatusExample);
      ResultSet rs =
          stmt.executeQuery(
              "select"
                  + (blockStatusExample.isDistinct() ? " distinct " : " ")
                  + "count(*) from block_status"
                  + clause);
      int count = -1;
      if (rs.next()) {
        count = rs.getInt(1);
      }
      rs.close();
      stmt.close();

      logger.debug(
          "DB:COUNT block_status[distinct="
              + blockStatusExample.isDistinct()
              + ",clause="
              + clause
              + "] => "
              + count);

      return count;
    } catch (Exception e) {
      throw new DaoException(e);
    }
  }
Example #3
0
  @Override
  public int insert(BlockStatus blockStatus) throws DaoException {
    if (blockStatus == null) {
      throw new DaoException("Cannot insert block_status with null value.");
    }

    try {
      Connection conn = DataSourceUtils.doGetConnection(dataSource);
      PreparedStatement ps =
          conn.prepareStatement(
              "insert into block_status(`id`,`id2`,`shipment_id`,`declaration_no`,`status`,`remark`,`block_date_time`,`unblock_date_time`,`company_code`,`company_type`,`user_block`,`mawb`,`hawb`,`flight_no`,`flight_date`,`user_unblock`,`modified_date_time`,`auto_block_profile_id`) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
              Statement.RETURN_GENERATED_KEYS);
      BlockStatusDaoImpl.setPreparedStatementValues(ps, blockStatus);
      ps.setNull(1, java.sql.Types.INTEGER);
      ps.execute();
      int id = -1;
      ResultSet rs = ps.getGeneratedKeys();
      if (rs.next()) {
        id = rs.getInt(1);
      }
      rs.close();
      ps.close();

      logger.info("DB:INSERT block_status[id=" + id + "]");

      return id;
    } catch (SQLException e) {
      throw new DaoException(e);
    }
  }
Example #4
0
  @Override
  public int update(BlockStatus blockStatus) throws DaoException {
    if (blockStatus == null) {
      throw new DaoException("Cannot insert block_status with null value.");
    }

    try {
      Connection conn = DataSourceUtils.doGetConnection(dataSource);
      PreparedStatement ps =
          conn.prepareStatement(
              "update block_status set `id`=?,`id2`=?,`shipment_id`=?,`declaration_no`=?,`status`=?,`remark`=?,`block_date_time`=?,`unblock_date_time`=?,`company_code`=?,`company_type`=?,`user_block`=?,`mawb`=?,`hawb`=?,`flight_no`=?,`flight_date`=?,`user_unblock`=?,`modified_date_time`=?,`auto_block_profile_id`=? where id=?");
      BlockStatusDaoImpl.setPreparedStatementValues(ps, blockStatus);
      ps.setInt(19, blockStatus.getId());
      int count = ps.executeUpdate();
      ps.close();

      logger.info("DB:UPDATE block_status[id=" + blockStatus.getId() + "] => " + count);

      return count;
    } catch (SQLException e) {
      throw new DaoException(e);
    }
  }
Example #5
0
  @Override
  public BlockStatus findById(Integer id) throws DaoException {
    try {
      Connection conn = DataSourceUtils.doGetConnection(dataSource);
      PreparedStatement ps =
          conn.prepareStatement(
              "select `id`,`id2`,`shipment_id`,`declaration_no`,`status`,`remark`,`block_date_time`,`unblock_date_time`,`company_code`,`company_type`,`user_block`,`mawb`,`hawb`,`flight_no`,`flight_date`,`user_unblock`,`modified_date_time`,`auto_block_profile_id` from block_status where id=?");
      ps.setInt(1, id);

      logger.debug("DB:FIND block_status[id=" + id + "]");

      ResultSet rs = ps.executeQuery();
      BlockStatus instance = null;
      if (rs.next()) {
        instance = BlockStatusDaoImpl.createInstanceFromResultSet(rs);
      }
      rs.close();
      ps.close();

      return instance;
    } catch (SQLException e) {
      throw new DaoException(e);
    }
  }