001
014
015 package com.liferay.portal.upgrade.v5_2_8;
016
017 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
018 import com.liferay.portal.kernel.upgrade.UpgradeProcess;
019 import com.liferay.portal.kernel.util.StringBundler;
020 import com.liferay.portal.kernel.util.StringPool;
021
022 import java.sql.Connection;
023 import java.sql.PreparedStatement;
024 import java.sql.ResultSet;
025 import java.sql.Timestamp;
026
027
030 public class UpgradeDocumentLibrary extends UpgradeProcess {
031
032 protected void addFileVersion(
033 long groupId, long companyId, long userId, String userName,
034 long folderId, String name, double version, int size)
035 throws Exception {
036
037 Timestamp now = new Timestamp(System.currentTimeMillis());
038
039 Connection con = null;
040 PreparedStatement ps = null;
041
042 try {
043 con = DataAccess.getUpgradeOptimizedConnection();
044
045 StringBundler sb = new StringBundler(4);
046
047 sb.append("insert into DLFileVersion (fileVersionId, groupId, ");
048 sb.append("companyId, userId, userName, createDate, folderId, ");
049 sb.append("name, description, version, size_) values (?, ?, ?, ");
050 sb.append("?, ?, ?, ?, ?, ?, ?, ?)");
051
052 String sql = sb.toString();
053
054 ps = con.prepareStatement(sql);
055
056 ps.setLong(1, increment());
057 ps.setLong(2, groupId);
058 ps.setLong(3, companyId);
059 ps.setLong(4, userId);
060 ps.setString(5, userName);
061 ps.setTimestamp(6, now);
062 ps.setLong(7, folderId);
063 ps.setString(8, name);
064 ps.setString(9, StringPool.BLANK);
065 ps.setDouble(10, version);
066 ps.setInt(11, size);
067
068 ps.executeUpdate();
069 }
070 finally {
071 DataAccess.cleanUp(con, ps);
072 }
073 }
074
075 @Override
076 protected void doUpgrade() throws Exception {
077 Connection con = null;
078 PreparedStatement ps = null;
079 ResultSet rs = null;
080
081 try {
082 con = DataAccess.getUpgradeOptimizedConnection();
083
084 ps = con.prepareStatement("select * from DLFileEntry");
085
086 rs = ps.executeQuery();
087
088 while (rs.next()) {
089 long companyId = rs.getLong("companyId");
090 long groupId = rs.getLong("groupId");
091 long userId = rs.getLong("userId");
092 String userName = rs.getString("userName");
093 long folderId = rs.getLong("folderId");
094 String name = rs.getString("name");
095 double version = rs.getDouble("version");
096 int size = rs.getInt("size_");
097
098 addFileVersion(
099 groupId, companyId, userId, userName, folderId, name,
100 version, size);
101 }
102 }
103 finally {
104 DataAccess.cleanUp(con, ps, rs);
105 }
106 }
107
108 }