package ca.sundog.dbTest.*;

import TOPLink.Public.Expressions.*;
import TOPLink.Public.Sessions.*;
import TOPLink.Public.QueryFramework.*;
import java.util.*;

public class TopLinkTest {

    public TopLinkTest() {
        TOPLink.Public.Sessions.Project builderProject =
            TOPLink.Tools.MappingWorkbench.XMLProjectReader.read(
            "~/Projects/Java/dbTest/toplink.xml");
        DatabaseSession session = builderProject.createDatabaseSession();
        //session.logMessages();
        Vector list;

        //Data class
        ProdGroup prodGroup;
        Iterator i;

        //login
        session.login();

        //create the objects for the main query & subquery
        ExpressionBuilder allProdGroups = new ExpressionBuilder();
        ExpressionBuilder latestVersion =  new ExpressionBuilder();
        ReportQuery subQuery = new ReportQuery( ProdGroup.class, latestVersion );

        //setup the main query "expression"
        Expression exp =
            allProdGroups.get("version").equal(subQuery).and(
            allProdGroups.get("default_indicator").equal("N"));

        //setup the subquery "expression"
        subQuery.addMaximum("version");
        subQuery.setSelectionCriteria(latestVersion.get("id").equal(allProdGroups.get("id")));

        //setup the "query" (with an ordering clause)
        ReadAllQuery query = new ReadAllQuery(ProdGroup.class, exp);
        query.addAscendingOrdering("id");

        //create a partial query
        //query.addPartialAttribute( "" );
        //query.dontMaintainCache();

        //get the data
        list = (Vector) session.executeQuery( query );

        //use the data
        i = list.iterator();
        while ( i.hasNext() ){
            System.out.println( (ProdGroup) i.next() );
        }


        //close the session
        session.logout();
    }

    public static void main(String[] args) {
        TopLinkTest topLinkTest1 = new TopLinkTest();
    }
}
1