1
14
15 package com.liferay.portal.upgrade.v5_2_8;
16
17 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
18 import com.liferay.portal.kernel.upgrade.UpgradeProcess;
19 import com.liferay.portal.kernel.util.StringBundler;
20 import com.liferay.portal.kernel.util.StringPool;
21
22 import java.sql.Connection;
23 import java.sql.PreparedStatement;
24 import java.sql.ResultSet;
25 import java.sql.Timestamp;
26
27
32 public class UpgradeDocumentLibrary extends UpgradeProcess {
33
34 protected void addFileVersion(
35 long groupId, long companyId, long userId, String userName,
36 long folderId, String name, double version, int size)
37 throws Exception {
38
39 Timestamp now = new Timestamp(System.currentTimeMillis());
40
41 Connection con = null;
42 PreparedStatement ps = null;
43
44 try {
45 con = DataAccess.getConnection();
46
47 StringBundler sb = new StringBundler(4);
48
49 sb.append("insert into DLFileVersion (fileVersionId, groupId, ");
50 sb.append("companyId, userId, userName, createDate, folderId, ");
51 sb.append("name, description, version, size_) values (?, ?, ?, ");
52 sb.append("?, ?, ?, ?, ?, ?, ?, ?)");
53
54 String sql = sb.toString();
55
56 ps = con.prepareStatement(sql);
57
58 ps.setLong(1, increment());
59 ps.setLong(2, groupId);
60 ps.setLong(3, companyId);
61 ps.setLong(4, userId);
62 ps.setString(5, userName);
63 ps.setTimestamp(6, now);
64 ps.setLong(7, folderId);
65 ps.setString(8, name);
66 ps.setString(9, StringPool.BLANK);
67 ps.setDouble(10, version);
68 ps.setInt(11, size);
69
70 ps.executeUpdate();
71 }
72 finally {
73 DataAccess.cleanUp(con, ps);
74 }
75 }
76
77 protected void doUpgrade() throws Exception {
78 Connection con = null;
79 PreparedStatement ps = null;
80 ResultSet rs = null;
81
82 try {
83 con = DataAccess.getConnection();
84
85 ps = con.prepareStatement("select * from DLFileEntry");
86
87 rs = ps.executeQuery();
88
89 while (rs.next()) {
90 long companyId = rs.getLong("companyId");
91 long groupId = rs.getLong("groupId");
92 long userId = rs.getLong("userId");
93 String userName = rs.getString("userName");
94 long folderId = rs.getLong("folderId");
95 String name = rs.getString("name");
96 double version = rs.getDouble("version");
97 int size = rs.getInt("size_");
98
99 addFileVersion(
100 groupId, companyId, userId, userName, folderId, name,
101 version, size);
102 }
103 }
104 finally {
105 DataAccess.cleanUp(con, ps, rs);
106 }
107 }
108
109 }