import java.sql.*;
import java.io.*;
import uk.ac.ic.doc.automed.*;
import uk.ac.ic.doc.automed.reps.*;

/*
 * An application to demonstrate how to setup models (i.e. modelling
 * languages such as ER, Relational, etc) using the
 * Automed API
 */

public class DefineRepository {
  // Generic reinitialise of a repository
  public static void initialiseRepository(String sourceName)  
  throws DataSourceRepositoryException, SQLException, IOException {
    String sa[]=new String[]{"",sourceName};

    DataSourceRepository.doDropdbCommand(sa);
    DataSourceRepository.doCreatedbCommand(sa);
    System.out.println("Repository "+sourceName+" initialised");
  }

  // A utility to wipe the contents of the MDR and set it 
  // back to its initial state
  public static void reinitialiseMDR() 
    throws DataSourceRepositoryException, SQLException, IOException {
    String sa[]=new String[]{
      "", 
      ModelDefinitionsRepository.getMDR_DataSourceName()};

    DataSourceRepository.doDropdbCommand(sa);
    DataSourceRepository.doCreatedbCommand(sa);
    System.out.println("MDR Recreated");
  }
    
  // A utility to wipe the contents of the STR and set it 
  // back to its initial state
  public static void reinitialiseSTR()  
  throws DataSourceRepositoryException, SQLException, IOException {
    String sn[]=new String[]{
      "", 
      SchemaTransformationRepository.getSTR_DataSourceName()
    };

    DataSourceRepository.doDropdbCommand(sn);
    DataSourceRepository.doCreatedbCommand(sn);
    System.out.println("STR Recreated");
  }

  public static void main(String[] args) {
    try {
      System.out.println("AutoMed Repository Reinitialisation");

      // Set this to 2 to see SQL executed
      SchemaTransformationRepository.setDebugLevel(0);

      initialiseRepository(ModelDefinitionsRepository.getDataSourceName());      
      initialiseRepository(SchemaTransformationRepository.getDataSourceName());
      initialiseRepository(SchemaModelingRepository.getDataSourceName());
      initialiseRepository(TemplateExecutionRepository.getDataSourceName());
      initialiseRepository(TemplateTransformationRepository.getDataSourceName());
      initialiseRepository(TemplateTransformationSyntaxRepository.getDataSourceName());
    }
    catch (SQLException se) { 
      se.printStackTrace();
    }
    catch (IOException ie) {
      ie.printStackTrace();
    }
    catch (AutoMedException ame) {
      ame.printStackTrace();
    }      
  }
}

























