Difference between revisions of "Java Examples"

From BaseX Documentation
Jump to navigation Jump to search
Line 33: Line 33:
 
</div><div style="float:left; width:4%;">&nbsp;
 
</div><div style="float:left; width:4%;">&nbsp;
 
</div><div style="float:left; width:48%;">
 
</div><div style="float:left; width:48%;">
 +
==[[Clients|Client API]]==
 +
 +
* [https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/api/BaseXClient.java BaseXClient.java]<br/>provides an implementation of the [[Server Protocol]].
 +
* [https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/api/Example.java Example.java]<br/>demonstrates how commands can be executed on a server.
 +
* [https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/api/QueryExample.java QueryExample.java]<br/>shows how queries can be executed in an iterative manner.
 +
* [https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/api/QueryBindExample.java QueryBindExample.java]<br/>shows how external variables can be bound to XQuery expressions.
 +
* [https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/api/CreateExample.java CreateExample.java]<br/>shows how new databases can be created.
 +
* [https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/api/AddExample.java AddExample.java]<br/>shows how documents can be added to databases, and how existing documents can be replaced.
 +
* [https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/api/EventExample.java EventExample.java]<br/>demonstrates how to trigger and receive database events.
 +
* [https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/api/BinaryExample.java BinaryExample.java]<br/>shows how binary resource can be added to and retrieved from the database.
  
 
==[[REST API]]==
 
==[[REST API]]==

Revision as of 10:38, 6 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

Server Examples

XQuery Module Examples

  • 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.
  • 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
    Java query modules can extend this class to get access to the current query context and enrich functions with properties (see more).
 

Client API

REST API

XQJ API

Our current XQJ API is based on Charles Foster’s XQJ implementation (closed-source). It communicates with the BaseX server. The basex-examples repository contains various examples on how to use XQJ.

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.