001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }