This one time, at band camp, Bruce Snyder said:

BS>This one time, at band camp, Stein M. Eliassen said:
BS>
BS>SME>Can someone wack me real hard, cause I don't understand how to use the 
BS>SME>SimpleQueryExecutor.
BS>SME>
BS>SME>A short code-snippet would also help...I think.
BS>
BS>Stein,
BS>
BS>I'm working on this. It's more tedious than I thought, so it's taking
BS>me some time. I'm not sure I would recommend using this because of
BS>this. It's really no easier than using an OQL query. I'll post it when
BS>I've got it working.

Attached is what I've come up with. It's not completely working because
I haven't built up the query yet. Like I said, I'm not sure that this
is any easier than using an OQL query.

Bruce
-- 
perl -e 'print unpack("u30","<0G)[EMAIL PROTECTED]&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'

package example;

import java.io.PrintWriter;

import org.exolab.castor.jdo.Database;
import org.exolab.castor.jdo.JDO;
import org.exolab.castor.jdo.QueryResults;
import org.exolab.castor.jdo.engine.DatabaseImpl;
import org.exolab.castor.jdo.engine.SimpleQueryExecutor;
import org.exolab.castor.jdo.drivers.JDBCQueryExpression;
import org.exolab.castor.jdo.drivers.PostgreSQLFactory;
import org.exolab.castor.persist.spi.PersistenceFactory;
import org.exolab.castor.persist.spi.QueryExpression;

public class SimpleQueryExecutorExample
{

    public static final String JDOConf       = "jdo-conf.xml";

    public static final String ObjectMapping = "mapping.xml";


    private JDO                 _jdo;



    public static void main( String[] args )
    {
        PrintWriter writer; 
        SimpleQueryExecutorExample example;
        
        writer = new Logger( System.out ).setPrefix( "example" );

        try
        {
            example = new SimpleQueryExecutor( writer );
            example.run( writer );
        }
        catch( Exception e )
        {
            writer.println( e );
            e.printStackTrace( writer );
        }
    }


    public SimpleQueryExecutor( PrintWriter aWriter )
        throws Exception
    {
        Database    db; 

        _jdo = new JDO();
        _jdo.setLogWriter( aWriter );
        _jdo.setConfiguration( getClass().getResource( JDOConf ).toString() );
        _jdo.setDatabaseName( "example" );

        db = _jdo.getDatabase();
    }


    public run( PrintWriter aWriter )
    {
        PersistenceFactory  factory;
        QueryExpression     queryExpr;
        SimpleQueryExecutor queryExecutor;
        QueryResults        results; 
        Object              obj;

        factory   = new PostgreSQLFactory();
        queryExpr = new JDBCQueryExpression( factory );

        // Build up the queryExpr here

        queryExecutor = new SimpleQueryExecutor( ( DatabaseImpl ) db );

        results = queryExecutor.execute( queryExpr, new Object[] { 1, "foo" } );

        while( results.hasMore() )
        {
            obj = results.next();
            writer.println( "Fetched object: " + obj );
        }
    }
}

Reply via email to