Post is a table that store records about posts and published torrent, information like info_hash and bencode are stored in corresponding row.
The idea behind this is that, any post must be accompanied by a related torrent file, of couse its info_hash and bencode will be stored together with the post for storage convenience.

Table structure

Postgresql provides byte array type bytea, thus I could store the bencoded torrent file into a line.
The info_hash column is for searching by.

Column   Type
pid   integer
uid   integer
title   character varying(50)
content   text
post_time   bigint
size   integer
enabled   boolean
min_level   integer
info_hash   character varying(50)
bencode   bytea


public class Post extends BaseObject<Post>

    @Basic(optional = false)
    @Column(nullable = false)
    private Integer pid;
    //primary key

    @Column(length = 50)
    private String title;
    //the title of the post showing in summary page

    @Column(length = 2147483647)
    private String content;
    //Postgresql provides text type for unlimited content
    //We will store user post content in markdown

    @Column(length = 50, name = "info_hash")
    private String infoHash;
    //The info hash for searching

    @Column(name = "post_time")
    private Long postTime;

    @Column(length = 2147483647)
    private byte[] bencode;
    //the original uploaded bencoded torrent file

    private Integer size;
    //size of total file storage to be downloaded

    private Boolean enabled;
    //set if current post is visible by all

    @JoinColumn(name = "min_level", referencedColumnName = "lid")
    private UserLevel minLevel;
    //the minimum user level that could access this post.

    private float rate;
    //average rate for this post

    @JoinColumn(name = "uid", referencedColumnName = "uid")
    private User uid;
    //user who upload this post

    @OneToMany(mappedBy = "pid")
    private List<PostTags> postTagsList;

    @OneToMany(mappedBy = "pid")
    private List<Thread> threadList;

    @OneToMany(mappedBy = "pid")
    private List<ClientAnnounce> clientAnnounceList;

The rate field will be dynamically computed when evaluatinng.


An example post object in json format is shown as below:

  "pid":1094,"title":"Test title","content":"TEST","postTime":1444791559704,


13 October 2015