@Override public String getModifyStatement() { Topic topic = (Topic) this.getEntity(); Timestamp ts = new Timestamp(topic.getDate().getTime()); String statement = String.format( MODIFY_STATEMENT, topic.getUserId(), topic.getTitle(), topic.getContent(), topic.getReplyCount(), topic.getDiggCount(), ts.toString(), topic.getId()); return statement; }
@Override public String getInsertStatement() { Topic topic = (Topic) this.getEntity(); long userId = topic.getUserId(); String title = topic.getTitle(); String content = topic.getContent(); EntityFactory ef; Long topicId; String statement; try { Connection conn = DriverManager.getConnection("proxool.mysql"); ef = new EntityFactory(conn); ResultSet rs = ef.executeQuery("SELECT MAX(topicId) FROM topic"); rs.next(); topicId = rs.getLong(1) + 1; statement = String.format(TopicWrapper.INSERT_STATEMENT, topicId, userId, title, content); conn.close(); return statement; } catch (Exception e) { e.printStackTrace(); return null; } }
@Override public List<Entity> getEntityFromResultSet(ResultSet rs) { ArrayList<Entity> list = new ArrayList<Entity>(); try { while (rs.next()) { Topic topic = new Topic(); topic.setId(rs.getLong(1)); topic.setUserId(rs.getLong(2)); topic.setTitle(rs.getString(3)); topic.setContent(rs.getString(4)); topic.setReplyCount(rs.getInt(5)); topic.setDiggCount(rs.getInt(6)); topic.setDate(rs.getTimestamp(7)); list.add(topic); } } catch (Exception e) { return null; } return list; }
@Override public String getDeleteStatement() { Topic topic = (Topic) this.getEntity(); String statement = "DELETE FROM Topic WHERE topicId = " + topic.getId(); return statement; }