1   /**
2    * Copyright (c) 2000-2007 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.portal.spring.hibernate;
24  
25  import com.liferay.portal.kernel.util.StringUtil;
26  import com.liferay.portal.model.Organization;
27  import com.liferay.portal.model.User;
28  import com.liferay.portal.model.UserGroup;
29  import com.liferay.portal.util.PortalUtil;
30  import com.liferay.portal.util.PropsUtil;
31  import com.liferay.portlet.blogs.model.BlogsEntry;
32  import com.liferay.portlet.bookmarks.model.BookmarksEntry;
33  import com.liferay.portlet.documentlibrary.model.DLFileEntry;
34  import com.liferay.portlet.imagegallery.model.IGImage;
35  
36  import java.sql.SQLException;
37  
38  /**
39   * <a href="PortalCustomSQLUtil.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Brian Wing Shun Chan
42   *
43   */
44  public class PortalCustomSQLUtil
45      extends com.liferay.util.dao.hibernate.CustomSQLUtil {
46  
47      public PortalCustomSQLUtil() throws SQLException {
48          super(HibernateUtil.getConnection(),
49                PropsUtil.get(PropsUtil.CUSTOM_SQL_FUNCTION_ISNULL),
50                PropsUtil.get(PropsUtil.CUSTOM_SQL_FUNCTION_ISNOTNULL));
51      }
52  
53      protected String[] getConfigs() {
54          return PropsUtil.getArray(PropsUtil.CUSTOM_SQL_CONFIGS);
55      }
56  
57      protected String transform(String sql) {
58          sql = super.transform(sql);
59  
60          long organizationClassNameId = PortalUtil.getClassNameId(
61              Organization.class);
62          long userClassNameId = PortalUtil.getClassNameId(User.class);
63          long userGroupClassNameId = PortalUtil.getClassNameId(UserGroup.class);
64          long blogsEntryClassNameId = PortalUtil.getClassNameId(
65              BlogsEntry.class);
66          long bookmarksEntryClassNameId = PortalUtil.getClassNameId(
67              BookmarksEntry.class);
68          long dlFileEntryClassNameId = PortalUtil.getClassNameId(
69              DLFileEntry.class);
70          long igImageClassNameId = PortalUtil.getClassNameId(IGImage.class);
71  
72          sql = StringUtil.replace(
73              sql,
74              new String[] {
75                  "[$CLASS_NAME_ID_COM.LIFERAY.PORTAL.MODEL.ORGANIZATION$]",
76                  "[$CLASS_NAME_ID_COM.LIFERAY.PORTAL.MODEL.USER$]",
77                  "[$CLASS_NAME_ID_COM.LIFERAY.PORTAL.MODEL.USERGROUP$]",
78                  "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.BLOGS.MODEL.BLOGSENTRY$]",
79                  "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.BOOKMARKS.MODEL.BOOKMARKSENTRY$]",
80                  "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.DOCUMENTLIBRARY.MODEL.DLFILEENTRY$]",
81                  "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.IMAGEGALLERY.MODEL.IGIMAGE$]"
82              },
83              new String[] {
84                  String.valueOf(organizationClassNameId),
85                  String.valueOf(userClassNameId),
86                  String.valueOf(userGroupClassNameId),
87                  String.valueOf(blogsEntryClassNameId),
88                  String.valueOf(bookmarksEntryClassNameId),
89                  String.valueOf(dlFileEntryClassNameId),
90                  String.valueOf(igImageClassNameId)
91              });
92  
93          return sql;
94      }
95  
96  }