Package jfix.db4o.xstream

Source Code of jfix.db4o.xstream.Db4oXStream

/*
    Copyright (C) 2010 maik.jablonski@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package jfix.db4o.xstream;

import com.db4o.Db4oEmbedded;
import com.db4o.ObjectContainer;
import com.db4o.config.EmbeddedConfiguration;

public class Db4oXStream {

  private String databaseFile;
  private String xstreamFile;

  public Db4oXStream(String databaseFile, String xstreamFile) {
    this.databaseFile = databaseFile;
    this.xstreamFile = xstreamFile;
  }

  public void toXML() {
    EmbeddedConfiguration config = Db4oEmbedded.newConfiguration();
    config.common().activationDepth(Integer.MAX_VALUE);
    ObjectContainer db4o = Db4oEmbedded.openFile(config, databaseFile);
    new XStreamFile(xstreamFile).write(db4o.queryByExample(null));
    db4o.close();
  }

  public void fromXML() {
    ObjectContainer db4o = Db4oEmbedded.openFile(databaseFile);
    for (Object obj : new XStreamFile(xstreamFile).read()) {
      db4o.store(obj);
    }
    db4o.commit();
    db4o.close();
  }
}
TOP

Related Classes of jfix.db4o.xstream.Db4oXStream

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.