com.liferay.commerce.discount.internal.upgrade.base.BaseCommerceDiscountUpgradeProcess Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.commerce.discount.service
Show all versions of com.liferay.commerce.discount.service
Liferay Commerce Discount Service
/**
* 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.commerce.discount.internal.upgrade.base;
import com.liferay.petra.string.StringPool;
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.StringBundler;
import com.liferay.portal.kernel.util.StringUtil;
/**
* @author Alessio Antonio Rendina
*/
public abstract class BaseCommerceDiscountUpgradeProcess
extends UpgradeProcess {
protected void addColumn(
Class> entityClass, String tableName, String columnName,
String columnType)
throws Exception {
if (_log.isInfoEnabled()) {
_log.info(
String.format(
"Adding column %s to table %s", columnName, tableName));
}
if (!hasColumn(tableName, columnName)) {
alter(
entityClass,
new AlterTableAddColumn(
columnName + StringPool.SPACE + columnType));
}
else {
if (_log.isInfoEnabled()) {
_log.info(
String.format(
"Column %s already exists on table %s", columnName,
tableName));
}
}
}
@Override
protected abstract void doUpgrade() throws Exception;
protected void dropColumn(String tableName, String columnName)
throws Exception {
if (_log.isInfoEnabled()) {
_log.info(
String.format(
"Dropping column %s from table %s", columnName, tableName));
}
if (hasColumn(tableName, columnName)) {
runSQL(
StringBundler.concat(
"alter table ", tableName, " drop column ", columnName));
}
else {
if (_log.isInfoEnabled()) {
_log.info(
String.format(
"Column %s does not exist on table %s", columnName,
tableName));
}
}
}
protected void renameColumn(
Class> tableClass, String tableName, String oldColumnName,
String newColumnName)
throws Exception {
if (_log.isInfoEnabled()) {
_log.info(
String.format(
"Renaming column %s to %s for table %s", oldColumnName,
newColumnName, tableName));
}
String newColumnSimpleName = StringUtil.extractFirst(
newColumnName, StringPool.SPACE);
if (!hasColumn(tableName, newColumnSimpleName)) {
alter(
tableClass, new AlterColumnName(oldColumnName, newColumnName));
}
else {
if (_log.isInfoEnabled()) {
_log.info(
String.format(
"Column %s already exists on table %s", newColumnName,
tableName));
}
}
}
private static final Log _log = LogFactoryUtil.getLog(
BaseCommerceDiscountUpgradeProcess.class);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy