Esempio n. 1
0
  /**
   * This method will be called to insert hashed data values.
   *
   * @param tableName :Name of the table
   * @param columnValues :List of column values
   * @param columnNames :List of column names.
   * @param jdbcDAO : Database jdbcDAO
   * @throws DAOException :DAOException
   * @throws SQLException : SQLException
   */
  public void insertHashedValues(
      String tableName, List<Object> columnValues, List<String> columnNames, JDBCDAO jdbcDAO)
      throws DAOException, SQLException {

    List<String> columnNamesList = new ArrayList<String>();
    ResultSetMetaData metaData;

    PreparedStatement stmt = null;
    try {
      if (columnNames != null && !columnNames.isEmpty()) {
        metaData = getMetaData(tableName, columnNames, jdbcDAO);
        columnNamesList = columnNames;
      } else {
        metaData = getMetaDataAndUpdateColumns(tableName, columnNamesList, jdbcDAO);
      }

      String insertQuery = createInsertQuery(tableName, columnNamesList);
      stmt = jdbcDAO.getPreparedStatement(insertQuery);
      setStmtIndexValue(columnValues, metaData, stmt);
      stmt.executeUpdate();
    } catch (SQLException sqlExp) {
      logger.error(sqlExp.getMessage(), sqlExp);
      ErrorKey errorKey = ErrorKey.getErrorKey("db.operation.error");
      throw new DAOException(
          errorKey, sqlExp, "HashedDataHandler.java :" + DAOConstants.INSERT_OBJ_ERROR);
    }
  }
Esempio n. 2
0
  /**
   * @return JDBCDAO object.
   * @throws DAOException throw DAOException
   */
  public JDBCDAO getJDBCDAO() throws DAOException {
    JDBCDAO dao = null;
    try {
      dao = (JDBCDAO) Class.forName(defaultDAOClassName).newInstance();
      dao.setConnectionManager(getConnectionManager());

    } catch (Exception excp) {
      ErrorKey errorKey = ErrorKey.getErrorKey("db.operation.error");
      throw new DAOException(errorKey, excp, "DAOFactory.java :");
    }
    return dao;
  }
Esempio n. 3
0
 /**
  * This method used to set Date values. to prepared statement
  *
  * @param stmt :TODO
  * @param index :
  * @param obj :
  * @throws SQLException : SQLException
  * @throws DAOException : DAOException
  */
 protected void setDateColumns(PreparedStatement stmt, int index, Object obj)
     throws SQLException, DAOException {
   if (obj != null && obj.toString().equals("##")) {
     java.util.Date date = null;
     try {
       date = Utility.parseDate("1-1-9999", "mm-dd-yyyy");
     } catch (ParseException exp) {
       // TODO have to replace this by parse key
       ErrorKey errorKey = ErrorKey.getErrorKey("db.operation.error");
       throw new DAOException(errorKey, exp, "HashedDataHandler.java :");
     }
     Date sqlDate = new Date(date.getTime());
     stmt.setDate(index, sqlDate);
   }
 }
Esempio n. 4
0
 /**
  * @return returns dummy list.
  * @throws DAOException throw DAOException when isTestForFail=true
  */
 public static List<Object> getList() throws DAOException {
   list = new ArrayList<Object>();
   if (isTestForFail) {
     ErrorKey errorKey = ErrorKey.getErrorKey("db.operation.error");
     throw new DAOException(errorKey, new Exception(""), "MyJDAOImpl.java :");
   } else if (identifierList) {
     list.add(Long.valueOf(1));
     list.add(Long.valueOf(2));
     list.add(Long.valueOf(3));
   } else if (isTestActivityStatus) {
     list.add("ActivityStatus");
   } else {
     Object[] list1 = {"1", "John", "Enterprise"};
     Object[] list2 = {"2", "Raghu", "IBM"};
     Object[] list3 = {"3", "Bame", "Enterprise"};
     list.add(list1);
     list.add(list2);
     list.add(list3);
   }
   return (List<Object>) list;
 }
Esempio n. 5
0
  /**
   * This method will returns the metaData associated to the table specified in tableName and update
   * the list columnNames.
   *
   * @param tableName Name of the table whose metaData is requested
   * @param columnNames Table columns
   * @param jdbcDAO : Database connections to retrieve meta data.
   * @return It will return the metaData associated to the table.
   * @throws DAOException : DAOException
   */
  protected final ResultSetMetaData getMetaDataAndUpdateColumns(
      String tableName, List<String> columnNames, JDBCDAO jdbcDAO) throws DAOException {
    ResultSetMetaData metaData;
    try {

      StringBuffer sqlBuff = new StringBuffer(DAOConstants.TAILING_SPACES);
      sqlBuff.append("Select * from ").append(tableName).append(" where 1!=1");
      metaData = jdbcDAO.getQueryResultSet(sqlBuff.toString()).getMetaData();

      for (int i = 1; i <= metaData.getColumnCount(); i++) {
        columnNames.add(metaData.getColumnName(i));
      }
    } catch (SQLException sqlExp) {
      logger.fatal(sqlExp.getMessage(), sqlExp);
      ErrorKey errorKey = ErrorKey.getErrorKey("db.operation.error");
      throw new DAOException(
          errorKey, sqlExp, "HashedDataHandler.java :" + DAOConstants.RS_METADATA_ERROR);
    }

    return metaData;
  }
Esempio n. 6
0
 /**
  * This method throws the DAOException.
  *
  * @throws DAOException throw DAOException.
  */
 public static void throwDaoException() throws DAOException {
   if (isTestForFail) {
     ErrorKey errorKey = ErrorKey.getErrorKey("db.operation.error");
     throw new DAOException(errorKey, new Exception(""), "MyJDAOImpl.java :");
   }
 }