This is a simple example that demonstrate how to use the SWIG generated binding to create, compile, and execute queries.
import org.zorbaxquery.api.Zorba;
import org.zorbaxquery.api.XQuery;
import org.zorbaxquery.api.Iterator;
import org.zorbaxquery.api.Item;
import org.zorbaxquery.api.XmlDataManager;
import org.zorbaxquery.api.DocumentManager;
import org.zorbaxquery.api.InMemoryStore;
public class Test_Zorba
{
static
{
System.loadLibrary ( "zorba_api" );
}
static boolean example_1(
Zorba aZorba)
{
System.out.println ( lQuery.
execute() );
return true;
}
static boolean example_2 (
Zorba aZorba )
{
while ( lIterator.
next(lItem) )
{
}
lIterator.delete();
return true;
}
static boolean example_3 (
Zorba aZorba )
{
try
{
System.out.println ( lQuery.
execute () );
}
catch ( RuntimeException e )
{
System.out.println ( e.getMessage() );
return true;
}
return false;
}
static boolean example_4 (
Zorba aZorba )
{
try
{
System.out.println ( lQuery.
execute () );
}
catch ( RuntimeException e )
{
System.out.println ( e.getMessage () );
return true;
}
return false;
}
static boolean example_5 (
Zorba zorba )
{
Iterator i = dm.
parseXML(
"<books><book>Book 1</book><book>Book 2</book></books>");
i.delete();
docMgr.
put(
"books.xml", doc);
doc.delete();
System.out.println ( xquery.
execute() );
return true;
}
public static void main ( String argv[] )
{
boolean res = false;
System.out.println ("executing example 1" );
res = example_1( zorba );
if ( !res )
System.exit ( 1 );
System.out.println ( "executing example 2" );
res = example_2 ( zorba );
if (!res)
System.exit ( 1 );
System.out.println ( "executing example 3" );
System.out.println ( "expecting [err:FOAR0001]" );
res = example_3 ( zorba );
if (!res)
System.exit ( 1 );
System.out.println ( "executing example 4" );
System.out.println ( "expecting [err:XPST0003]" );
res = example_4 ( zorba );
if (!res)
System.exit ( 1 );
System.out.println ( "executing example 5" );
res = example_5 ( zorba );
if (!res)
System.exit ( 1 );
return;
}
}