package org.wei.test;

import TOPLink.Public.Sessions.*;
import TOPLink.Public.Expressions.*;
import TOPLink.Public.QueryFramework.*;
import org.wei.dbpoc2.*;
import java.util.*;

public class Test {

    public Test() {
        TOPLink.Public.Sessions.Project builderProject = TOPLink.Tools.MappingWorkbench.XMLProjectReader.read(
            "C:\\java\\projects\\dbpoc2\\persistence\\toplink\\dbpoc2.xml");
            //"C:\\java\\projects\\dbpoc2\\persistence\\toplink.old\\toplink.xml");
        DatabaseSession session = builderProject.createDatabaseSession();
        session.logMessages();
        Vector employees;
        //Employee emp;
        Person person;
        Iterator i;

        //login
        session.login();

        //set up the expression
        ExpressionBuilder builder = new ExpressionBuilder();
        Expression expression = builder.get("id").equal(2);

        //create a partial query
        ReadAllQuery query = new ReadAllQuery(Person.class, expression);

        //query.addPartialAttribute( "" );  // todo: add original notice id
        //query.dontMaintainCache();

        System.out.println( "before query" );
        employees = (Vector) session.executeQuery( query );
        System.out.println( "after query" );
        i = employees.iterator();
        while ( i.hasNext() ){
            person = (Person) i.next();
            System.out.println( person );
            System.out.println( ((Skill)person.getSkills().toArray()[0]).getName());
        }

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

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