1
22
23 package com.liferay.portlet.expando.service.impl;
24
25 import com.liferay.portal.PortalException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.util.Validator;
28 import com.liferay.portal.util.PortalUtil;
29 import com.liferay.portlet.expando.ValueDataException;
30 import com.liferay.portlet.expando.model.ExpandoColumn;
31 import com.liferay.portlet.expando.model.ExpandoTable;
32 import com.liferay.portlet.expando.model.ExpandoTableConstants;
33 import com.liferay.portlet.expando.model.ExpandoValue;
34 import com.liferay.portlet.expando.service.base.ExpandoValueLocalServiceBaseImpl;
35
36 import java.util.List;
37
38
46 public class ExpandoValueLocalServiceImpl
47 extends ExpandoValueLocalServiceBaseImpl {
48
49 public ExpandoValue addValue(
50 long columnId, long rowId, long classPK, String data)
51 throws PortalException, SystemException {
52
53 validate(data);
54
55 ExpandoColumn column = expandoColumnPersistence.findByPrimaryKey(
56 columnId);
57
58 ExpandoValue value = expandoValuePersistence.fetchByT_C_R(
59 column.getTableId(), columnId, rowId);
60
61 if (value == null) {
62 ExpandoTable table = expandoTablePersistence.findByPrimaryKey(
63 column.getTableId());
64
65 long valueId = counterLocalService.increment();
66
67 value = expandoValuePersistence.create(valueId);
68
69 value.setTableId(column.getTableId());
70 value.setColumnId(columnId);
71 value.setRowId(rowId);
72 value.setClassNameId(table.getClassNameId());
73 value.setClassPK(classPK);
74 }
75
76 value.setData(data);
77
78 expandoValuePersistence.update(value, false);
79
80 return value;
81 }
82
83 public void deleteColumnValues(long columnId) throws SystemException {
84 expandoValuePersistence.removeByColumnId(columnId);
85 }
86
87 public void deleteRowValues(long rowId) throws SystemException {
88 expandoValuePersistence.removeByRowId(rowId);
89 }
90
91 public void deleteTableValues(long tableId) throws SystemException {
92 expandoValuePersistence.removeByTableId(tableId);
93 }
94
95 public void deleteValue(long valueId)
96 throws PortalException, SystemException {
97
98 expandoValuePersistence.remove(valueId);
99 }
100
101 public void deleteValues(String className, long classPK)
102 throws PortalException, SystemException {
103
104 long classNameId = PortalUtil.getClassNameId(className);
105
106 deleteValues(classNameId, classPK);
107 }
108
109 public void deleteValues(long classNameId, long classPK)
110 throws PortalException, SystemException {
111
112 expandoValuePersistence.removeByC_C(classNameId, classPK);
113 }
114
115 public List<ExpandoValue> getColumnValues(long columnId, int begin, int end)
116 throws SystemException {
117
118 return expandoValuePersistence.findByColumnId(columnId, begin, end);
119 }
120
121 public List<ExpandoValue> getColumnValues(
122 String className, String tableName, String columnName, int begin,
123 int end)
124 throws SystemException {
125
126 long classNameId = PortalUtil.getClassNameId(className);
127
128 return getColumnValues(classNameId, tableName, columnName, begin, end);
129 }
130
131 public List<ExpandoValue> getColumnValues(
132 long classNameId, String tableName, String columnName, int begin,
133 int end)
134 throws SystemException {
135
136 return expandoValueFinder.findByTC_TN_CN(
137 classNameId, tableName, columnName, begin, end);
138 }
139
140 public int getColumnValuesCount(long columnId) throws SystemException {
141 return expandoValuePersistence.countByColumnId(columnId);
142 }
143
144 public int getColumnValuesCount(
145 String className, String tableName, String columnName)
146 throws SystemException {
147
148 long classNameId = PortalUtil.getClassNameId(className);
149
150 return getColumnValuesCount(classNameId, tableName, columnName);
151 }
152
153 public int getColumnValuesCount(
154 long classNameId, String tableName, String columnName)
155 throws SystemException {
156
157 return expandoValueFinder.countByTC_TN_CN(
158 classNameId, tableName, columnName);
159 }
160
161 public List<ExpandoValue> getDefaultTableColumnValues(
162 String className, String columnName, int begin, int end)
163 throws SystemException {
164
165 long classNameId = PortalUtil.getClassNameId(className);
166
167 return getDefaultTableColumnValues(classNameId, columnName, begin, end);
168 }
169
170 public List<ExpandoValue> getDefaultTableColumnValues(
171 long classNameId, String columnName, int begin, int end)
172 throws SystemException {
173
174 return getColumnValues(
175 classNameId, ExpandoTableConstants.DEFAULT_TABLE_NAME, columnName,
176 begin, end);
177 }
178
179 public int getDefaultTableColumnValuesCount(
180 String className, String columnName)
181 throws SystemException {
182
183 long classNameId = PortalUtil.getClassNameId(className);
184
185 return getDefaultTableColumnValuesCount(classNameId, columnName);
186 }
187
188 public int getDefaultTableColumnValuesCount(
189 long classNameId, String columnName)
190 throws SystemException {
191
192 return getColumnValuesCount(
193 classNameId, ExpandoTableConstants.DEFAULT_TABLE_NAME, columnName);
194 }
195
196 public List<ExpandoValue> getRowValues(long rowId) throws SystemException {
197 return expandoValuePersistence.findByRowId(rowId);
198 }
199
200 public List<ExpandoValue> getRowValues(long rowId, int begin, int end)
201 throws SystemException {
202
203 return expandoValuePersistence.findByRowId(rowId, begin, end);
204 }
205
206 public int getRowValuesCount(long rowId) throws SystemException {
207 return expandoValuePersistence.countByRowId(rowId);
208 }
209
210 public ExpandoValue getValue(long valueId)
211 throws PortalException, SystemException {
212
213 return expandoValuePersistence.findByPrimaryKey(valueId);
214 }
215
216 public ExpandoValue getValue(long columnId, long rowId)
217 throws PortalException, SystemException {
218
219 return expandoValuePersistence.findByC_R(columnId, rowId);
220 }
221
222 public ExpandoValue getValue(
223 String className, String tableName, String name, long rowId)
224 throws PortalException, SystemException {
225
226 long classNameId = PortalUtil.getClassNameId(className);
227
228 return getValue(classNameId, tableName, name, rowId);
229 }
230
231 public ExpandoValue getValue(
232 long classNameId, String tableName, String name, long rowId)
233 throws PortalException, SystemException {
234
235 return expandoValueFinder.findByTC_TN_N(
236 classNameId, tableName, name, rowId);
237 }
238
239 protected void validate(String data) throws PortalException {
240 if (Validator.isNull(data)) {
241 throw new ValueDataException();
242 }
243 }
244
245 }