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