1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
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.util.PortalUtil;
25  import com.liferay.portlet.expando.model.ExpandoRow;
26  import com.liferay.portlet.expando.model.ExpandoTable;
27  import com.liferay.portlet.expando.model.ExpandoTableConstants;
28  import com.liferay.portlet.expando.service.base.ExpandoRowLocalServiceBaseImpl;
29  
30  import java.util.Collections;
31  import java.util.List;
32  
33  /**
34   * <a href="ExpandoRowLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class ExpandoRowLocalServiceImpl extends ExpandoRowLocalServiceBaseImpl {
40  
41      public ExpandoRow addRow(long tableId, long classPK)
42          throws SystemException {
43  
44          long rowId = counterLocalService.increment();
45  
46          ExpandoRow row = expandoRowPersistence.create(rowId);
47  
48          row.setTableId(tableId);
49          row.setClassPK(classPK);
50  
51          expandoRowPersistence.update(row, false);
52  
53          return row;
54      }
55  
56      public void deleteRow(long rowId)
57          throws PortalException, SystemException {
58  
59          // Values
60  
61          expandoValueLocalService.deleteRowValues(rowId);
62  
63          // Row
64  
65          expandoRowPersistence.remove(rowId);
66      }
67  
68      public void deleteRow(long tableId, long classPK)
69          throws PortalException, SystemException {
70  
71          ExpandoRow row = expandoRowPersistence.findByT_C(tableId, classPK);
72  
73          deleteRow(row.getRowId());
74      }
75  
76      public void deleteRow(long classNameId, String tableName, long classPK)
77          throws PortalException, SystemException {
78  
79          ExpandoTable table = expandoTablePersistence.findByC_N(
80              classNameId, tableName);
81  
82          deleteRow(table.getTableId(), classPK);
83      }
84  
85      public void deleteRow(String className, String tableName, long classPK)
86          throws PortalException, SystemException {
87  
88          long classNameId = PortalUtil.getClassNameId(className);
89  
90          deleteRow(classNameId, tableName, classPK);
91      }
92  
93      public List<ExpandoRow> getDefaultTableRows(
94              long classNameId, int start, int end)
95          throws SystemException {
96  
97          ExpandoTable table = expandoTablePersistence.fetchByC_N(
98              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         ExpandoTable table = expandoTablePersistence.fetchByC_N(
121             classNameId, ExpandoTableConstants.DEFAULT_TABLE_NAME);
122 
123         if (table == null) {
124             return 0;
125         }
126 
127         return expandoRowPersistence.countByTableId(table.getTableId());
128     }
129 
130     public int getDefaultTableRowsCount(String className)
131         throws SystemException {
132 
133         long classNameId = PortalUtil.getClassNameId(className);
134 
135         return getDefaultTableRowsCount(classNameId);
136     }
137 
138     public ExpandoRow getRow(long rowId)
139         throws PortalException, SystemException {
140 
141         return expandoRowPersistence.findByPrimaryKey(rowId);
142     }
143 
144     public ExpandoRow getRow(long tableId, long classPK)
145         throws PortalException, SystemException {
146 
147         return expandoRowPersistence.findByT_C(tableId, classPK);
148     }
149 
150     public ExpandoRow getRow(long classNameId, String tableName, long classPK)
151         throws SystemException {
152 
153         ExpandoTable table = expandoTablePersistence.fetchByC_N(
154             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(String className, String tableName, long classPK)
164         throws SystemException {
165 
166         long classNameId = PortalUtil.getClassNameId(className);
167 
168         return getRow(classNameId, tableName, classPK);
169     }
170 
171     public List<ExpandoRow> getRows(long tableId, int start, int end)
172         throws SystemException {
173 
174         return expandoRowPersistence.findByTableId(tableId, start, end);
175     }
176 
177     public List<ExpandoRow> getRows(
178             long classNameId, String tableName, int start, int end)
179         throws SystemException {
180 
181         ExpandoTable table = expandoTablePersistence.fetchByC_N(
182             classNameId, tableName);
183 
184         if (table == null) {
185             return Collections.EMPTY_LIST;
186         }
187 
188         return expandoRowPersistence.findByTableId(
189             table.getTableId(), start, end);
190     }
191 
192     public List<ExpandoRow> getRows(
193             String className, String tableName, int start, int end)
194         throws SystemException {
195 
196         long classNameId = PortalUtil.getClassNameId(className);
197 
198         return getRows(classNameId, tableName, start, end);
199     }
200 
201     public int getRowsCount(long tableId) throws SystemException {
202         return expandoRowPersistence.countByTableId(tableId);
203     }
204 
205     public int getRowsCount(long classNameId, String tableName)
206         throws SystemException {
207 
208         ExpandoTable table = expandoTablePersistence.fetchByC_N(
209             classNameId, tableName);
210 
211         if (table == null) {
212             return 0;
213         }
214 
215         return expandoRowPersistence.countByTableId(table.getTableId());
216     }
217 
218     public int getRowsCount(String className, String tableName)
219         throws SystemException {
220 
221         long classNameId = PortalUtil.getClassNameId(className);
222 
223         return getRowsCount(classNameId, tableName);
224     }
225 
226 }