Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

source files from agraph32 install agsrc-3.2jar

  • Loading branch information...
commit 754ad6726b01e80fe973b9b32eadc4021e1acdac 1 parent 95d0287
@mikehinchey mikehinchey authored
Showing with 33,609 additions and 0 deletions.
  1. +456 −0 LICENSE.txt
  2. +16 −0 overview.htm
  3. +3 −0  src/META-INF/MANIFEST.MF
  4. +76 −0 src/com/franz/ag/AllegroGraphException.java
  5. +190 −0 src/com/franz/ag/NamespaceRegistry.java
  6. +32 −0 src/com/franz/ag/UPI.java
  7. +12 −0 src/com/franz/ag/package.html
  8. +70 −0 src/com/franz/ag/repository/AGBindingSet.java
  9. +26 −0 src/com/franz/ag/repository/AGBooleanQuery.java
  10. +31 −0 src/com/franz/ag/repository/AGCloseableIteration.java
  11. +48 −0 src/com/franz/ag/repository/AGGraphQuery.java
  12. +40 −0 src/com/franz/ag/repository/AGGraphQueryResult.java
  13. +114 −0 src/com/franz/ag/repository/AGQuery.java
  14. +171 −0 src/com/franz/ag/repository/AGRepository.java
  15. +565 −0 src/com/franz/ag/repository/AGRepositoryConnection.java
  16. +40 −0 src/com/franz/ag/repository/AGTupleQuery.java
  17. +44 −0 src/com/franz/ag/repository/AGTupleQueryResult.java
  18. +12 −0 src/com/franz/ag/repository/package.html
  19. +861 −0 src/com/franz/ag/repository/test/AGRepositoryConnectionTest.java
  20. +2,901 −0 src/com/franz/agbase/AllegroGraph.java
  21. +1,756 −0 src/com/franz/agbase/AllegroGraphConnection.java
  22. +72 −0 src/com/franz/agbase/AllegroGraphException.java
  23. +133 −0 src/com/franz/agbase/AllegroGraphSerializer.java
  24. +47 −0 src/com/franz/agbase/BlankNode.java
  25. +44 −0 src/com/franz/agbase/DefaultGraph.java
  26. +97 −0 src/com/franz/agbase/EncodedLiteral.java
  27. +594 −0 src/com/franz/agbase/GeoExtension.java
  28. +35 −0 src/com/franz/agbase/GeospatialSubtype.java
  29. +128 −0 src/com/franz/agbase/LiteralNode.java
  30. +139 −0 src/com/franz/agbase/NTriplesSerializer.java
  31. +32 −0 src/com/franz/agbase/NamespaceRegistry.java
  32. +199 −0 src/com/franz/agbase/Polygon.java
  33. +664 −0 src/com/franz/agbase/PrologSelectQuery.java
  34. +65 −0 src/com/franz/agbase/RDFManifestSerializer.java
  35. +99 −0 src/com/franz/agbase/RDFN3Serializer.java
  36. +201 −0 src/com/franz/agbase/RDFSerializer.java
  37. +17 −0 src/com/franz/agbase/ResourceNode.java
  38. +694 −0 src/com/franz/agbase/SNAExtension.java
  39. +860 −0 src/com/franz/agbase/SPARQLQuery.java
  40. +47 −0 src/com/franz/agbase/SPARQLQueryConstants.java
  41. +227 −0 src/com/franz/agbase/Triple.java
  42. +326 −0 src/com/franz/agbase/TriplesIterator.java
  43. +622 −0 src/com/franz/agbase/TriplesQuery.java
  44. +14 −0 src/com/franz/agbase/UPI.java
  45. +100 −0 src/com/franz/agbase/URINode.java
  46. +26 −0 src/com/franz/agbase/ValueNode.java
  47. +10 −0 src/com/franz/agbase/ValueObject.java
  48. +78 −0 src/com/franz/agbase/ValueSetIterator.java
  49. +183 −0 src/com/franz/agbase/XmlSchema.java
  50. +77 −0 src/com/franz/agbase/impl/AGFactory.java
  51. +100 −0 src/com/franz/agbase/impl/BlankNodeImpl.java
  52. +69 −0 src/com/franz/agbase/impl/DefaultGraphImpl.java
  53. +159 −0 src/com/franz/agbase/impl/EncodedLiteralImpl.java
  54. +67 −0 src/com/franz/agbase/impl/GeospatialSubtypeImpl.java
  55. +289 −0 src/com/franz/agbase/impl/LiteralNodeImpl.java
  56. +71 −0 src/com/franz/agbase/impl/NamedAttributeList.java
  57. +55 −0 src/com/franz/agbase/impl/ResourceNodeImpl.java
  58. +522 −0 src/com/franz/agbase/impl/TripleImpl.java
  59. +1,211 −0 src/com/franz/agbase/impl/TriplesIteratorImpl.java
  60. +291 −0 src/com/franz/agbase/impl/UPIImpl.java
  61. +204 −0 src/com/franz/agbase/impl/URINodeImpl.java
  62. +105 −0 src/com/franz/agbase/impl/ValueNodeImpl.java
  63. +54 −0 src/com/franz/agbase/impl/ValueObjectImpl.java
  64. +285 −0 src/com/franz/agbase/impl/ValueSetIteratorImpl.java
  65. +14 −0 src/com/franz/agbase/impl/package.html
  66. +12 −0 src/com/franz/agbase/package.html
  67. +762 −0 src/com/franz/agbase/transport/AGConnector.java
  68. +281 −0 src/com/franz/agbase/transport/AGDTest.java
  69. +1,106 −0 src/com/franz/agbase/transport/AGDirectConnector.java
  70. +1,670 −0 src/com/franz/agbase/transport/AGDirectLink.java
  71. +222 −0 src/com/franz/agbase/transport/AGDirectLinkDebug.java
  72. +19 −0 src/com/franz/agbase/transport/package.html
  73. +205 −0 src/com/franz/agbase/util/AGBase.java
  74. +465 −0 src/com/franz/agbase/util/AGC.java
  75. +174 −0 src/com/franz/agbase/util/AGConnInternals.java
  76. +483 −0 src/com/franz/agbase/util/AGInternals.java
  77. +34 −0 src/com/franz/agbase/util/AllegroGraphBuilder.java
  78. +80 −0 src/com/franz/agbase/util/QueryBase.java
  79. +124 −0 src/com/franz/agbase/util/SPARQLQueryInternals.java
  80. +14 −0 src/com/franz/agbase/util/package.html
  81. +115 −0 src/com/franz/agjena/AGBulkUpdateHandler.java
  82. +130 −0 src/com/franz/agjena/AGTripleIterator.java
  83. +492 −0 src/com/franz/agjena/AllegroGraphGraph.java
  84. +344 −0 src/com/franz/agjena/AllegroGraphGraphMaker.java
  85. +307 −0 src/com/franz/agjena/AllegroGraphModel.java
  86. +75 −0 src/com/franz/agjena/AllegroGraphReasoner.java
  87. +70 −0 src/com/franz/agjena/EmptyExtendedIterator.java
  88. +263 −0 src/com/franz/agjena/JenaToAGManager.java
  89. +281 −0 src/com/franz/agjena/StartUp.java
  90. +191 −0 src/com/franz/agjena/TempGraph.java
  91. +83 −0 src/com/franz/agjena/Utils.java
  92. +91 −0 src/com/franz/agjena/exceptions/NiceException.java
  93. +34 −0 src/com/franz/agjena/exceptions/UnimplementedMethodException.java
  94. +12 −0 src/com/franz/agjena/package.html
  95. +110 −0 src/com/franz/agjena/query/AllegroGraphBinding.java
  96. +402 −0 src/com/franz/agjena/query/AllegroGraphQuery.java
  97. +176 −0 src/com/franz/agjena/query/AllegroGraphQueryExecution.java
  98. +589 −0 src/com/franz/agjena/query/AllegroGraphQueryExecutionFactory.java
  99. +195 −0 src/com/franz/agjena/query/AllegroGraphQueryFactory.java
  100. +130 −0 src/com/franz/agjena/query/AllegroGraphQuerySolution.java
  101. +161 −0 src/com/franz/agjena/query/AllegroGraphResultSet.java
  102. +137 −0 src/com/franz/agjena/query/UnusedAllegroGraphDataset.java
  103. +1,022 −0 src/com/franz/agjena/test/AbstractTestGraph.java
  104. +279 −0 src/com/franz/agjena/test/AbstractTestGraphMaker.java
  105. +395 −0 src/com/franz/agjena/test/SimpleTests.java
  106. +222 −0 src/com/franz/agjena/test/TestARQueries.java
  107. +240 −0 src/com/franz/agsail/AGForSail.java
  108. +47 −0 src/com/franz/agsail/AGSailBlankNode.java
  109. +326 −0 src/com/franz/agsail/AGSailCursor.java
  110. +12 −0 src/com/franz/agsail/AGSailDefaultGraph.java
  111. +128 −0 src/com/franz/agsail/AGSailLiteral.java
  112. +10 −0 src/com/franz/agsail/AGSailResource.java
  113. +232 −0 src/com/franz/agsail/AGSailTriple.java
  114. +471 −0 src/com/franz/agsail/AGSailTriplesQuery.java
  115. +95 −0 src/com/franz/agsail/AGSailURI.java
  116. +21 −0 src/com/franz/agsail/AGSailValue.java
  117. +11 −0 src/com/franz/agsail/AGSailValueObject.java
  118. +112 −0 src/com/franz/agsail/impl/AGSailBlankNodeImpl.java
  119. +331 −0 src/com/franz/agsail/impl/AGSailCursorImpl.java
  120. +9 −0 src/com/franz/agsail/impl/AGSailDefaultGraphImpl.java
  121. +41 −0 src/com/franz/agsail/impl/AGSailFactory.java
  122. +254 −0 src/com/franz/agsail/impl/AGSailLiteralImpl.java
  123. +52 −0 src/com/franz/agsail/impl/AGSailResourceImpl.java
  124. +380 −0 src/com/franz/agsail/impl/AGSailTripleImpl.java
  125. +196 −0 src/com/franz/agsail/impl/AGSailURIImpl.java
  126. +72 −0 src/com/franz/agsail/impl/AGSailValueImpl.java
  127. +64 −0 src/com/franz/agsail/impl/AGSailValueObjectImpl.java
  128. +12 −0 src/com/franz/agsail/package.html
  129. +152 −0 src/com/franz/agsail/util/AGSInternal.java
  130. +248 −0 src/com/knowledgereefsystems/agsail/AllegroSail.java
  131. +499 −0 src/com/knowledgereefsystems/agsail/AllegroSailConnection.java
  132. +31 −0 src/com/knowledgereefsystems/agsail/AllegroSailException.java
  133. +87 −0 src/com/knowledgereefsystems/agsail/AllegroSailTestCase.java
  134. +43 −0 src/com/knowledgereefsystems/agsail/ContextIteration.java
  135. +22 −0 src/com/knowledgereefsystems/agsail/EmptyCloseableIteration.java
  136. +60 −0 src/com/knowledgereefsystems/agsail/NamespaceIteration.java
  137. +63 −0 src/com/knowledgereefsystems/agsail/QueryEvaluationIteration.java
  138. +60 −0 src/com/knowledgereefsystems/agsail/ResourceIteration.java
  139. +49 −0 src/com/knowledgereefsystems/agsail/SailConnectionTripleSource.java
  140. +29 −0 src/com/knowledgereefsystems/agsail/SimpleListener.java
  141. +110 −0 src/com/knowledgereefsystems/agsail/StatementIteration.java
  142. +68 −0 src/com/knowledgereefsystems/agsail/TestExtendedFeatures.java
  143. +76 −0 src/com/knowledgereefsystems/agsail/TestListeners.java
  144. +149 −0 src/com/knowledgereefsystems/agsail/TestNamespaces.java
Sorry, we could not display the entire diff because it was too big.
View
456 LICENSE.txt
@@ -0,0 +1,456 @@
+ MOZILLA PUBLIC LICENSE
+ Version 1.1
+
+ ---------------
+
+1. Definitions.
+
+ 1.0.1. "Commercial Use" means distribution or otherwise making the
+ Covered Code available to a third party.
+
+ 1.1. "Contributor" means each entity that creates or contributes to
+ the creation of Modifications.
+
+ 1.2. "Contributor Version" means the combination of the Original
+ Code, prior Modifications used by a Contributor, and the Modifications
+ made by that particular Contributor.
+
+ 1.3. "Covered Code" means the Original Code or Modifications or the
+ combination of the Original Code and Modifications, in each case
+ including portions thereof.
+
+ 1.4. "Electronic Distribution Mechanism" means a mechanism generally
+ accepted in the software development community for the electronic
+ transfer of data.
+
+ 1.5. "Executable" means Covered Code in any form other than Source
+ Code.
+
+ 1.6. "Initial Developer" means the individual or entity identified
+ as the Initial Developer in the Source Code notice required by Exhibit
+ A.
+
+ 1.7. "Larger Work" means a work which combines Covered Code or
+ portions thereof with code not governed by the terms of this License.
+
+ 1.8. "License" means this document.
+
+ 1.8.1. "Licensable" means having the right to grant, to the maximum
+ extent possible, whether at the time of the initial grant or
+ subsequently acquired, any and all of the rights conveyed herein.
+
+ 1.9. "Modifications" means any addition to or deletion from the
+ substance or structure of either the Original Code or any previous
+ Modifications. When Covered Code is released as a series of files, a
+ Modification is:
+ A. Any addition to or deletion from the contents of a file
+ containing Original Code or previous Modifications.
+
+ B. Any new file that contains any part of the Original Code or
+ previous Modifications.
+
+ 1.10. "Original Code" means Source Code of computer software code
+ which is described in the Source Code notice required by Exhibit A as
+ Original Code, and which, at the time of its release under this
+ License is not already Covered Code governed by this License.
+
+ 1.10.1. "Patent Claims" means any patent claim(s), now owned or
+ hereafter acquired, including without limitation, method, process,
+ and apparatus claims, in any patent Licensable by grantor.
+
+ 1.11. "Source Code" means the preferred form of the Covered Code for
+ making modifications to it, including all modules it contains, plus
+ any associated interface definition files, scripts used to control
+ compilation and installation of an Executable, or source code
+ differential comparisons against either the Original Code or another
+ well known, available Covered Code of the Contributor's choice. The
+ Source Code can be in a compressed or archival form, provided the
+ appropriate decompression or de-archiving software is widely available
+ for no charge.
+
+ 1.12. "You" (or "Your") means an individual or a legal entity
+ exercising rights under, and complying with all of the terms of, this
+ License or a future version of this License issued under Section 6.1.
+ For legal entities, "You" includes any entity which controls, is
+ controlled by, or is under common control with You. For purposes of
+ this definition, "control" means (a) the power, direct or indirect,
+ to cause the direction or management of such entity, whether by
+ contract or otherwise, or (b) ownership of more than fifty percent
+ (50%) of the outstanding shares or beneficial ownership of such
+ entity.
+
+2. Source Code License.
+
+ 2.1. The Initial Developer Grant.
+ The Initial Developer hereby grants You a world-wide, royalty-free,
+ non-exclusive license, subject to third party intellectual property
+ claims:
+ (a) under intellectual property rights (other than patent or
+ trademark) Licensable by Initial Developer to use, reproduce,
+ modify, display, perform, sublicense and distribute the Original
+ Code (or portions thereof) with or without Modifications, and/or
+ as part of a Larger Work; and
+
+ (b) under Patents Claims infringed by the making, using or
+ selling of Original Code, to make, have made, use, practice,
+ sell, and offer for sale, and/or otherwise dispose of the
+ Original Code (or portions thereof).
+
+ (c) the licenses granted in this Section 2.1(a) and (b) are
+ effective on the date Initial Developer first distributes
+ Original Code under the terms of this License.
+
+ (d) Notwithstanding Section 2.1(b) above, no patent license is
+ granted: 1) for code that You delete from the Original Code; 2)
+ separate from the Original Code; or 3) for infringements caused
+ by: i) the modification of the Original Code or ii) the
+ combination of the Original Code with other software or devices.
+
+ 2.2. Contributor Grant.
+ Subject to third party intellectual property claims, each Contributor
+ hereby grants You a world-wide, royalty-free, non-exclusive license
+
+ (a) under intellectual property rights (other than patent or
+ trademark) Licensable by Contributor, to use, reproduce, modify,
+ display, perform, sublicense and distribute the Modifications
+ created by such Contributor (or portions thereof) either on an
+ unmodified basis, with other Modifications, as Covered Code
+ and/or as part of a Larger Work; and
+
+ (b) under Patent Claims infringed by the making, using, or
+ selling of Modifications made by that Contributor either alone
+ and/or in combination with its Contributor Version (or portions
+ of such combination), to make, use, sell, offer for sale, have
+ made, and/or otherwise dispose of: 1) Modifications made by that
+ Contributor (or portions thereof); and 2) the combination of
+ Modifications made by that Contributor with its Contributor
+ Version (or portions of such combination).
+
+ (c) the licenses granted in Sections 2.2(a) and 2.2(b) are
+ effective on the date Contributor first makes Commercial Use of
+ the Covered Code.
+
+ (d) Notwithstanding Section 2.2(b) above, no patent license is
+ granted: 1) for any code that Contributor has deleted from the
+ Contributor Version; 2) separate from the Contributor Version;
+ 3) for infringements caused by: i) third party modifications of
+ Contributor Version or ii) the combination of Modifications made
+ by that Contributor with other software (except as part of the
+ Contributor Version) or other devices; or 4) under Patent Claims
+ infringed by Covered Code in the absence of Modifications made by
+ that Contributor.
+
+3. Distribution Obligations.
+
+ 3.1. Application of License.
+ The Modifications which You create or to which You contribute are
+ governed by the terms of this License, including without limitation
+ Section 2.2. The Source Code version of Covered Code may be
+ distributed only under the terms of this License or a future version
+ of this License released under Section 6.1, and You must include a
+ copy of this License with every copy of the Source Code You
+ distribute. You may not offer or impose any terms on any Source Code
+ version that alters or restricts the applicable version of this
+ License or the recipients' rights hereunder. However, You may include
+ an additional document offering the additional rights described in
+ Section 3.5.
+
+ 3.2. Availability of Source Code.
+ Any Modification which You create or to which You contribute must be
+ made available in Source Code form under the terms of this License
+ either on the same media as an Executable version or via an accepted
+ Electronic Distribution Mechanism to anyone to whom you made an
+ Executable version available; and if made available via Electronic
+ Distribution Mechanism, must remain available for at least twelve (12)
+ months after the date it initially became available, or at least six
+ (6) months after a subsequent version of that particular Modification
+ has been made available to such recipients. You are responsible for
+ ensuring that the Source Code version remains available even if the
+ Electronic Distribution Mechanism is maintained by a third party.
+
+ 3.3. Description of Modifications.
+ You must cause all Covered Code to which You contribute to contain a
+ file documenting the changes You made to create that Covered Code and
+ the date of any change. You must include a prominent statement that
+ the Modification is derived, directly or indirectly, from Original
+ Code provided by the Initial Developer and including the name of the
+ Initial Developer in (a) the Source Code, and (b) in any notice in an
+ Executable version or related documentation in which You describe the
+ origin or ownership of the Covered Code.
+
+ 3.4. Intellectual Property Matters
+ (a) Third Party Claims.
+ If Contributor has knowledge that a license under a third party's
+ intellectual property rights is required to exercise the rights
+ granted by such Contributor under Sections 2.1 or 2.2,
+ Contributor must include a text file with the Source Code
+ distribution titled "LEGAL" which describes the claim and the
+ party making the claim in sufficient detail that a recipient will
+ know whom to contact. If Contributor obtains such knowledge after
+ the Modification is made available as described in Section 3.2,
+ Contributor shall promptly modify the LEGAL file in all copies
+ Contributor makes available thereafter and shall take other steps
+ (such as notifying appropriate mailing lists or newsgroups)
+ reasonably calculated to inform those who received the Covered
+ Code that new knowledge has been obtained.
+
+ (b) Contributor APIs.
+ If Contributor's Modifications include an application programming
+ interface and Contributor has knowledge of patent licenses which
+ are reasonably necessary to implement that API, Contributor must
+ also include this information in the LEGAL file.
+
+ (c) Representations.
+ Contributor represents that, except as disclosed pursuant to
+ Section 3.4(a) above, Contributor believes that Contributor's
+ Modifications are Contributor's original creation(s) and/or
+ Contributor has sufficient rights to grant the rights conveyed by
+ this License.
+
+ 3.5. Required Notices.
+ You must duplicate the notice in Exhibit A in each file of the Source
+ Code. If it is not possible to put such notice in a particular Source
+ Code file due to its structure, then You must include such notice in a
+ location (such as a relevant directory) where a user would be likely
+ to look for such a notice. If You created one or more Modification(s)
+ You may add your name as a Contributor to the notice described in
+ Exhibit A. You must also duplicate this License in any documentation
+ for the Source Code where You describe recipients' rights or ownership
+ rights relating to Covered Code. You may choose to offer, and to
+ charge a fee for, warranty, support, indemnity or liability
+ obligations to one or more recipients of Covered Code. However, You
+ may do so only on Your own behalf, and not on behalf of the Initial
+ Developer or any Contributor. You must make it absolutely clear than
+ any such warranty, support, indemnity or liability obligation is
+ offered by You alone, and You hereby agree to indemnify the Initial
+ Developer and every Contributor for any liability incurred by the
+ Initial Developer or such Contributor as a result of warranty,
+ support, indemnity or liability terms You offer.
+
+ 3.6. Distribution of Executable Versions.
+ You may distribute Covered Code in Executable form only if the
+ requirements of Section 3.1-3.5 have been met for that Covered Code,
+ and if You include a notice stating that the Source Code version of
+ the Covered Code is available under the terms of this License,
+ including a description of how and where You have fulfilled the
+ obligations of Section 3.2. The notice must be conspicuously included
+ in any notice in an Executable version, related documentation or
+ collateral in which You describe recipients' rights relating to the
+ Covered Code. You may distribute the Executable version of Covered
+ Code or ownership rights under a license of Your choice, which may
+ contain terms different from this License, provided that You are in
+ compliance with the terms of this License and that the license for the
+ Executable version does not attempt to limit or alter the recipient's
+ rights in the Source Code version from the rights set forth in this
+ License. If You distribute the Executable version under a different
+ license You must make it absolutely clear that any terms which differ
+ from this License are offered by You alone, not by the Initial
+ Developer or any Contributor. You hereby agree to indemnify the
+ Initial Developer and every Contributor for any liability incurred by
+ the Initial Developer or such Contributor as a result of any such
+ terms You offer.
+
+ 3.7. Larger Works.
+ You may create a Larger Work by combining Covered Code with other code
+ not governed by the terms of this License and distribute the Larger
+ Work as a single product. In such a case, You must make sure the
+ requirements of this License are fulfilled for the Covered Code.
+
+4. Inability to Comply Due to Statute or Regulation.
+
+ If it is impossible for You to comply with any of the terms of this
+ License with respect to some or all of the Covered Code due to
+ statute, judicial order, or regulation then You must: (a) comply with
+ the terms of this License to the maximum extent possible; and (b)
+ describe the limitations and the code they affect. Such description
+ must be included in the LEGAL file described in Section 3.4 and must
+ be included with all distributions of the Source Code. Except to the
+ extent prohibited by statute or regulation, such description must be
+ sufficiently detailed for a recipient of ordinary skill to be able to
+ understand it.
+
+5. Application of this License.
+
+ This License applies to code to which the Initial Developer has
+ attached the notice in Exhibit A and to related Covered Code.
+
+6. Versions of the License.
+
+ 6.1. New Versions.
+ Netscape Communications Corporation ("Netscape") may publish revised
+ and/or new versions of the License from time to time. Each version
+ will be given a distinguishing version number.
+
+ 6.2. Effect of New Versions.
+ Once Covered Code has been published under a particular version of the
+ License, You may always continue to use it under the terms of that
+ version. You may also choose to use such Covered Code under the terms
+ of any subsequent version of the License published by Netscape. No one
+ other than Netscape has the right to modify the terms applicable to
+ Covered Code created under this License.
+
+ 6.3. Derivative Works.
+ If You create or use a modified version of this License (which you may
+ only do in order to apply it to code which is not already Covered Code
+ governed by this License), You must (a) rename Your license so that
+ the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape",
+ "MPL", "NPL" or any confusingly similar phrase do not appear in your
+ license (except to note that your license differs from this License)
+ and (b) otherwise make it clear that Your version of the license
+ contains terms which differ from the Mozilla Public License and
+ Netscape Public License. (Filling in the name of the Initial
+ Developer, Original Code or Contributor in the notice described in
+ Exhibit A shall not of themselves be deemed to be modifications of
+ this License.)
+
+7. DISCLAIMER OF WARRANTY.
+
+ COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF
+ DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING.
+ THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE
+ IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT,
+ YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE
+ COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER
+ OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
+ ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
+
+8. TERMINATION.
+
+ 8.1. This License and the rights granted hereunder will terminate
+ automatically if You fail to comply with terms herein and fail to cure
+ such breach within 30 days of becoming aware of the breach. All
+ sublicenses to the Covered Code which are properly granted shall
+ survive any termination of this License. Provisions which, by their
+ nature, must remain in effect beyond the termination of this License
+ shall survive.
+
+ 8.2. If You initiate litigation by asserting a patent infringement
+ claim (excluding declatory judgment actions) against Initial Developer
+ or a Contributor (the Initial Developer or Contributor against whom
+ You file such action is referred to as "Participant") alleging that:
+
+ (a) such Participant's Contributor Version directly or indirectly
+ infringes any patent, then any and all rights granted by such
+ Participant to You under Sections 2.1 and/or 2.2 of this License
+ shall, upon 60 days notice from Participant terminate prospectively,
+ unless if within 60 days after receipt of notice You either: (i)
+ agree in writing to pay Participant a mutually agreeable reasonable
+ royalty for Your past and future use of Modifications made by such
+ Participant, or (ii) withdraw Your litigation claim with respect to
+ the Contributor Version against such Participant. If within 60 days
+ of notice, a reasonable royalty and payment arrangement are not
+ mutually agreed upon in writing by the parties or the litigation claim
+ is not withdrawn, the rights granted by Participant to You under
+ Sections 2.1 and/or 2.2 automatically terminate at the expiration of
+ the 60 day notice period specified above.
+
+ (b) any software, hardware, or device, other than such Participant's
+ Contributor Version, directly or indirectly infringes any patent, then
+ any rights granted to You by such Participant under Sections 2.1(b)
+ and 2.2(b) are revoked effective as of the date You first made, used,
+ sold, distributed, or had made, Modifications made by that
+ Participant.
+
+ 8.3. If You assert a patent infringement claim against Participant
+ alleging that such Participant's Contributor Version directly or
+ indirectly infringes any patent where such claim is resolved (such as
+ by license or settlement) prior to the initiation of patent
+ infringement litigation, then the reasonable value of the licenses
+ granted by such Participant under Sections 2.1 or 2.2 shall be taken
+ into account in determining the amount or value of any payment or
+ license.
+
+ 8.4. In the event of termination under Sections 8.1 or 8.2 above,
+ all end user license agreements (excluding distributors and resellers)
+ which have been validly granted by You or any distributor hereunder
+ prior to termination shall survive termination.
+
+9. LIMITATION OF LIABILITY.
+
+ UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
+ (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL
+ DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE,
+ OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR
+ ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY
+ CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL,
+ WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
+ COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
+ INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
+ LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY
+ RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW
+ PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
+ EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO
+ THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
+
+10. U.S. GOVERNMENT END USERS.
+
+ The Covered Code is a "commercial item," as that term is defined in
+ 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer
+ software" and "commercial computer software documentation," as such
+ terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48
+ C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995),
+ all U.S. Government End Users acquire Covered Code with only those
+ rights set forth herein.
+
+11. MISCELLANEOUS.
+
+ This License represents the complete agreement concerning subject
+ matter hereof. If any provision of this License is held to be
+ unenforceable, such provision shall be reformed only to the extent
+ necessary to make it enforceable. This License shall be governed by
+ California law provisions (except to the extent applicable law, if
+ any, provides otherwise), excluding its conflict-of-law provisions.
+ With respect to disputes in which at least one party is a citizen of,
+ or an entity chartered or registered to do business in the United
+ States of America, any litigation relating to this License shall be
+ subject to the jurisdiction of the Federal Courts of the Northern
+ District of California, with venue lying in Santa Clara County,
+ California, with the losing party responsible for costs, including
+ without limitation, court costs and reasonable attorneys' fees and
+ expenses. The application of the United Nations Convention on
+ Contracts for the International Sale of Goods is expressly excluded.
+ Any law or regulation which provides that the language of a contract
+ shall be construed against the drafter shall not apply to this
+ License.
+
+12. RESPONSIBILITY FOR CLAIMS.
+
+ As between Initial Developer and the Contributors, each party is
+ responsible for claims and damages arising, directly or indirectly,
+ out of its utilization of rights under this License and You agree to
+ work with Initial Developer and Contributors to distribute such
+ responsibility on an equitable basis. Nothing herein is intended or
+ shall be deemed to constitute any admission of liability.
+
+13. MULTIPLE-LICENSED CODE.
+
+ Initial Developer may designate portions of the Covered Code as
+ "Multiple-Licensed". "Multiple-Licensed" means that the Initial
+ Developer permits you to utilize portions of the Covered Code under
+ Your choice of the NPL or the alternative licenses, if any, specified
+ by the Initial Developer in the file described in Exhibit A.
+
+EXHIBIT A -Mozilla Public License.
+
+ ``The contents of this file are subject to the Mozilla Public License
+ Version 1.1 (the "License"); you may not use this file except in
+ compliance with the License. You may obtain a copy of the License at
+ http://www.mozilla.org/MPL/
+
+ Software distributed under the License is distributed on an "AS IS"
+ basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ License for the specific language governing rights and limitations
+ under the License.
+
+ The Original Code is the AllegroGraph Java Client interface.
+
+ The Original Code was written by Franz Inc.
+ Copyright (C) 2006 Franz Inc. All Rights Reserved.
+
+ [NOTE: The text of this Exhibit A may differ slightly from the text of
+ the notices in the Source Code files of the Original Code. You should
+ use the text of this Exhibit A rather than the text found in the
+ Original Code Source Code for Your Modifications.]
+
View
16 overview.htm
@@ -0,0 +1,16 @@
+<body>
+A Java API to the AllegroGraph triple store implementation.
+<p>
+We provide adapters for Sesame 2.x and Jena 2.5.
+<h3>Compatibility Note</h3>
+This Java API is similar to the AllegroGraph Java API in earlier releases (3.1.1 and older),
+but it is significantly different in many details. Existing Java programs will need to be
+modified substantially.
+<ul>
+<li>The primary public package is <code>com.franz.agbase</code>
+<li>New classes: ValueSetIterator, PrologSelectQuery
+<li>All the methods in AllegroGraph for making Prolog queries have been
+eliminated in favor of the PrologSelectQuery class.
+<li>The ValueObject class hierarchy is completely separate form Sesame classes.
+</ul>
+</body>
View
3  src/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Created-By: 1.5.0 (Sun Microsystems Inc.)
+
View
76 src/com/franz/ag/AllegroGraphException.java
@@ -0,0 +1,76 @@
+
+//***** BEGIN LICENSE BLOCK *****
+//Version: MPL 1.1
+//
+//The contents of this file are subject to the Mozilla Public License Version
+//1.1 (the "License"); you may not use this file except in compliance with
+//the License. You may obtain a copy of the License at
+//http://www.mozilla.org/MPL/
+//
+//Software distributed under the License is distributed on an "AS IS" basis,
+//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+//for the specific language governing rights and limitations under the
+//License.
+//
+//The Original Code is the AllegroGraph Java Client interface.
+//
+//The Original Code was written by Franz Inc.
+//Copyright (C) 2006 Franz Inc. All Rights Reserved.
+//
+//***** END LICENSE BLOCK *****
+
+/*
+ * Created on Jun 30, 2006
+ *
+ */
+package com.franz.ag;
+
+
+/**
+ * AllegroGraph exceptions.
+ *
+ * @author mm
+ *
+ */
+public class AllegroGraphException extends Exception {
+
+ //FIXME
+ // THIS CLASS CAN BE ELIMINATED by merging down to the subclass
+ // in com.franz.agbase when com.franz.ag package is discarded.
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -1311774930268277268L;
+
+ /**
+ *
+ */
+ public AllegroGraphException() {
+ super();
+ }
+
+ /**
+ * @param arg0
+ */
+ public AllegroGraphException(String arg0) {
+ super(arg0);
+
+ }
+
+ /**
+ * @param arg0
+ * @param arg1
+ */
+ public AllegroGraphException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+
+ /**
+ * @param arg0
+ */
+ public AllegroGraphException(Throwable arg0) {
+ super(arg0);
+ }
+
+}
View
190 src/com/franz/ag/NamespaceRegistry.java
@@ -0,0 +1,190 @@
+package com.franz.ag;
+
+import java.util.ArrayList;
+
+
+/**
+ * Instances of this class define mappings from prefixes or abbreviations to full
+ * URI fragments.
+ *
+ * @author mm
+ *
+ */
+public class NamespaceRegistry {
+
+ //FIXME
+ // THIS CLASS CAN BE ELIMINATED by merging down to the subclass
+ // in com.franz.agbase when com.franz.ag package is discarded.
+ //
+ // Since the constructors in package ag are public, we cannot ensure that
+ // all instances are agbase instances. Therefore, make sure that all declarations
+ // in agbase code refer to the ag.NamespaceRegistry declaration.
+
+
+ private ArrayList<Object> regs = new ArrayList<Object>();
+
+ /**
+ * Create a new empty NamaspaceRegistry instance.
+ *
+ */
+ public NamespaceRegistry () {}
+
+ /**
+ * Create a new NamaspaceRegistry instance containing the same definitions
+ * as another.
+ * @param ns the NamaspaceRegistry instance from which definitions are copied.
+ */
+ public NamespaceRegistry ( NamespaceRegistry ns ) {
+ register(ns);
+ }
+
+ /**
+ * Create a new NamaspaceRegistry instance containing the definitions
+ * specified in an array of strings.
+ * @param defs an array of alternating prefix and fragment strings.
+ */
+ public NamespaceRegistry ( String[] defs ) {
+ register(defs);
+ }
+
+
+
+
+ private static final String[] preDefs = new String[] {
+ "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+ "rdfs", "http://www.w3.org/2000/01/rdf-schema#",
+ "owl", "http://www.w3.org/2002/07/owl#"
+ };
+
+ /**
+ * A pre-defined namespace registry with three definitions:
+ * <pre>
+ * {
+ * "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+ * "rdfs", "http://www.w3.org/2000/01/rdf-schema#",
+ * "owl", "http://www.w3.org/2002/07/owl#"
+ * }
+ * </pre>
+ */
+ public static final NamespaceRegistry RDFandOwl = new com.franz.agbase.NamespaceRegistry(preDefs);
+
+
+// register(prefix, uri) - add entry to collection or rplace
+// existing entry
+// if uri is null, delete the entry
+// clear() - delete all entries
+// getPrefixes() -> array of prefixes
+// getURI(prefix) -> uri string
+
+ /**
+ * Add one prefix definition to this instance.
+ * @param prefix the prefix string
+ * @param uri the associated URI fragment
+ */
+ public void register ( String prefix, String uri ) {
+ boolean found = false;
+ find:
+ for (int i = 0; i < regs.size(); i=i+2) {
+ String e = (String) regs.get(i);
+ if ( e.equals(prefix) )
+ {
+ if ( uri==null )
+ {
+ regs.remove(i); regs.remove(i);
+ }
+ else
+ regs.set(i+1, uri);
+ found = true;
+ break find;
+ }
+ }
+ if ( !found )
+ {
+ regs.add(prefix); regs.add(uri);
+ }
+ }
+
+ /**
+ * Add all the definitions in some other instance to this one.
+ * @param moreDefs the source instance
+ */
+ public void register ( NamespaceRegistry moreDefs ) {
+ ArrayList<Object> defs = moreDefs.regs;
+ for (int i = 0; i < defs.size(); i=i+2) {
+ register((String)defs.get(i), (String)defs.get(i+1));
+ }
+ }
+
+ /**
+ * Add all the definitions in an array to this instance.
+ * @param moreDefs and alternating array of prefix strings and URI fragments
+ */
+ public void register ( String[] moreDefs ) {
+ for (int i = 0; i < moreDefs.length; i=i+2)
+ register(moreDefs[i], moreDefs[i+1]);
+ }
+
+
+ /**
+ * Query the URI fragment associated with some prefix.
+ * @param prefix the prefix string
+ * @return the URI fragment
+ * @throws UndefinedPrefix
+ */
+ public String getURI ( String prefix ) throws UndefinedPrefix {
+ for (int i = 0; i < regs.size(); i=i+2) {
+ String e = (String) regs.get(i);
+ if ( e.equals(prefix) )
+ return (String) regs.get(i+1);
+ }
+ throw new UndefinedPrefix();
+ }
+
+ public static class UndefinedPrefix extends AllegroGraphException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -3244320712290446205L;
+
+ }
+
+ /**
+ * Query the prefixes defined in this instance.
+ * @return an array of the prefixes.
+ */
+ public String[] getPrefixes () {
+ String[] prefixes = new String[(regs.size())/2];
+ for (int i = 0; i < prefixes.length; i++) {
+ prefixes[i] = (String) regs.get(2*i);
+ }
+ return prefixes;
+ }
+
+ /**
+ * Discard all the definitions in this instance.
+ *
+ */
+ public void clear () {
+ regs = new ArrayList<Object>();
+ }
+
+ /**
+ * Convert a namespace registry to an array of strings.
+ * @return an array of alternating abbreviation and URI strings
+ */
+ public String[] toArray () {
+ String[] out = new String[regs.size()];
+ for (int i = 0; i < out.length; i++) {
+ out[i] = (String) regs.get(i);
+ }
+ return out;
+ }
+
+ public com.franz.agbase.NamespaceRegistry promote () {
+ if ( this instanceof com.franz.agbase.NamespaceRegistry )
+ return (com.franz.agbase.NamespaceRegistry) this;
+ return new com.franz.agbase.NamespaceRegistry(this);
+ }
+
+}
View
32 src/com/franz/ag/UPI.java
@@ -0,0 +1,32 @@
+package com.franz.ag;
+
+/**
+ * This interface defines instances of Universal Part Identifiers.
+ * UPIs are used to denote nodes and literals in AllegroGraph.
+ * They are returned as values of queries or accessors, and may be used
+ * as arguments to queries and accessors. In general, UPI references
+ * are more efficient than string references.
+ *
+ * <p>
+ * UPIs are discussed in more detail in the AllegroGraph Introduction.
+ *
+ * @author mm
+ *
+ */
+public interface UPI {
+
+ //FIXME
+ //TODO - when ag package is discarded, this interface can be moved to
+ // the agbase package after the sub-interface is deleted.
+ // Any code outside these internal modules can already mention
+ // agbase.UPI and will work without change after the move.
+ //
+ // Any instance can be cast to agbase.UPI because the only constructor is in agbase.
+
+ public boolean equals(Object x);
+
+ public int hashCode();
+
+ public String toString();
+
+}
View
12 src/com/franz/ag/package.html
@@ -0,0 +1,12 @@
+<html>
+<head></head>
+<body>
+Java API to the AllegroGraph implementation.
+<p>
+
+The classes and interfaces in this package provide access
+to the native features and capabilites of AllegroGraph.
+
+
+</body>
+</html>
View
70 src/com/franz/ag/repository/AGBindingSet.java
@@ -0,0 +1,70 @@
+package com.franz.ag.repository;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.openrdf.model.Value;
+import org.openrdf.query.Binding;
+import org.openrdf.query.BindingSet;
+import org.openrdf.query.impl.BindingImpl;
+
+import com.franz.agbase.ValueNode;
+import com.franz.agbase.ValueObject;
+import com.franz.agbase.ValueSetIterator;
+import com.franz.agsail.util.AGSInternal;
+
+public class AGBindingSet implements BindingSet {
+
+ AGSInternal ags = null;
+ ValueObject[] vals = null;
+ Map<String,Integer> nameIndex = new HashMap<String,Integer>();
+
+ AGBindingSet(AGSInternal ags, ValueSetIterator iter) {
+ this.ags = ags;
+ String[] names = iter.getNames();
+ for (int i = 0; i < names.length; i++) {
+ nameIndex.put(names[i], i);
+ }
+ vals = iter.get();
+ }
+
+
+ // BindingSet API
+
+ public Binding getBinding(String bindingName) {
+ return new BindingImpl(bindingName,getValue(bindingName));
+ }
+
+ public Set<String> getBindingNames() {
+ return nameIndex.keySet();
+ }
+
+ public Value getValue(String bindingName) {
+ // TODO Check that this cast is safe
+ return ags.coerceToSailValue((ValueNode)vals[nameIndex.get(bindingName)]);
+ }
+
+ public boolean hasBinding(String bindingName) {
+ return nameIndex.containsKey(bindingName);
+ }
+
+ public Iterator<Binding> iterator() {
+ Set<Binding> bindings = new HashSet<Binding>();
+ Set<String> bn = getBindingNames();
+ for (String name: bn) {
+// System.out.println(" name=" + name);
+ Value bv = getValue(name);
+ if ( bv!=null) // Interface Binding requires value to be non-null.
+ bindings.add(new BindingImpl(name, bv));
+ }
+ return bindings.iterator();
+ }
+
+ public int size() {
+ return nameIndex.size();
+ }
+
+}
View
26 src/com/franz/ag/repository/AGBooleanQuery.java
@@ -0,0 +1,26 @@
+package com.franz.ag.repository;
+
+import org.openrdf.query.BooleanQuery;
+import org.openrdf.query.QueryEvaluationException;
+
+import com.franz.agbase.AllegroGraphException;
+import com.franz.agbase.SPARQLQuery;
+import com.franz.agsail.util.AGSInternal;
+
+public class AGBooleanQuery extends AGQuery implements BooleanQuery {
+
+ public AGBooleanQuery(AGSInternal ags, SPARQLQuery sq) {
+ super(ags,sq);
+ }
+
+ public boolean evaluate() throws QueryEvaluationException {
+ boolean result;
+ try {
+ result = sq.ask();
+ } catch (AllegroGraphException e) {
+ throw new QueryEvaluationException(e);
+ }
+ return result;
+ }
+
+}
View
31 src/com/franz/ag/repository/AGCloseableIteration.java
@@ -0,0 +1,31 @@
+package com.franz.ag.repository;
+
+import info.aduna.iteration.ExceptionConvertingIteration;
+import info.aduna.iteration.Iteration;
+
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.sail.SailException;
+
+public class AGCloseableIteration<E> extends
+ ExceptionConvertingIteration<E, RepositoryException> {
+
+ public AGCloseableIteration(
+ Iteration<? extends E, ? extends SailException> iter) {
+ super(iter);
+ }
+
+ @Override
+ protected RepositoryException convert(Exception e) {
+ if (e instanceof SailException) {
+ return new RepositoryException(e);
+ } else if (e instanceof RuntimeException) {
+ throw (RuntimeException) e;
+ } else if (e == null) {
+ throw new IllegalArgumentException("e must not be null");
+ } else {
+ throw new IllegalArgumentException("Unexpected exception type: "
+ + e.getClass());
+ }
+ }
+}
+
View
48 src/com/franz/ag/repository/AGGraphQuery.java
@@ -0,0 +1,48 @@
+package com.franz.ag.repository;
+
+import org.openrdf.query.GraphQuery;
+import org.openrdf.query.GraphQueryResult;
+import org.openrdf.query.QueryEvaluationException;
+import org.openrdf.rio.RDFHandler;
+import org.openrdf.rio.RDFHandlerException;
+
+import com.franz.agbase.AllegroGraphException;
+import com.franz.agbase.SPARQLQuery;
+import com.franz.agbase.TriplesIterator;
+import com.franz.agsail.AGSailCursor;
+import com.franz.agsail.util.AGSInternal;
+
+public class AGGraphQuery extends AGQuery implements GraphQuery {
+
+ public AGGraphQuery(AGSInternal ags, SPARQLQuery sq) {
+ super(ags,sq);
+ }
+
+ public GraphQueryResult evaluate() throws QueryEvaluationException {
+ TriplesIterator iter;
+ try {
+ iter = sq.construct();
+ } catch (AllegroGraphException e) {
+ throw new QueryEvaluationException(e);
+ }
+ return new AGGraphQueryResult(ags.coerceToSailCursor(iter));
+ }
+
+ public void evaluate(RDFHandler handler)
+ throws QueryEvaluationException, RDFHandlerException {
+ // TODO flesh out the spec for this (no test cases use it).
+ TriplesIterator iter;
+ try {
+ iter = sq.construct();
+ handler.startRDF();
+ AGSailCursor c = ags.coerceToSailCursor(iter);
+ while (c.hasNext()) {
+ handler.handleStatement(c.getNext());
+ }
+ handler.endRDF();
+ } catch (AllegroGraphException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+}
View
40 src/com/franz/ag/repository/AGGraphQueryResult.java
@@ -0,0 +1,40 @@
+package com.franz.ag.repository;
+
+import java.util.Map;
+
+import org.openrdf.model.Statement;
+import org.openrdf.query.GraphQueryResult;
+import org.openrdf.query.QueryEvaluationException;
+
+import com.franz.agsail.AGSailCursor;
+
+public class AGGraphQueryResult implements GraphQueryResult {
+
+ AGSailCursor iter = null;
+
+ AGGraphQueryResult(AGSailCursor iter) {
+ this.iter = iter;
+ }
+
+ public Map<String, String> getNamespaces() {
+ // TODO flesh out the spec for this
+ return null;
+ }
+
+ public void close() throws QueryEvaluationException {
+ iter.close();
+ }
+
+ public boolean hasNext() throws QueryEvaluationException {
+ return iter.hasNext();
+ }
+
+ public Statement next() throws QueryEvaluationException {
+ return iter.next();
+ }
+
+ public void remove() throws QueryEvaluationException {
+ iter.remove();
+ }
+
+}
View
114 src/com/franz/ag/repository/AGQuery.java
@@ -0,0 +1,114 @@
+package com.franz.ag.repository;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.model.impl.URIImpl;
+import org.openrdf.query.Binding;
+import org.openrdf.query.BindingSet;
+import org.openrdf.query.Dataset;
+import org.openrdf.query.Query;
+import org.openrdf.query.impl.DatasetImpl;
+import org.openrdf.query.impl.MapBindingSet;
+
+import com.franz.agbase.SPARQLQuery;
+import com.franz.agsail.util.AGSInternal;
+
+public class AGQuery implements Query {
+
+ AGSInternal ags = null;
+ SPARQLQuery sq = null;
+
+ protected MapBindingSet bindings = new MapBindingSet();
+ protected int maxQueryTime = 0;
+
+ public AGQuery(AGSInternal ags, SPARQLQuery sq) {
+ this.ags = ags;
+ this.sq = sq;
+ // TODO: only do this if engine isn't already set, when AG2 :with-variables is fixed
+ sq.setEngine(SPARQLQuery.ENGINE.ALGEBRA);
+ }
+
+ public SPARQLQuery getSPARQLQuery() {
+ return sq;
+ }
+
+ // Query API below
+
+ public BindingSet getBindings() {
+ return bindings;
+ }
+
+ public Dataset getDataset() {
+ DatasetImpl dataset = new DatasetImpl();
+ String[] defaultGraphURIs = sq.getFrom();
+ for (String uristr : defaultGraphURIs) {
+ dataset.addDefaultGraph(new URIImpl(uristr));
+ }
+ String[] namedGraphURIs = sq.getFromNamed();
+ for (String uristr : namedGraphURIs) {
+ dataset.addNamedGraph(new URIImpl(uristr));
+ }
+ return dataset;
+ }
+
+ public boolean getIncludeInferred() {
+ return sq.isIncludeInferred();
+ }
+
+ public int getMaxQueryTime() {
+ return maxQueryTime;
+ }
+
+ public void removeBinding(String name) {
+ bindings.removeBinding(name);
+ }
+
+ public void setBinding(String name, Value value) {
+ bindings.addBinding(name, value);
+ Iterator<Binding> it = bindings.iterator();
+ Object[] varvals = new Object[2*bindings.size()];
+ for (int i=0; it.hasNext(); i+=2) {
+ Binding b = it.next();
+ varvals[i] = b.getName();
+ varvals[i+1] = ags.coerceToAGPart(b.getValue());
+ }
+ // FIXME: needs bug18180 fixed
+ sq.setWithVariables(ags.getDirectInstance(), varvals);
+ }
+
+ public void setDataset(Dataset dataset) {
+ // specify default graphs
+ Set<URI> defaultGraphs = dataset.getDefaultGraphs();
+ String[] defaultURIStrings = new String[defaultGraphs.size()];
+ int i = 0;
+ for (Iterator<URI> iterator = defaultGraphs.iterator(); iterator.hasNext();i++) {
+ URI uri = iterator.next();
+ defaultURIStrings[i] = uri.stringValue();
+ }
+ // FIXME: needs bug18181 fixed
+ sq.setFrom(defaultURIStrings);
+
+ // specify named graphs
+ Set<URI> namedGraphs = dataset.getNamedGraphs();
+ String[] namedURIStrings = new String[namedGraphs.size()];
+ i = 0;
+ for (Iterator<URI> iterator = namedGraphs.iterator(); iterator.hasNext();i++) {
+ URI uri = iterator.next();
+ namedURIStrings[i] = uri.stringValue();
+ }
+ sq.setFromNamed(namedURIStrings);
+ }
+
+ public void setIncludeInferred(boolean includeInferred) {
+ sq.setIncludeInferred(includeInferred);
+ }
+
+ public void setMaxQueryTime(int maxQueryTime) {
+ // TODO: can we support this in SPARQLQuery, rfe8384?
+ this.maxQueryTime = maxQueryTime;
+ }
+
+}
View
171 src/com/franz/ag/repository/AGRepository.java
@@ -0,0 +1,171 @@
+package com.franz.ag.repository;
+
+import java.io.File;
+
+import org.openrdf.model.ValueFactory;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.sail.SailException;
+
+import com.franz.agbase.AllegroGraph;
+import com.franz.agsail.util.AGSInternal;
+import com.knowledgereefsystems.agsail.AllegroSail;
+
+/**
+ * An implementation of the Repository interface that stores triples in an AllegroGraph
+ * triple store. The Java application communicates with the AllegroGraph server
+ * through a socket.
+ * <p>
+ *
+ * @author mm
+ *
+ */
+public class AGRepository implements Repository {
+
+ /**
+ * The name of this class identifies the version of the AllegroGraph
+ * Java implementation.
+ * This name is also visible in the list of members in a jar file
+ * when it is inspected with Emacs or WinZip.
+ */
+ public static class V3_2Jan27 {}
+
+ /**
+ * Query the current AGRepository version.
+ * @return a version string.
+ */
+ @SuppressWarnings("unchecked")
+ public static String version () {
+ Class thisClass = AGRepository.class;
+ Class[] mems = thisClass.getDeclaredClasses();
+ String home = thisClass.getName();
+ String s = "";
+ home = home + "$V";
+ for (int i = 0; i < mems.length; i++) {
+ String sub = mems[i].getName();
+ if ( sub.startsWith(home) )
+ s = sub;
+ }
+ return s; }
+
+
+ AllegroGraph store = null;
+ AGSInternal ags = null;
+ AllegroSail sail = null;
+
+ /**
+ * Create a new Repository instance to access an AllegroGraph triple store.
+ * @param ts An {@link AllegroGraph} instance created by the application.
+ * The application code is responsible for closing the store instance and
+ * disconnecting from the server.
+ */
+ public AGRepository(AllegroGraph ts) {
+ store = ts;
+ sail = new AllegroSail(ts);
+ }
+
+ /**
+ * Specify whether indexing should be done at each commit.
+ * @param roc When true, index the triples added up to the commit call.
+ */
+ public void setReindexOnCommit ( boolean roc ) {
+ sail.setReindexOnCommit(roc);
+ }
+
+ /**
+ * Control the indexing strategy of this access to the store.
+ * @param roc When true, reindex the entire store at each commit.
+ * Otherwise, index only the new triples.
+ */
+ public void setIndexAllOnCommit ( boolean roc ) {
+ sail.setIndexAllOnCommit(roc);
+ }
+
+ /**
+ * Control the indexing mode of this access to the store.
+ * @param bi When true, index triples asynchronously.
+ */
+ public void setBackgroundIndexing ( boolean bi ) {
+ sail.setBackgroundIndexing(bi);
+ }
+
+ public AllegroGraph getAllegroGraph() {
+ return store;
+ }
+
+ // Repository API below
+
+ private AGRepositoryConnection repoConn = null;
+
+ /**
+ * Opens a connection to this repository that can be used for querying and
+ * updating the contents of the repository.
+ * Created connections need to be closed to make sure that any resources they
+ * keep hold of are released.
+ * The best way to do this is to use a try-finally-block as follows:
+ * <pre>
+
+ RepositoryConnection con = repository.getConnection();
+ try {
+ // perform operations on the connection
+ }
+ finally {
+ con.close();
+ }
+ </pre>
+ * @return A connection that allows operations on this repository.
+ * Only <strong>one</strong> connection instance is created for each Repository
+ * instance.
+ * @throws RepositoryException - If something went wrong during the creation of the Connection.
+ */
+ public RepositoryConnection getConnection() throws RepositoryException {
+ if ( repoConn==null )
+ repoConn = new AGRepositoryConnection(this);
+ return repoConn;
+ }
+
+ public File getDataDir() {
+ return sail.getDataDir();
+ }
+
+ public ValueFactory getValueFactory() {
+ return sail.getValueFactory();
+ }
+
+ public void initialize() throws RepositoryException {
+ try {
+ sail.initialize();
+ ags = sail.getAGSInternal();
+ } catch (SailException e) {
+ throw new RepositoryException(e.getLocalizedMessage());
+ }
+ }
+
+ public boolean isWritable() throws RepositoryException {
+ try {
+ return sail.isWritable();
+ } catch (SailException e) {
+ throw new RepositoryException(e.getLocalizedMessage());
+ }
+ }
+
+ public void setDataDir(File arg0) {
+ sail.setDataDir(arg0);
+ }
+
+ public void shutDown() throws RepositoryException {
+ try {
+ if ( repoConn!=null )
+ {
+ repoConn.close();
+ repoConn = null;
+ }
+ sail.shutDown();
+ sail = null;
+ } catch (SailException e) {
+ throw new RepositoryException(e.getLocalizedMessage());
+ }
+ }
+
+}
View
565 src/com/franz/ag/repository/AGRepositoryConnection.java
@@ -0,0 +1,565 @@
+package com.franz.ag.repository;
+
+import info.aduna.iteration.Iteration;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
+import java.util.Iterator;
+
+import org.openrdf.model.Namespace;
+import org.openrdf.model.Resource;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.query.BooleanQuery;
+import org.openrdf.query.GraphQuery;
+import org.openrdf.query.MalformedQueryException;
+import org.openrdf.query.Query;
+import org.openrdf.query.QueryLanguage;
+import org.openrdf.query.TupleQuery;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.RepositoryResult;
+import org.openrdf.rio.RDFFormat;
+import org.openrdf.rio.RDFHandler;
+import org.openrdf.rio.RDFHandlerException;
+import org.openrdf.rio.RDFParseException;
+import org.openrdf.rio.UnsupportedRDFormatException;
+import org.openrdf.sail.SailException;
+
+import com.franz.agbase.AllegroGraphException;
+import com.franz.agbase.SPARQLQuery;
+import com.knowledgereefsystems.agsail.AllegroSail;
+import com.knowledgereefsystems.agsail.AllegroSailConnection;
+
+public class AGRepositoryConnection implements RepositoryConnection {
+
+ boolean isOpen = false;
+ AGRepository repository = null;
+ AllegroSail sail = null;
+ AllegroSailConnection sailconn = null;
+ int batchSize = 1000;
+
+ AGRepositoryConnection(AGRepository repository) throws RepositoryException {
+ // let's assume an initialized repository
+ this.repository = repository;
+ sail = repository.sail;
+ try {
+ sailconn = sail.getConnection();
+ isOpen = true;
+ } catch (SailException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ // RepositoryConnection API below
+
+ public void add(Statement st, Resource... contexts) throws RepositoryException {
+ add(st.getSubject(),st.getPredicate(),st.getObject(), contexts);
+ }
+
+ public void add(Iterable<? extends Statement> statements,
+ Resource... contexts) throws RepositoryException {
+ // TODO: review for efficiency and intended use
+ // TODO: can we stream this over instead?
+ try {
+ Statement[] st = new Statement[batchSize];
+ Iterator<? extends Statement> iter = statements.iterator();
+ for (int i = 0; iter.hasNext();) {
+ st[i] = iter.next();
+ i++;
+ if (batchSize == i || !iter.hasNext()) {
+ // set up a batch of at most batchSize
+ // i of the statements are set
+ Object[] s = new Object[i];
+ Object[] p = new Object[i];
+ Object[] o = new Object[i];
+ Object[] c = new Object[i];
+ for (int j = 0; j < i; j++) {
+ s[j] = repository.ags.coerceToAGPart(st[j].getSubject());
+ p[j] = repository.ags.coerceToAGPart(st[j].getPredicate());
+ o[j] = repository.ags.coerceToAGPart(st[j].getObject());
+ c[j] = repository.ags.coerceToAGPart(st[j].getContext());
+ if (contexts.length == 0) {
+ // send 1 batch over using the context specified
+ // in each statement
+ repository.store.addStatements(s, p, o, c);
+ } else {
+ // send 1 batch over for each of the contexts
+ // ignoring the context part of each statement
+ for (Resource ctx : contexts) {
+ repository.store.addStatements(s, p, o,
+ repository.ags.coerceToAGPart(ctx));
+ }
+ }
+ i = 0;
+ sailconn.setUncommittedInsertions(true);
+ }
+ }
+ }
+ } catch (AllegroGraphException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public <E extends Exception> void add(
+ Iteration<? extends Statement, E> statementIter,
+ Resource... contexts) throws RepositoryException, E {
+ // TODO: review for efficiency and intended use
+ // TODO: can we stream this over instead?
+ // TODO: refactor this to share code with the above method
+ try {
+ Statement[] st = new Statement[batchSize];
+ for (int i = 0; statementIter.hasNext();) {
+ st[i] = statementIter.next();
+ i++;
+ if (batchSize == i || !statementIter.hasNext()) {
+ // set up a batch of at most batchSize
+ // i of the statements are set
+ Object[] s = new Object[i];
+ Object[] p = new Object[i];
+ Object[] o = new Object[i];
+ Object[] c = new Object[i];
+ for (int j = 0; j < i; j++) {
+ s[j] = repository.ags.coerceToAGPart(st[j].getSubject());
+ p[j] = repository.ags.coerceToAGPart(st[j].getPredicate());
+ o[j] = repository.ags.coerceToAGPart(st[j].getObject());
+ c[j] = repository.ags.coerceToAGPart(st[j].getContext());
+ if (contexts.length == 0) {
+ // send 1 batch over using the context specified
+ // in each statement
+ repository.store.addStatements(s, p, o, c);
+ } else {
+ // send 1 batch over for each of the contexts
+ // ignoring the context part of each statement
+ for (Resource ctx : contexts) {
+ repository.store.addStatements(s, p, o,
+ repository.ags.coerceToAGPart(ctx));
+ }
+ }
+ i = 0;
+ sailconn.setUncommittedInsertions(true);
+ }
+ }
+ }
+ } catch (AllegroGraphException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public void add(InputStream in, String baseURI, RDFFormat dataFormat,
+ Resource... contexts) throws IOException, RDFParseException,
+ RepositoryException {
+ // TODO: can we stream this directly instead?
+ // FIXME: assume UTF-8 encoding
+ add(new InputStreamReader(in, "UTF-8"), baseURI, dataFormat, contexts);
+ }
+
+ public void add(Reader reader, String baseURI, RDFFormat dataFormat,
+ Resource... contexts) throws IOException, RDFParseException,
+ RepositoryException {
+ if (dataFormat!=RDFFormat.NTRIPLES && dataFormat!=RDFFormat.RDFXML) {
+ throw new UnsupportedRDFormatException("Only RDFFormat.NTRIPLES and RDFFormat.RDFXML are supported)");
+ }
+ BufferedReader br = new BufferedReader(reader);
+ StringBuffer sb = new StringBuffer();
+ String line;
+ while ( (line = br.readLine()) != null) {
+ sb.append(line);
+ }
+ try {
+ if (dataFormat==RDFFormat.NTRIPLES) {
+ if (0 == contexts.length) {
+ // TODO: need a baseURI arg here?
+ repository.store.parseNTriples(sb.toString());
+ } else {
+ for (Resource c : contexts) {
+ // TODO: need a baseURI arg here?
+ repository.store.parseNTriples(sb.toString(), repository.ags.coerceToAGPart(c));
+ }
+ }
+ } else if (dataFormat == RDFFormat.RDFXML) {
+ if (0 == contexts.length) {
+ repository.store.parseRDFXML(sb.toString(), "", baseURI);
+ } else {
+ for (Resource c : contexts) {
+ repository.store.parseRDFXML(sb.toString(), repository.ags.coerceToAGPart(c), baseURI);
+ }
+ }
+ }
+ //} catch (IOException e) {
+ // FIXME: AllegroGraph should throw IOException
+ // throw new IOException(e);
+ } catch (IllegalArgumentException e) {
+ // FIXME: AllegroGraph should throw a proper parse exception
+ throw new RDFParseException(e);
+ } catch (AllegroGraphException e) {
+ throw new RepositoryException(e);
+ }
+ sailconn.setUncommittedInsertions(true);
+ }
+
+ public void add(URL url, String baseURI, RDFFormat dataFormat,
+ Resource... contexts) throws IOException, RDFParseException,
+ RepositoryException {
+ if (dataFormat!=RDFFormat.NTRIPLES && dataFormat!=RDFFormat.RDFXML) {
+ throw new UnsupportedRDFormatException("Only RDFFormat.NTRIPLES and RDFFormat.RDFXML are supported)");
+ }
+ String urlstring = url.toString();
+ try {
+ if (dataFormat == RDFFormat.NTRIPLES) {
+ if (0 == contexts.length) {
+ // TODO: need a baseURI arg here?
+ repository.store.loadNTriples(urlstring);
+ } else {
+ for (Resource c : contexts) {
+ // TODO: need a baseURI arg here?
+ repository.store.loadNTriples(urlstring, repository.ags
+ .coerceToAGPart(c));
+ }
+ }
+ } else if (dataFormat == RDFFormat.RDFXML) {
+ if (0 == contexts.length) {
+ repository.store.loadRDFXML(urlstring, "", baseURI);
+ } else {
+ for (Resource c : contexts) {
+ repository.store.loadRDFXML(urlstring, repository.ags
+ .coerceToAGPart(c), baseURI);
+ }
+ }
+ }
+ //} catch (IOException e) {
+ // FIXME: AllegroGraph should throw IOException
+ // throw new IOException(e);
+ } catch (IllegalArgumentException e) {
+ // TODO: check that loadRDFXML throws IllegalArg for parse error
+ // FIXME: AllegroGraph should throw a proper parse exception
+ throw new RDFParseException(e);
+ } catch (AllegroGraphException e) {
+ throw new RepositoryException(e);
+ }
+ sailconn.setUncommittedInsertions(true);
+ }
+
+ public void add(File file, String baseURI, RDFFormat dataFormat,
+ Resource... contexts) throws IOException, RDFParseException,
+ RepositoryException {
+ FileInputStream s = new FileInputStream(file);
+ try {
+ add(s, baseURI, dataFormat, contexts);
+ } finally {
+ s.close();
+ }
+ }
+
+ public void add(Resource subject, URI predicate, Value object, Resource... contexts) throws RepositoryException {
+ try {
+ sailconn.addStatement(subject, predicate, object, contexts);
+ } catch (SailException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public void clear(Resource... contexts) throws RepositoryException {
+ try {
+ sailconn.clear(contexts);
+ } catch (SailException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public void clearNamespaces() throws RepositoryException {
+ try {
+ sailconn.clearNamespaces();
+ } catch (SailException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public void close() throws RepositoryException {
+ try {
+ sailconn.close();
+ isOpen = false;
+ } catch (SailException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public void commit() throws RepositoryException {
+ try {
+ sailconn.commit();
+ } catch (SailException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public void export(RDFHandler handler, Resource... contexts)
+ throws RepositoryException, RDFHandlerException {
+ exportStatements(null,null,null,false,handler,contexts);
+ }
+
+ public void exportStatements(Resource subj, URI pred, Value obj,
+ boolean includeInferred, RDFHandler handler, Resource... contexts)
+ throws RepositoryException, RDFHandlerException {
+ // TODO: need to call handler.handleNamespace and handler.handleComment here?
+ RepositoryResult<Statement> results = getStatements(subj,pred,obj,includeInferred,contexts);
+ handler.startRDF();
+ while (results.hasNext()) {
+ handler.handleStatement(results.next());
+ }
+ handler.endRDF();
+ }
+
+ public RepositoryResult<Resource> getContextIDs()
+ throws RepositoryException {
+ RepositoryResult<Resource> result;
+ try {
+ result = new RepositoryResult<Resource>(new AGCloseableIteration<Resource>(sailconn.getContextIDs()));
+
+ } catch (SailException e) {
+ throw new RepositoryException(e);
+ }
+ return result;
+ }
+
+ public String getNamespace(String prefix) throws RepositoryException {
+ String ns = null;
+ try {
+ ns = sailconn.getNamespace(prefix);
+ } catch (SailException e) {
+ throw new RepositoryException(e);
+ }
+ return ns;
+ }
+
+ public RepositoryResult<Namespace> getNamespaces()
+ throws RepositoryException {
+ RepositoryResult<Namespace> result;
+ try {
+ result = new RepositoryResult<Namespace>(new AGCloseableIteration<Namespace>(sailconn.getNamespaces()));
+
+ } catch (SailException e) {
+ throw new RepositoryException(e);
+ }
+ return result;
+ }
+
+ public Repository getRepository() {
+ return repository;
+ }
+
+ public RepositoryResult<Statement> getStatements(Resource subj, URI pred,
+ Value obj, boolean includeInferred, Resource... contexts)
+ throws RepositoryException {
+ RepositoryResult<Statement> result;
+ try {
+ result = new RepositoryResult<Statement>(new AGCloseableIteration<Statement>(sailconn.getStatements(subj, pred, obj, includeInferred, contexts)));
+ } catch (SailException e) {
+ throw new RepositoryException(e);
+ }
+ return result;
+ }
+
+ public boolean hasStatement(Statement st, boolean includeInferred,
+ Resource... contexts) throws RepositoryException {
+ return hasStatement(st.getSubject(),st.getPredicate(),st.getObject(),includeInferred, contexts);
+ }
+
+ public boolean hasStatement(Resource subj, URI pred, Value obj,
+ boolean includeInferred, Resource... contexts)
+ throws RepositoryException {
+ boolean found = false;
+ try {
+ if (contexts.length == 0) {
+ found = repository.store.hasStatement(includeInferred,
+ repository.ags.coerceToAGPart(subj), repository.ags
+ .coerceToAGPart(pred), repository.ags
+ .coerceToAGPart(obj), null); // looks in all contexts in the store
+ } else {
+ for (int i = 0; i < contexts.length && !found; i++) {
+ if (contexts[i] == null) {
+ // looks only in the null context
+ // coerceToAGPart(null) returns null, so this case needs
+ // to be addressed separately.
+ found = repository.store.hasStatement(includeInferred,
+ repository.ags.coerceToAGPart(subj),
+ repository.ags.coerceToAGPart(pred),
+ repository.ags.coerceToAGPart(obj));
+ } else {
+ found = repository.store.hasStatement(includeInferred,
+ repository.ags.coerceToAGPart(subj),
+ repository.ags.coerceToAGPart(pred),
+ repository.ags.coerceToAGPart(obj),
+ repository.ags.coerceToAGPart(contexts[i]));
+ }
+ }
+ }
+ } catch (AllegroGraphException e) {
+ throw new RepositoryException(e);
+ }
+ return found;
+ }
+
+ public boolean isAutoCommit() throws RepositoryException {
+ return true;
+ }
+
+ public boolean isEmpty() throws RepositoryException {
+ return (size()==0);
+ }
+
+ public boolean isOpen() throws RepositoryException {
+ return isOpen;
+ }
+
+ public BooleanQuery prepareBooleanQuery(QueryLanguage ql, String query)
+ throws RepositoryException, MalformedQueryException {
+ return prepareBooleanQuery(ql, query, null);
+ }
+
+ public BooleanQuery prepareBooleanQuery(QueryLanguage ql, String query,
+ String baseURI) throws RepositoryException, MalformedQueryException {
+ if (ql != QueryLanguage.SPARQL) {
+ throw new MalformedQueryException("Only SPARQL queries are supported.");
+ }
+ SPARQLQuery sq = new SPARQLQuery();
+ sq.setTripleStore(repository.store);
+ sq.setQuery(query);
+ sq.setIncludeInferred(true); // The default in Sesame is true.
+ if (baseURI!=null) sq.setDefaultBase(baseURI);
+
+ return new AGBooleanQuery(repository.ags, sq);
+ }
+
+ public GraphQuery prepareGraphQuery(QueryLanguage ql, String query)
+ throws RepositoryException, MalformedQueryException {
+ return prepareGraphQuery(ql, query, null);
+ }
+
+ public GraphQuery prepareGraphQuery(QueryLanguage ql, String query,
+ String baseURI) throws RepositoryException, MalformedQueryException {
+ if (ql != QueryLanguage.SPARQL) {
+ throw new MalformedQueryException("Only SPARQL queries are supported.");
+ }
+ SPARQLQuery sq = new SPARQLQuery();
+ sq.setTripleStore(repository.store);
+ sq.setQuery(query);
+ sq.setIncludeInferred(true); // The default in Sesame is true.
+ if (baseURI!=null) sq.setDefaultBase(baseURI);
+
+ return new AGGraphQuery(repository.ags,sq);
+ }
+
+ public Query prepareQuery(QueryLanguage ql, String query)
+ throws RepositoryException, MalformedQueryException {
+ return prepareQuery(ql, query, null);
+ }
+
+ public Query prepareQuery(QueryLanguage ql, String query, String baseURI)
+ throws RepositoryException, MalformedQueryException {
+ // TODO review the need for this optional method
+ return null;
+ }
+
+ public TupleQuery prepareTupleQuery(QueryLanguage ql, String query)
+ throws RepositoryException, MalformedQueryException {
+ return prepareTupleQuery(ql, query, null);
+ }
+
+ public TupleQuery prepareTupleQuery(QueryLanguage ql, String query,
+ String baseURI) throws RepositoryException, MalformedQueryException {
+ if (ql != QueryLanguage.SPARQL) {
+ throw new MalformedQueryException("Only SPARQL queries are supported.");
+ }
+ SPARQLQuery sq = new SPARQLQuery();
+ sq.setTripleStore(repository.store);
+ sq.setQuery(query);
+ sq.setIncludeInferred(true); // The default in Sesame is true.
+ if (baseURI!=null) sq.setDefaultBase(baseURI);
+
+ return new AGTupleQuery(repository.ags,sq);
+ }
+
+ public void remove(Statement st, Resource... contexts)
+ throws RepositoryException {
+ remove(st.getSubject(),st.getPredicate(),st.getObject(),contexts);
+ }
+
+ public void remove(Iterable<? extends Statement> statements,
+ Resource... contexts) throws RepositoryException {
+ // TODO: review for efficiency and intended use
+ Iterator<? extends Statement> iter = statements.iterator();
+ while(iter.hasNext()) {
+ remove(iter.next(),contexts);
+ }
+ }
+
+ public <E extends Exception> void remove(
+ Iteration<? extends Statement, E> statementIter,
+ Resource... contexts) throws RepositoryException, E {
+ // TODO: review for efficiency and intended use
+ while(statementIter.hasNext()) {
+ remove(statementIter.next(),contexts);
+ }
+ }
+
+ public void remove(Resource subject, URI predicate, Value object, Resource... contexts) throws RepositoryException {
+ try {
+ sailconn.removeStatements(subject, predicate, object, contexts);
+ } catch (SailException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public void removeNamespace(String prefix) throws RepositoryException {
+ try {
+ sailconn.removeNamespace(prefix);
+ } catch (SailException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public void rollback() throws RepositoryException {
+ try {
+ sailconn.rollback();
+ } catch (SailException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public void setAutoCommit(boolean autoCommit) throws RepositoryException {
+ if (!autoCommit) {
+ throw new RepositoryException(new UnsupportedOperationException());
+ }
+ }
+
+ public void setNamespace(String prefix, String name) throws RepositoryException {
+ try {
+ sailconn.setNamespace(prefix, name);
+ } catch (SailException e) {
+ throw new RepositoryException(e);
+ }
+
+ }
+
+ public long size(Resource... contexts) throws RepositoryException {
+ try {
+ return sailconn.size(contexts);
+ } catch (SailException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public ValueFactory getValueFactory() {
+ return sail.getValueFactory();
+ }
+
+}
View
40 src/com/franz/ag/repository/AGTupleQuery.java
@@ -0,0 +1,40 @@
+package com.franz.ag.repository;
+
+import org.openrdf.query.QueryEvaluationException;
+import org.openrdf.query.TupleQuery;
+import org.openrdf.query.TupleQueryResult;
+import org.openrdf.query.TupleQueryResultHandler;
+import org.openrdf.query.TupleQueryResultHandlerException;
+
+import com.franz.agbase.AllegroGraphException;
+import com.franz.agbase.SPARQLQuery;
+import com.franz.agbase.ValueSetIterator;
+import com.franz.agsail.util.AGSInternal;
+
+public class AGTupleQuery extends AGQuery implements TupleQuery {
+
+ public AGTupleQuery(AGSInternal ags, SPARQLQuery sq) {
+ super(ags,sq);
+ }
+
+ public TupleQueryResult evaluate() throws QueryEvaluationException {
+ ValueSetIterator vsi;
+ try {
+ vsi = sq.select();
+ } catch (AllegroGraphException e) {
+ throw new QueryEvaluationException(e);
+ }
+ return new AGTupleQueryResult(ags, vsi);
+ }
+
+ public void evaluate(TupleQueryResultHandler handler)
+ throws QueryEvaluationException, TupleQueryResultHandlerException {
+ TupleQueryResult result = evaluate();
+ handler.startQueryResult(result.getBindingNames());
+ while (result.hasNext()) {
+ handler.handleSolution(result.next());
+ }
+ handler.endQueryResult();
+ }
+
+}
View
44 src/com/franz/ag/repository/AGTupleQueryResult.java
@@ -0,0 +1,44 @@
+package com.franz.ag.repository;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.openrdf.query.BindingSet;
+import org.openrdf.query.QueryEvaluationException;
+import org.openrdf.query.TupleQueryResult;
+
+import com.franz.agbase.ValueSetIterator;
+import com.franz.agsail.util.AGSInternal;
+
+public class AGTupleQueryResult implements TupleQueryResult {
+
+ AGSInternal ags = null;
+ ValueSetIterator iter = null;
+
+ AGTupleQueryResult(AGSInternal ags, ValueSetIterator iter) {
+ this.ags = ags;
+ this.iter = iter;
+ }
+
+ public List<String> getBindingNames() {
+ return Arrays.asList(iter.getNames());
+ }
+
+ public void close() throws QueryEvaluationException {
+ // TODO check that this can be a no-op.
+ }
+
+ public boolean hasNext() throws QueryEvaluationException {
+ return iter.hasNext();
+ }
+
+ public BindingSet next() throws QueryEvaluationException {
+ iter.next();
+ return new AGBindingSet(ags, iter);
+ }
+
+ public void remove() throws QueryEvaluationException {
+ iter.remove();
+ }
+
+}
View
12 src/com/franz/ag/repository/package.html
@@ -0,0 +1,12 @@
+<html>
+<head></head>
+<body>
+Sesame 2.x Repository adapter for AllegroGraph.
+<p>
+
+The classes and interfaces in this package implement the infrastructure
+needed to access AllegroGraph stores through the Sesame 2.x Repository API.
+
+
+</body>
+</html>
View
861 src/com/franz/ag/repository/test/AGRepositoryConnectionTest.java
@@ -0,0 +1,861 @@
+package com.franz.ag.repository.test;
+
+import info.aduna.iteration.CloseableIteration;
+import info.aduna.iteration.Iterations;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.junit.Ignore;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.model.vocabulary.RDF;
+import org.openrdf.query.BindingSet;
+import org.openrdf.query.BooleanQuery;
+import org.openrdf.query.GraphQuery;
+import org.openrdf.query.GraphQueryResult;
+import org.openrdf.query.QueryLanguage;
+import org.openrdf.query.TupleQuery;
+import org.openrdf.query.TupleQueryResult;
+import org.openrdf.query.impl.DatasetImpl;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryConnectionTest;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.RepositoryResult;
+import org.openrdf.rio.RDFFormat;
+import org.openrdf.rio.RDFHandlerException;
+import org.openrdf.rio.RDFParseException;
+import org.openrdf.rio.helpers.RDFHandlerBase;
+
+import com.franz.ag.repository.AGRepository;
+import com.franz.agbase.AllegroGraph;
+import com.franz.agbase.AllegroGraphConnection;
+import com.franz.agbase.SPARQLQuery;
+
+public class AGRepositoryConnectionTest extends RepositoryConnectionTest {
+
+ private final String TEST_DIR_PREFIX = System.getProperty("user.dir") + "\\";
+
+ AllegroGraph ts = null;
+ AllegroGraphConnection ags = null;
+ AGRepository repo = null;
+
+ public AGRepositoryConnectionTest(String name) {
+ super(name);
+ }
+
+ protected Repository createRepository() throws Exception {
+ ags = new AllegroGraphConnection();
+ ags.enable();
+ ts = ags.renew("RepositoryConnectionTestStore", "/tmp/");
+ repo = new AGRepository(ts);
+ return repo;
+ }
+
+ public void testHasStatementWithoutBNodes() throws Exception {
+ testCon.add(name, name, nameBob);
+
+ assertTrue("Repository should contain newly added statement", testCon
+ .hasStatement(name, name, nameBob, false));
+ }
+
+ public void testHasStatementWithBNodes() throws Exception {
+ testCon.add(bob, name, nameBob);
+
+ assertTrue("Repository should contain newly added statement", testCon
+ .hasStatement(bob, name, nameBob, false));
+
+ }
+
+ public void testAddStatement() throws Exception {
+ testCon.add(bob, name, nameBob);
+
+ assertTrue("Repository should contain newly added statement", testCon
+ .hasStatement(bob, name, nameBob, false));
+
+ Statement statement = vf.createStatement(alice, name, nameAlice);
+ testCon.add(statement);
+
+ assertTrue("Repository should contain newly added statement", testCon
+ .hasStatement(statement, false));
+ assertTrue("Repository should contain newly added statement", testCon
+ .hasStatement(alice, name, nameAlice, false));
+
+ }
+ public void testSimpleTupleQuery() throws Exception {
+ testCon.add(alice, name, nameAlice, context2);
+ testCon.add(alice, mbox, mboxAlice, context2);
+ testCon.add(context2, publisher, nameAlice);
+
+ testCon.add(bob, name, nameBob, context1);
+ testCon.add(bob, mbox, mboxBob, context1);
+ testCon.add(context1, publisher, nameBob);
+
+ StringBuilder queryBuilder = new StringBuilder();
+ queryBuilder.append(" PREFIX foaf: <" + FOAF_NS + ">");
+ queryBuilder.append(" SELECT ?name ?mbox");
+ queryBuilder.append(" WHERE { ?x foaf:name ?name .");
+ queryBuilder.append(" ?x foaf:mbox ?mbox .}");
+
+ TupleQueryResult result = testCon.prepareTupleQuery(
+ QueryLanguage.SPARQL, queryBuilder.toString()).evaluate();
+
+ try {
+ assertTrue(result != null);
+ assertTrue(result.hasNext());
+
+ while (result.hasNext()) {
+ BindingSet solution = result.next();
+ assertTrue(solution.hasBinding("name"));
+ assertTrue(solution.hasBinding("mbox"));
+
+ Value nameResult = solution.getValue("name");
+ Value mboxResult = solution.getValue("mbox");
+
+ assertTrue((nameAlice.equals(nameResult) || nameBob
+ .equals(nameResult)));
+ assertTrue((mboxAlice.equals(mboxResult) || mboxBob
+ .equals(mboxResult)));
+ }
+ } finally {
+ result.close();
+ }
+ }
+
+ public void testSimpleTupleQueryUnicode() throws Exception {
+ // TODO: revert strangeUnicodeVarname to original value
+ testCon.add(alexander, name, strangeUnicodeVarname);
+
+ StringBuilder queryBuilder = new StringBuilder();
+ queryBuilder.append(" PREFIX foaf: <" + FOAF_NS + ">");
+ queryBuilder.append(" SELECT ?person");
+ queryBuilder.append(" WHERE { ?person foaf:name '");
+ queryBuilder.append( strangeUnicodeVarname.getLabel()).append("' .}");
+
+ TupleQueryResult result = testCon.prepareTupleQuery(
+ QueryLanguage.SPARQL, queryBuilder.toString()).evaluate();
+
+ try {
+ assertTrue(result != null);
+ assertTrue(result.hasNext());
+
+ while (result.hasNext()) {
+ BindingSet solution = result.next();
+ assertTrue(solution.hasBinding("person"));
+ assertEquals(alexander, solution.getValue("person"));
+ }
+ } finally {
+ result.close();
+ }
+ }
+
+ public void testPreparedTupleQuery() throws Exception {
+ testCon.add(alice, name, nameAlice, context2);
+ testCon.add(alice, mbox, mboxAlice, context2);
+ testCon.add(context2, publisher, nameAlice);
+
+ testCon.add(bob, name, nameBob, context1);
+ testCon.add(bob, mbox, mboxBob, context1);
+ testCon.add(context1, publisher, nameBob);
+
+ StringBuilder queryBuilder = new StringBuilder();
+ queryBuilder.append(" PREFIX foaf: <" + FOAF_NS + ">");
+ queryBuilder.append(" SELECT ?name ?mbox");
+ queryBuilder.append(" WHERE { ?x foaf:name ?name .");
+ queryBuilder.append(" ?x foaf:mbox ?mbox .}");
+
+ TupleQuery query = testCon.prepareTupleQuery(QueryLanguage.SPARQL,
+ queryBuilder.toString());
+ query.setBinding("name", nameBob);
+
+
+ TupleQueryResult result = query.evaluate();
+
+ try {
+ assertTrue(result != null);
+ assertTrue(result.hasNext());
+
+ while (result.hasNext()) {
+ BindingSet solution = result.next();
+ assertTrue(solution.hasBinding("name"));
+ assertTrue(solution.hasBinding("mbox"));
+
+ Value nameResult = solution.getValue("name");
+ Value mboxResult = solution.getValue("mbox");
+
+ assertEquals("unexpected value for name: " + nameResult,
+ nameBob, nameResult);
+ assertEquals("unexpected value for mbox: " + mboxResult,
+ mboxBob, mboxResult);
+ }
+ } finally {
+ result.close();
+ }
+ }
+
+ public void testPreparedTupleQueryUnicode() throws Exception {
+ // TODO: revert strangeUnicodeVarname to original value
+ testCon.add(alexander, name, strangeUnicodeVarname);
+
+ StringBuilder queryBuilder = new StringBuilder();
+ queryBuilder.append(" PREFIX foaf: <" + FOAF_NS + ">");
+ queryBuilder.append(" SELECT ?person");
+ queryBuilder.append(" WHERE { ?person foaf:name '");
+ queryBuilder.append( strangeUnicodeVarname.getLabel()).append("' .}");
+
+ TupleQuery query = testCon.prepareTupleQuery(QueryLanguage.SPARQL,