001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchLayoutSetBranchException;
018 import com.liferay.portal.kernel.dao.orm.QueryPos;
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.kernel.util.StringBundler;
023 import com.liferay.portal.model.Layout;
024 import com.liferay.portal.model.LayoutSetBranch;
025 import com.liferay.portal.model.impl.LayoutSetBranchImpl;
026 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
027 import com.liferay.util.dao.orm.CustomSQLUtil;
028
029 import java.util.List;
030
031
034 public class LayoutSetBranchFinderImpl
035 extends BasePersistenceImpl<Layout> implements LayoutSetBranchFinder {
036
037 public static final String FIND_BY_MASTER =
038 LayoutSetBranchFinder.class.getName() + ".findByMaster";
039
040 public LayoutSetBranch findByMaster(long groupId, boolean privateLayout)
041 throws NoSuchLayoutSetBranchException, SystemException {
042
043 Session session = null;
044
045 try {
046 session = openSession();
047
048 String sql = CustomSQLUtil.get(FIND_BY_MASTER);
049
050 SQLQuery q = session.createSQLQuery(sql);
051
052 q.addEntity("LayoutSetBranch", LayoutSetBranchImpl.class);
053
054 QueryPos qPos = QueryPos.getInstance(q);
055
056 qPos.add(groupId);
057 qPos.add(privateLayout);
058 qPos.add(true);
059
060 List<LayoutSetBranch> layoutSetBranches = q.list();
061
062 if (!layoutSetBranches.isEmpty()) {
063 return layoutSetBranches.get(0);
064 }
065 }
066 catch (Exception e) {
067 throw new SystemException(e);
068 }
069 finally {
070 closeSession(session);
071 }
072
073 StringBundler sb = new StringBundler(5);
074
075 sb.append("No LayoutSetBranch exists with the key {groupId=");
076 sb.append(groupId);
077 sb.append(", privateLayout=");
078 sb.append(privateLayout);
079 sb.append(", master=true}");
080
081 throw new NoSuchLayoutSetBranchException(sb.toString());
082 }
083
084 }