Database Reference
In-Depth Information
Example
The source code of a small example of using the Fluent API from Java to store a file,
query the database, and remove a file is included in the folder
chapters/integration/
fluent-embedded
of the
book-code
Git repository (see
“Getting the Source Code” on
page 15
).
This example is a direct port of the XML:DB Local API example from the previous
section, and hopefully will allow you to easily compare the code of the two
approaches and decide which you prefer.
To compile the example, enter the
fluent-embedded
folder and run
mvn package
.
Fluent API example.
You can then execute the ExampleApp example like so:
java -jar fluent-embedded-example/target/fluent-embedded-example-1.0-example.jar
This shows the available arguments for using the ExampleApp.
A complete example of using the application might look like the following:
java -jar fluent-embedded-example/target/fluent-embedded-example-1.0-example.jar
/db/my-new-collection /tmp/test.xml "//thing" admin
Given the preceding arguments, the example application would perform the follow‐
ing steps:
1. Start up the embedded eXist database.
2. Get a reference to the folder (collection)
/db/my-new-collection
in eXist (the
folder will be created if it does not already exist).
3. Upload the file
/tmp/test.xml
to the folder
/db/my-new-collection
in eXist (again,
the folder will be created if it does not already exist).
4. Execute the query
//thing
against the
/db/my-new-collection
folder, and print
the results.
5. Remove the
/db/my-new-collection/test.xml
file.
6. Shut down the eXist database.
Search WWH ::
Custom Search