/** * 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.upgrade.v7_0_3; import com.liferay.portal.kernel.dao.db.DB; import com.liferay.portal.kernel.dao.db.DBManagerUtil; import com.liferay.portal.kernel.dao.db.DBType; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.upgrade.UpgradeProcess; import com.liferay.portal.kernel.util.LoggingTimer; import com.liferay.portal.kernel.util.StringBundler; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; /** * @author Cristina González */ public class UpgradeSybase extends UpgradeProcess { protected void alterVarcharColumns() throws Exception { StringBundler sb = new StringBundler(3); sb.append("select o.name, c.name from sysobjects o, syscolumns c, "); sb.append("systypes t where o.id = c.id and c.type = t.type and "); sb.append("t.name = 'varchar' and c.length = 1000"); try (LoggingTimer loggingTimer = new LoggingTimer(); PreparedStatement ps = connection.prepareStatement(sb.toString()); ResultSet rs = ps.executeQuery()) { while (rs.next()) { String tableName = rs.getString(1); String columnName = rs.getString(2); try { runSQL( "alter table " + tableName + " modify " + columnName + " varchar(4000)"); } catch (SQLException sqle) { if (sqle.getErrorCode() == 1441) { if (_log.isWarnEnabled()) { sb = new StringBundler(6); sb.append("Unable to alter length of column "); sb.append(columnName); sb.append(" for table "); sb.append(tableName); sb.append(" because it contains values larger "); sb.append("than the new column length"); _log.warn(sb.toString()); } } else { throw sqle; } } } } } @Override protected void doUpgrade() throws Exception { DB db = DBManagerUtil.getDB(); if (db.getDBType() != DBType.SYBASE) { return; } alterVarcharColumns(); } private static final Log _log = LogFactoryUtil.getLog(UpgradeSybase.class); }