public MyDocumentsContext() {
    Type type = new Type();
    type.setName("PDF");
    type.setDesc("Portable Document Format");
    type.setExtension(".pdf");

    Document document = new Document();
    document.setName("Book Template");
    document.setType(type);
    document.setLocation("/Users/felipeg/Documents/Random/Book Template.pdf");

    documents.put("doc1", document);
    types.put("pdf", type);

    document = new Document();
    document.setName("Sample Contract");
    document.setType(type);
    document.setLocation("/Users/felipeg/Documents/Contracts/Sample Contract.pdf");

    documents.put("doc2", document);

    type = new Type();
    type.setName("NOTE");
    type.setDesc("Text Notes");
    type.setExtension(".txt");

    document = new Document();
    document.setName("Clustering with RabbitMQ");
    document.setType(type);
    document.setLocation("/Users/felipeg/Documents/Random/Clustering with RabbitMQ.txt");

    documents.put("doc3", document);
    types.put("note", type);

    type = new Type();
    type.setName("WEB");
    type.setDesc("Web Link");
    type.setExtension(".url");

    document = new Document();
    document.setName("Pro Spring Security Book");
    document.setType(type);
    document.setLocation("http://www.apress.com/9781430248187");

    documents.put("doc4", document);
    types.put("web", type);
  }
Пример #2
0
  public List<Document> getAll() {
    List<Document> result = new ArrayList<Document>();
    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;
    Document document = null;
    Type type = null;
    try {
      connection = dataSource.getConnection();
      statement = connection.createStatement();
      resultSet = statement.executeQuery(queryAll);
      while (resultSet.next()) {
        document = new Document();
        document.setDocumentId(resultSet.getString("documentId"));
        document.setName(resultSet.getString("name"));
        document.setLocation(resultSet.getString("location"));
        document.setCreated(resultSet.getDate("created"));
        document.setModified(resultSet.getDate("modified"));
        document.setDescription("doc_desc");
        type = new Type();
        type.setTypeId(resultSet.getString("typeId"));
        type.setName(resultSet.getString("type_name"));
        type.setDesc(resultSet.getString("type_desc"));
        type.setExtension(resultSet.getString("extension"));
        document.setType(type);

        result.add(document);
      }
    } catch (SQLException ex) {
      throw new RuntimeException(ex);
    } finally {
      if (null != connection) {
        try {
          connection.close();
        } catch (SQLException ex) {
        }
      }
    }
    return result;
  }