1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
14  
15  package com.liferay.portal.upgrade.v4_3_0;
16  
17  import com.liferay.counter.model.Counter;
18  import com.liferay.counter.service.CounterLocalServiceUtil;
19  import com.liferay.portal.kernel.upgrade.UpgradeProcess;
20  import com.liferay.portal.kernel.upgrade.util.UpgradeTable;
21  import com.liferay.portal.kernel.upgrade.util.UpgradeTableFactoryUtil;
22  import com.liferay.portal.model.Permission;
23  import com.liferay.portal.model.Resource;
24  import com.liferay.portal.model.ResourceCode;
25  import com.liferay.portal.model.UserTracker;
26  
27  import java.sql.Types;
28  
29  import java.util.List;
30  
31  /**
32   * <a href="UpgradeCounter.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   */
36  public class UpgradeCounter extends UpgradeProcess {
37  
38      protected void doUpgrade() throws Exception {
39  
40          // Counter
41  
42          List<String> names = CounterLocalServiceUtil.getNames();
43  
44          for (String name : names) {
45              if (name.startsWith("com.liferay.") &&
46                  !name.equals(Counter.class.getName()) &&
47                  !name.equals(Permission.class.getName()) &&
48                  !name.equals(Resource.class.getName()) &&
49                  !name.equals(ResourceCode.class.getName()) &&
50                  !name.equals(UserTracker.class.getName())) {
51  
52                  CounterLocalServiceUtil.reset(name);
53              }
54          }
55  
56          UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
57              _TABLE_COUNTER, _COLUMNS_COUNTER);
58  
59          upgradeTable.setCreateSQL(_CREATE_COUNTER);
60  
61          upgradeTable.updateTable();
62      }
63  
64      private static final String _TABLE_COUNTER = "Counter";
65  
66      private static final Object[][] _COLUMNS_COUNTER = {
67          {"name", new Integer(Types.VARCHAR)},
68          {"currentId", new Integer(Types.BIGINT)}
69      };
70  
71      private static final String _CREATE_COUNTER =
72          "create table Counter (" +
73              "name VARCHAR(75) not null primary key," +
74              "currentId LONG" +
75          ")";
76  
77  }