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.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.tools.sql.DBUtil;
30  import com.liferay.portal.util.PortalUtil;
31  import com.liferay.portal.util.PropsUtil;
32  import com.liferay.portlet.blogs.model.BlogsEntry;
33  import com.liferay.portlet.bookmarks.model.BookmarksEntry;
34  import com.liferay.portlet.documentlibrary.model.DLFileEntry;
35  import com.liferay.portlet.imagegallery.model.IGImage;
36  import com.liferay.portlet.messageboards.model.MBMessage;
37  import com.liferay.portlet.wiki.model.WikiPage;
38  
39  import java.sql.SQLException;
40  
41  /**
42   * <a href="PortalCustomSQLUtil.java.html"><b><i>View Source</i></b></a>
43   *
44   * @author Brian Wing Shun Chan
45   *
46   */
47  public class PortalCustomSQLUtil
48      extends com.liferay.util.dao.hibernate.CustomSQLUtil {
49  
50      public PortalCustomSQLUtil() throws SQLException {
51          super(
52              HibernateUtil.getConnection(),
53              PropsUtil.get(PropsUtil.CUSTOM_SQL_FUNCTION_ISNULL),
54              PropsUtil.get(PropsUtil.CUSTOM_SQL_FUNCTION_ISNOTNULL));
55      }
56  
57      protected String[] getConfigs() {
58          return PropsUtil.getArray(PropsUtil.CUSTOM_SQL_CONFIGS);
59      }
60  
61      protected String transform(String sql) {
62          sql = super.transform(sql);
63  
64          long organizationClassNameId = PortalUtil.getClassNameId(
65              Organization.class);
66          long userClassNameId = PortalUtil.getClassNameId(User.class);
67          long userGroupClassNameId = PortalUtil.getClassNameId(UserGroup.class);
68          long blogsEntryClassNameId = PortalUtil.getClassNameId(
69              BlogsEntry.class);
70          long bookmarksEntryClassNameId = PortalUtil.getClassNameId(
71              BookmarksEntry.class);
72          long dlFileEntryClassNameId = PortalUtil.getClassNameId(
73              DLFileEntry.class);
74          long igImageClassNameId = PortalUtil.getClassNameId(IGImage.class);
75          long mbMessageClassNameId = PortalUtil.getClassNameId(MBMessage.class);
76          long wikiPageClassNameId = PortalUtil.getClassNameId(WikiPage.class);
77  
78          DBUtil dbUtil = DBUtil.getInstance();
79  
80          sql = StringUtil.replace(
81              sql,
82              new String[] {
83                  "[$CLASS_NAME_ID_COM.LIFERAY.PORTAL.MODEL.ORGANIZATION$]",
84                  "[$CLASS_NAME_ID_COM.LIFERAY.PORTAL.MODEL.USER$]",
85                  "[$CLASS_NAME_ID_COM.LIFERAY.PORTAL.MODEL.USERGROUP$]",
86                  "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.BLOGS.MODEL.BLOGSENTRY$]",
87                  "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.BOOKMARKS.MODEL.BOOKMARKSENTRY$]",
88                  "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.DOCUMENTLIBRARY.MODEL.DLFILEENTRY$]",
89                  "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.IMAGEGALLERY.MODEL.IGIMAGE$]",
90                  "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.MESSAGEBOARDS.MODEL.MBMESSAGE$]",
91                  "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.WIKI.MODEL.WIKIPAGE$]",
92                  "[$FALSE$]",
93                  "[$TRUE$]"
94              },
95              new String[] {
96                  String.valueOf(organizationClassNameId),
97                  String.valueOf(userClassNameId),
98                  String.valueOf(userGroupClassNameId),
99                  String.valueOf(blogsEntryClassNameId),
100                 String.valueOf(bookmarksEntryClassNameId),
101                 String.valueOf(dlFileEntryClassNameId),
102                 String.valueOf(igImageClassNameId),
103                 String.valueOf(mbMessageClassNameId),
104                 String.valueOf(wikiPageClassNameId),
105                 dbUtil.getTemplateFalse(),
106                 dbUtil.getTemplateTrue()
107             });
108 
109         return sql;
110     }
111 
112 }