Difference between revisions of "Java Examples"
(3 intermediate revisions by the same user not shown) | |||
Line 23: | Line 23: | ||
* [https://github.com/BaseXdb/basex/blob/master/basex-examples/src/main/java/org/basex/examples/server/ServerConcurrency.java ServerConcurrency.java]<br/>runs concurrent queries. | * [https://github.com/BaseXdb/basex/blob/master/basex-examples/src/main/java/org/basex/examples/server/ServerConcurrency.java ServerConcurrency.java]<br/>runs concurrent queries. | ||
* [https://github.com/BaseXdb/basex/blob/master/basex-examples/src/main/java/org/basex/examples/server/ServerQueries.java ServerQueries.java]<br/>shows how iterative queries can be performed. | * [https://github.com/BaseXdb/basex/blob/master/basex-examples/src/main/java/org/basex/examples/server/ServerQueries.java ServerQueries.java]<br/>shows how iterative queries can be performed. | ||
− | |||
* [https://github.com/BaseXdb/basex/blob/master/basex-examples/src/main/java/org/basex/examples/server/UserExample.java UserExample.java]<br/>manages database users. | * [https://github.com/BaseXdb/basex/blob/master/basex-examples/src/main/java/org/basex/examples/server/UserExample.java UserExample.java]<br/>manages database users. | ||
Line 41: | Line 40: | ||
The implementation of the [http://xqj.net/basex/ BaseX XQJ API] (closed-source) has been written by Charles Foster. It uses the client/server architecture. | The implementation of the [http://xqj.net/basex/ BaseX XQJ API] (closed-source) has been written by Charles Foster. It uses the client/server architecture. | ||
− | The basex-examples repository contains [https://github.com/BaseXdb/basex | + | The basex-examples repository contains [https://github.com/BaseXdb/basex/tree/master/basex-examples/src/main/java/org/basex/examples/xqj various examples] on how to use XQJ. |
==[[Clients|Client API]]== | ==[[Clients|Client API]]== | ||
Line 51: | Line 50: | ||
* [https://github.com/BaseXdb/basex/blob/master/basex-examples/src/main/java/org/basex/examples/api/CreateExample.java CreateExample.java]<br/>shows how new databases can be created. | * [https://github.com/BaseXdb/basex/blob/master/basex-examples/src/main/java/org/basex/examples/api/CreateExample.java CreateExample.java]<br/>shows how new databases can be created. | ||
* [https://github.com/BaseXdb/basex/blob/master/basex-examples/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/blob/master/basex-examples/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/blob/master/basex-examples/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. | * [https://github.com/BaseXdb/basex/blob/master/basex-examples/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. | ||
Line 69: | Line 67: | ||
* [https://github.com/BaseXdb/basex/blob/master/basex-examples/src/main/java/org/basex/examples/xmldb/XMLDBInsert.java XMLDBInsert.java]<br/>inserts a document into a database using XML:DB. | * [https://github.com/BaseXdb/basex/blob/master/basex-examples/src/main/java/org/basex/examples/xmldb/XMLDBInsert.java XMLDBInsert.java]<br/>inserts a document into a database using XML:DB. | ||
</div> | </div> | ||
− | |||
− | |||
__NOTOC__ | __NOTOC__ |
Revision as of 15:56, 17 January 2016
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 work in embedded mode; they do not rely on an additional server instance:
- RunCommands.java
creates and drops database and index instances, prints a list of all existing databases. - RunQueries.java
shows three variants of running queries. - BindContext.java
demonstrates how a value can be bound as context item. - BindVariables.java
demonstrates how a value can be bound to a variable. - CreateCollection.java
creates and manages a collection. - QueryCollection.java
creates, runs queries against it and drops a collection. - WikiExample.java
creates a database from an url (wiki instance), runs a query against it and drops the database.
Server Examples
The examples below take advantage of the client/server architecture:
- ServerCommands.java
launches server-side commands using a client session. - ServerAndLocal.java
processes server results locally. - ServerConcurrency.java
runs concurrent queries. - ServerQueries.java
shows how iterative queries can be performed. - UserExample.java
manages database users.
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 byFruitsExample
. - ModuleDemo.java
is a simple XQuery demo module that demonstrates how XQuery items can be processed from Java. It is derived from theQueryModule
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
- BaseXClient.java
provides an implementation of the Server Protocol. - Example.java
demonstrates how commands can be executed on a server. - QueryExample.java
shows how queries can be executed in an iterative manner. - QueryBindExample.java
shows how external variables can be bound to XQuery expressions. - CreateExample.java
shows how new databases can be created. - AddExample.java
shows how documents can be added to databases, and how existing documents can be replaced. - BinaryExample.java
shows how binary resource can be added to and retrieved from the database.
REST API
- RESTGet.java
presents the HTTP GET method. - RESTPost.java
presents the HTTP POST method. - RESTPut.java
presents the HTTP PUT method. - RESTAll.java
runs all examples at one go.
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.
- XMLDBCreate.java
creates a collection using XML:DB. - XMLDBQuery.java
runs a query using XML:DB. - XMLDBInsert.java
inserts a document into a database using XML:DB.