1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.security.auth.CompanyThreadLocal;
28  import com.liferay.portal.util.PortalUtil;
29  import com.liferay.portlet.expando.model.ExpandoRow;
30  import com.liferay.portlet.expando.model.ExpandoTable;
31  import com.liferay.portlet.expando.model.ExpandoTableConstants;
32  import com.liferay.portlet.expando.service.base.ExpandoRowLocalServiceBaseImpl;
33  
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   */
42  public class ExpandoRowLocalServiceImpl extends ExpandoRowLocalServiceBaseImpl {
43  
44      public ExpandoRow addRow(long tableId, long classPK)
45          throws PortalException, SystemException {
46  
47          ExpandoTable table = expandoTablePersistence.findByPrimaryKey(tableId);
48  
49          long rowId = counterLocalService.increment();
50  
51          ExpandoRow row = expandoRowPersistence.create(rowId);
52  
53          row.setCompanyId(table.getCompanyId());
54          row.setTableId(tableId);
55          row.setClassPK(classPK);
56  
57          expandoRowPersistence.update(row, false);
58  
59          return row;
60      }
61  
62      public void deleteRow(long rowId)
63          throws PortalException, SystemException {
64  
65          // Values
66  
67          expandoValueLocalService.deleteRowValues(rowId);
68  
69          // Row
70  
71          expandoRowPersistence.remove(rowId);
72      }
73  
74      public void deleteRow(long tableId, long classPK)
75          throws PortalException, SystemException {
76  
77          ExpandoRow row = expandoRowPersistence.findByT_C(tableId, classPK);
78  
79          deleteRow(row.getRowId());
80      }
81  
82      public void deleteRow(String className, String tableName, long classPK)
83          throws PortalException, SystemException {
84  
85          long classNameId = PortalUtil.getClassNameId(className);
86  
87          deleteRow(classNameId, tableName, classPK);
88      }
89  
90      public void deleteRow(long classNameId, String tableName, long classPK)
91          throws PortalException, SystemException {
92  
93          ExpandoTable table = expandoTableLocalService.getTable(
94              classNameId, tableName);
95  
96          deleteRow(table.getTableId(), classPK);
97      }
98  
99      public List<ExpandoRow> getDefaultTableRows(
100             String className, int start, int end)
101         throws SystemException {
102 
103         long classNameId = PortalUtil.getClassNameId(className);
104 
105         return getDefaultTableRows(classNameId, start, end);
106     }
107 
108     public List<ExpandoRow> getDefaultTableRows(
109             long classNameId, int start, int end)
110         throws SystemException {
111 
112         long companyId = CompanyThreadLocal.getCompanyId();
113 
114         return expandoRowFinder.findByTC_TC_TN(
115             companyId, classNameId, ExpandoTableConstants.DEFAULT_TABLE_NAME,
116             start, end);
117     }
118 
119     public int getDefaultTableRowsCount(String className)
120         throws SystemException {
121 
122         long classNameId = PortalUtil.getClassNameId(className);
123 
124         return getDefaultTableRowsCount(classNameId);
125     }
126 
127     public int getDefaultTableRowsCount(long classNameId)
128         throws SystemException {
129 
130         long companyId = CompanyThreadLocal.getCompanyId();
131 
132         return expandoRowFinder.countByTC_TC_TN(
133             companyId, classNameId, ExpandoTableConstants.DEFAULT_TABLE_NAME);
134     }
135 
136     public ExpandoRow getRow(long rowId)
137         throws PortalException, SystemException {
138 
139         return expandoRowPersistence.findByPrimaryKey(rowId);
140     }
141 
142     public ExpandoRow getRow(long tableId, long classPK)
143         throws PortalException, SystemException {
144 
145         return expandoRowPersistence.findByT_C(tableId, classPK);
146     }
147 
148     public ExpandoRow getRow(String className, String tableName, long classPK)
149         throws SystemException {
150 
151         long classNameId = PortalUtil.getClassNameId(className);
152 
153         return getRow(classNameId, tableName, classPK);
154     }
155 
156     public ExpandoRow getRow(long classNameId, String tableName, long classPK)
157         throws SystemException {
158 
159         long companyId = CompanyThreadLocal.getCompanyId();
160 
161         return expandoRowFinder.fetchByTC_TC_TN_C(
162             companyId, classNameId, tableName, classPK);
163     }
164 
165     public List<ExpandoRow> getRows(long tableId, int start, int end)
166         throws SystemException {
167 
168         return expandoRowPersistence.findByTableId(tableId, start, end);
169     }
170 
171     public List<ExpandoRow> getRows(
172             String className, String tableName, int start, int end)
173         throws SystemException {
174 
175         long classNameId = PortalUtil.getClassNameId(className);
176 
177         return getRows(classNameId, tableName, start, end);
178     }
179 
180     public List<ExpandoRow> getRows(
181             long classNameId, String tableName, int start, int end)
182         throws SystemException {
183 
184         long companyId = CompanyThreadLocal.getCompanyId();
185 
186         return expandoRowFinder.findByTC_TC_TN(
187             companyId, classNameId, tableName, start, end);
188     }
189 
190     public int getRowsCount(long tableId) throws SystemException {
191         return expandoRowPersistence.countByTableId(tableId);
192     }
193 
194     public int getRowsCount(String className, String tableName)
195         throws SystemException {
196 
197         long classNameId = PortalUtil.getClassNameId(className);
198 
199         return getRowsCount(classNameId, tableName);
200     }
201 
202     public int getRowsCount(long classNameId, String tableName)
203         throws SystemException {
204 
205         long companyId = CompanyThreadLocal.getCompanyId();
206 
207         return expandoRowFinder.countByTC_TC_TN(
208             companyId, classNameId, tableName);
209     }
210 
211 }