/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.workflow.kaleo.internal.upgrade.v1_3_4;
import com.liferay.portal.kernel.upgrade.UpgradeProcess;
import com.liferay.portal.kernel.util.LoggingTimer;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.upgrade.AutoBatchPreparedStatementUtil;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
/**
* @author InĂ¡cio Nery
*/
public class UpgradeKaleoDefinitionVersion extends UpgradeProcess {
@Override
protected void doUpgrade() throws Exception {
upgradeKaleoDefinitionVersion();
}
protected String getVersion(int version) {
return version + StringPool.PERIOD + 0;
}
protected void upgradeKaleoDefinitionVersion() throws SQLException {
StringBundler sb1 = new StringBundler(3);
sb1.append("select * from KaleoDefinition kd where not exists ");
sb1.append("(select 1 from KaleoDefinitionVersion kdv where ");
sb1.append("kdv.name = kd.name and kdv.companyId = kd.companyId)");
StringBundler sb2 = new StringBundler(6);
sb2.append("insert into KaleoDefinitionVersion ");
sb2.append("(kaleoDefinitionVersionId, groupId, companyId, userId, ");
sb2.append("userName, statusByUserId, statusByUserName, statusDate, ");
sb2.append("createDate, modifiedDate, name, title, description, ");
sb2.append("content, version, status) values (?, ?, ?, ?, ?, ?, ?, ");
sb2.append("?, ?, ?, ?, ?, ?, ?, ?, ? )");
try (LoggingTimer loggingTimer = new LoggingTimer();
PreparedStatement ps1 = connection.prepareStatement(sb1.toString());
PreparedStatement ps2 =
AutoBatchPreparedStatementUtil.concurrentAutoBatch(
connection, sb2.toString());
ResultSet rs = ps1.executeQuery()) {
while (rs.next()) {
long groupId = rs.getLong("groupId");
long companyId = rs.getLong("companyId");
long userId = rs.getLong("userId");
String userName = rs.getString("userName");
Timestamp createDate = rs.getTimestamp("createDate");
Timestamp modifiedDate = rs.getTimestamp("modifiedDate");
String name = rs.getString("name");
String title = rs.getString("title");
String description = rs.getString("description");
String content = rs.getString("content");
int version = rs.getInt("version");
ps2.setLong(1, increment());
ps2.setLong(2, groupId);
ps2.setLong(3, companyId);
ps2.setLong(4, userId);
ps2.setString(5, userName);
ps2.setLong(6, userId);
ps2.setString(7, userName);
ps2.setTimestamp(8, modifiedDate);
ps2.setTimestamp(9, createDate);
ps2.setTimestamp(10, modifiedDate);
ps2.setString(11, name);
ps2.setString(12, title);
ps2.setString(13, description);
ps2.setString(14, content);
ps2.setString(15, getVersion(version));
ps2.setInt(16, WorkflowConstants.STATUS_APPROVED);
ps2.addBatch();
}
ps2.executeBatch();
}
}
}