001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.convert.util;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.upgrade.util.Table;
020    
021    import java.sql.Types;
022    
023    import java.util.ArrayList;
024    import java.util.List;
025    
026    /**
027     * @author Alexander Chow
028     */
029    public class ResourcePermissionView extends Table {
030    
031            public static String getActionId(String[] values) {
032                    return values[4];
033            }
034    
035            public static long getCompanyId(String[] values) {
036                    return Long.parseLong(values[0]);
037            }
038    
039            public static String getPrimaryKey(String[] values) {
040                    return values[2];
041            }
042    
043            public static long getRoleId(String[] values) {
044                    return Long.parseLong(values[3]);
045            }
046    
047            public static int getScope(String[] values) {
048                    return Integer.parseInt(values[1]);
049            }
050    
051            public ResourcePermissionView(String name) {
052                    super("ResourcePermissionView");
053    
054                    List<Object[]> columns = new ArrayList<Object[]>();
055    
056                    columns.add(new Object[] {"companyId", Types.BIGINT});
057                    columns.add(new Object[] {"scope", Types.INTEGER});
058                    columns.add(new Object[] {"primKey", Types.VARCHAR});
059                    columns.add(new Object[] {"roleId", Types.BIGINT});
060                    columns.add(new Object[] {"actionId", Types.VARCHAR});
061    
062                    setColumns(columns.toArray(new Object[0][]));
063    
064                    _name = name;
065            }
066    
067            public String getSelectSQL() throws Exception {
068                    StringBundler sb = new StringBundler(4);
069    
070                    sb.append(_SELECT_SQL);
071                    sb.append(StringPool.APOSTROPHE);
072                    sb.append(_name);
073                    sb.append(StringPool.APOSTROPHE);
074    
075                    return sb.toString();
076            }
077    
078            private String _name = StringPool.BLANK;
079    
080            private static final String _SELECT_SQL =
081                    "SELECT Permission_.companyId, ResourceCode.scope, " +
082                    "Resource_.primKey, Roles_Permissions.roleId, Permission_.actionId " +
083                    "FROM Roles_Permissions, Permission_, Resource_, ResourceCode WHERE " +
084                    "Permission_.permissionId = Roles_Permissions.permissionId AND " +
085                    "Permission_.resourceId = Resource_.resourceId AND " +
086                    "Resource_.codeId = ResourceCode.codeId AND ResourceCode.name = ";
087    
088    }