XQuery API for Java

XQJ
Developer(s)Java Community Process
Stable release
1.0 / 24 June 2009 (2009-06-24)
TypeData Access API
WebsiteJSR 225: XQuery API for Java
General architecture of how an XQJ driver is used to communicate with an XML Database from Java Applications.

XQuery API for Java (XQJ) refers to the common Java API for the W3C XQuery 1.0 specification.

The XQJ API enables Java programmers to execute XQuery against an XML data source (e.g. an XML database) while reducing or eliminating vendor lock in.

The XQJ API provides Java developers with an interface to the XQuery Data Model.[1] Its design is similar to the JDBC API which has a client/server feel and as such lends itself well to Server-based XML Databases and less well to client-side XQuery processors, although the "connection" part is a very minor part of the entire API. Users of the XQJ API can bind Java values to XQuery expressions, preventing code injection attacks.[2] Also, multiple XQuery expressions can be executed as part of an atomic transaction.

History and implementation

The XQuery API for Java was developed at the Java Community Process as JSR 225. It had some big technology backers such as Oracle,[3][4][5][6] IBM,[5][6] BEA Systems,[7] Software AG,[8] Intel, Nokia and DataDirect.[4]

Version 1.0 of the XQuery API for Java Specification was released on June 24, 2009,[9] along with JavaDocs, a reference implementation and a TCK (Technology Compatibility Kit) which implementing vendors must conform to.

The XQJ classes are contained in the Java package javax.xml.xquery

There is no (visible) activity to create a version of XQJ that provides support for XQuery 3.0 or 3.1, for example by providing Java bindings for additions to the data model such as functions, arrays, or maps.

Functionality

XQJ allows multiple implementations to exist and be used by the same application.

XQJ connections support creating and executing XQuery expressions. Expressions may be updating[10] and may include full text searches.[11] XQJ represents XQuery expressions using one of the following classes:

  • XQExpression – the expression is sent to the XQuery processor every time.
  • XQPreparedExpression – the expression is cached and the execution path is pre-determined allowing it to be executed multiple times in an efficient manner.

XQuery expressions return a result sequence of XDM[1] items which in XQJ are represented through the XQResultSequence interface. The programmer can use an XQResultSequence to walk over individual XDM[1] items in the result sequence. Each item in the sequence has XDM[1] type information associated with it, such as its node type e.g. element(), document-node() or an XDM atomic type such as xs:string, xs:integer or xs:dateTime. XDM type information in XQJ can be retrieved via the XQItemType interface.

Atomic XQuery items can be easily cast to Java primitives via XQItemAccessor methods such as getByte() and getFloat(). Also XQuery items and sequences can be serialized to DOM Node, SAX ContentHandler, StAX XMLStreamReader and the generic IO Reader and InputStream classes.

Examples

Basic example

The following example illustrates creating a connection to an XML Database, submitting an XQuery expression, then processing the results in Java. Once all of the results have been processed, the connection is closed to free up all resources associated with it.

// Create a new connection to an XML database
XQConnection conn = vendorDataSource.getConnection("myUser", "myPassword");

XQExpression expr = conn.createExpression(); // Create a reusable XQuery Expression object

XQResultSequence result = expr.executeQuery(
  "for $n in fn:collection('catalog')//item " +
  "return fn:data($n/name)"); // execute an XQuery expression

// Process the result sequence iteratively
while (result.next()) {
    // Print the current item in the sequence
    System.out.println("Product name: " + result.getItemAsString(null));
}

// Free all resources created by the connection
conn.close();

Binding a value to an external variable

The following example illustrates how a Java value can be bound to an external variable in an XQuery expression. Assume that the connection conn already exists:

XQExpression expr = conn.createExpression();

// The XQuery expression to be executed
String es = "declare variable $x as xs:integer external;" +
            " for $n in fn:collection('catalog')//item" +
            " where $n/price <= $x" +
            " return fn:data($n/name)";

// Bind a value (21) to an external variable with the QName x
expr.bindInt(new QName("x"), 21, null);

// Execute the XQuery expression
XQResultSequence result = expr.executeQuery(es);

// Process the result (sequence) iteratively
while (result.next()) {
    // Process the result ...
}

Default data type mapping

Mapping between Java and XQuery data types is largely flexible, however the XQJ 1.0 specification does have default mapping rules mapping data types when they are not specified by the user. These mapping rules bear great similarities to the mapping rules found in JAXB.

The following table illustrates the default mapping rules for when binding Java values to external variables in XQuery expressions.

Default conversion rules when mapping from Java data types to XQuery data types
Java Datatype Default XQuery Data Type(s)
boolean xs:boolean
byte xs:byte
byte[] xs:hexBinary
double xs:double
float xs:float
int xs:int
long xs:long
short xs:short
Boolean xs:boolean
Byte xs:byte
Float xs:float
Double xs:double
Integer xs:int
Long xs:long
Short xs:short
String xs:string
BigDecimal xs:decimal
BigInteger xs:integer
Duration xs:dayTimeDuration if the Duration Object's state is xs:dayTimeDuration
xs:yearMonthDuration if the Duration Object's state is xs:yearMonthDuration
xs:duration if the Duration Object's state is xs:duration
XMLGregorianCalendar xs:date if the XMLGregorianCalendar Object's state is xs:date
xs:dateTime if the XMLGregorianCalendar Object's state is xs:dateTime
xs:gDay if the XMLGregorianCalendar Object's state is xs:gDay
xs:gMonth if the XMLGregorianCalendar Object's state is xs:gMonth
xs:gMonthDay if the XMLGregorianCalendar Object's state is xs:gMonthDay
xs:gYear if the XMLGregorianCalendar Object's state is xs:gYear
xs:gYearMonth if the XMLGregorianCalendar Object's state is xs:gYearMonth
xs:time if the XMLGregorianCalendar Object's state is xs:time
QName xs:QName
Document document-node(element(*, xs:untyped))
DocumentFragment document-node(element(*, xs:untyped))
Element element(*, xs:untyped)
Attr attribute(*, xs:untypedAtomic)
Comment comment()
ProcessingInstruction processing-instruction()
Text text()

Known implementations

Native XML databases

The following is a list of Native XML Databases which are known to have XQuery API for Java implementations.

Relational databases

DataDirect provide XQJ adapters for relational databases, by translating XQuery code into SQL on the fly, then converting SQL result sets into a format suitable for XQJ to process further. The following is a couple of known implementations.

Non-database implementations

The following is a list of non-database XQuery processors which provide an XQuery API for Java interface (typically allowing query against documents parsed from XML in filestore, and held in memory as DOM or similar trees).

License

The specification is marked as "Copyright © 2003, 2006 - 2009 Oracle. All rights reserved."

The specification contains two separate licenses: a "specification license" and a "reference implementation license".

The specification license allows free copying of the specification provided that copyright notices are retained; it also grants a license to create and distribute an implementation of the specification provided that it fully implements the entire specification, that it does not modify or extend any interfaces, and that it passes the compatibility tests.

This provision has caused some controversy. Firstly, it is not universally accepted that implementing a published specification is something that requires a license (that is, that copyright law would disallow this in the absence of a license).[20][21] Secondly, the license does not meet the criteria to qualify as an open source license (see Open Source Definition), because of the ban on making extensions and modifications. This has led some open source enthusiasts to challenge whether XQJ implementations can ever be considered truly open source.

The license for the reference implementation is a fairly conventional BSD-style open source license.

References

  1. ^ a b c d XQuery 1.0 and XPath 2.0 Data Model (XDM)
  2. ^ Binding Java Variables
  3. ^ Querying XML: XQuery, XPath, and SQL/XML in context - Jim Melton and Stephen Buxton. ISBN 978-1558607118
  4. ^ a b XQJ - XQuery Java API is Completed, Marc Van Cappellen, Zhen Hua Liu, Jim Melton and Maxim Orgiyan Archived 28 July 2012 at the Wayback Machine
  5. ^ a b IBM and Oracle Submit XQuery API for Java (XQJ) Java Specification Request.
  6. ^ a b An Early Look at XQuery API for Java (XQJ) - Andrew Eisenberg, IBM and Jim Melton, Oracle Archived 28 July 2012 at the Wayback Machine
  7. ^ The BEA Streaming XQuery Processor
  8. ^ XQJ Interface for Tamino Native XML Database Archived 30 May 2013 at the Wayback Machine
  9. ^ JSR-000225 XQuery API for Java (Final Release)
  10. ^ XQuery Update Facility
  11. ^ XQuery Full Text
  12. ^ MarkLogic XQJ API
  13. ^ eXist XQJ API
  14. ^ BaseX XQJ API
  15. ^ Sedna XQJ API
  16. ^ Oracle XML DB Support for XQJ
  17. ^ Software AG - Working with the CentraSite XQJ Interface
  18. ^ Zorba 2.5 ships with a long awaited XQJ binding, 14 June 2012
  19. ^ Oracle XML Developer's Kit (XDK) provides a standalone XQuery 1.0 processor for use by Java applications.
  20. ^ "Open Standards" (PDF). Retrieved 7 September 2023.
  21. ^ "Groklaw - Oracle v. Google - Understanding the Copyright Issue with API Specifications". www.groklaw.net. Archived from the original on 5 May 2012.

Read other articles:

Ed “Rolly” Conen Tanda tanganInformasi pribadiNama lengkap Edmund ConenTanggal lahir (1914-11-10)10 November 1914Tempat lahir Ürzig, JermanTanggal meninggal 5 Maret 1990(1990-03-05) (umur 75)Tempat meninggal Leverkusen, JermanPosisi bermain PenyerangKarier junior1924–1928 SV Ürzig1928–1932 1. FC SaarbrückenKarier senior*Tahun Tim Tampil (Gol)1932–1935 1. FC Saarbrücken 1938–1944 Stuttgarter Kickers 1943–1944 → Mulhouse (pemain tamu) 1943–1944 → HSV Groß Born (pe...

 

Direktorat Jenderal Penanganan Masalah Agraria, Pemanfaatan Ruang, dan Tanah Kementerian Agraria dan Tata Ruang Republik IndonesiaGambaran umumDasar hukumPeraturan Presiden Nomor 17 Tahun 2015Susunan organisasiDirektur Jenderal-Situs webwww.atrbpn.go.id Direktorat Jenderal Penanganan Masalah Agraria, Pemanfaatan Ruang, dan Tanah merupakan unsur pelaksana pada Kementerian Agraria dan Tata Ruang Republik Indonesia yang berada di bawah dan bertanggung jawab kepada Menteri Agraria dan Tata R...

 

This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: KZMP-FM – news · newspapers · books · scholar · JSTOR (July 2020) (Learn how and when to remove this templa...

العلاقات اليمنية المارشالية اليمن جزر مارشال   اليمن   جزر مارشال تعديل مصدري - تعديل   العلاقات اليمنية المارشالية هي العلاقات الثنائية التي تجمع بين اليمن وجزر مارشال.[1][2][3][4][5] مقارنة بين البلدين هذه مقارنة عامة ومرجعية للدولتين: وجه ال�...

 

Radio station in Colfax, IllinoisWRPWColfax, IllinoisBroadcast areaBloomington-NormalFrequency92.9 MHzBrandingCities Talk FM 92.9ProgrammingFormatTalk radioAffiliationsPremiere NetworksWestwood OneSalem Radio NetworkCompass Media NetworksFox News RadioOwnershipOwnerGreat Plains MediaSister stationsWZIM, WIBLHistoryFirst air dateMay 5, 1996; 27 years ago (1996-05-05)Former call signsWAPU (1996-1998)WSNI (1998-2001)Call sign meaningPoWer (previous format)Technical informationC...

 

1942 studio album by Almanac SingersDear Mr. PresidentStudio album by Almanac SingersReleased1942GenreFolkLabelKeynoteProducerAlan LomaxAlmanac Singers chronology Songs Of The Lincoln Battalion(1940) Dear Mr. President(1942) Dear Mr. President is a 1942 album by the Almanac Singers.[1] History After the Japanese attacks on Pearl Harbor, in February 1942 the Almanacs went into the studio to record a set of songs supporting the American war effort.[1] This was partly bec...

Marie Anne de La TrémoilleRitratto di Marie Anne de La Trémoille, opera di un anonimo di scuola francese, olio su tela, c. 1760 (Museo Condé, Chantilly, Francia)Duchessa consorte di BraccianoStemma In carica1675 –1698 PredecessoreIppolita Ludovisi SuccessoreNessuno, titolo venduto a Livio Odescalchi e Ducato annesso allo Stato Pontificio Principessa consorte di ChalaisIn carica1659 –1663 Altri titoliPrincesse des Ursins (Principessa degli Orsini)Camarera Mayor de Palacio (1701–...

 

Peer-reviewed scientific mega journal Academic journalZootaxaDisciplineTaxonomyZoologyLanguageEnglishEdited byZhi-Qiang ZhangPublication detailsHistory2001–presentPublisherMagnolia Press (New Zealand)FrequencyUpon acceptanceOpen accessHybridImpact factor1.091 (2020)Standard abbreviationsISO 4 (alt) · Bluebook (alt1 · alt2)NLM (alt) · MathSciNet (alt )ISO 4ZootaxaIndexingCODEN (alt · alt2) · JSTOR (alt) ...

 

Bell 214ST adalah helikopter media-angkat bermesin ganda, diturunkan dari seri Bell Helicopter UH-1 Huey. Meskipun berbagi nomor jenis dengan Bell agak terkait 214, 214ST lebih besar dan penampilan yang sangat berbeda. Referensi A Big Lifter From Bell. Air International. Vol. 23, No. 4, October 1982. pp. 163–169. Lambert, Mark. 214ST: Bell's Super Transport. Flight International. Vol. 115, No. 3667. 30 June 1979. pp. 2345–2348. Pranala luar Wikimedia Commons memiliki media mengenai Bell ...

District in Bakool, SomaliaWajidDistrictCountry SomaliaRegionBakoolCapitalWajidTime zoneUTC+3 (EAT) Wajid District (Somali: Degmada Waajid) is a district in the southwestern Bakool region of Somalia. Its capital is Wajid. References External links Districts of Somalia Administrative map of Wajid District vte Administrative divisions of SomaliaAwdal Region Dilla District Baki District Borama District Lughaya District Zeila District Bakool Region Hudur District Rabdhure District Tiyeglow D...

 

此条目序言章节没有充分总结全文内容要点。 (2019年3月21日)请考虑扩充序言,清晰概述条目所有重點。请在条目的讨论页讨论此问题。 哈萨克斯坦總統哈薩克總統旗現任Қасым-Жомарт Кемелұлы Тоқаев卡瑟姆若马尔特·托卡耶夫自2019年3月20日在任任期7年首任努尔苏丹·纳扎尔巴耶夫设立1990年4月24日(哈薩克蘇維埃社會主義共和國總統) 哈萨克斯坦 哈萨克斯坦政府...

 

У Вікіпедії є статті про інші значення цього терміна: 104-та бригада. 104-та окрема бригада територіальної оборони Нарукавний знак бригадиЗасновано червень 2018Країна  УкраїнаВид Сили ТрОБазування Рівненська областьОперації Російське вторгнення в Україну (2022) Битва за Ба...

شدة المجال الكهربائي (بالإنجليزية : electric field strength) هي كمية فيزيائية متجهة تستخدم في الكهرباء الساكنة وفي الإلكتروديناميكا ( علم الحركية الكهربائية)، وهي تصف شدة مجال كهربائي واتجاهه.[1][2] وهي تصف القوة التي يؤثر بها مجال كهربائي على شحنة كهربائية. وتعرف شدة المجال ...

 

German philosopher of South Korean origin In this Korean name, the family name is Han. Byung-Chul HanByung-Chul Han in 2015Born1959 (1959) (age 65)Seoul, South KoreaAlma materUniversity of FreiburgUniversity of BaselEra20th- / 21st-century philosophyRegionWestern philosophySchoolContinental philosophy, Post-structuralism, DeconstructionMain interestsBurnoutDepressionInternetLovePolitical TheoryPowerReligionSocial MediaTransparencyViolenceNotable ideasShanzhai as Deconstruction ...

 

People of Indian birth or origin who reside in Saudi Arabia Not to be confused with Indian Saudis. This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Non-Resident Indians in Saudi Arabia – news · newspapers · books · scholar · JSTOR (August 2017) (Learn how and when to remove this message) Ethnic group Indians ...

2026 edition of the IIHF World Championship Main article: 2026 Men's Ice Hockey World Championships 2026 IIHF World ChampionshipTournament detailsHost country  SwitzerlandVenue(s)2 (in 2 host cities)Dates15–31 MayTeams16← 20252027 → The 2026 IIHF World Championship will be hosted by Switzerland from 15 to 31 May 2026, as the International Ice Hockey Federation (IIHF) announced on 27 May 2022 in Tampere, Finland. Host nation bid The only bidders were Kaza...

 

Neighbourhood in Kolkata in West Bengal, IndiaBowbazarNeighbourhood in Kolkata (Calcutta)Ceramic mural on the wall of Central Station, Kolkata Metro, located on B.B. Ganguly StreetBowbazarLocation in KolkataCoordinates: 22°34′07″N 88°21′48″E / 22.5687°N 88.3632°E / 22.5687; 88.3632Country IndiaStateWest BengalCityKolkataDistrictKolkataMetro StationChandni Chowk, Central, Mahakaran and SealdahRailway stationSealdahMunicipal CorporationKolkata Municipal...

 

Sport and entertainment venue in England The derelict Cornwall Coliseum seen in 2009 Cornwall Coliseum was a sport and entertainment venue located at Carlyon Bay near St Austell, Cornwall, England. It hosted exhibitions, tennis tournaments and many concerts by leading musicians, but lost its importance with the opening of the Plymouth Pavilions in 1991. History The Carlyon Beach area began to develop as a popular recreation area in the 20th century, with one of the visitors being Edward VIII ...

Swedish television program This article needs to be updated. Please help update this article to reflect recent events or newly available information. (May 2023) Allt för SverigeCreated byDavid Berner, Eric R. Williams (The Oxymorons)Presented byAnders LundinCountry of originNorwayOriginal languagesSwedishEnglishNo. of seasons11No. of episodes89ProductionProducerChrister ÅkerlundProduction locationSverigeCamera setupOla FredholmRunning time60 minutesProduction companyMeter Television (Swedis...

 

Plateau in Egypt and Libya Gilf KebirView from the top of Gilf Kebir overlooking Wadi SuraHighest pointElevation1,014 to 1,016 m (3,327 to 3,333 ft) Coordinates23°26′29″N 25°50′23″E / 23.44139°N 25.83972°E / 23.44139; 25.83972GeographyGilf Kebir CountryEgypt Gilf Kebir (جلف كبير) (var. Gilf al-Kebir, Jilf al Kabir, Gilf Kebir Plateau) is a plateau in the New Valley Governorate of the remote southwest corner of Egypt, and southeast...