package fi.tekislauta.db.objects;

/**
 * Created by Hugo on 14.10.2016.
 */
public class PostDao {
}

@@ -32,71 +32,1987 @@
 s;%0A%0A
-/**%0A * Created by Hugo on 14.10.2016.%0A */%0Apublic class PostDao %7B
+import fi.tekislauta.db.Database;%0Aimport fi.tekislauta.models.DatabaseObject;%0Aimport fi.tekislauta.models.Post;%0A%0Aimport java.sql.PreparedStatement;%0Aimport java.sql.ResultSet;%0Aimport java.sql.SQLException;%0Aimport java.util.ArrayList;%0Aimport java.util.*;%0A%0Apublic class PostDao implements DatabaseObject%7B%0A%0A    public PostDao() %7B%0A%0A%0A    %7D%0A%0A    @Override%0A    public Object fetch(Database db, String filter) throws SQLException %7B%0A        PreparedStatement statement = db.getConnection().prepareStatement(%22SELECT * FROM Board b, Post p WHERE b.id = p.board_ip AND p.id= ?%22);%0A        statement.setString(1, filter);%0A%0A        ResultSet rs = statement.executeQuery();%0A%0A        Post p = new Post();%0A        if (!rs.next()) %7B%0A            p.setError(%22OH NO! Cannot find post %22 + filter + %22 :(%22);%0A            return p;%0A        %7D%0A%0A        return p;%0A    %7D%0A%0A    @Override%0A    public List%3CObject%3E fetchAll(Database db) throws SQLException %7B%0A        PreparedStatement statement = db.getConnection().prepareStatement(%22SELECT * FROM Board b, Post p WHERE b.id = p.board_ip%22);%0A        ResultSet rs = statement.executeQuery();%0A%0A        ArrayList%3CPost%3E postList = new ArrayList%3C%3E();%0A%0A        while(rs.next()) %7B%0A            Post p = new Post();%0A%0A            p.setId(rs.getInt(%22id%22));%0A            p.setTopic_id(rs.getInt(%22topic_id%22));%0A            p.setIp(rs.getInt(%22ip%22));%0A            p.setPost_time(rs.getInt(%22post_time%22));%0A            p.setSubject(rs.getString(%22subject%22));%0A            p.setMessage(rs.getString(%22message%22));%0A%0A            postList.add(p);%0A        %7D%0A%0A        return (List)postList;%0A    %7D%0A%0A    @Override%0A    public Object post(Database db, Object o) throws SQLException %7B%0A        return null;%0A    %7D%0A%0A    @Override%0A    public void delete(Database db, String params) throws SQLException %7B%0A        PreparedStatement statement = db.getConnection().prepareStatement(%22DELETE FROM Post WHERE id = ?%22);%0A        statement.setObject(1, params);%0A        ResultSet rs = statement.executeQuery();%0A%0A%0A    %7D
 %0A%7D%0A

Tweak postDao