importData(false);
}
else if (sCommand.equals("recreate"))
{
init();
new DataLoader(m_context).recreateSchema(getDataSourceSet());
importData(true);
}
else if (sCommand.equals("reset"))
{
init();
new DataLoader(m_context).deleteData(getDataSourceSet());
importData(true);
}
else if (sCommand.equals("recreateschema"))
{
init();
new DataLoader(m_context).recreateSchema(getDataSourceSet());
}
else if (sCommand.equals("upgrade"))
{
init();
upgradeData(false);
}
else if (sCommand.equals("upgradedump"))
{
String sDumpURLs = getProperty("dump.urls");
String sDumpURLArray[];
if (sDumpURLs != null)
{
if (hasProperty("dump.url") || hasProperty("old.dump.url"))
{
throw new IllegalArgumentException(
"Properties \"dump.url\" and \"old.dump.url\" cannot be specified with \"dump.urls\"");
}
sDumpURLArray = StringUtil.split(sDumpURLs, ' ');
}
else
{
sDumpURLArray = new String[] {getRequiredProperty("dump.url")};
}
String sPreviousMetaURL = getRequiredProperty("old.meta.url");
String sBaseURLProperty = getProperty("old.meta.base.url");
Properties properties = new Properties(SysUtil.getConfigProperties())
{
private static final long serialVersionUID = -6961684990382643373L;
/**
* @see java.util.Properties#getProperty(java.lang.String,
* java.lang.String)
*/
public String getProperty(String sKey, String sDefaultValue)
{
String sValue = getOverride(sKey);
return (sValue != null) ? sValue : super.getProperty(sKey, sDefaultValue);
}
/**
* @see java.util.Properties#getProperty(java.lang.String)
*/
public String getProperty(String sKey)
{
String sValue = getOverride(sKey);
return (sValue != null) ? sValue : super.getProperty(sKey);
}
protected String getOverride(String sKey)
{
if (sKey.startsWith("meta.") && !sKey.equals(XMLMetadataLoader.BASE_URL_PROPERTY))
{
return DataLoadTool.this.getProperty("old." + sKey);
}
return null;
}
};
properties.setProperty(XMLMetadataLoader.BASE_URL_PROPERTY, sBaseURLProperty == null ? "" : sBaseURLProperty);
Metadata oldMetadata = null;
for (int nDumpIndex = 0; nDumpIndex < sDumpURLArray.length; ++nDumpIndex)
{
String sPreviousDumpURL;
if (sDumpURLs == null)
{
sPreviousDumpURL = getProperty("old.dump.url", sDumpURLArray[nDumpIndex]);
}
else
{
sPreviousDumpURL = sDumpURLArray[nDumpIndex];
setProperty("dump.url", sDumpURLArray[nDumpIndex]);
}
if (s_logger.isInfoEnabled())
{
s_logger.info("Upgrading dump " + sDumpURLArray[nDumpIndex] + "...");
}
s_logger.info("Loading current repository");
init();
// drop any tables that may exist for the current schema
new DataLoader(m_context).dropSchema(getDataSourceSet());
s_logger.info("Loading old repository");
if (oldMetadata == null)
{
oldMetadata = new MetadataLoaderDispatcher().load(sPreviousMetaURL, properties, MetadataLoader.DEFAULT, null);
}
init(oldMetadata);
s_logger.info("Recreating the old data");
new DataLoader(m_context).recreateSchema(getDataSourceSet());
importData(true, sPreviousDumpURL);
s_logger.info("Upgrading the data");
init();
upgradeData(true);
s_logger.info("Exporting the data");
init();
exportData();
}
s_logger.info("Upgrade dump completed");
}
else if (sCommand.equals("version"))
{
init();
DataLoader loader = new DataLoader(m_context);
for (Iterator itr = loader.getDataSourceIterator(getDataSourceSet()); itr.hasNext();)
{
DataSource ds = (DataSource)itr.next();
SchemaVersion version = loader.getSchemaVersion(ds);
if (version != null)
{
printVersion(version.getNamespace(), version.getVersion());