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