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