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.ExpandoTableConstants;
30  import com.liferay.portlet.expando.service.base.ExpandoRowLocalServiceBaseImpl;
31  
32  import java.util.List;
33  
34  /**
35   * <a href="ExpandoRowLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Brian Wing Shun Chan
38   *
39   */
40  public class ExpandoRowLocalServiceImpl extends ExpandoRowLocalServiceBaseImpl {
41  
42      public ExpandoRow addRow(long tableId)
43          throws PortalException, SystemException {
44  
45          long rowId = counterLocalService.increment();
46  
47          ExpandoRow row = expandoRowPersistence.create(rowId);
48  
49          row.setTableId(tableId);
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 List<ExpandoRow> getDefaultTableRows(
69              String className, int begin, int end)
70          throws SystemException {
71  
72          long classNameId = PortalUtil.getClassNameId(className);
73  
74          return getDefaultTableRows(classNameId, begin, end);
75      }
76  
77      public List<ExpandoRow> getDefaultTableRows(
78              long classNameId, int begin, int end)
79          throws SystemException {
80  
81          return expandoRowFinder.findByTC_TN(
82              classNameId, ExpandoTableConstants.DEFAULT_TABLE_NAME, begin, end);
83      }
84  
85      public int getDefaultTableRowsCount(String className)
86          throws SystemException {
87  
88          long classNameId = PortalUtil.getClassNameId(className);
89  
90          return getDefaultTableRowsCount(classNameId);
91      }
92  
93      public int getDefaultTableRowsCount(long classNameId)
94          throws SystemException {
95  
96          return expandoRowFinder.countByTC_TN(
97              classNameId, ExpandoTableConstants.DEFAULT_TABLE_NAME);
98      }
99  
100     public List<ExpandoRow> getRows(long tableId, int begin, int end)
101         throws SystemException {
102 
103         return expandoRowPersistence.findByTableId(tableId, begin, end);
104     }
105 
106     public List<ExpandoRow> getRows(
107             String className, String tableName, int begin, int end)
108         throws SystemException {
109 
110         long classNameId = PortalUtil.getClassNameId(className);
111 
112         return getRows(classNameId, tableName, begin, end);
113     }
114 
115     public List<ExpandoRow> getRows(
116             long classNameId, String tableName, int begin, int end)
117         throws SystemException {
118 
119         return expandoRowFinder.findByTC_TN(
120             classNameId, tableName, begin, end);
121     }
122 
123     public int getRowsCount(long tableId) throws SystemException {
124         return expandoRowPersistence.countByTableId(tableId);
125     }
126 
127     public int getRowsCount(String className, String tableName)
128         throws SystemException {
129 
130         long classNameId = PortalUtil.getClassNameId(className);
131 
132         return getRowsCount(classNameId, tableName);
133     }
134 
135     public int getRowsCount(long classNameId, String tableName)
136         throws SystemException {
137 
138         return expandoRowFinder.countByTC_TN(classNameId, tableName);
139     }
140 
141 }