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.dao.orm.SQLQuery;
018    import com.liferay.portal.kernel.dao.orm.Session;
019    import com.liferay.portal.kernel.exception.SystemException;
020    import com.liferay.portal.model.ServiceComponent;
021    import com.liferay.portal.model.impl.ServiceComponentImpl;
022    import com.liferay.portal.service.persistence.ServiceComponentFinder;
023    import com.liferay.util.dao.orm.CustomSQLUtil;
024    
025    import java.util.List;
026    
027    /**
028     * @author Alberto Chaparro
029     */
030    public class ServiceComponentFinderImpl
031            extends ServiceComponentFinderBaseImpl implements ServiceComponentFinder {
032    
033            public static final String FIND_BY_MAX_BUILD_NUMBER =
034                    ServiceComponentFinder.class.getName() + ".findByMaxBuildNumber";
035    
036            @Override
037            public List<ServiceComponent> findByMaxBuildNumber() {
038                    Session session = null;
039    
040                    try {
041                            session = openSession();
042    
043                            String sql = CustomSQLUtil.get(FIND_BY_MAX_BUILD_NUMBER);
044    
045                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
046    
047                            q.addEntity("ServiceComponent", ServiceComponentImpl.class);
048    
049                            return q.list(true);
050                    }
051                    catch (Exception e) {
052                            throw new SystemException(e);
053                    }
054                    finally {
055                            closeSession(session);
056                    }
057            }
058    
059    }