001
014
015 package com.liferay.portal.convert;
016
017 import com.liferay.portal.kernel.dao.jdbc.DataSourceFactoryUtil;
018 import com.liferay.portal.kernel.util.StringPool;
019 import com.liferay.portal.util.MaintenanceUtil;
020 import com.liferay.portal.util.ShutdownUtil;
021 import com.liferay.registry.collections.ServiceTrackerCollections;
022
023 import java.util.List;
024
025 import javax.sql.DataSource;
026
027
030 public class DatabaseConvertProcess extends BaseConvertProcess {
031
032 public void destroy() {
033 _databaseConverters.clear();
034
035 _databaseConverters = null;
036 }
037
038 @Override
039 public String getDescription() {
040 return "migrate-data-from-one-database-to-another";
041 }
042
043 @Override
044 public String getParameterDescription() {
045 return "please-enter-jdbc-information-for-new-database";
046 }
047
048 @Override
049 public String[] getParameterNames() {
050 return new String[] {
051 "jdbc-driver-class-name", "jdbc-url", "jdbc-user-name",
052 "jdbc-password"
053 };
054 }
055
056 @Override
057 public boolean isEnabled() {
058 return true;
059 }
060
061 @Override
062 protected void doConvert() throws Exception {
063 MaintenanceUtil.appendStatus("Starting database migration.");
064
065 for (DatabaseConverter databaseConverter : _databaseConverters) {
066 databaseConverter.convert(getDataSource());
067 }
068
069 MaintenanceUtil.appendStatus(
070 "Please change your JDBC settings before restarting server");
071
072 ShutdownUtil.shutdown(0);
073 }
074
075 protected DataSource getDataSource() throws Exception {
076 String[] values = getParameterValues();
077
078 String driverClassName = values[0];
079 String url = values[1];
080 String userName = values[2];
081 String password = values[3];
082 String jndiName = StringPool.BLANK;
083
084 return DataSourceFactoryUtil.initDataSource(
085 driverClassName, url, userName, password, jndiName);
086 }
087
088 private List<DatabaseConverter> _databaseConverters =
089 ServiceTrackerCollections.openList(DatabaseConverter.class);
090
091 }