Java API
Java application programming interface (API) is a list of all classes that are part of the Java development kit (JDK). It includes all Java packages, classes, and interfaces, along with their methods, fields, and constructors. These prewritten classes provide a tremendous amount of functionality to a programmer. The Java API, included with the JDK, describes the function of each of its components. In Java programming, many of these components are pre-created and commonly used. Thus, the programmer is able to apply prewritten code via the Java API. After referring to the available API classes and packages, the programmer easily invokes the necessary code classes and packages for implementation.
Introduction to the Java API
The Java Client API is an open source API for creating applications that use MarkLogic Server for document and search operations. Developers can easily take advantage of the advanced capabilities for persistence and search of unstructured documents that MarkLogic Server provides. The capabilities provided by the JAVA API include:
- Insert, update, or remove documents and document metadata. For details, see Document Operations.
- Query text and lexicon values. For details, see Searching.
- Configure persistent and dynamic query options. For details, see Query Options.
- Apply transformations to new content and search results. For details, see Content Transformations.
- Extend the Java API to expose custom capabilities you install on MarkLogic Server. For details, see Extending the Java API.
Thread Safety of the Java API
You should be aware of the following API characteristics with respect to thread safety:
- DatabaseClient is thread safe after initialization.
- The various manager classes are thread safe after initial configuration. Examples: DocumentManager, QueryManager, ResourceManager.
- Handles are not thread safe. Examples: StringHandle, FileHandle, SearchHandle.
- Builders are not thread safe. Examples: DocumentPatchBuilder, StructuredQueryBuilder.
For example, you can create a DocumentManager for manipulating XML documents and share it across multiple threads. Similarly, you can create a QueryManager, set the page length, and then share it between multiple threads. Handles can be used across multiple requests within the same thread, but cannot be used across threads, so whenever you create a new thread, you must create new Handle objects to use in that thread.