package basic;

import uk.ac.ic.doc.automed.*;
import uk.ac.ic.doc.automed.modelmanagement.modeldef.SQLModelDef;
import uk.ac.ic.doc.automed.reps.*;

import java.util.*;

/*
 * An application to demonstrate how various aspects of the AutoMed
 * repository may be used to automatically transform an ER schema
 * into a SQL schema
 */
import uk.ac.ic.doc.automed.modelmanagement.operators.ModelGen;

public class DefineAutoTransformation {

    public static void main(String[] args) {
        try {
            System.out.println("AutoMed Repository: Automatic Transformation Demo");
            
            // level 5 prints all the old debug information, 0 makes it silent
            STR.setDebugLevel(0);
            
            Schema s4c=Schema.getSchema("er_s2e");
            
            if (Schema.exists("er_s2f")) {
                Schema.retract("er_s2f");
            }
            
            // Now transform this into the sql model
            SQLModelDef smd = new SQLModelDef();
            smd.setFeatures(30);
            smd.getAutoMedModel();
            String targetModelName = smd.getAutoMedModelName();
            
            ModelGen mg = new ModelGen();
            Schema sqlSchema = mg.modelGen(s4c, targetModelName);
            sqlSchema.listSchema();
            
            // IMPORTANT: for embedded dbs with auto-commit=false, must
            // gracefully shutdown db after use
            DSR.shutdown();
            
            System.exit(0);
            
        } catch (AutoMedException ame) {
            ame.printStackTrace();
        }
    }
}
