001    /**
002     * Copyright (c) 2000-present 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.service.persistence.impl;
016    
017    import com.liferay.portal.kernel.util.OrderByComparator;
018    import com.liferay.portal.model.BaseModel;
019    
020    import java.util.List;
021    
022    /**
023     * @author Shuyang Zhou
024     */
025    public class ReverseTableMapper<L extends BaseModel<L>, R extends BaseModel<R>>
026            implements TableMapper<L, R> {
027    
028            public ReverseTableMapper(TableMapper<R, L> tableMapper) {
029                    _tableMapper = tableMapper;
030            }
031    
032            @Override
033            public boolean addTableMapping(
034                    long companyId, long leftPrimaryKey, long rightPrimaryKey) {
035    
036                    return _tableMapper.addTableMapping(
037                            companyId, rightPrimaryKey, leftPrimaryKey);
038            }
039    
040            @Override
041            public boolean containsTableMapping(
042                    long companyId, long leftPrimaryKey, long rightPrimaryKey) {
043    
044                    return _tableMapper.containsTableMapping(
045                            companyId, rightPrimaryKey, leftPrimaryKey);
046            }
047    
048            @Override
049            public int deleteLeftPrimaryKeyTableMappings(
050                    long companyId, long leftPrimaryKey) {
051    
052                    return _tableMapper.deleteRightPrimaryKeyTableMappings(
053                            companyId, leftPrimaryKey);
054            }
055    
056            @Override
057            public int deleteRightPrimaryKeyTableMappings(
058                    long companyId, long rightPrimaryKey) {
059    
060                    return _tableMapper.deleteLeftPrimaryKeyTableMappings(
061                            companyId, rightPrimaryKey);
062            }
063    
064            @Override
065            public boolean deleteTableMapping(
066                    long companyId, long leftPrimaryKey, long rightPrimaryKey) {
067    
068                    return _tableMapper.deleteTableMapping(
069                            companyId, rightPrimaryKey, leftPrimaryKey);
070            }
071    
072            @Override
073            public void destroy() {
074                    _tableMapper.destroy();
075            }
076    
077            @Override
078            public List<L> getLeftBaseModels(
079                    long companyId, long rightPrimaryKey, int start, int end,
080                    OrderByComparator<L> obc) {
081    
082                    return _tableMapper.getRightBaseModels(
083                            companyId, rightPrimaryKey, start, end, obc);
084            }
085    
086            @Override
087            public long[] getLeftPrimaryKeys(long companyId, long rightPrimaryKey) {
088                    return _tableMapper.getRightPrimaryKeys(companyId, rightPrimaryKey);
089            }
090    
091            @Override
092            public TableMapper<R, L> getReverseTableMapper() {
093                    return _tableMapper;
094            }
095    
096            @Override
097            public List<R> getRightBaseModels(
098                    long companyId, long leftPrimaryKey, int start, int end,
099                    OrderByComparator<R> obc) {
100    
101                    return _tableMapper.getLeftBaseModels(
102                            companyId, leftPrimaryKey, start, end, obc);
103            }
104    
105            @Override
106            public long[] getRightPrimaryKeys(long companyId, long leftPrimaryKey) {
107                    return _tableMapper.getLeftPrimaryKeys(companyId, leftPrimaryKey);
108            }
109    
110            @Override
111            public boolean matches(String leftColumnName, String rightColumnName) {
112                    return _tableMapper.matches(rightColumnName, leftColumnName);
113            }
114    
115            private final TableMapper<R, L> _tableMapper;
116    
117    }