001
014
015 package com.liferay.portlet.asset.service.persistence.impl;
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.dao.orm.Type;
022 import com.liferay.portal.kernel.exception.SystemException;
023 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
024 import com.liferay.portlet.asset.model.AssetCategoryProperty;
025 import com.liferay.portlet.asset.model.impl.AssetCategoryPropertyImpl;
026 import com.liferay.portlet.asset.service.persistence.AssetCategoryPropertyFinder;
027 import com.liferay.util.dao.orm.CustomSQLUtil;
028
029 import java.util.ArrayList;
030 import java.util.Iterator;
031 import java.util.List;
032
033
037 public class AssetCategoryPropertyFinderImpl
038 extends BasePersistenceImpl<AssetCategoryProperty>
039 implements AssetCategoryPropertyFinder {
040
041 public static final String COUNT_BY_G_K =
042 AssetCategoryPropertyFinder.class.getName() + ".countByG_K";
043
044 public static final String FIND_BY_G_K =
045 AssetCategoryPropertyFinder.class.getName() + ".findByG_K";
046
047 @Override
048 public int countByG_K(long groupId, String key) {
049 Session session = null;
050
051 try {
052 session = openSession();
053
054 String sql = CustomSQLUtil.get(COUNT_BY_G_K);
055
056 SQLQuery q = session.createSynchronizedSQLQuery(sql);
057
058 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
059
060 QueryPos qPos = QueryPos.getInstance(q);
061
062 qPos.add(groupId);
063 qPos.add(key);
064
065 Iterator<Long> itr = q.iterate();
066
067 if (itr.hasNext()) {
068 Long count = itr.next();
069
070 if (count != null) {
071 return count.intValue();
072 }
073 }
074
075 return 0;
076 }
077 catch (Exception e) {
078 throw new SystemException(e);
079 }
080 finally {
081 closeSession(session);
082 }
083 }
084
085 @Override
086 public List<AssetCategoryProperty> findByG_K(long groupId, String key) {
087 return findByG_K(groupId, key, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
088 }
089
090 @Override
091 public List<AssetCategoryProperty> findByG_K(
092 long groupId, String key, int start, int end) {
093
094 Session session = null;
095
096 try {
097 session = openSession();
098
099 String sql = CustomSQLUtil.get(FIND_BY_G_K);
100
101 SQLQuery q = session.createSynchronizedSQLQuery(sql);
102
103 q.addScalar("categoryPropertyValue", Type.STRING);
104
105 QueryPos qPos = QueryPos.getInstance(q);
106
107 qPos.add(groupId);
108 qPos.add(key);
109
110 List<AssetCategoryProperty> categoryProperties = new ArrayList<>();
111
112 Iterator<String> itr = (Iterator<String>)QueryUtil.iterate(
113 q, getDialect(), start, end);
114
115 while (itr.hasNext()) {
116 String value = itr.next();
117
118 AssetCategoryProperty categoryProperty =
119 new AssetCategoryPropertyImpl();
120
121 categoryProperty.setKey(key);
122 categoryProperty.setValue(value);
123
124 categoryProperties.add(categoryProperty);
125 }
126
127 return categoryProperties;
128 }
129 catch (Exception e) {
130 throw new SystemException(e);
131 }
132 finally {
133 closeSession(session);
134 }
135 }
136
137 }