1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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  }