1   /**
2    * Copyright (c) 2000-2008 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.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.List;
34  
35  /**
36   * <a href="ExpandoRowLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   *
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(String className, String tableName, long classPK)
79          throws PortalException, SystemException {
80  
81          long classNameId = PortalUtil.getClassNameId(className);
82  
83          deleteRow(classNameId, tableName, classPK);
84      }
85  
86      public void deleteRow(long classNameId, String tableName, long classPK)
87          throws PortalException, SystemException {
88  
89          ExpandoTable table = expandoTableLocalService.getTable(
90              classNameId, tableName);
91  
92          deleteRow(table.getTableId(), classPK);
93      }
94  
95      public List<ExpandoRow> getDefaultTableRows(
96              String className, int start, int end)
97          throws SystemException {
98  
99          long classNameId = PortalUtil.getClassNameId(className);
100 
101         return getDefaultTableRows(classNameId, start, end);
102     }
103 
104     public List<ExpandoRow> getDefaultTableRows(
105             long classNameId, int start, int end)
106         throws SystemException {
107 
108         return expandoRowFinder.findByTC_TN(
109             classNameId, ExpandoTableConstants.DEFAULT_TABLE_NAME, start, end);
110     }
111 
112     public int getDefaultTableRowsCount(String className)
113         throws SystemException {
114 
115         long classNameId = PortalUtil.getClassNameId(className);
116 
117         return getDefaultTableRowsCount(classNameId);
118     }
119 
120     public int getDefaultTableRowsCount(long classNameId)
121         throws SystemException {
122 
123         return expandoRowFinder.countByTC_TN(
124             classNameId, ExpandoTableConstants.DEFAULT_TABLE_NAME);
125     }
126 
127     public ExpandoRow getRow(long rowId)
128         throws PortalException, SystemException {
129 
130         return expandoRowPersistence.findByPrimaryKey(rowId);
131     }
132 
133     public ExpandoRow getRow(long tableId, long classPK)
134         throws PortalException, SystemException {
135 
136         return expandoRowPersistence.findByT_C(tableId, classPK);
137     }
138 
139     public ExpandoRow getRow(String className, String tableName, long classPK)
140         throws SystemException {
141 
142         long classNameId = PortalUtil.getClassNameId(className);
143 
144         return getRow(classNameId, tableName, classPK);
145     }
146 
147     public ExpandoRow getRow(long classNameId, String tableName, long classPK)
148         throws SystemException {
149 
150         return expandoRowFinder.fetchByTC_TN_C(classNameId, tableName, classPK);
151     }
152 
153     public List<ExpandoRow> getRows(long tableId, int start, int end)
154         throws SystemException {
155 
156         return expandoRowPersistence.findByTableId(tableId, start, end);
157     }
158 
159     public List<ExpandoRow> getRows(
160             String className, String tableName, int start, int end)
161         throws SystemException {
162 
163         long classNameId = PortalUtil.getClassNameId(className);
164 
165         return getRows(classNameId, tableName, start, end);
166     }
167 
168     public List<ExpandoRow> getRows(
169             long classNameId, String tableName, int start, int end)
170         throws SystemException {
171 
172         return expandoRowFinder.findByTC_TN(
173             classNameId, tableName, start, end);
174     }
175 
176     public int getRowsCount(long tableId) throws SystemException {
177         return expandoRowPersistence.countByTableId(tableId);
178     }
179 
180     public int getRowsCount(String className, String tableName)
181         throws SystemException {
182 
183         long classNameId = PortalUtil.getClassNameId(className);
184 
185         return getRowsCount(classNameId, tableName);
186     }
187 
188     public int getRowsCount(long classNameId, String tableName)
189         throws SystemException {
190 
191         return expandoRowFinder.countByTC_TN(classNameId, tableName);
192     }
193 
194 }