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