record(null);
}
private void record(MappingTool.Flags flags) {
MappingRepository repos = getRepository();
MetaDataFactory io = repos.getMetaDataFactory();
ClassMapping[] mappings;
if (!ACTION_DROP.equals(_action))
mappings = repos.getMappings();
else if (_dropMap != null)
mappings = (ClassMapping[]) _dropMap.toArray
(new ClassMapping[_dropMap.size()]);
else
mappings = new ClassMapping[0];
try {
if (_dropCls != null && !_dropCls.isEmpty()) {
Class[] cls = (Class[]) _dropCls.toArray
(new Class[_dropCls.size()]);
if (!io.drop(cls, _mode, null))
_log.warn(_loc.get("bad-drop", _dropCls));
}
if (_flushSchema) {
// drop portions of the known schema that no mapping uses, and
// add sequences used for value generation
if (_dropUnused)
dropUnusedSchemaComponents(mappings);
addSequenceComponents(mappings);
// now run the schematool as long as we're doing some schema
// action and the user doesn't just want an xml output
String[] schemaActions = _schemaActions.split(",");
for (int i = 0; i < schemaActions.length; i++) {
if (!SCHEMA_ACTION_NONE.equals(schemaActions[i])
&& (_schemaWriter == null || (_schemaTool != null
&& _schemaTool.getWriter() != null))) {
SchemaTool tool = newSchemaTool(schemaActions[i]);
// configure the tool with additional settings
if (flags != null) {
tool.setDropTables(flags.dropTables);
tool.setDropSequences(flags.dropSequences);
tool.setWriter(flags.sqlWriter);
tool.setOpenJPATables(flags.openjpaTables);
}
tool.setSchemaGroup(getSchemaGroup());
tool.run();
tool.record();
}
}
// xml output of schema?
if (_schemaWriter != null) {
// serialize the planned schema to the stream
SchemaSerializer ser = new XMLSchemaSerializer(_conf);
ser.addAll(getSchemaGroup());
ser.serialize(_schemaWriter, ser.PRETTY);
_schemaWriter.flush();
}
}
if (!_flush)
return;
QueryMetaData[] queries = repos.getQueryMetaDatas();
SequenceMetaData[] seqs = repos.getSequenceMetaDatas();
Map output = null;
// if we're outputting to stream, set all metas to same file so
// they get placed in single string
if (_mappingWriter != null) {
output = new HashMap();
File tmp = new File("openjpatmp");
for (int i = 0; i < mappings.length; i++)
mappings[i].setSource(tmp, mappings[i].SRC_OTHER);
for (int i = 0; i < queries.length; i++)
queries[i].setSource(tmp, queries[i].getSourceScope(),
queries[i].SRC_OTHER);
for (int i = 0; i < seqs.length; i++)
seqs[i].setSource(tmp, seqs[i].getSourceScope(),
seqs[i].SRC_OTHER);
}
// store
if (!io.store(mappings, queries, seqs, _mode, output))
throw new MetaDataException(_loc.get("bad-store"));
// write to stream
if (_mappingWriter != null) {
PrintWriter out = new PrintWriter(_mappingWriter);