1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.upgrade.v4_3_0;
24  
25  import com.liferay.portal.upgrade.UpgradeException;
26  import com.liferay.portal.upgrade.UpgradeProcess;
27  import com.liferay.portal.upgrade.util.DefaultPKMapper;
28  import com.liferay.portal.upgrade.util.DefaultUpgradeTableImpl;
29  import com.liferay.portal.upgrade.util.PKUpgradeColumnImpl;
30  import com.liferay.portal.upgrade.util.SwapUpgradeColumnImpl;
31  import com.liferay.portal.upgrade.util.TempUpgradeColumnImpl;
32  import com.liferay.portal.upgrade.util.UpgradeColumn;
33  import com.liferay.portal.upgrade.util.UpgradeTable;
34  import com.liferay.portal.upgrade.util.ValueMapper;
35  import com.liferay.portal.upgrade.v4_3_0.util.AvailableMappersUtil;
36  import com.liferay.portal.upgrade.v4_3_0.util.DLFileEntryIdUpgradeColumnImpl;
37  import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryImpl;
38  import com.liferay.portlet.documentlibrary.model.impl.DLFileRankImpl;
39  import com.liferay.portlet.documentlibrary.model.impl.DLFileShortcutImpl;
40  import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionImpl;
41  import com.liferay.portlet.documentlibrary.model.impl.DLFolderImpl;
42  
43  import java.sql.Types;
44  
45  import org.apache.commons.logging.Log;
46  import org.apache.commons.logging.LogFactory;
47  
48  /**
49   * <a href="UpgradeDocumentLibrary.java.html"><b><i>View Source</i></b></a>
50   *
51   * @author Brian Wing Shun Chan
52   *
53   */
54  public class UpgradeDocumentLibrary extends UpgradeProcess {
55  
56      public void upgrade() throws UpgradeException {
57          _log.info("Upgrading");
58  
59          try {
60              doUpgrade();
61          }
62          catch (Exception e) {
63              throw new UpgradeException(e);
64          }
65      }
66  
67      protected void doUpgrade() throws Exception {
68  
69          // DLFolder
70  
71          UpgradeColumn upgradeCompanyIdColumn = new SwapUpgradeColumnImpl(
72              "companyId", new Integer(Types.VARCHAR),
73              AvailableMappersUtil.getCompanyIdMapper());
74  
75          UpgradeColumn upgradeGroupIdColumn = new SwapUpgradeColumnImpl(
76              "groupId", AvailableMappersUtil.getGroupIdMapper());
77  
78          UpgradeColumn upgradeUserIdColumn = new SwapUpgradeColumnImpl(
79              "userId", new Integer(Types.VARCHAR),
80              AvailableMappersUtil.getUserIdMapper());
81  
82          PKUpgradeColumnImpl upgradePKColumn = new PKUpgradeColumnImpl(
83              "folderId", true);
84  
85          UpgradeTable upgradeTable = new DefaultUpgradeTableImpl(
86              DLFolderImpl.TABLE_NAME, DLFolderImpl.TABLE_COLUMNS,
87              upgradePKColumn, upgradeGroupIdColumn, upgradeUserIdColumn);
88  
89          upgradeTable.setCreateSQL(DLFolderImpl.TABLE_SQL_CREATE);
90  
91          upgradeTable.updateTable();
92  
93          ValueMapper folderIdMapper = new DefaultPKMapper(
94              upgradePKColumn.getValueMapper());
95  
96          AvailableMappersUtil.setDLFolderIdMapper(folderIdMapper);
97  
98          UpgradeColumn upgradeParentFolderIdColumn = new SwapUpgradeColumnImpl(
99              "parentFolderId", folderIdMapper);
100 
101         upgradeTable = new DefaultUpgradeTableImpl(
102             DLFolderImpl.TABLE_NAME, DLFolderImpl.TABLE_COLUMNS,
103             upgradeParentFolderIdColumn);
104 
105         upgradeTable.updateTable();
106 
107         UpgradeColumn upgradeFolderIdColumn = new SwapUpgradeColumnImpl(
108             "folderId", folderIdMapper);
109 
110         UpgradeColumn upgradeToFolderIdColumn = new SwapUpgradeColumnImpl(
111             "toFolderId", folderIdMapper);
112 
113         // DLFileEntry
114 
115         UpgradeColumn upgradeNameColumn = new TempUpgradeColumnImpl("name");
116 
117         PKUpgradeColumnImpl fileEntryIdColumn =
118             new DLFileEntryIdUpgradeColumnImpl(
119                 upgradeCompanyIdColumn, upgradeFolderIdColumn,
120                 upgradeNameColumn);
121 
122         UpgradeColumn upgradeVersionUserIdColumn = new SwapUpgradeColumnImpl(
123             "versionUserId", new Integer(Types.VARCHAR),
124             AvailableMappersUtil.getUserIdMapper());
125 
126         upgradeTable = new DefaultUpgradeTableImpl(
127             DLFileEntryImpl.TABLE_NAME, DLFileEntryImpl.TABLE_COLUMNS,
128             upgradeCompanyIdColumn, upgradeFolderIdColumn, upgradeNameColumn,
129             fileEntryIdColumn, upgradeUserIdColumn, upgradeVersionUserIdColumn);
130 
131         upgradeTable.setCreateSQL(DLFileEntryImpl.TABLE_SQL_CREATE);
132 
133         upgradeTable.updateTable();
134 
135         ValueMapper fileEntryIdMapper = fileEntryIdColumn.getValueMapper();
136 
137         AvailableMappersUtil.setDLFileEntryIdMapper(fileEntryIdMapper);
138 
139         // DLFileRank
140 
141         upgradeTable = new DefaultUpgradeTableImpl(
142             DLFileRankImpl.TABLE_NAME, DLFileRankImpl.TABLE_COLUMNS,
143             new PKUpgradeColumnImpl("fileRankId", false),
144             upgradeUserIdColumn, upgradeFolderIdColumn);
145 
146         upgradeTable.setCreateSQL(DLFileRankImpl.TABLE_SQL_CREATE);
147 
148         upgradeTable.updateTable();
149 
150         // DLFileShortcut
151 
152         upgradePKColumn = new PKUpgradeColumnImpl("fileShortcutId", true);
153 
154         upgradeTable = new DefaultUpgradeTableImpl(
155             DLFileShortcutImpl.TABLE_NAME, DLFileShortcutImpl.TABLE_COLUMNS,
156             upgradePKColumn, upgradeUserIdColumn, upgradeFolderIdColumn,
157             upgradeToFolderIdColumn);
158 
159         upgradeTable.setCreateSQL(DLFileShortcutImpl.TABLE_SQL_CREATE);
160 
161         upgradeTable.updateTable();
162 
163         ValueMapper fileShortcutIdMapper = upgradePKColumn.getValueMapper();
164 
165         AvailableMappersUtil.setDLFileShortcutIdMapper(fileShortcutIdMapper);
166 
167         // DLFileVersion
168 
169         upgradeTable = new DefaultUpgradeTableImpl(
170             DLFileVersionImpl.TABLE_NAME, DLFileVersionImpl.TABLE_COLUMNS,
171             new PKUpgradeColumnImpl("fileVersionId", false),
172             upgradeUserIdColumn, upgradeFolderIdColumn);
173 
174         upgradeTable.setCreateSQL(DLFileVersionImpl.TABLE_SQL_CREATE);
175 
176         upgradeTable.updateTable();
177     }
178 
179     private static Log _log = LogFactory.getLog(UpgradeDocumentLibrary.class);
180 
181 }