Difference between revisions of "Java Examples"

From BaseX Documentation
Jump to navigation Jump to search
Line 27: Line 27:
  
 
==XQuery Module Examples==
 
==XQuery Module Examples==
 +
 +
BaseX provides [[Java Bindings]] for accessing external Java code via XQuery functions. The following examples show how this feature can be utilized:
  
 
* [https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/module/FruitsExample.java FruitsExample.java]<br/>demonstrates how Java classes can be imported as XQuery modules.
 
* [https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/module/FruitsExample.java FruitsExample.java]<br/>demonstrates how Java classes can be imported as XQuery modules.
 
* [https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/module/FruitsModule.java FruitsModule.java]<br/>is a simple demo module called by {{Code|FruitsExample}}.
 
* [https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/module/FruitsModule.java FruitsModule.java]<br/>is a simple demo module called by {{Code|FruitsExample}}.
 
* [https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/module/ModuleDemo.java ModuleDemo.java]<br/>is a simple XQuery demo module that demonstrates how XQuery items can be processed from Java. It is derived from the {{Code|QueryModule}} class.
 
* [https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/module/ModuleDemo.java ModuleDemo.java]<br/>is a simple XQuery demo module that demonstrates how XQuery items can be processed from Java. It is derived from the {{Code|QueryModule}} class.
* [https://github.com/BaseXdb/basex/blob/master/src/main/java/org/basex/query/QueryModule.java QueryModule.java]<br/>is located in the BaseX core. Java query modules can extend this class to get access to the current query context and enrich functions with properties ([[Java Bindings|see more]]).
+
* [https://github.com/BaseXdb/basex/blob/master/src/main/java/org/basex/query/QueryModule.java QueryModule.java]<br/>is located in the BaseX core. Java query modules can extend this class to get access to the current query context and enrich functions with properties ().
  
 
</div><div style="float:left; width:4%;">&nbsp;
 
</div><div style="float:left; width:4%;">&nbsp;

Revision as of 08:55, 10 June 2013

This page is part of the Developer Section. The following Java code snippets demonstrate how easy it is to run database commands, create collections, perform queries, etc. by integrating the BaseX code. Most examples are taken from our basex-examples repository, in which you will find some more use cases.

Local Examples

The following code snippets do not require any server instance:

Server Examples

The examples below take advantage of the client/server architecture:

XQuery Module Examples

BaseX provides Java Bindings for accessing external Java code via XQuery functions. The following examples show how this feature can be utilized:

  • FruitsExample.java
    demonstrates how Java classes can be imported as XQuery modules.
  • FruitsModule.java
    is a simple demo module called by FruitsExample.
  • ModuleDemo.java
    is a simple XQuery demo module that demonstrates how XQuery items can be processed from Java. It is derived from the QueryModule class.
  • QueryModule.java
    is located in the BaseX core. Java query modules can extend this class to get access to the current query context and enrich functions with properties ().
 

XQJ API

The implementation of the BaseX XQJ API (closed-source) has been written by Charles Foster. It uses the client/server architecture. The basex-examples repository contains various examples on how to use XQJ.

Client API

REST API

XML:DB API (deprecated)

Note that the XML:DB API does not talk to the server and can thus only be used in embedded mode.