0

preface: The Oracle implementation might not be open source. The work-around appears to be to use saxonica.

How do I import OXQDataSource?

Oracle uses:

import oracle.xml.xquery.OXQDataSource;

But from where does this originate?

I'm not understanding what to import nor what JAR's should be on the classpath for the XQJ example 7-1 from the Oracle docs because I get error: package oracle.xml.xquery does not exist when trying to compile.

Is the package for XQJ under java.lang.Object?

compile error, package does not exist:

thufir@dur:~/NetBeansProjects/helloWorldBaseX$ 
thufir@dur:~/NetBeansProjects/helloWorldBaseX$ gradle clean run

> Task :compileJava FAILED
/home/thufir/NetBeansProjects/helloWorldBaseX/src/main/java/org/basex/examples/local/App.java:15: error: package oracle.xml.xquery does not exist
import oracle.xml.xquery.OXQDataSource;
                        ^
/home/thufir/NetBeansProjects/helloWorldBaseX/src/main/java/org/basex/examples/local/App.java:46: error: cannot find symbol
        OXQDataSource ds = new OXQDataSource();
        ^
  symbol:   class OXQDataSource
  location: class App
/home/thufir/NetBeansProjects/helloWorldBaseX/src/main/java/org/basex/examples/local/App.java:46: error: cannot find symbol
        OXQDataSource ds = new OXQDataSource();
                               ^
  symbol:   class OXQDataSource
  location: class App
3 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
2 actionable tasks: 2 executed
thufir@dur:~/NetBeansProjects/helloWorldBaseX$ 

code with import:

package org.basex.examples.local;

import java.io.IOException;
import java.util.Properties;
import java.util.logging.Logger;
import javax.xml.xquery.XQConnection;
import javax.xml.xquery.XQException;
import javax.xml.xquery.XQPreparedExpression;
import javax.xml.xquery.XQSequence;
import org.basex.core.BaseXException;
import org.basex.core.Context;
import org.basex.core.cmd.CreateDB;
import org.basex.core.cmd.DropDB;
import org.basex.core.cmd.List;
import oracle.xml.xquery.OXQDataSource;

public final class App {

    private static final Logger LOG = Logger.getLogger(App.class.getName());
    private final Properties properties = new Properties();
    private final Context context = new Context();

    public static void main(String[] args) throws BaseXException, IOException {
        LOG.fine("starting..");
        new App().helloWorld();
    }

    private void list() throws BaseXException {
        LOG.info(new List().execute(context));
    }

    private void helloWorld() throws BaseXException, IOException {
        properties.loadFromXML(App.class.getResourceAsStream("/basex.xml"));
        String databaseName = properties.getProperty("databaseName");
        String databasePath = properties.getProperty("databasePath");

        list();
        new CreateDB(databaseName, databasePath).execute(context);
        list();
        new DropDB(databaseName).execute(context);
        list();

    }

    private void oracleXQJ() throws XQException {
        OXQDataSource ds = new OXQDataSource();
        XQConnection con = ds.getConnection();
        String query = "<hello-world>{1 + 1}</hello-world>";
        XQPreparedExpression expr = con.prepareExpression(query);
        XQSequence result = expr.executeQuery();
        // prints "<hello-world>2</hello-world>"
        System.out.println(result.getSequenceAsString(null));
        result.close();
        expr.close();
        con.close();
    }

}

I just threw that import statement in there to generate a specific error. What should be imported, and from what?

It's only this one class which is giving problems, for unknown reasons. Not sure how to import, nor what to put on the classpath for that import.


I see:

The lib directory contains these JAR and ZIP files:

         classgen.jar
         jdev-rt.zip
         oraclexsql.jar
         transx.zip
         xml.jar
         xml2.jar
         xmldemo.jar
         xmlmesg.jar
         xmlparserv2.jar
         xschema.jar
         xsqlserializers.jar
         xsu12.jar

The jlib directory contains these JAR files:

         orai18n.jar
         orai18n-collation.jar
         orai18n-mapping.jar
         orai18n-utility.jar

One of those, presumably, has OXQDataSource.

Thufir
  • 8,216
  • 28
  • 125
  • 273

1 Answers1

1

The design of XQJ is that you start by creating a data source representing a particular XQuery engine and database, you then establish a connection from your application to that data source, and then you use standard interfaces to execute queries against the data source. In principle, if you want to switch to a different query engine, you just need to instantiate a different data source. So if you want to switch from Oracle to Saxon, you instantiate a Saxon DataSource rather than an Oracle DataSource.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • To clarify: https://softwarerecs.stackexchange.com/q/54194/13043 It's so much material to slog through only to potentially find out that the technology isn't the right fit. – Thufir Jan 02 '19 at 14:31
  • Unfortunately for you, it's probably easier for you to learn about the available technologies than for an outsider to learn about your project requirements. But if you want to save time and improve your chances of making a good technology choice, then hiring a consultant who knows the technology and will spend time understanding your needs is often a good option. – Michael Kay Jan 02 '19 at 15:13