<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="net.lybbs.util.*"%>
<%@ page import="net.lybbs.session.util.*"%>
<%@ page import="net.lybbs.db.*"%>
<%@ page import="net.lybbs.post.bean.*"%>
<%@ page import="net.lybbs.post.proxy.*"%>
<%@ page import="net.lybbs.post.dao.jdbc.*"%>
<%@ page import="net.lybbs.post.dao.*"%>
<%@ page import="java.util.*"%>
<%@ page errorPage="errorException.jsp" %>
<%
out.println("<br>");
out.println("Next upgrade from 6.0 to 6.1, if connection failed, please check test.jsp first:<br>");
try {
  DBConnect dbConnect2=DBConnectManager.getInstance().getDBConnect();
  dbConnect2.createConnection();
  DBConnect dbConnect=DBConnectManager.getInstance().getDBConnect();
  dbConnect.createConnection();
  dbConnect.createPrepareStatement("select id from posts where parentid=0");
  dbConnect.executeQuery();
  int parentID=0;
  ILastTopic lastTopic;
  ITopicDAO topicDAO=TopicDAO.getInstance();
  while(dbConnect.next()) {
    parentID=dbConnect.getInt(1);
    lastTopic=topicDAO.getLastReply(dbConnect2,parentID);
    if(lastTopic.getLastPostAuthorID()>0) {
      dbConnect2.createPrepareStatement("update posts set lastauthorid=? where id=?");
      dbConnect2.setInt(1,lastTopic.getLastPostAuthorID());
      dbConnect2.setInt(2,parentID);
      dbConnect2.executeUpdate();
      dbConnect2.closePreStmt();
    }
  }
  dbConnect.close();
  dbConnect2.close();
  out.println("&nbsp;&nbsp;&nbsp;&nbsp;<b>Upgrade success!</b>");
  
  long totalMemory=java.lang.Runtime.getRuntime().totalMemory();
  long freeMemory=java.lang.Runtime.getRuntime().freeMemory();
  long usedMemory=totalMemory-freeMemory;
  out.println("<br><br>Total Memory is: " +totalMemory/1024+"K");
  out.println("<br>Used &nbsp;Memory is: " +usedMemory/1024+"K");
  out.println("<br>Free &nbsp;Memory is: " +freeMemory/1024+"K");
  out.println("<br>");
}
catch(Exception ex) {
  out.println("&nbsp;&nbsp;&nbsp;&nbsp;Upgrade error:"+ex.toString());
}
%>