protected void upgradeRatingsStats() throws Exception { try (LoggingTimer loggingTimer = new LoggingTimer()) { StringBundler sb = new StringBundler(4); sb.append("select classNameId, classPK, count(1) as totalEntries,"); sb.append(" sum(RatingsEntry.score) as totalScore, "); sb.append("sum(RatingsEntry.score) / count(1) as averageScore "); sb.append("from RatingsEntry group by classNameId, classPK"); String selectSQL = sb.toString(); String updateSQL = "update RatingsStats set totalEntries = ?, totalScore = ?, " + "averageScore = ? where classNameId = ? and classPK = ?"; try (PreparedStatement ps1 = connection.prepareStatement(selectSQL); ResultSet rs = ps1.executeQuery(); PreparedStatement ps2 = AutoBatchPreparedStatementUtil.autoBatch(connection.prepareStatement(updateSQL))) { while (rs.next()) { ps2.setInt(1, rs.getInt("totalEntries")); ps2.setDouble(2, rs.getDouble("totalScore")); ps2.setDouble(3, rs.getDouble("averageScore")); ps2.setLong(4, rs.getLong("classNameId")); ps2.setLong(5, rs.getLong("classPK")); ps2.addBatch(); } ps2.executeBatch(); } } }
protected void updateAssetEntryClassTypeId() throws Exception { try (LoggingTimer loggingTimer = new LoggingTimer(); PreparedStatement ps1 = connection.prepareStatement( "select companyId, groupId, resourcePrimKey, structureId " + "from JournalArticle where structureId != ''"); ResultSet rs = ps1.executeQuery()) { long classNameId = PortalUtil.getClassNameId("com.liferay.portlet.journal.model.JournalArticle"); try (PreparedStatement ps2 = AutoBatchPreparedStatementUtil.concurrentAutoBatch( connection, "update AssetEntry set classTypeId = ? where " + "classNameId = ? AND classPK = ?")) { while (rs.next()) { long groupId = rs.getLong("groupId"); long companyId = rs.getLong("companyId"); long resourcePrimKey = rs.getLong("resourcePrimKey"); String structureId = rs.getString("structureId"); long ddmStructureId = getDDMStructureId(groupId, getCompanyGroupId(companyId), structureId); ps2.setLong(1, ddmStructureId); ps2.setLong(2, classNameId); ps2.setLong(3, resourcePrimKey); ps2.addBatch(); } ps2.executeBatch(); } } }