import java.sql.*;
import java.io.*;
import uk.ac.ic.doc.automed.*;
import uk.ac.ic.doc.automed.reps.*;
import uk.ac.ic.doc.automed.ssd.*;
import java.util.*;
import uk.ac.ic.doc.automed.wrappers.*;
import uk.ac.bbk.dcs.automed.qproc.*;
import uk.ac.bbk.dcs.automed.wrappers.*;


public class TestYattaWrapper 
{
    static String driver="org.postgresql.Driver";
    static String url="jdbc:postgresql://db.doc.ic.ac.uk:5432/sk297";
    static String username="sk297";
    static String password="prodzestma";

    public static void TestYattaWrapper(YattaWrapper yw)
	throws DataSourceException 
    {
	YattaQuery student= 
	    //new YattaQuery(new Object[]{"x"},"<<name,string,-,1,<<root,list>>,<<student,list,*,1,<<root,list>>>>>>"); 
	    new YattaQuery(new Object[]{"x"},"<<name,root,<<student,root>>>>"); 

	YattaQuery course= new YattaQuery(new Object[] {"x", "y"}, "<<course,list,+,2,<<root,list>>,<<student,list,*,1,<<root,list>>>>>>"); 

	YattaQuery student_root= new YattaQuery(new Object[] {"x", "y"}, "<<student,list,*,1,<<root,list>>>>");
	
  	System.out.println("Querying students' name ...");
  	YattaQueryResult result1=yw.executeYattaQuery(student);
 	System.out.print("Query result: ");
  	System.out.println(result1.toString());

	System.out.println();
	System.out.println("Querying courses and codes ...");
	YattaQueryResult result2=yw.executeYattaQuery(course);
	System.out.print("Query result: ");
	System.out.println(result2.toString());

	System.out.println();
	System.out.println("Querying students and root ...");
	YattaQueryResult result3=yw.executeYattaQuery(student_root);
	System.out.print("Query result: ");
	System.out.println(result3.toString());


	//Here is to test the method "executeIQL"
	try{
	    System.out.println();    
	    System.out.println("Test processing IQL query.");
	    System.out.println("--------------------------");
	    ASG q=new ASG("<<name,root,<<student,root>>>>");
	    ASG r=yw.executeIQL(q);
	    System.out.print("Query result: ");
	    System.out.println(r);
	}
	catch(Throwable t){
	    t.printStackTrace();
	}
	
    }

    public static void main(String[] args)
    {
	try{
	
	    STR.setDebugLevel(0);
	    //AutoMedWrapper.setDebugLevel(0);

	    Schema y1=Schema.getSchema("y1");
	    AccessMethod [] am = y1.getAccessMethods();
	    YattaWrapper yw_y1=new YattaWrapper(am[0], null);
	    
	    System.out.println("Yatta Schema Listing:");
	    yw_y1.getWrapperSchema().listSchema();

	    System.out.println();
	    System.out.println("Query Testing");
	    System.out.println("*************");
	    TestYattaWrapper(yw_y1);
	}
	catch(Throwable t){
	    t.printStackTrace();
	}
    }

}


