@Override
  public int create(LinkCrawled linkCrawled) throws SQLException {
    if (linkCrawled.getLink() == null) {
      return -1;
    }

    // If the time crawled is not specified, use the current time
    if (linkCrawled.getTimeCrawled() == null || linkCrawled.getDateCrawled() == null) {
      linkCrawled.setTimeCrawled(Helper.getCurrentTime());
      linkCrawled.setDateCrawled(Helper.getCurrentDate());
    }

    Connection connection = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;

    try {
      connection = this.daoFactory.getConnection();

      final Object[] values = {
        linkCrawled.getLink(), linkCrawled.get_originalLink(),
        linkCrawled.getPriority(), linkCrawled.getDomainTableId1(),
        linkCrawled.get_downloadDuration(), linkCrawled.get_extractedTime(),
        linkCrawled.get_httpStatusCode(), linkCrawled.get_relevance(),
        linkCrawled.get_distanceFromRelevantPage(), linkCrawled.get_freshness(),
        linkCrawled.getTimeCrawled(), linkCrawled.getDateCrawled()
      };

      preparedStatement = DAOUtil.prepareStatement(connection, this.SQL_INSERT, true, values);

      preparedStatement.executeUpdate();

      // Get the generated key (id)
      resultSet = preparedStatement.getGeneratedKeys();
      int generatedKey = -1;

      if (resultSet.next()) {
        generatedKey = resultSet.getInt(1);
      }

      return generatedKey;
    } catch (final SQLException e) {
      LOG.error("Insert into link_crawled_table fails, " + e.getMessage());

      return -1;
    } finally {
      DAOUtil.close(connection, preparedStatement, resultSet);
    }
  }
Example #2
0
 /** Aufgabe b */
 @Override
 public void load(String fileName) {
   try {
     String content = Helper.loadText(fileName);
     String[] lines = content.split("\r\n");
     ImplGraph newGraph = new ImplGraph();
     for (String line : lines) {
       String[] edge = line.split("-");
       Node<Integer> a = newGraph.setNode(Integer.parseInt(edge[0]));
       Node<Integer> b = newGraph.setNode(Integer.parseInt(edge[1]));
       newGraph.setEdge(a, b);
     }
     this.adjacencyList = newGraph.adjacencyList;
   } catch (IOException e) {
     System.out.println("Ladefehler... f**k!");
   } catch (Exception e) {
     System.out.println("AnyFehler... f**k!");
   }
 }
Example #3
0
 /** Aufgabe b */
 @Override
 public void save(String fileName) {
   StringBuilder sb = new StringBuilder();
   if (this.adjacencyList.size() > 0) {
     Node<Integer>[] keys = this.adjacencyList.keySet().toArray(new Node[0]);
     Arrays.sort(keys);
     for (int i = 0; i < keys.length; i++) {
       Node<Integer> current = keys[i];
       ArrayList<Node<Integer>> adj = this.adjacencyList.get(current);
       for (Node<Integer> adjElement : adj) {
         if (adjElement.value() >= current.value()) {
           sb.append(current.value());
           sb.append("-");
           sb.append(adjElement.value());
           sb.append("\r\n");
         }
       }
     }
   }
   Helper.writeText(fileName, sb.toString());
 }