Package models

Examples of models.Comment


    assertNotNull("Post should be found from db by bigint id", foundPost);

    foundPost = posts.find(postId);
    assertNotNull("Post should be found in cache by bigint id", foundPost);

    Comment c = new Comment(1, "comment content", 1, postId, System.currentTimeMillis(), getDBS());
    assertNotNull("Post should be findable by foreign key", c.getPost());
  }
View Full Code Here


  }

  public void testFindAllByForeignKey() throws Exception {
    ICommentPersistence comments = dbs.getDatabase1().comments();
    int userId = 1;
    Comment c1 = comments.create("comment1", userId, 1L, 1);
    Comment c2 = comments.create("comment2", userId, 1L, 1);
    Comment c3 = comments.create("comment3", userId, 1L, 1);

    Set<Comment> userComments = comments.findAllByForeignKey("commenter_id", userId);
    assertEquals(3, userComments.size());
    assertTrue(userComments.contains(c1));
    assertTrue(userComments.contains(c2));
View Full Code Here

  public void testFindAllByForeignKeyFromSet() throws Exception {
    ICommentPersistence comments = dbs.getDatabase1().comments();
    comments.deleteAll();
    Long userId = 1L;
    Long otherUserId = 2L;
    Comment c1 = comments.create("comment1", userId.intValue(), 1L, 0);
    Comment c2 = comments.create("comment2", userId.intValue(), 1L, 0);
    Comment c3 = comments.create("comment3", userId.intValue(), 1L, 0);
    Comment c4 = comments.create("comment4", otherUserId.intValue(), 1L, 0);
    Comment c5 = comments.create("comment5", 3, 1L, 0);

    Set<Long> commenterIds = new HashSet<Long>();
    commenterIds.add(userId);
    commenterIds.add(otherUserId);
    Set<Comment> userComments = comments.findAllByForeignKey("commenter_id", commenterIds);
View Full Code Here

          stmt.setInt(2, commenter_id);
          stmt.setLong(3, commented_on_id);
          stmt.setTimestamp(4, new Timestamp(created_at));
      }
    }, getInsertStatement(Arrays.<String>asList("content", "commenter_id", "commented_on_id", "created_at")));
    Comment newInst = new Comment(__id, content, commenter_id, commented_on_id, created_at, databases);
    newInst.setCreated(true);
    cachedById.put(__id, newInst);
    clearForeignKeyCache();
    return newInst;
  }
View Full Code Here

          stmt.setInt(1, commenter_id);
          stmt.setLong(2, commented_on_id);
          stmt.setTimestamp(3, new Timestamp(created_at));
      }
    }, getInsertStatement(Arrays.<String>asList("commenter_id", "commented_on_id", "created_at")));
    Comment newInst = new Comment(__id, null, commenter_id, commented_on_id, created_at, databases);
    newInst.setCreated(true);
    cachedById.put(__id, newInst);
    clearForeignKeyCache();
    return newInst;
  }
View Full Code Here

  }

  @Override
  protected Comment instanceFromResultSet(ResultSet rs, Set<Enum> selectedFields) throws SQLException {
    boolean allFields = selectedFields == null || selectedFields.isEmpty();
    return new Comment(rs.getLong("id"),
      allFields || selectedFields.contains(Comment._Fields.content) ? rs.getString("content") : null,
      allFields || selectedFields.contains(Comment._Fields.commenter_id) ? getIntOrNull(rs, "commenter_id") : 0,
      allFields || selectedFields.contains(Comment._Fields.commented_on_id) ? getLongOrNull(rs, "commented_on_id") : 0L,
      allFields || selectedFields.contains(Comment._Fields.created_at) ? getDateAsLong(rs, "created_at") : 0L,
      databases
View Full Code Here

  }


  public Comment create(final String content, final int commenter_id, final long commented_on_id, final long created_at) throws IOException {
    long __id = curId.getAndIncrement();
    Comment newInst = new Comment(__id, content, commenter_id, commented_on_id, created_at, databases);
    records.put(__id, newInst);
    clearForeignKeyCache();
    return newInst.getCopy();
  }
View Full Code Here



  public Comment create(final int commenter_id, final long commented_on_id, final long created_at) throws IOException {
    long __id = curId.getAndIncrement();
    Comment newInst = new Comment(__id, null, commenter_id, commented_on_id, created_at, databases);
    records.put(__id, newInst);
    clearForeignKeyCache();
    return newInst.getCopy();
  }
View Full Code Here

        // Create a new post
        Post bobPost = new Post(bob, "My first post", "Hello world").save();

        // Post a first comment
        new Comment(bobPost, "Jeff", "Nice post").save();
        new Comment(bobPost, "Tom", "I knew that !").save();

        // Retrieve all comments
        List<Comment> bobPostComments = Comment.q().filter("post in", bobPost).asList();

        // Tests
        assertEquals(2, bobPostComments.size());

        Comment firstComment = bobPostComments.get(0);
        assertNotNull(firstComment);
        assertEquals("Jeff", firstComment.author);
        assertEquals("Nice post", firstComment.content);
        assertNotNull(firstComment.postedAt);

        Comment secondComment = bobPostComments.get(1);
        assertNotNull(secondComment);
        assertEquals("Tom", secondComment.author);
        assertEquals("I knew that !", secondComment.content);
        assertNotNull(secondComment.postedAt);
    }
View Full Code Here

TOP

Related Classes of models.Comment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.