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.security.auth.CompanyThreadLocal;
28 import com.liferay.portal.util.PortalUtil;
29 import com.liferay.portlet.expando.model.ExpandoRow;
30 import com.liferay.portlet.expando.model.ExpandoTable;
31 import com.liferay.portlet.expando.model.ExpandoTableConstants;
32 import com.liferay.portlet.expando.service.base.ExpandoRowLocalServiceBaseImpl;
33
34 import java.util.Collections;
35 import java.util.List;
36
37
42 public class ExpandoRowLocalServiceImpl extends ExpandoRowLocalServiceBaseImpl {
43
44 public ExpandoRow addRow(long tableId, long classPK)
45 throws PortalException, SystemException {
46
47 ExpandoTable table = expandoTablePersistence.findByPrimaryKey(tableId);
48
49 long rowId = counterLocalService.increment();
50
51 ExpandoRow row = expandoRowPersistence.create(rowId);
52
53 row.setCompanyId(table.getCompanyId());
54 row.setTableId(tableId);
55 row.setClassPK(classPK);
56
57 expandoRowPersistence.update(row, false);
58
59 return row;
60 }
61
62 public void deleteRow(long rowId)
63 throws PortalException, SystemException {
64
65
67 expandoRowPersistence.remove(rowId);
68
69
71 expandoValueLocalService.deleteRowValues(rowId);
72 }
73
74 public void deleteRow(long tableId, long classPK)
75 throws PortalException, SystemException {
76
77 ExpandoRow row = expandoRowPersistence.findByT_C(tableId, classPK);
78
79 deleteRow(row.getRowId());
80 }
81
82 public void deleteRow(long classNameId, String tableName, long classPK)
83 throws PortalException, SystemException {
84
85 ExpandoTable table = expandoTableLocalService.getTable(
86 classNameId, tableName);
87
88 deleteRow(table.getTableId(), classPK);
89 }
90
91 public void deleteRow(String className, String tableName, long classPK)
92 throws PortalException, SystemException {
93
94 long classNameId = PortalUtil.getClassNameId(className);
95
96 deleteRow(classNameId, tableName, classPK);
97 }
98
99 public List<ExpandoRow> getDefaultTableRows(
100 long classNameId, int start, int end)
101 throws SystemException {
102
103 long companyId = CompanyThreadLocal.getCompanyId();
104
105 ExpandoTable table = expandoTablePersistence.fetchByC_C_N(
106 companyId, classNameId, ExpandoTableConstants.DEFAULT_TABLE_NAME);
107
108 if (table == null) {
109 return Collections.EMPTY_LIST;
110 }
111
112 return expandoRowPersistence.findByTableId(
113 table.getTableId(), start, end);
114 }
115
116 public List<ExpandoRow> getDefaultTableRows(
117 String className, int start, int end)
118 throws SystemException {
119
120 long classNameId = PortalUtil.getClassNameId(className);
121
122 return getDefaultTableRows(classNameId, start, end);
123 }
124
125 public int getDefaultTableRowsCount(long classNameId)
126 throws SystemException {
127
128 long companyId = CompanyThreadLocal.getCompanyId();
129
130 ExpandoTable table = expandoTablePersistence.fetchByC_C_N(
131 companyId, classNameId, ExpandoTableConstants.DEFAULT_TABLE_NAME);
132
133 if (table == null) {
134 return 0;
135 }
136
137 return expandoRowPersistence.countByTableId(table.getTableId());
138 }
139
140 public int getDefaultTableRowsCount(String className)
141 throws SystemException {
142
143 long classNameId = PortalUtil.getClassNameId(className);
144
145 return getDefaultTableRowsCount(classNameId);
146 }
147
148 public ExpandoRow getRow(long rowId)
149 throws PortalException, SystemException {
150
151 return expandoRowPersistence.findByPrimaryKey(rowId);
152 }
153
154 public ExpandoRow getRow(long tableId, long classPK)
155 throws PortalException, SystemException {
156
157 return expandoRowPersistence.findByT_C(tableId, classPK);
158 }
159
160 public ExpandoRow getRow(long classNameId, String tableName, long classPK)
161 throws SystemException {
162
163 long companyId = CompanyThreadLocal.getCompanyId();
164
165 ExpandoTable table = expandoTablePersistence.fetchByC_C_N(
166 companyId, classNameId, tableName);
167
168 if (table == null) {
169 return null;
170 }
171
172 return expandoRowPersistence.fetchByT_C(table.getTableId(), classPK);
173 }
174
175 public ExpandoRow getRow(String className, String tableName, long classPK)
176 throws SystemException {
177
178 long classNameId = PortalUtil.getClassNameId(className);
179
180 return getRow(classNameId, tableName, classPK);
181 }
182
183 public List<ExpandoRow> getRows(long tableId, int start, int end)
184 throws SystemException {
185
186 return expandoRowPersistence.findByTableId(tableId, start, end);
187 }
188
189 public List<ExpandoRow> getRows(
190 long classNameId, String tableName, int start, int end)
191 throws SystemException {
192
193 long companyId = CompanyThreadLocal.getCompanyId();
194
195 ExpandoTable table = expandoTablePersistence.fetchByC_C_N(
196 companyId, classNameId, tableName);
197
198 if (table == null) {
199 return Collections.EMPTY_LIST;
200 }
201
202 return expandoRowPersistence.findByTableId(
203 table.getTableId(), start, end);
204 }
205
206 public List<ExpandoRow> getRows(
207 String className, String tableName, int start, int end)
208 throws SystemException {
209
210 long classNameId = PortalUtil.getClassNameId(className);
211
212 return getRows(classNameId, tableName, start, end);
213 }
214
215 public int getRowsCount(long tableId) throws SystemException {
216 return expandoRowPersistence.countByTableId(tableId);
217 }
218
219 public int getRowsCount(long classNameId, String tableName)
220 throws SystemException {
221
222 long companyId = CompanyThreadLocal.getCompanyId();
223
224 ExpandoTable table = expandoTablePersistence.fetchByC_C_N(
225 companyId, classNameId, tableName);
226
227 if (table == null) {
228 return 0;
229 }
230
231 return expandoRowPersistence.countByTableId(table.getTableId());
232 }
233
234 public int getRowsCount(String className, String tableName)
235 throws SystemException {
236
237 long classNameId = PortalUtil.getClassNameId(className);
238
239 return getRowsCount(classNameId, tableName);
240 }
241
242 }