UNSOLVED

jelmer1

updated

17 years ago

J

jelmer1

1 Message

0

2976

April 22nd, 2009 03:00

Executing queries with XAM

Hi I am trying to run a query against the centera test environment. I've pasted the code I am using below

The problem I am having is that while i am able to retrieve the total number of results found, i am unable to read any of the results via the XSet.XAM_JOB_QUERY_RESULTS stream

Could someone tell me what it is I am doing wrong ?

Also Its been suggested in the api documentation that its possible to asynchronously execute a query and register a callback to handle the results. I have been unable figure out I would go about this. Does anyone have any clues ?

I did try commiting the query before calling submit job. However when i later fetched the xset it couldnt find the fiields,

XSet.XAM_JOB_STATUS or XSet.XAM_JOB_QUERY_RESULTS

--- Java code ---

public class QueryExample {

    public static void main(String[] args) throws Exception {

        XAMLibrary library = XAMLibraryFactory.newXAMLibrary();

        library.setProperty(XAMLibrary.XAM_LOG_LEVEL, XAMLibrary.XAM_LOG_ALL);
        library.setProperty(XAMLibrary.XAM_LOG_PATH, "/home/jelmer/my.log");

        XSystem system = library.connect(
                "snia-xam://centera_vim!128.221.200.63:3218?/home/jelmer/peas/xamconnect.pea");

        XSet query = system.createXSet(XSet.MODE_UNRESTRICTED);

        query.createProperty(XSet.XAM_JOB_COMMAND, false, XSet.XAM_JOB_QUERY);

        // use a stream because queries can exceed 255 characters

        // String queryString = "select \".xset.xuid\" where \"nl.qiy.name\" = 'Jelmer'";

        String queryString = "select \".xset.xuid\"";

        System.out.println("Executing query : " + queryString);

        byte[] queryBytes = queryString.getBytes("UTF-8");

        XStream queryStream = query.createXStream(XSet.XAM_JOB_QUERY_COMMAND, true, XAMLibrary.TEXT_PLAIN_MIME_TYPE);
        queryStream.write(queryBytes, 0, queryBytes.length);
        queryStream.close();

        query.submitJob();


        System.out.print("polling");
        // poll every second
        while (!XSet.XAM_JOB_STATUS_COMPLETE.equals(query.getString(XSet.XAM_JOB_STATUS))) {
            Thread.sleep(1000);
            System.out.print(".");
        }

        System.out.println("\r\n\r\nTotal results : " + query.getLong(XSet.XAM_JOB_QUERY_RESULTS_COUNT));

        XStream results = query.openXStream(XSet.XAM_JOB_QUERY_RESULTS, XStream.MODE_READ_ONLY);

        byte rawXUID[] = new byte[80];

       
        while ((results.read(rawXUID)) != -1) {
            XUID localXUID = system.createXUID(rawXUID);

            System.out.println("Got xuid " + localXUID);
//            XSet data = system.openXSet(localXUID, XSet.MODE_READ_ONLY);
//            // Process results                               }
//            data.close();
        }

        results.close();

        query.close();

        system.close();

    }