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.convert.util;
16  
17  import com.liferay.portal.kernel.util.StringBundler;
18  import com.liferay.portal.kernel.util.StringPool;
19  import com.liferay.portal.upgrade.util.Table;
20  
21  import java.sql.Types;
22  
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  /**
27   * <a href="ResourcePermissionView.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Alexander Chow
30   */
31  public class ResourcePermissionView extends Table {
32  
33      public static String getActionId(String[] values) {
34          return values[4];
35      }
36  
37      public static long getCompanyId(String[] values) {
38          return Long.parseLong(values[0]);
39      }
40  
41      public static String getPrimaryKey(String[] values) {
42          return values[2];
43      }
44  
45      public static long getRoleId(String[] values) {
46          return Long.parseLong(values[3]);
47      }
48  
49      public static int getScope(String[] values) {
50          return Integer.parseInt(values[1]);
51      }
52  
53      public ResourcePermissionView(String name) {
54          super("ResourcePermissionView");
55  
56          List<Object[]> columns = new ArrayList<Object[]>();
57  
58          columns.add(new Object[] {"companyId", Types.BIGINT});
59          columns.add(new Object[] {"scope", Types.INTEGER});
60          columns.add(new Object[] {"primKey", Types.VARCHAR});
61          columns.add(new Object[] {"roleId", Types.BIGINT});
62          columns.add(new Object[] {"actionId", Types.VARCHAR});
63  
64          setColumns(columns.toArray(new Object[0][]));
65  
66          _name = name;
67      }
68  
69      public String getSelectSQL() throws Exception {
70          StringBundler sb = new StringBundler(4);
71  
72          sb.append(_SELECT_SQL);
73          sb.append(StringPool.APOSTROPHE);
74          sb.append(_name);
75          sb.append(StringPool.APOSTROPHE);
76  
77          return sb.toString();
78      }
79  
80      private String _name = StringPool.BLANK;
81  
82      private static final String _SELECT_SQL =
83          "SELECT Permission_.companyId, ResourceCode.scope, " +
84          "Resource_.primKey, Roles_Permissions.roleId, Permission_.actionId " +
85          "FROM Roles_Permissions, Permission_, Resource_, ResourceCode WHERE " +
86          "Permission_.permissionId = Roles_Permissions.permissionId AND " +
87          "Permission_.resourceId = Resource_.resourceId AND " +
88          "Resource_.codeId = ResourceCode.codeId AND ResourceCode.name = ";
89  
90  }