0

我有以下pojo

   public class Like {
     private Long commentId;
     private Collection<Long> accountIds;
   }

   public class Comment {
private Long personId;
    private Long pageId;
    private Long Id;
    private String text;
    private Like like;
    private LocalDate commentDate;
   }

   public class Page {
     private Long Id;
     private Long textId;
     private Collection<Comment> comments;
     private LocalTime postingDate;
     private ViewType type;
     private String mediaUrl;
     private Collection<Long> openAccountIds;
     private Like like;
   }

    public class Text{
      private Long accountId;
      private Long Id;
      private String name;
      private LocalTime firstPostedTime;
      private LocalTime lastPostedTime;
      private ViewType type;
      private Collection<Page> pages;
      private Like like;
      private String description;
      private Collection<Long> openAccountIds;
     }

现在我的文本存储库如下:

 public interface TextRepository {

Collection<Text> getAllTexts(Long accountId);

Diary getText(Long TextId);

Page getPage(Long pageId);

Comment getComment(Long commentId);

void addPageToText(Long TextId , Page page);

void addCommentToPage(Long pageId , Comment comment);

void updateText(Text text);

void deletePage(Long pageId);

void deleteComment(Long commentId);

void updateLikeToText(Long textIds);

void updateLikeToPage(Long pageId);

void updateLikeToComment(Long commentId);

}

我是mysql的新手。我想知道如何有效地创建 mysql 表,以便我可以在更短的时间内检索数据。此外,如果我的 pojo 包含任何结构缺陷,请继续更改它们或提供建议。

4

1 回答 1

0

Here are some suggestions for the object model to consider (see comments),

// Specifying all the fields as private will not allow
// any other class to use the data!
public class Account
{
    public String name;
    public String location;
}

public class Text
{
    public Collection<Account> likedBy;
    public Collection<Account> openAccounts;
    public Collection<Page> pages;
    public Account postedBy; 
    public String name; // Not sure what this field represents...
    public LocalTime firstPostedTime;
    public LocalTime lastPostedTime;
    public ViewType type;
    public String description;

    // Consider using get/set methods for collections, 
    // so as to expose only minimal required information 
//  public like(Account account)
//  {
//      likedBy.add(account);
//  }
//  
//  public dislike(Account account)
//  {
//      likedBy.remove(account);
//  }
}

public class Page
{
    public Collection<Comment> comments;
    public LocalTime postingDate;
    public ViewType type;
    public String mediaUrl;
    public Collection<Account> openAccounts;
    public Collection<Account> likedBy;

//  public addComment(Comment comment)
//  {
//      ...
//      Update posting date
//  }
//  
//  public addOpenAccount(Account account)
//  {
//      ...
//  }
}

public class Comment 
{
    public Account postedBy;
    public String text;
    public Collection<Account> likedBy;
    public LocalDate commentDate;
}

The next step would be to construct an entity-relationship diagram. The primary keys and foreign keys (xxxId) are introduced while normalizing the schema.

The schema could look like this,

  • Account [id, name, location]
  • ViewType [id, description]
  • Comment [id, posted_by_account_id, text, postedDate]
  • CommentLikes [comment_id, account_id]
  • Text [id, account_id, name, firstPostedTime, lastPostedTime, type_Id, description]
  • TextAccounts [text_id, account_id]
  • TextLikes [text_id, account_id]
  • TextPages [text_id, page_id]
  • Page [id, mediaUrl, type_id, postingDate]
  • PageLikes [page_id, account_id]
  • PageComments [page_id, comment_id]
  • PageAccounts [page_id, account_id]
于 2013-02-24T10:26:19.720 回答