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