1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.upgrade.v4_3_0;
21  
22  import com.liferay.counter.model.Counter;
23  import com.liferay.counter.service.CounterLocalServiceUtil;
24  import com.liferay.portal.kernel.log.Log;
25  import com.liferay.portal.kernel.log.LogFactoryUtil;
26  import com.liferay.portal.model.Permission;
27  import com.liferay.portal.model.Resource;
28  import com.liferay.portal.model.ResourceCode;
29  import com.liferay.portal.model.UserTracker;
30  import com.liferay.portal.upgrade.UpgradeException;
31  import com.liferay.portal.upgrade.UpgradeProcess;
32  import com.liferay.portal.upgrade.util.DefaultUpgradeTableImpl;
33  import com.liferay.portal.upgrade.util.UpgradeTable;
34  
35  import java.sql.Types;
36  
37  import java.util.List;
38  
39  /**
40   * <a href="UpgradeCounter.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class UpgradeCounter extends UpgradeProcess {
46  
47      public void upgrade() throws UpgradeException {
48          _log.info("Upgrading");
49  
50          try {
51              doUpgrade();
52          }
53          catch (Exception e) {
54              throw new UpgradeException(e);
55          }
56      }
57  
58      protected void doUpgrade() throws Exception {
59  
60          // Counter
61  
62          List<String> names = CounterLocalServiceUtil.getNames();
63  
64          for (String name : names) {
65              if (name.startsWith("com.liferay.") &&
66                  !name.equals(Counter.class.getName()) &&
67                  !name.equals(Permission.class.getName()) &&
68                  !name.equals(Resource.class.getName()) &&
69                  !name.equals(ResourceCode.class.getName()) &&
70                  !name.equals(UserTracker.class.getName())) {
71  
72                  CounterLocalServiceUtil.reset(name);
73              }
74          }
75  
76          UpgradeTable upgradeTable = new DefaultUpgradeTableImpl(
77              _TABLE_COUNTER, _COLUMNS_COUNTER);
78  
79          upgradeTable.setCreateSQL(_CREATE_COUNTER);
80  
81          upgradeTable.updateTable();
82      }
83  
84      private static final String _TABLE_COUNTER = "Counter";
85  
86      private static final Object[][] _COLUMNS_COUNTER = {
87          {"name", new Integer(Types.VARCHAR)},
88          {"currentId", new Integer(Types.BIGINT)}
89      };
90  
91      private static final String _CREATE_COUNTER =
92          "create table Counter (" +
93              "name VARCHAR(75) not null primary key," +
94              "currentId LONG" +
95          ")";
96  
97      private static Log _log = LogFactoryUtil.getLog(UpgradeCounter.class);
98  
99  }