001
014
015 package com.liferay.portlet.expando.service.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.security.auth.CompanyThreadLocal;
020 import com.liferay.portal.util.PortalUtil;
021 import com.liferay.portlet.expando.model.ExpandoRow;
022 import com.liferay.portlet.expando.model.ExpandoTable;
023 import com.liferay.portlet.expando.model.ExpandoTableConstants;
024 import com.liferay.portlet.expando.service.base.ExpandoRowLocalServiceBaseImpl;
025
026 import java.util.Collections;
027 import java.util.List;
028
029
033 public class ExpandoRowLocalServiceImpl extends ExpandoRowLocalServiceBaseImpl {
034
035 @Override
036 public ExpandoRow addRow(long tableId, long classPK)
037 throws PortalException, SystemException {
038
039 ExpandoTable table = expandoTablePersistence.findByPrimaryKey(tableId);
040
041 long rowId = counterLocalService.increment();
042
043 ExpandoRow row = expandoRowPersistence.create(rowId);
044
045 row.setCompanyId(table.getCompanyId());
046 row.setTableId(tableId);
047 row.setClassPK(classPK);
048
049 expandoRowPersistence.update(row, false);
050
051 return row;
052 }
053
054 @Override
055 public void deleteRow(ExpandoRow row) throws SystemException {
056
057
058
059 expandoRowPersistence.remove(row);
060
061
062
063 expandoValueLocalService.deleteRowValues(row.getRowId());
064 }
065
066 @Override
067 public void deleteRow(long rowId) throws PortalException, SystemException {
068 ExpandoRow row = expandoRowPersistence.findByPrimaryKey(rowId);
069
070 deleteRow(row);
071 }
072
073 @Override
074 public void deleteRow(long tableId, long classPK)
075 throws PortalException, SystemException {
076
077 ExpandoRow row = expandoRowPersistence.findByT_C(tableId, classPK);
078
079 deleteRow(row);
080 }
081
082 @Override
083 public void deleteRow(
084 long companyId, long classNameId, String tableName, long classPK)
085 throws PortalException, SystemException {
086
087 ExpandoTable table = expandoTableLocalService.getTable(
088 companyId, classNameId, tableName);
089
090 expandoRowLocalService.deleteRow(table.getTableId(), classPK);
091 }
092
093 @Override
094 public void deleteRow(
095 long companyId, String className, String tableName, long classPK)
096 throws PortalException, SystemException {
097
098 long classNameId = PortalUtil.getClassNameId(className);
099
100 expandoRowLocalService.deleteRow(
101 companyId, classNameId, tableName, classPK);
102 }
103
104 @Override
105 public List<ExpandoRow> getDefaultTableRows(
106 long companyId, long classNameId, int start, int end)
107 throws SystemException {
108
109 return expandoRowLocalService.getRows(
110 companyId, classNameId, ExpandoTableConstants.DEFAULT_TABLE_NAME,
111 start, end);
112 }
113
114 @Override
115 public List<ExpandoRow> getDefaultTableRows(
116 long companyId, String className, int start, int end)
117 throws SystemException {
118
119 long classNameId = PortalUtil.getClassNameId(className);
120
121 return expandoRowLocalService.getDefaultTableRows(
122 companyId, classNameId, start, end);
123 }
124
125 @Override
126 public int getDefaultTableRowsCount(long companyId, long classNameId)
127 throws SystemException {
128
129 return expandoRowLocalService.getRowsCount(
130 companyId, classNameId, ExpandoTableConstants.DEFAULT_TABLE_NAME);
131 }
132
133 @Override
134 public int getDefaultTableRowsCount(long companyId, String className)
135 throws SystemException {
136
137 long classNameId = PortalUtil.getClassNameId(className);
138
139 return expandoRowLocalService.getDefaultTableRowsCount(
140 companyId, classNameId);
141 }
142
143 @Override
144 public ExpandoRow getRow(long rowId)
145 throws PortalException, SystemException {
146
147 return expandoRowPersistence.findByPrimaryKey(rowId);
148 }
149
150 @Override
151 public ExpandoRow getRow(long tableId, long classPK)
152 throws PortalException, SystemException {
153
154 return expandoRowPersistence.findByT_C(tableId, classPK);
155 }
156
157 @Override
158 public ExpandoRow getRow(
159 long companyId, long classNameId, String tableName, long classPK)
160 throws SystemException {
161
162 ExpandoTable table = expandoTablePersistence.fetchByC_C_N(
163 companyId, classNameId, tableName);
164
165 if (table == null) {
166 return null;
167 }
168
169 return expandoRowPersistence.fetchByT_C(table.getTableId(), classPK);
170 }
171
172 @Override
173 public ExpandoRow getRow(
174 long companyId, String className, String tableName, long classPK)
175 throws SystemException {
176
177 long classNameId = PortalUtil.getClassNameId(className);
178
179 return expandoRowLocalService.getRow(
180 companyId, classNameId, tableName, classPK);
181 }
182
183 @Override
184 public List<ExpandoRow> getRows(long tableId, int start, int end)
185 throws SystemException {
186
187 return expandoRowPersistence.findByTableId(tableId, start, end);
188 }
189
190 @Override
191 public List<ExpandoRow> getRows(
192 long companyId, long classNameId, String tableName, int start,
193 int end)
194 throws SystemException {
195
196 ExpandoTable table = expandoTablePersistence.fetchByC_C_N(
197 companyId, classNameId, tableName);
198
199 if (table == null) {
200 return Collections.emptyList();
201 }
202
203 return expandoRowPersistence.findByTableId(
204 table.getTableId(), start, end);
205 }
206
207 @Override
208 public List<ExpandoRow> getRows(
209 long companyId, String className, String tableName, int start,
210 int end)
211 throws SystemException {
212
213 long classNameId = PortalUtil.getClassNameId(className);
214
215 return expandoRowLocalService.getRows(
216 companyId, classNameId, tableName, start, end);
217 }
218
219
222 @Override
223 public List<ExpandoRow> getRows(
224 String className, String tableName, int start, int end)
225 throws SystemException {
226
227 long companyId = CompanyThreadLocal.getCompanyId();
228
229 return expandoRowLocalService.getRows(
230 companyId, className, tableName, start, end);
231 }
232
233 @Override
234 public int getRowsCount(long tableId) throws SystemException {
235 return expandoRowPersistence.countByTableId(tableId);
236 }
237
238 @Override
239 public int getRowsCount(long companyId, long classNameId, String tableName)
240 throws SystemException {
241
242 ExpandoTable table = expandoTablePersistence.fetchByC_C_N(
243 companyId, classNameId, tableName);
244
245 if (table == null) {
246 return 0;
247 }
248
249 return expandoRowPersistence.countByTableId(table.getTableId());
250 }
251
252 @Override
253 public int getRowsCount(long companyId, String className, String tableName)
254 throws SystemException {
255
256 long classNameId = PortalUtil.getClassNameId(className);
257
258 return expandoRowLocalService.getRowsCount(
259 companyId, classNameId, tableName);
260 }
261
262
265 @Override
266 public int getRowsCount(String className, String tableName)
267 throws SystemException {
268
269 long companyId = CompanyThreadLocal.getCompanyId();
270
271 return expandoRowLocalService.getRowsCount(
272 companyId, className, tableName);
273 }
274
275 }