001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.spring.hibernate;
022:
023: import com.liferay.portal.kernel.util.StringUtil;
024: import com.liferay.portal.model.Organization;
025: import com.liferay.portal.model.User;
026: import com.liferay.portal.model.UserGroup;
027: import com.liferay.portal.util.PortalUtil;
028: import com.liferay.portal.util.PropsUtil;
029: import com.liferay.portlet.blogs.model.BlogsEntry;
030: import com.liferay.portlet.bookmarks.model.BookmarksEntry;
031: import com.liferay.portlet.documentlibrary.model.DLFileEntry;
032: import com.liferay.portlet.imagegallery.model.IGImage;
033: import com.liferay.portlet.messageboards.model.MBMessage;
034: import com.liferay.portlet.wiki.model.WikiPage;
035:
036: import java.sql.SQLException;
037:
038: /**
039: * <a href="PortalCustomSQLUtil.java.html"><b><i>View Source</i></b></a>
040: *
041: * @author Brian Wing Shun Chan
042: *
043: */
044: public class PortalCustomSQLUtil extends
045: com.liferay.util.dao.hibernate.CustomSQLUtil {
046:
047: public PortalCustomSQLUtil() throws SQLException {
048: super (HibernateUtil.getConnection(), PropsUtil
049: .get(PropsUtil.CUSTOM_SQL_FUNCTION_ISNULL), PropsUtil
050: .get(PropsUtil.CUSTOM_SQL_FUNCTION_ISNOTNULL));
051: }
052:
053: protected String[] getConfigs() {
054: return PropsUtil.getArray(PropsUtil.CUSTOM_SQL_CONFIGS);
055: }
056:
057: protected String transform(String sql) {
058: sql = super .transform(sql);
059:
060: long organizationClassNameId = PortalUtil
061: .getClassNameId(Organization.class);
062: long userClassNameId = PortalUtil.getClassNameId(User.class);
063: long userGroupClassNameId = PortalUtil
064: .getClassNameId(UserGroup.class);
065: long blogsEntryClassNameId = PortalUtil
066: .getClassNameId(BlogsEntry.class);
067: long bookmarksEntryClassNameId = PortalUtil
068: .getClassNameId(BookmarksEntry.class);
069: long dlFileEntryClassNameId = PortalUtil
070: .getClassNameId(DLFileEntry.class);
071: long igImageClassNameId = PortalUtil
072: .getClassNameId(IGImage.class);
073: long mbMessageClassNameId = PortalUtil
074: .getClassNameId(MBMessage.class);
075: long wikiPageClassNameId = PortalUtil
076: .getClassNameId(WikiPage.class);
077:
078: sql = StringUtil
079: .replace(
080: sql,
081: new String[] {
082: "[$CLASS_NAME_ID_COM.LIFERAY.PORTAL.MODEL.ORGANIZATION$]",
083: "[$CLASS_NAME_ID_COM.LIFERAY.PORTAL.MODEL.USER$]",
084: "[$CLASS_NAME_ID_COM.LIFERAY.PORTAL.MODEL.USERGROUP$]",
085: "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.BLOGS.MODEL.BLOGSENTRY$]",
086: "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.BOOKMARKS.MODEL.BOOKMARKSENTRY$]",
087: "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.DOCUMENTLIBRARY.MODEL.DLFILEENTRY$]",
088: "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.IMAGEGALLERY.MODEL.IGIMAGE$]",
089: "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.MESSAGEBOARDS.MODEL.MBMESSAGE$]",
090: "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.WIKI.MODEL.WIKIPAGE$]" },
091: new String[] {
092: String.valueOf(organizationClassNameId),
093: String.valueOf(userClassNameId),
094: String.valueOf(userGroupClassNameId),
095: String.valueOf(blogsEntryClassNameId),
096: String
097: .valueOf(bookmarksEntryClassNameId),
098: String.valueOf(dlFileEntryClassNameId),
099: String.valueOf(igImageClassNameId),
100: String.valueOf(mbMessageClassNameId),
101: String.valueOf(wikiPageClassNameId) });
102:
103: return sql;
104: }
105:
106: }
|