System.out.println();
}
}
// Create a PMF for use with this mode
PersistenceManagerFactory pmf = null;
try
{
if (tool.getPropsFileName() != null)
{
pmf = getPMFForMode(mode, tool.getApi(), tool.getOptions(), tool.getStringProperty("org.jpox.PersistenceUnitName"),
ddlFilename, tool.isVerbose());
}
else
{
pmf = getPMFForMode(mode, tool.getApi(), null, tool.getStringProperty("org.jpox.PersistenceUnitName"), ddlFilename,
tool.isVerbose());
}
}
catch (Exception e)
{
// Unable to create a PMF so likely input errors
JPOXLogger.SCHEMATOOL.error("Error creating PMF", e);
System.out.println(LOCALISER.msg(false, "014008", e.getMessage()));
System.exit(1);
return;
}
List classNames = null;
if (mode != SCHEMATOOL_SCHEMA_INFO_MODE && mode != SCHEMATOOL_DATABASE_INFO_MODE)
{
// Find the names of the classes to be processed
// This will load up all MetaData for the specified input and throw exceptions where errors are found
try
{
MetaDataManager metaDataMgr = ((ObjectManagerFactoryImpl)pmf).getOMFContext().getMetaDataManager();
ClassLoaderResolver clr = ((ObjectManagerFactoryImpl)pmf).getOMFContext().getClassLoaderResolver(null);
FileMetaData[] filemds = getFileMetaDataForInput(metaDataMgr, clr, tool.isVerbose(),
tool.getStringProperty("org.jpox.PersistenceUnitName"), tool.getDefaultArgs());
classNames = new ArrayList();
if (filemds == null)
{
msg = LOCALISER.msg(false, "014021");
JPOXLogger.SCHEMATOOL.error(msg);
System.out.println(msg);
System.exit(2);
return;
}
for (int i=0;i<filemds.length;i++)
{
for (int j=0;j<filemds[i].getNoOfPackages();j++)
{
for (int k=0;k<filemds[i].getPackage(j).getNoOfClasses();k++)
{
classNames.add(filemds[i].getPackage(j).getClass(k).getFullClassName());
}
}
}
}
catch (Exception e)
{
// Exception will have been logged and sent to System.out in "getFileMetaDataForInput()"
System.exit(2);
return;
}
}
// Run SchemaTool
try
{
if (mode == SCHEMATOOL_CREATE_MODE)
{
createSchema(pmf, classNames, ddlFilename, tool.getCompleteDdl());
}
else if (mode == SCHEMATOOL_DELETE_MODE)
{
deleteSchema(pmf, classNames);
}
else if (mode == SCHEMATOOL_VALIDATE_MODE)
{
validateSchema(pmf, classNames);
}
else if (mode == SCHEMATOOL_DATABASE_INFO_MODE)
{
StoreManager srm = ((AbstractPersistenceManager) pmf.getPersistenceManager()).getObjectManager().getStoreManager();
srm.outputDatastoreInformation(System.out);
}
else if (mode == SCHEMATOOL_SCHEMA_INFO_MODE)
{
StoreManager srm = ((AbstractPersistenceManager) pmf.getPersistenceManager()).getObjectManager().getStoreManager();
srm.outputSchemaInformation(System.out);
}
msg = LOCALISER.msg(false, "014043");
JPOXLogger.SCHEMATOOL.info(msg);