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.portlet.asset.service.persistence;
016    
017    import com.liferay.portal.kernel.dao.orm.QueryPos;
018    import com.liferay.portal.kernel.dao.orm.QueryUtil;
019    import com.liferay.portal.kernel.dao.orm.SQLQuery;
020    import com.liferay.portal.kernel.dao.orm.Session;
021    import com.liferay.portal.kernel.exception.SystemException;
022    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
023    import com.liferay.portlet.asset.model.AssetLink;
024    import com.liferay.portlet.asset.model.impl.AssetLinkImpl;
025    import com.liferay.util.dao.orm.CustomSQLUtil;
026    
027    import java.util.List;
028    
029    /**
030     * @author Julio Camarero
031     */
032    public class AssetLinkFinderImpl
033            extends BasePersistenceImpl<AssetLink> implements AssetLinkFinder {
034    
035            public static final String FIND_BY_E1_V =
036                    AssetLinkFinder.class.getName() + ".findByE1_V";
037    
038            public static final String FIND_BY_E1_T_V =
039                    AssetLinkFinder.class.getName() + ".findByE1_T_V";
040    
041            public List<AssetLink> findByE1_V(long entryId1, boolean visible)
042                    throws SystemException {
043    
044                    Session session = null;
045    
046                    try {
047                            session = openSession();
048    
049                            String sql = CustomSQLUtil.get(FIND_BY_E1_V);
050    
051                            SQLQuery q = session.createSQLQuery(sql);
052    
053                            q.addEntity("AssetLink", AssetLinkImpl.class);
054    
055                            QueryPos qPos = QueryPos.getInstance(q);
056    
057                            qPos.add(entryId1);
058                            qPos.add(visible);
059    
060                            return (List<AssetLink>)QueryUtil.list(
061                                    q, getDialect(), QueryUtil.ALL_POS, QueryUtil.ALL_POS);
062                    }
063                    catch (Exception e) {
064                            throw new SystemException(e);
065                    }
066                    finally {
067                            closeSession(session);
068                    }
069            }
070    
071            public List<AssetLink> findByE1_T_V(
072                            long entryId1, int type, boolean visible)
073                    throws SystemException {
074    
075                    Session session = null;
076    
077                    try {
078                            session = openSession();
079    
080                            String sql = CustomSQLUtil.get(FIND_BY_E1_T_V);
081    
082                            SQLQuery q = session.createSQLQuery(sql);
083    
084                            q.addEntity("AssetLink", AssetLinkImpl.class);
085    
086                            QueryPos qPos = QueryPos.getInstance(q);
087    
088                            qPos.add(entryId1);
089                            qPos.add(type);
090                            qPos.add(visible);
091    
092                            return (List<AssetLink>)QueryUtil.list(
093                                    q, getDialect(), QueryUtil.ALL_POS, QueryUtil.ALL_POS);
094                    }
095                    catch (Exception e) {
096                            throw new SystemException(e);
097                    }
098                    finally {
099                            closeSession(session);
100                    }
101            }
102    
103    }