* @param filename virtual filename: If the filename suffix is "gz" then the dump will be compressed.
* @param out
*/
public void dumpDatabase(final String filename, final OutputStream out)
{
final HibernateXmlConverter converter = new HibernateXmlConverter() {
@Override
protected void init(final XStream xstream)
{
xstream.omitField(AbstractBaseDO.class, "minorChange");
xstream.omitField(AbstractBaseDO.class, "selected");
xstream.registerConverter(new UserRightIdSingleValueConverter(), 20);
xstream.registerConverter(new UserPrefAreaSingleValueConverter(), 19);
}
};
converter.setHibernate(hibernate);
converter.appendIgnoredTopLevelObjects(embeddedClasses);
Writer writer = null;
GZIPOutputStream gzipOut = null;
try {
if (filename.endsWith(".gz") == true) {
gzipOut = new GZIPOutputStream(out);
writer = new OutputStreamWriter(gzipOut, "utf-8");
} else {
writer = new OutputStreamWriter(out, "utf-8");
}
converter.dumpDatabaseToXml(writer, true); // history=false, preserveIds=true
} catch (final IOException ex) {
log.error(ex.getMessage(), ex);
} finally {
IOUtils.closeQuietly(gzipOut);
IOUtils.closeQuietly(writer);