View Javadoc

1   /*
2    * org.riverock.dbrevision - Database revision engine
3    * For more information about DbRevision, please visit project site
4    * http://www.riverock.org
5    *
6    * Copyright (C) 2006-2006, Riverock Software, All Rights Reserved.
7    *
8    * Riverock - The Open-source Java Development Community
9    * http://www.riverock.org
10   *
11   *
12   * This library is free software; you can redistribute it and/or
13   * modify it under the terms of the GNU Lesser General Public
14   * License as published by the Free Software Foundation; either
15   * version 2.1 of the License, or (at your option) any later version.
16   *
17   * This library is distributed in the hope that it will be useful,
18   * but WITHOUT ANY WARRANTY; without even the implied warranty of
19   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20   * Lesser General Public License for more details.
21   *
22   * You should have received a copy of the GNU Lesser General Public
23   * License along with this library; if not, write to the Free Software
24   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25   */
26  package org.riverock.dbrevision.system;
27  
28  import java.io.OutputStream;
29  
30  import org.riverock.dbrevision.annotation.schema.db.DbSchema;
31  import org.riverock.dbrevision.annotation.schema.db.DbTable;
32  import org.riverock.dbrevision.db.Database;
33  import org.riverock.dbrevision.db.DatabaseManager;
34  import org.riverock.dbrevision.db.DatabaseStructureManager;
35  import org.riverock.dbrevision.exception.DbRevisionException;
36  import org.riverock.dbrevision.utils.Utils;
37  
38  /**
39   * Export data from DB to XML file
40   * <p/>
41   * Author: mill
42   * Date: Nov 28, 2002
43   * Time: 3:10:19 PM
44   * <p/>
45   * $Id: DbStructureExport.java 1141 2006-12-14 14:43:29Z serg_main $
46   */
47  public class DbStructureExport {
48  
49      public static void export(Database adapter, OutputStream outputStream, boolean isData) {
50          export(adapter, outputStream, isData, true);
51      }
52  
53      public static void export(Database adapter, OutputStream outputStream, boolean isData, boolean isOnlyCurrent) {
54          try {
55              DbSchema schema = DatabaseManager.getDbStructure(adapter, isOnlyCurrent);
56              if (isData) {
57                  for (DbTable table : schema.getTables()) {
58                      table.setData(DatabaseStructureManager.getDataTable(adapter, table));
59                  }
60              }
61              Utils.writeObjectAsXml(schema, outputStream, "utf-8");
62          } catch (Exception e) {
63              throw new DbRevisionException(e);
64          }
65      }
66  }