Application Developer's Guide (PDF)
Total Page:16
File Type:pdf, Size:1020Kb
MarkLogic Server Application Developer’s Guide 1Application Developer’s Guide MarkLogic 8 February, 2015 Last Revised: 8.0-7, August, 2017 Copyright © 2017 MarkLogic Corporation. All rights reserved. MarkLogic Server Table of Contents Table of Contents Application Developer’s Guide 1.0 Developing Applications in MarkLogic Server ...........................................12 1.1 Overview of MarkLogic Server Application Development .................................12 1.2 Skills Needed to Develop MarkLogic Server Applications ..................................12 1.3 Where to Find Specific Information .....................................................................13 2.0 Loading Schemas .........................................................................................14 2.1 Configuring Your Database ..................................................................................14 2.2 Loading Your Schema ..........................................................................................15 2.3 Referencing Your Schema ....................................................................................16 2.4 Working With Your Schema ................................................................................16 2.5 Validating XML Against a Schema ......................................................................17 3.0 Understanding Transactions in MarkLogic Server ......................................19 3.1 Terms and Definitions ..........................................................................................20 3.2 Overview of MarkLogic Server Transactions ......................................................22 3.2.1 Key Transaction Attributes .......................................................................23 3.2.2 Understanding Statement Boundaries .......................................................24 3.2.3 Single-Statement Transaction Concept Summary ....................................26 3.2.4 Multi-Statement Transaction Concept Summary .....................................27 3.3 Commit Mode .......................................................................................................28 3.4 Transaction Type ..................................................................................................29 3.4.1 Transaction Type Overview ......................................................................29 3.4.2 Controlling Transaction Type in XQuery .................................................30 3.4.3 Controlling Transaction Type in JavaScript .............................................33 3.4.4 Query Transactions: Point-in-Time Evaluation ........................................35 3.4.5 Update Transactions: Readers/Writers Locks ...........................................36 3.4.6 Example: Query and Update Transaction Interaction ...............................38 3.5 Single vs. Multi-statement Transactions ...............................................................39 3.5.1 Single-Statement, Automatically Committed Transactions ......................39 3.5.2 Multi-Statement, Explicitly Committed Transactions ..............................40 3.5.3 Semi-Colon as a Statement Separator .......................................................45 3.6 Transaction Mode .................................................................................................47 3.6.1 Transaction Mode Overview ....................................................................47 3.6.2 Auto Transaction Mode ............................................................................48 3.6.3 Query Transaction Mode ..........................................................................49 3.6.4 Update Transaction Mode .........................................................................50 3.7 Interactions with xdmp:eval/invoke ......................................................................51 3.7.1 Isolation Option to xdmp:eval/invoke ......................................................51 MarkLogic 8—February, 2015 Application Developer’s Guide—Page 2 MarkLogic Server Table of Contents 3.7.2 Preventing Deadlocks ...............................................................................52 3.7.3 Seeing Updates From eval/invoke Later in the Transaction .....................54 3.7.4 Running Multi-Statement Transactions under xdmp:eval/invoke ............55 3.8 Functions With Non-Transactional Side Effects ..................................................56 3.9 Reducing Blocking with Multi-Version Concurrency Control .............................57 3.10 Administering Transactions ..................................................................................57 3.11 Transaction Examples ...........................................................................................58 3.11.1 Example: Multi-statement Transactions and Same-statement Isolation ...58 3.11.2 Example: Multi-Statement Transactions and Different-transaction Isolation 60 3.11.3 Example: Generating a Transaction Report With xdmp:host-status ........61 4.0 Working With Binary Documents ...............................................................63 4.1 Terminology ..........................................................................................................63 4.2 Loading Binary Documents ..................................................................................64 4.3 Configuring MarkLogic Server for Binary Content .............................................64 4.3.1 Setting the Large Size Threshold ..............................................................64 4.3.2 Sizing and Scalability of Binary Content .................................................65 4.3.3 Selecting a Location For Binary Content .................................................66 4.3.4 Monitoring the Total Size of Large Binary Data in a Forest ....................67 4.3.5 Detecting and Removing Orphaned Binaries ...........................................68 4.4 Developing Applications That Use Binary Documents ........................................69 4.4.1 Adding Metadata to Binary Documents Using Properties ........................69 4.4.2 Downloading Binary Content With HTTP Range Requests ....................70 4.4.3 Creating Binary Email Attachments .........................................................72 4.5 Useful Built-ins for Manipulating Binary Documents .........................................73 5.0 Importing XQuery Modules, XSLT Stylesheets, and Resolving Paths .......75 5.1 XQuery Library Modules and Main Modules ......................................................75 5.1.1 Main Modules ...........................................................................................75 5.1.2 Library Modules .......................................................................................76 5.2 Rules for Resolving Import, Invoke, and Spawn Paths ........................................76 5.3 Module Caching Notes .........................................................................................78 5.4 Example Import Module Scenario ........................................................................79 6.0 Library Services Applications ......................................................................80 6.1 Understanding Library Services ...........................................................................80 6.2 Building Applications with Library Services .......................................................82 6.3 Required Range Element Indexes .........................................................................82 6.4 Library Services API ............................................................................................83 6.4.1 Library Services API Categories ..............................................................84 6.4.2 Managed Document Update Wrapper Functions ......................................84 6.5 Security Considerations of Library Services Applications ...................................85 6.5.1 dls-admin Role ..........................................................................................85 6.5.2 dls-user Role .............................................................................................85 MarkLogic 8—February, 2015 Application Developer’s Guide—Page 3 MarkLogic Server Table of Contents 6.5.3 dls-internal Role ........................................................................................86 6.6 Transactions and Library Services ........................................................................86 6.7 Putting Documents Under Managed Version Control ..........................................86 6.8 Checking Out Managed Documents .....................................................................87 6.8.1 Displaying the Checkout Status of Managed Documents ........................87 6.8.2 Breaking the Checkout of Managed Documents ......................................87 6.9 Checking In Managed Documents ........................................................................88 6.10 Updating Managed Documents ............................................................................88 6.11 Defining a Retention Policy ..................................................................................89 6.11.1 Purging Versions of Managed Document .................................................89 6.11.2 About Retention Rules ..............................................................................90 6.11.3 Creating Retention Rules ..........................................................................90