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