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