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 leftPrimaryKey, long rightPrimaryKey) {
043    
044                    return _tableMapper.containsTableMapping(
045                            rightPrimaryKey, leftPrimaryKey);
046            }
047    
048            @Override
049            public int deleteLeftPrimaryKeyTableMappings(long leftPrimaryKey) {
050                    return _tableMapper.deleteRightPrimaryKeyTableMappings(leftPrimaryKey);
051            }
052    
053            @Override
054            public int deleteRightPrimaryKeyTableMappings(long rightPrimaryKey) {
055                    return _tableMapper.deleteLeftPrimaryKeyTableMappings(rightPrimaryKey);
056            }
057    
058            @Override
059            public boolean deleteTableMapping(
060                    long leftPrimaryKey, long rightPrimaryKey) {
061    
062                    return _tableMapper.deleteTableMapping(rightPrimaryKey, leftPrimaryKey);
063            }
064    
065            @Override
066            public void destroy() {
067                    _tableMapper.destroy();
068            }
069    
070            @Override
071            public List<L> getLeftBaseModels(
072                    long rightPrimaryKey, int start, int end, OrderByComparator<L> obc) {
073    
074                    return _tableMapper.getRightBaseModels(
075                            rightPrimaryKey, start, end, obc);
076            }
077    
078            @Override
079            public long[] getLeftPrimaryKeys(long rightPrimaryKey) {
080                    return _tableMapper.getRightPrimaryKeys(rightPrimaryKey);
081            }
082    
083            @Override
084            public TableMapper<R, L> getReverseTableMapper() {
085                    return _tableMapper;
086            }
087    
088            @Override
089            public List<R> getRightBaseModels(
090                    long leftPrimaryKey, int start, int end, OrderByComparator<R> obc) {
091    
092                    return _tableMapper.getLeftBaseModels(leftPrimaryKey, start, end, obc);
093            }
094    
095            @Override
096            public long[] getRightPrimaryKeys(long leftPrimaryKey) {
097                    return _tableMapper.getLeftPrimaryKeys(leftPrimaryKey);
098            }
099    
100            @Override
101            public boolean matches(String leftColumnName, String rightColumnName) {
102                    return _tableMapper.matches(rightColumnName, leftColumnName);
103            }
104    
105            private final TableMapper<R, L> _tableMapper;
106    
107    }