protected void updatePortalPreferences() throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "select ownerId, ownerType, preferences from " + "PortletPreferences where portletId = ?"); ps.setString(1, PortletKeys.LIFERAY_PORTAL); rs = ps.executeQuery(); while (rs.next()) { long ownerId = rs.getLong("ownerId"); int ownerType = rs.getInt("ownerType"); String preferences = rs.getString("preferences"); addPortalPreferences(ownerId, ownerType, preferences); } runSQL( "delete from PortletPreferences where portletId = '" + PortletKeys.LIFERAY_PORTAL + "'"); } finally { DataAccess.cleanUp(con, ps, rs); } }
protected long getPortletPreferencesId(long ownerId, int ownerType, long plid, String portletId) throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "select portletPreferencesId from PortletPreferences where " + "ownerId = ? and ownerType = ? and plid = ? and " + "portletId = ?"); ps.setLong(1, ownerId); ps.setInt(2, ownerType); ps.setLong(3, plid); ps.setString(4, portletId); rs = ps.executeQuery(); if (rs.next()) { return rs.getLong("portletPreferencesId"); } } finally { DataAccess.cleanUp(con, ps, rs); } return 0; }
protected void updateVotes() throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement("select voteId, questionId from PollsVote"); rs = ps.executeQuery(); while (rs.next()) { long voteId = rs.getLong("voteId"); long questionId = rs.getLong("questionId"); long groupId = getGroupId(questionId); if (groupId > 0) { runSQL("update PollsVote set groupId = " + groupId + " where voteId = " + voteId); } } } finally { DataAccess.cleanUp(con, ps, rs); } }
protected void updateURLTitle(long groupId, String articleId, String urlTitle) throws Exception { String normalizedURLTitle = FriendlyURLNormalizerUtil.normalize(urlTitle, _friendlyURLPattern); if (urlTitle.equals(normalizedURLTitle)) { return; } normalizedURLTitle = JournalArticleLocalServiceUtil.getUniqueUrlTitle(groupId, articleId, normalizedURLTitle); Connection con = null; PreparedStatement ps = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement("update JournalArticle set urlTitle = ? where urlTitle = ?"); ps.setString(1, normalizedURLTitle); ps.setString(2, urlTitle); ps.executeUpdate(); } finally { DataAccess.cleanUp(con, ps); } }
protected void verifySearch() throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "select groupId, portletId from JournalContentSearch group " + "by groupId, portletId having count(groupId) > 1 and " + "count(portletId) > 1"); rs = ps.executeQuery(); while (rs.next()) { long groupId = rs.getLong("groupId"); String portletId = rs.getString("portletId"); verifyContentSearch(groupId, portletId); } } finally { DataAccess.cleanUp(con, ps, rs); } }
protected void addPortletPreferences( long ownerId, int ownerType, long plid, String portletId, String preferences) throws Exception { Connection con = null; PreparedStatement ps = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "insert into PortletPreferences (portletPreferencesId, " + "ownerId, ownerType, plid, portletId, preferences) " + "values (?, ?, ?, ?, ?, ?)"); ps.setLong(1, increment()); ps.setLong(2, ownerId); ps.setInt(3, ownerType); ps.setLong(4, plid); ps.setString(5, portletId); ps.setString(6, preferences); ps.executeUpdate(); } finally { DataAccess.cleanUp(con, ps); } }
protected long getCompanyGroupId(long companyId) throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "select groupId from Group_ where classNameId = ? and " + "classPK = ?"); ps.setLong(1, PortalUtil.getClassNameId(Company.class.getName())); ps.setLong(2, companyId); rs = ps.executeQuery(); if (rs.next()) { return rs.getLong("groupId"); } return 0; } finally { DataAccess.cleanUp(con, ps, rs); } }
protected boolean hasFileEntry(long groupId, long folderId, String fileName) throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "select count(*) from DLFileEntry where groupId = ? and " + "folderId = ? and fileName = ?"); ps.setLong(1, groupId); ps.setLong(2, folderId); ps.setString(3, fileName); rs = ps.executeQuery(); while (rs.next()) { int count = rs.getInt(1); if (count > 0) { return true; } } return false; } finally { DataAccess.cleanUp(con, ps, rs); } }
protected void updatePortletPreference( long portletPreferencesId, String newPortletId, String newPreferences) throws Exception { Connection con = null; PreparedStatement ps = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "update PortletPreferences set preferences = ?, " + "portletId = ? where portletPreferencesId = " + portletPreferencesId); ps.setString(1, newPreferences); ps.setString(2, newPortletId); ps.executeUpdate(); } catch (SQLException sqle) { if (_log.isWarnEnabled()) { _log.warn(sqle, sqle); } } finally { DataAccess.cleanUp(con, ps); } }
protected long getCategoryId(long companyId, String type) throws Exception { if (Validator.isNull(type)) { return 0; } long groupId = getCompanyGroupId(companyId); Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "select categoryId from AssetCategory where groupId = " + groupId + " and name = ?"); ps.setString(1, type); rs = ps.executeQuery(); while (rs.next()) { return rs.getLong("categoryId"); } return 0; } finally { DataAccess.cleanUp(con, ps, rs); } }
protected long getGroupId(long questionId) throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement("select groupId from PollsQuestion where questionId = ?"); ps.setLong(1, questionId); rs = ps.executeQuery(); if (rs.next()) { return rs.getLong("groupId"); } if (_log.isDebugEnabled()) { _log.debug("Unable to find question " + questionId); } return 0; } finally { DataAccess.cleanUp(con, ps, rs); } }
protected String getUserName(long userId) throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "select firstName, middleName, lastName from User_ where " + "userId = ?"); ps.setLong(1, userId); rs = ps.executeQuery(); if (rs.next()) { String firstName = rs.getString("firstName"); String middleName = rs.getString("middleName"); String lastName = rs.getString("lastName"); FullNameGenerator fullNameGenerator = FullNameGeneratorFactory.getInstance(); return fullNameGenerator.getFullName(firstName, middleName, lastName); } return StringPool.BLANK; } finally { DataAccess.cleanUp(con, ps, rs); } }
public Connection getUpgradeOptimizedConnection() { try { return DataAccess.getUpgradeOptimizedConnection(); } catch (SQLException e) { throw new RuntimeException(e); } }
protected void upgradeMicroblogActivities() throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "select activityId, extraData from SocialActivity where " + "classNameId = ?"); ps.setLong(1, PortalUtil.getClassNameId(MicroblogsEntry.class)); rs = ps.executeQuery(); while (rs.next()) { long activityId = rs.getLong("activityId"); String extraData = rs.getString("extraData"); JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(extraData); long parentMicroblogsEntryId = extraDataJSONObject.getLong("receiverMicroblogsEntryId"); extraDataJSONObject.put("parentMicroblogsEntryId", parentMicroblogsEntryId); extraDataJSONObject.remove("receiverMicroblogsEntryId"); updateSocialActivity(activityId, extraDataJSONObject); } } finally { DataAccess.cleanUp(con, ps, rs); } }
public void upgrade() throws UpgradeException { long start = System.currentTimeMillis(); if (_log.isInfoEnabled()) { _log.info("Upgrading " + ClassUtil.getClassName(this)); } try (Connection con = DataAccess.getUpgradeOptimizedConnection()) { connection = con; doUpgrade(); } catch (Exception e) { throw new UpgradeException(e); } finally { connection = null; if (_log.isInfoEnabled()) { _log.info( "Completed upgrade process " + ClassUtil.getClassName(this) + " in " + (System.currentTimeMillis() - start) + "ms"); } } }
protected void updateFileVersionFileNames() throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement("select fileVersionId, extension, title from DLFileVersion"); rs = ps.executeQuery(); while (rs.next()) { long fileVersionId = rs.getLong("fileVersionId"); String extension = GetterUtil.getString(rs.getString("extension")); String title = GetterUtil.getString(rs.getString("title")); String fileName = DLUtil.getSanitizedFileName(title, extension); updateFileVersionFileName(fileVersionId, fileName); } } finally { DataAccess.cleanUp(con, ps, rs); } }
protected void updateFileVersions() throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement("select fileEntryId, folderId from DLFileEntry"); rs = ps.executeQuery(); while (rs.next()) { long fileEntryId = rs.getLong("fileEntryId"); long folderId = rs.getLong("folderId"); StringBundler sb = new StringBundler(4); sb.append("update DLFileVersion set folderId = "); sb.append(folderId); sb.append(" where fileEntryId = "); sb.append(fileEntryId); runSQL(sb.toString()); } } finally { DataAccess.cleanUp(con, ps, rs); } }
protected void verifyURLTitle() throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "select distinct groupId, articleId, urlTitle from " + "JournalArticle"); rs = ps.executeQuery(); while (rs.next()) { long groupId = rs.getLong("groupId"); String articleId = rs.getString("articleId"); String urlTitle = GetterUtil.getString(rs.getString("urlTitle")); updateURLTitle(groupId, articleId, urlTitle); } } finally { DataAccess.cleanUp(con, ps, rs); } }
protected void updateFileEntryTitle(long fileEntryId, String title, String version) throws Exception { Connection con = null; PreparedStatement ps = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement("update DLFileEntry set title = ? where fileEntryId = ?"); ps.setString(1, title); ps.setLong(2, fileEntryId); ps.executeUpdate(); ps = con.prepareStatement( "update DLFileVersion set title = ? where fileEntryId = " + "? and version = ?"); ps.setString(1, title); ps.setLong(2, fileEntryId); ps.setString(3, version); ps.executeUpdate(); } finally { DataAccess.cleanUp(con, ps); } }
protected void updateFileEntryTypeNamesAndDescriptions() throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement("select companyId, groupId from Group_ where classNameId = ?"); long classNameId = PortalUtil.getClassNameId(Company.class); ps.setLong(1, classNameId); rs = ps.executeQuery(); while (rs.next()) { long companyId = rs.getLong(1); long groupId = rs.getLong(2); updateFileEntryTypeNamesAndDescriptions(companyId, groupId); } } finally { DataAccess.cleanUp(con, ps, rs); } }
protected void updateFileEntryFileNames() throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "select fileEntryId, groupId, folderId, extension, title, " + "version from DLFileEntry"); rs = ps.executeQuery(); while (rs.next()) { long fileEntryId = rs.getLong("fileEntryId"); long groupId = rs.getLong("groupId"); long folderId = rs.getLong("folderId"); String extension = GetterUtil.getString(rs.getString("extension")); String title = GetterUtil.getString(rs.getString("title")); String version = rs.getString("version"); String uniqueFileName = DLUtil.getSanitizedFileName(title, extension); String titleExtension = StringPool.BLANK; String titleWithoutExtension = title; if (title.endsWith(StringPool.PERIOD + extension)) { titleExtension = extension; titleWithoutExtension = FileUtil.stripExtension(title); } String uniqueTitle = StringPool.BLANK; for (int i = 1; ; i++) { if (!hasFileEntry(groupId, folderId, uniqueFileName)) { break; } uniqueTitle = titleWithoutExtension + StringPool.UNDERLINE + String.valueOf(i); if (Validator.isNotNull(titleExtension)) { uniqueTitle += StringPool.PERIOD.concat(titleExtension); } uniqueFileName = DLUtil.getSanitizedFileName(uniqueTitle, extension); } updateFileEntryFileName(fileEntryId, uniqueFileName); if (Validator.isNotNull(uniqueTitle)) { updateFileEntryTitle(fileEntryId, uniqueTitle, version); } } } finally { DataAccess.cleanUp(con, ps, rs); } }
protected void updatePortletPreferencesOwner() throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); StringBundler sb = new StringBundler(8); sb.append("select portletPreferencesId, plid, portletId, "); sb.append("preferences from PortletPreferences where ownerId = "); sb.append(PortletKeys.PREFS_OWNER_ID_DEFAULT); sb.append(" and ownerType = "); sb.append(PortletKeys.PREFS_OWNER_TYPE_LAYOUT); sb.append(" and portletId in ('8', '19', '33')"); String sql = sb.toString(); ps = con.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { long plid = rs.getLong("plid"); String portletId = rs.getString("portletId"); String preferences = rs.getString("preferences"); long ownerId = getOwnerId(plid); if (ownerId == 0) { continue; } long portletPreferencesId = getPortletPreferencesId( ownerId, PortletKeys.PREFS_OWNER_TYPE_GROUP, PortletKeys.PREFS_PLID_SHARED, portletId); if (portletPreferencesId != 0) { continue; } addPortletPreferences( ownerId, PortletKeys.PREFS_OWNER_TYPE_GROUP, PortletKeys.PREFS_PLID_SHARED, portletId, preferences); } } finally { DataAccess.cleanUp(con, ps, rs); } }
@Override protected void updateInstanceablePortletPreferences( String oldRootPortletId, String newRootPortletId) throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); StringBundler sb = new StringBundler(9); sb.append("select portletPreferencesId, plid, portletId, "); sb.append("preferences from PortletPreferences where portletId "); sb.append("= '"); sb.append(oldRootPortletId); sb.append("' OR portletId like '"); sb.append(oldRootPortletId); sb.append("_INSTANCE_%' OR portletId like '"); sb.append(oldRootPortletId); sb.append("_USER_%_INSTANCE_%'"); ps = con.prepareStatement(sb.toString()); rs = ps.executeQuery(); while (rs.next()) { long portletPreferencesId = rs.getLong("portletPreferencesId"); long plid = rs.getLong("plid"); String portletId = rs.getString("portletId"); String preferences = rs.getString("preferences"); if (preferences.equals("<portlet-preferences />")) { continue; } String newPreferences = getNewPreferences(plid, preferences); long userId = PortletConstants.getUserId(portletId); String instanceId = PortletConstants.getInstanceId(portletId); String newPortletId = PortletConstants.assemblePortletId(PortletKeys.ASSET_PUBLISHER, userId, instanceId); updatePortletPreference(portletPreferencesId, newPortletId, newPreferences); } } finally { DataAccess.cleanUp(con, ps, rs); } }
protected void updateSyncs() throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); StringBundler sb = new StringBundler(10); sb.append("select DLFileEntry.fileEntryId as fileId, "); sb.append("DLFileEntry.groupId as groupId, DLFileEntry.companyId"); sb.append(" as companyId, DLFileEntry.createDate as createDate, "); sb.append("DLFileEntry.folderId as parentFolderId, 'file' as "); sb.append("type from DLFileEntry union all select "); sb.append("DLFolder.folderId as fileId, DLFolder.groupId as "); sb.append("groupId, DLFolder.companyId as companyId, "); sb.append("DLFolder.createDate as createDate, "); sb.append("DLFolder.parentFolderId as parentFolderId, 'folder' "); sb.append("as type from DLFolder"); String sql = sb.toString(); ps = con.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { long fileId = rs.getLong("fileId"); long groupId = rs.getLong("groupId"); long companyId = rs.getLong("companyId"); Timestamp createDate = rs.getTimestamp("createDate"); long parentFolderId = rs.getLong("parentFolderId"); String type = rs.getString("type"); addDLSync( increment(), companyId, createDate, createDate, fileId, groupId, parentFolderId, "add", type); } } finally { DataAccess.cleanUp(con, ps, rs); } }
protected void updateThumbnails(long fileEntryId) throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "select fileVersionId, userId, extension, mimeType, version " + "from DLFileVersion where fileEntryId = " + fileEntryId + " order by version asc"); rs = ps.executeQuery(); while (rs.next()) { long fileVersionId = rs.getLong("fileVersionId"); long userId = rs.getLong("userId"); String extension = rs.getString("extension"); String mimeType = rs.getString("mimeType"); String version = rs.getString("version"); if (_imageMimeTypes.contains(mimeType)) { DLFileVersion dlFileVersion = new DLFileVersionImpl(); dlFileVersion.setFileVersionId(fileVersionId); dlFileVersion.setUserId(userId); dlFileVersion.setFileEntryId(fileEntryId); dlFileVersion.setExtension(extension); dlFileVersion.setMimeType(mimeType); dlFileVersion.setVersion(version); FileVersion fileVersion = new LiferayFileVersion(dlFileVersion); try { ImageProcessorUtil.generateImages(null, fileVersion); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Unable to generate thumbnails for " + fileVersion.getFileVersionId(), e); } } } } } finally { DataAccess.cleanUp(con, ps, rs); } }
protected void verifyContentSearch(long groupId, String portletId) throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "select preferences from PortletPreferences inner join " + "Layout on PortletPreferences.plid = Layout.plid where " + "groupId = ? and portletId = ?"); ps.setLong(1, groupId); ps.setString(2, portletId); rs = ps.executeQuery(); while (rs.next()) { String xml = rs.getString("preferences"); PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.fromDefaultXML(xml); String articleId = portletPreferences.getValue("articleId", null); List<JournalContentSearch> contentSearches = JournalContentSearchLocalServiceUtil.getArticleContentSearches(groupId, articleId); if (contentSearches.isEmpty()) { continue; } JournalContentSearch contentSearch = contentSearches.get(0); JournalContentSearchLocalServiceUtil.updateContentSearch( contentSearch.getGroupId(), contentSearch.isPrivateLayout(), contentSearch.getLayoutId(), contentSearch.getPortletId(), articleId, true); } } finally { DataAccess.cleanUp(con, ps, rs); } }
protected void updateEvent(long eventId, String recurrence) throws Exception { Connection con = null; PreparedStatement ps = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement("update CalEvent set recurrence = ? where eventId = ?"); ps.setString(1, recurrence); ps.setLong(2, eventId); ps.executeUpdate(); } finally { DataAccess.cleanUp(con, ps); } }
protected void updateFileEntryFileName(long fileEntryId, String fileName) throws Exception { Connection con = null; PreparedStatement ps = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement("update DLFileEntry set fileName = ? where fileEntryId = ?"); ps.setString(1, fileName); ps.setLong(2, fileEntryId); ps.executeUpdate(); } finally { DataAccess.cleanUp(con, ps); } }
protected void updateSocialActivity(long activityId, JSONObject jsonObject) throws Exception { Connection con = null; PreparedStatement ps = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement("update SocialActivity set extraData = ? where activityId = ?"); ps.setString(1, jsonObject.toString()); ps.setLong(2, activityId); ps.executeUpdate(); } finally { DataAccess.cleanUp(con, ps); } }
protected void updateFileEntryTypeNamesAndDescriptions( long companyId, long groupId, String dlFileEntryTypeKey, String nameLanguageKey) throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "select fileEntryTypeId, name, description from " + "DLFileEntryType where groupId = ? and fileEntryTypeKey " + "= ?"); ps.setLong(1, groupId); ps.setString(2, dlFileEntryTypeKey); rs = ps.executeQuery(); if (!rs.next()) { return; } long fileEntryTypeId = rs.getLong(1); String name = rs.getString(2); String description = rs.getString(3); if (rs.next()) { throw new IllegalStateException( String.format( "Found more than one row in table DLFileEntryType " + "with groupId %s and fileEntryTypeKey %s", groupId, dlFileEntryTypeKey)); } updateFileEntryTypeNamesAndDescriptions( companyId, fileEntryTypeId, nameLanguageKey, name, description); } finally { DataAccess.cleanUp(con, ps, rs); } }