Clone wiki

jqcML / XmlToQcdb

Store qcML files in a qcDB

jqcML can be used to very easily and quickly store a bunch of qcML files in a qcDB for long-term storage. As an example on how to use jqcML, this conversion between the XML-based files and a qcDB will be outlined here through some code that is ready for use.

In order to read XML-based qcML files, a QcMLFileReader has to be created. Furthermore, to write to a qcDB, a QcDBWriter has to be created as well. (This Writer can be based on different types of databases, for example a SQLite or a MySQL database.)

To store the XML-based qcML files in the qcDB, these files simply need to be read one by one using the QcMLFileReader, after which they will be persisted in the qcDB using the QcDBWriter.

Through the simple and intuitive functionality provided by jqcML, this process only requires a very limited amount of code, as is shown below.

// create a reader to read the qcML files
QcMLReader reader = new QcMLFileReader();

// create a writer to write to a qcDB
// SQLite or MySQL
EntityManagerFactory emf = QcDBManagerFactory.createSQLiteFactory("qcml.sqlite");
//EntityManagerFactory emf = QcDBManagerFactory.createMySQLFactory(null, null, "qcml", "root", null);
QcMLWriter writer = new QcDBWriter(emf);

// read each file individually and write it to the qcDB
File qcmlDir = new File("data/qcml");   // path to the folder containing the qcML files
File[] files = qcmlDir.listFiles();
    if(files != null)
        for(File file : files)
            if(FilenameUtils.getExtension(file.getName()).equalsIgnoreCase("qcML")) {
                // read the qcML file
                QcML qcml = reader.getQcML(file.getAbsolutePath());
                // write to the qcDB