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