Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

2nd commit

  • Loading branch information...
commit 5a5d91ca46f94d19740e7f0b5a7fd60068c5355f 1 parent 2f96eb8
@helun authored
Showing with 15,127 additions and 0 deletions.
  1. +8 −0 doc/src/docbkx/customization.xsl
  2. +10 −0 doc/src/docbkx/docbook.css
  3. +35 −0 doc/src/docbkx/index.html
  4. +201 −0 license.txt
  5. +115 −0 org.ektorp.spring/src/main/java/org/ektorp/spring/HttpClientFactoryBean.java
  6. +97 −0 org.ektorp.spring/src/main/java/org/ektorp/spring/InitialDataLoader.java
  7. +58 −0 org.ektorp.spring/src/main/java/org/ektorp/spring/RetryAdvice.java
  8. +19 −0 org.ektorp.spring/src/main/java/org/ektorp/spring/Retryable.java
  9. +40 −0 org.ektorp.spring/src/test/java/org/ektorp/spring/RetryAdviceTest.java
  10. +101 −0 org.ektorp/src/main/java/org/ektorp/Attachment.java
  11. +42 −0 org.ektorp/src/main/java/org/ektorp/AttachmentInputStream.java
  12. +80 −0 org.ektorp/src/main/java/org/ektorp/BulkDeleteDocument.java
  13. +60 −0 org.ektorp/src/main/java/org/ektorp/ComplexKey.java
  14. +344 −0 org.ektorp/src/main/java/org/ektorp/CouchDbConnector.java
  15. +39 −0 org.ektorp/src/main/java/org/ektorp/CouchDbInstance.java
  16. +22 −0 org.ektorp/src/main/java/org/ektorp/DbAccessException.java
  17. +129 −0 org.ektorp/src/main/java/org/ektorp/DbInfo.java
  18. +85 −0 org.ektorp/src/main/java/org/ektorp/DbPath.java
  19. +117 −0 org.ektorp/src/main/java/org/ektorp/DesignDocInfo.java
  20. +17 −0 org.ektorp/src/main/java/org/ektorp/DocumentExistsException.java
  21. +44 −0 org.ektorp/src/main/java/org/ektorp/DocumentNotFoundException.java
  22. +82 −0 org.ektorp/src/main/java/org/ektorp/DocumentOperationResult.java
  23. +15 −0 org.ektorp/src/main/java/org/ektorp/InvalidDocumentException.java
  24. +159 −0 org.ektorp/src/main/java/org/ektorp/ReplicationCommand.java
  25. +169 −0 org.ektorp/src/main/java/org/ektorp/ReplicationStatus.java
  26. +62 −0 org.ektorp/src/main/java/org/ektorp/Revision.java
  27. +29 −0 org.ektorp/src/main/java/org/ektorp/UpdateConflictException.java
  28. +755 −0 org.ektorp/src/main/java/org/ektorp/ViewQuery.java
  29. +145 −0 org.ektorp/src/main/java/org/ektorp/ViewResult.java
  30. +25 −0 org.ektorp/src/main/java/org/ektorp/ViewResultException.java
  31. +120 −0 org.ektorp/src/main/java/org/ektorp/changes/ChangesCommand.java
  32. +42 −0 org.ektorp/src/main/java/org/ektorp/changes/ChangesFeed.java
  33. +40 −0 org.ektorp/src/main/java/org/ektorp/changes/DocumentChange.java
  34. +24 −0 org.ektorp/src/main/java/org/ektorp/dataload/DataLoader.java
  35. +68 −0 org.ektorp/src/main/java/org/ektorp/dataload/DefaultDataLoader.java
  36. +31 −0 org.ektorp/src/main/java/org/ektorp/docref/CascadeType.java
  37. +68 −0 org.ektorp/src/main/java/org/ektorp/docref/DocumentReferences.java
  38. +21 −0 org.ektorp/src/main/java/org/ektorp/docref/FetchType.java
  39. +422 −0 org.ektorp/src/main/java/org/ektorp/http/AndroidSSLSocketFactory.java
  40. +25 −0 org.ektorp/src/main/java/org/ektorp/http/HttpClient.java
  41. +15 −0 org.ektorp/src/main/java/org/ektorp/http/HttpResponse.java
  42. +49 −0 org.ektorp/src/main/java/org/ektorp/http/HttpStatus.java
  43. +42 −0 org.ektorp/src/main/java/org/ektorp/http/IdleConnectionMonitor.java
  44. +43 −0 org.ektorp/src/main/java/org/ektorp/http/PreemptiveAuthRequestInterceptor.java
  45. +17 −0 org.ektorp/src/main/java/org/ektorp/http/ResponseCallback.java
  46. +110 −0 org.ektorp/src/main/java/org/ektorp/http/RestTemplate.java
  47. +359 −0 org.ektorp/src/main/java/org/ektorp/http/StdHttpClient.java
  48. +151 −0 org.ektorp/src/main/java/org/ektorp/http/StdHttpResponse.java
  49. +69 −0 org.ektorp/src/main/java/org/ektorp/http/StdResponseHandler.java
  50. +96 −0 org.ektorp/src/main/java/org/ektorp/http/URI.java
  51. +50 −0 org.ektorp/src/main/java/org/ektorp/impl/BulkDocumentWriter.java
  52. +33 −0 org.ektorp/src/main/java/org/ektorp/impl/BulkOperation.java
  53. +70 −0 org.ektorp/src/main/java/org/ektorp/impl/BulkOperationResponseHandler.java
  54. +54 −0 org.ektorp/src/main/java/org/ektorp/impl/DocIdResponseHandler.java
  55. +206 −0 org.ektorp/src/main/java/org/ektorp/impl/EmbeddedDocViewResponseHandler.java
  56. +12 −0 org.ektorp/src/main/java/org/ektorp/impl/JsonSerializer.java
  57. +28 −0 org.ektorp/src/main/java/org/ektorp/impl/NameConventions.java
  58. +23 −0 org.ektorp/src/main/java/org/ektorp/impl/ObjectMapperFactory.java
  59. +25 −0 org.ektorp/src/main/java/org/ektorp/impl/RevisionResponseHandler.java
  60. +494 −0 org.ektorp/src/main/java/org/ektorp/impl/StdCouchDbConnector.java
  61. +93 −0 org.ektorp/src/main/java/org/ektorp/impl/StdCouchDbInstance.java
  62. +70 −0 org.ektorp/src/main/java/org/ektorp/impl/StdObjectMapperFactory.java
  63. +93 −0 org.ektorp/src/main/java/org/ektorp/impl/StreamingJsonSerializer.java
  64. +30 −0 org.ektorp/src/main/java/org/ektorp/impl/ThreadLocalBulkBufferHolder.java
  65. +130 −0 org.ektorp/src/main/java/org/ektorp/impl/changes/ContinuousChangesFeed.java
  66. +64 −0 org.ektorp/src/main/java/org/ektorp/impl/changes/StdDocumentChange.java
  67. +97 −0 org.ektorp/src/main/java/org/ektorp/impl/docref/BackReferencedBeanDeserializer.java
  68. +118 −0 org.ektorp/src/main/java/org/ektorp/impl/docref/BackReferencedBeanSerializer.java
  69. +52 −0 org.ektorp/src/main/java/org/ektorp/impl/docref/ConstructibleAnnotatedCollection.java
  70. +140 −0 org.ektorp/src/main/java/org/ektorp/impl/docref/DocumentReferenceDeserializerFactory.java
  71. +105 −0 org.ektorp/src/main/java/org/ektorp/impl/docref/DocumentReferenceSerializerFactory.java
  72. +136 −0 org.ektorp/src/main/java/org/ektorp/impl/docref/DocumentReferenceSerializerProvider.java
  73. +37 −0 org.ektorp/src/main/java/org/ektorp/impl/docref/LazyLoadingViewBasedCollection.java
  74. +246 −0 org.ektorp/src/main/java/org/ektorp/impl/docref/ViewBasedCollection.java
  75. +108 −0 org.ektorp/src/main/java/org/ektorp/support/CouchDbDocument.java
  76. +283 −0 org.ektorp/src/main/java/org/ektorp/support/CouchDbRepositorySupport.java
  77. +290 −0 org.ektorp/src/main/java/org/ektorp/support/DesignDocument.java
  78. +17 −0 org.ektorp/src/main/java/org/ektorp/support/DesignDocumentFactory.java
  79. +33 −0 org.ektorp/src/main/java/org/ektorp/support/Entity.java
  80. +35 −0 org.ektorp/src/main/java/org/ektorp/support/Filter.java
  81. +11 −0 org.ektorp/src/main/java/org/ektorp/support/Filters.java
  82. +18 −0 org.ektorp/src/main/java/org/ektorp/support/GenerateView.java
  83. +58 −0 org.ektorp/src/main/java/org/ektorp/support/GenericRepository.java
  84. +34 −0 org.ektorp/src/main/java/org/ektorp/support/ListFunction.java
  85. +10 −0 org.ektorp/src/main/java/org/ektorp/support/Lists.java
  86. +49 −0 org.ektorp/src/main/java/org/ektorp/support/OpenCouchDbDocument.java
  87. +34 −0 org.ektorp/src/main/java/org/ektorp/support/ShowFunction.java
  88. +10 −0 org.ektorp/src/main/java/org/ektorp/support/Shows.java
  89. +366 −0 org.ektorp/src/main/java/org/ektorp/support/SimpleViewGenerator.java
  90. +144 −0 org.ektorp/src/main/java/org/ektorp/support/StdDesignDocumentFactory.java
  91. +27 −0 org.ektorp/src/main/java/org/ektorp/support/TypeDiscriminator.java
  92. +48 −0 org.ektorp/src/main/java/org/ektorp/support/View.java
  93. +18 −0 org.ektorp/src/main/java/org/ektorp/support/ViewGenerationException.java
  94. +16 −0 org.ektorp/src/main/java/org/ektorp/support/Views.java
  95. +70 −0 org.ektorp/src/main/java/org/ektorp/util/Assert.java
  96. +112 −0 org.ektorp/src/main/java/org/ektorp/util/ClassHierarchyMap.java
  97. +21 −0 org.ektorp/src/main/java/org/ektorp/util/DocumentAccessor.java
  98. +495 −0 org.ektorp/src/main/java/org/ektorp/util/Documents.java
  99. +26 −0 org.ektorp/src/main/java/org/ektorp/util/Exceptions.java
  100. +123 −0 org.ektorp/src/main/java/org/ektorp/util/JSONComparator.java
  101. +18 −0 org.ektorp/src/main/java/org/ektorp/util/JSONEncoding.java
  102. +18 −0 org.ektorp/src/main/java/org/ektorp/util/Joiner.java
  103. +7 −0 org.ektorp/src/main/java/org/ektorp/util/Predicate.java
  104. +109 −0 org.ektorp/src/main/java/org/ektorp/util/ReflectionUtils.java
  105. +18 −0 org.ektorp/src/test/java/org/ektorp/BulkDeleteDocumentTest.java
  106. +31 −0 org.ektorp/src/test/java/org/ektorp/ComplexKeyTest.java
  107. +29 −0 org.ektorp/src/test/java/org/ektorp/DesignDocInfoTest.java
  108. +19 −0 org.ektorp/src/test/java/org/ektorp/DocumentNotFoundExceptionTest.java
  109. +32 −0 org.ektorp/src/test/java/org/ektorp/DocumentOperationResponseTest.java
  110. +52 −0 org.ektorp/src/test/java/org/ektorp/ReplicationCommandTest.java
  111. +33 −0 org.ektorp/src/test/java/org/ektorp/ReplicationStatusTest.java
  112. +264 −0 org.ektorp/src/test/java/org/ektorp/ViewQueryTest.java
  113. +89 −0 org.ektorp/src/test/java/org/ektorp/ViewResultTest.java
  114. +28 −0 org.ektorp/src/test/java/org/ektorp/changes/ChangesCommandTest.java
  115. +74 −0 org.ektorp/src/test/java/org/ektorp/http/BulkTest.java
  116. +304 −0 org.ektorp/src/test/java/org/ektorp/http/RestTemplateTest.java
  117. +40 −0 org.ektorp/src/test/java/org/ektorp/http/URITest.java
  118. +86 −0 org.ektorp/src/test/java/org/ektorp/impl/BulkDocumentWriterTest.java
  119. +54 −0 org.ektorp/src/test/java/org/ektorp/impl/BulkOperationResponseHandlerTest.java
  120. +90 −0 org.ektorp/src/test/java/org/ektorp/impl/EmbeddedDocViewResponseHandlerTest.java
  121. +52 −0 org.ektorp/src/test/java/org/ektorp/impl/HttpResponseStub.java
  122. +79 −0 org.ektorp/src/test/java/org/ektorp/impl/ResponseOnFileStub.java
  123. +574 −0 org.ektorp/src/test/java/org/ektorp/impl/StdCouchDbConnectorTest.java
  124. +61 −0 org.ektorp/src/test/java/org/ektorp/impl/StdCouchDbInstanceTest.java
  125. +49 −0 org.ektorp/src/test/java/org/ektorp/impl/StreamingJsonSerializerTest.java
  126. +72 −0 org.ektorp/src/test/java/org/ektorp/impl/ThreadLocalBulkBufferHolderTest.java
  127. +188 −0 org.ektorp/src/test/java/org/ektorp/impl/changes/ContinuousChangesFeedTest.java
  128. +51 −0 org.ektorp/src/test/java/org/ektorp/impl/changes/StdDocumentChangeTest.java
  129. +28 −0 org.ektorp/src/test/java/org/ektorp/impl/docref/BasicSofa.java
  130. +115 −0 org.ektorp/src/test/java/org/ektorp/impl/docref/DocumentReferenceDeserializerTest.java
  131. +262 −0 org.ektorp/src/test/java/org/ektorp/impl/docref/DocumentReferenceTest.java
  132. +178 −0 org.ektorp/src/test/java/org/ektorp/impl/docref/DocumentReferencesCouchDbTest.java
  133. +66 −0 org.ektorp/src/test/java/org/ektorp/impl/docref/InputStreamAsJsonMatcher.java
  134. +28 −0 org.ektorp/src/test/java/org/ektorp/impl/docref/JSONMatcher.java
  135. +21 −0 org.ektorp/src/test/java/org/ektorp/impl/docref/LazyLounge.java
  136. +36 −0 org.ektorp/src/test/java/org/ektorp/impl/docref/NoCascadeLounge.java
  137. +12 −0 org.ektorp/src/test/java/org/ektorp/impl/docref/People.java
  138. +84 −0 org.ektorp/src/test/java/org/ektorp/impl/docref/Person.java
  139. +36 −0 org.ektorp/src/test/java/org/ektorp/impl/docref/SetLounge.java
  140. +118 −0 org.ektorp/src/test/java/org/ektorp/impl/docref/ViewBasedCollectionTest.java
  141. +41 −0 org.ektorp/src/test/java/org/ektorp/support/CouchDbDocumentTest.java
  142. +227 −0 org.ektorp/src/test/java/org/ektorp/support/CouchDbRepositorySupportTest.java
  143. +60 −0 org.ektorp/src/test/java/org/ektorp/support/DesignDocumentFactoryTest.java
  144. +129 −0 org.ektorp/src/test/java/org/ektorp/support/DesignDocumentTest.java
  145. +51 −0 org.ektorp/src/test/java/org/ektorp/support/OpenCouchDbDocumentTest.java
  146. +427 −0 org.ektorp/src/test/java/org/ektorp/support/SimpleViewGeneratorTest.java
  147. +66 −0 org.ektorp/src/test/java/org/ektorp/util/ClassHierarchyMapTest.java
  148. +339 −0 org.ektorp/src/test/java/org/ektorp/util/DocumentsTest.java
  149. +37 −0 org.ektorp/src/test/java/org/ektorp/util/JSONComparatorTest.java
  150. +30 −0 org.ektorp/src/test/java/org/ektorp/util/JoinerTest.java
  151. +52 −0 org.ektorp/src/test/java/org/ektorp/util/ReflectionUtilsTest.java
  152. +24 −0 org.ektorp/src/test/java/org/ektorp/util/RegexMatcher.java
  153. +1 −0  org.ektorp/src/test/resources/org/ektorp/basic_replication_command.json
  154. +13 −0 org.ektorp/src/test/resources/org/ektorp/design_doc_info.json
  155. +5 −0 org.ektorp/src/test/resources/org/ektorp/document_operation_response.json
  156. +9 −0 org.ektorp/src/test/resources/org/ektorp/full_replication_command.json
  157. +4 −0 org.ektorp/src/test/resources/org/ektorp/impl/all_docs_result.json
  158. +4 −0 org.ektorp/src/test/resources/org/ektorp/impl/array_and_object_view_result.json
  159. +5 −0 org.ektorp/src/test/resources/org/ektorp/impl/bulk_response.json
  160. +1 −0  org.ektorp/src/test/resources/org/ektorp/impl/changes/change_message.json
  161. +1 −0  org.ektorp/src/test/resources/org/ektorp/impl/changes/change_message_w_deleted_doc.json
  162. +1 −0  org.ektorp/src/test/resources/org/ektorp/impl/changes/change_message_w_included_doc.json
  163. +5 −0 org.ektorp/src/test/resources/org/ektorp/impl/charset.json
  164. +4 −0 org.ektorp/src/test/resources/org/ektorp/impl/complex_key_view_result.json
  165. +1 −0  org.ektorp/src/test/resources/org/ektorp/impl/create.json
  166. +1 −0  org.ektorp/src/test/resources/org/ektorp/impl/create_attachment_rsp.json
  167. +1 −0  org.ektorp/src/test/resources/org/ektorp/impl/create_from_json_node.json
  168. +1 −0  org.ektorp/src/test/resources/org/ektorp/impl/create_with_no_id.json
  169. +1 −0  org.ektorp/src/test/resources/org/ektorp/impl/dates.json
  170. +11 −0 org.ektorp/src/test/resources/org/ektorp/impl/db_info.json
  171. +4 −0 org.ektorp/src/test/resources/org/ektorp/impl/docref/expected_lounge_persons_update.json
  172. +5 −0 org.ektorp/src/test/resources/org/ektorp/impl/docref/lounge.json
  173. +5 −0 org.ektorp/src/test/resources/org/ektorp/impl/docref/lounge_person_kalle.json
  174. +5 −0 org.ektorp/src/test/resources/org/ektorp/impl/docref/lounge_person_nisse.json
  175. +4 −0 org.ektorp/src/test/resources/org/ektorp/impl/docref/setlounge_persons_nisse_kalle.json
  176. +1 −0  org.ektorp/src/test/resources/org/ektorp/impl/empty_reduced_view_result.json
  177. +1 −0  org.ektorp/src/test/resources/org/ektorp/impl/erroneous_cloudant_view_result.json
  178. +4 −0 org.ektorp/src/test/resources/org/ektorp/impl/int_view_result.json
  179. +5 −0 org.ektorp/src/test/resources/org/ektorp/impl/reduce_view_result.json
  180. +10 −0 org.ektorp/src/test/resources/org/ektorp/impl/revisions.json
  181. +1 −0  org.ektorp/src/test/resources/org/ektorp/impl/set_dbname.json
  182. +1 −0  org.ektorp/src/test/resources/org/ektorp/impl/update.json
  183. +1 −0  org.ektorp/src/test/resources/org/ektorp/impl/update_conflict.json
  184. +4 −0 org.ektorp/src/test/resources/org/ektorp/impl/view_result.json
  185. +4 −0 org.ektorp/src/test/resources/org/ektorp/impl/view_result_with_embedded_docs.json
  186. +4 −0 org.ektorp/src/test/resources/org/ektorp/impl/view_result_with_error.json
  187. +4 −0 org.ektorp/src/test/resources/org/ektorp/impl/view_result_with_included_docs.json
  188. +3 −0  org.ektorp/src/test/resources/org/ektorp/impl/view_result_with_single_row.json
  189. +1 −0  org.ektorp/src/test/resources/org/ektorp/replication_response.json
  190. +16 −0 org.ektorp/src/test/resources/org/ektorp/support/complicated_view.json
  191. +17 −0 org.ektorp/src/test/resources/org/ektorp/support/design_doc.json
  192. +9 −0 org.ektorp/src/test/resources/org/ektorp/support/open_doc.json
  193. +1 −0  org.ektorp/src/test/resources/org/ektorp/util/doc_a.json
  194. +1 −0  org.ektorp/src/test/resources/org/ektorp/util/doc_b.json
  195. +1 −0  org.ektorp/src/test/resources/org/ektorp/util/doc_c.json
  196. +180 −0 pom.xml
View
8 doc/src/docbkx/customization.xsl
@@ -0,0 +1,8 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xslthl="http://xslthl.sf.net" exclude-result-prefixes="xslthl"
+ version="1.0">
+
+ <xsl:import href="urn:docbkx:stylesheet" />
+ <xsl:import href="urn:docbkx:stylesheet/highlight.xsl" />
+
+</xsl:stylesheet>
View
10 doc/src/docbkx/docbook.css
@@ -0,0 +1,10 @@
+@IMPORT url("http://yui.yahooapis.com/combo?3.0.0/build/cssfonts/fonts-min.css&3.0.0/build/cssreset/reset-min.css&3.0.0/build/cssbase/base-min.css");
+html, body {background: #fefefe;}
+.book { margin: 0 10%; font-size:123.1%; font-family: 'Lucida Grande', Calibri, Arial, Verdana, sans-serif;}
+.author, .pubdate { color: #aaa;}
+.programlisting { background: #eee; border: 1px solid #ccc; padding: 1em; font-size: 93%;}
+h2 { border-bottom: 1px solid #ccc; }
+.hl-keyword {color: #82075a; }
+.hl-string i {color: #2a00ff !important; font-weight: normal; font-style: normal;}
+.emphasis { font-family: monospace;}
+.emphasis em { font-style: normal; }
View
35 doc/src/docbkx/index.html
@@ -0,0 +1,35 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+ <title>Ektorp Java API for CouchDB</title>
+ <link rel="stylesheet" href="docbook.css" type="text/css">
+<body>
+ <div class="book">
+ <h1 style="font-size: 300%;">Welcome to Ektorp!</h1>
+ <p>Ektorp is a Java persistence API that uses CouchDB as storage engine.</p>
+ <p>The goal of Ektorp is to combine JPA-like functionality with the simplicity and flexibility that CouchDB provides.</p>
+ <h2>Useful links</h2>
+ <ul>
+ <li><a href="reference_documentation.html">Reference Documentation</a></li>
+ <li><a href="tutorial.html">Tutorial</a></li>
+ <li><a href="/javadoc/ektorp/1.0.2/">Javadoc for org.ektorp</a></li>
+ <li><a href="/javadoc/ektorp.spring/1.0.2/">Javadoc for org.ektorp.spring</a></li>
+ <li><a href="http://groups.google.com/group/ektorp-discuss">Mailing List</a></li>
+ <li><a href="http://twitter.com/#!/org_ektorp">Follow Ektorp on Twitter</a></li>
+ </ul>
+ <p>Also see the ektorp site at Google Code for the <a href="http://code.google.com/p/ektorp/downloads/list">downloads</a> and <a href="http://code.google.com/p/ektorp/issues/list">issue tracking.</a></p>
+ <h2>Contact</h2>
+ <p>Ektorp is brought to you by Henrik Lundgren and friends.</p>
+ <p>Send a mail to carl.henrik.lundgren [at] gmail.com if you have questions regarding Ektorp</p>
+ </div>
+ <script type="text/javascript">
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+ document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+ </script>
+ <script type="text/javascript">
+ try{
+ var pageTracker = _gat._getTracker("UA-504305-5");
+ pageTracker._trackPageview();
+ } catch(err) {}
+ </script>
+</body>
+</html>
View
201 license.txt
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
View
115 org.ektorp.spring/src/main/java/org/ektorp/spring/HttpClientFactoryBean.java
@@ -0,0 +1,115 @@
+package org.ektorp.spring;
+
+import org.apache.http.conn.ssl.*;
+import org.ektorp.http.*;
+import org.ektorp.support.*;
+import org.slf4j.*;
+import org.springframework.beans.factory.*;
+import org.springframework.beans.factory.annotation.*;
+/**
+ * FactoryBean that produces a HttpClient.
+ * Configuration parameters are set through @Value annotations.
+ *
+ * The application context must define properties along the line of:
+ * <code>
+ * <util:properties id="couchdbProperties" location="classpath:/couchdb.properties"/>
+ * </code>
+ * @author henrik lundgren
+ *
+ */
+public class HttpClientFactoryBean implements FactoryBean<HttpClient> {
+
+ private final static Logger LOG = LoggerFactory.getLogger(HttpClientFactoryBean.class);
+
+ public @Value("#{couchdbProperties['host']?:'localhost'}") String host;
+ public @Value("#{couchdbProperties['port']?:5984}") int port;
+ public @Value("#{couchdbProperties['maxConnections']?:20}") int maxConnections;
+ public @Value("#{couchdbProperties['connectionTimeout']?:1000}") int connectionTimeout;
+ public @Value("#{couchdbProperties['socketTimeout']?:10000}") int socketTimeout;
+ public @Value("#{couchdbProperties['autoUpdateViewOnChange']?:false}") boolean autoUpdateViewOnChange;
+ public @Value("#{couchdbProperties['username']}") String username;
+ public @Value("#{couchdbProperties['password']}") String password;
+ public @Value("#{couchdbProperties['testConnectionAtStartup']?:false}") boolean testConnectionAtStartup;
+ public @Value("#{couchdbProperties['cleanupIdleConnections']?:true}") boolean cleanupIdleConnections;
+ public @Value("#{couchdbProperties['enableSSL']?:false}") boolean enableSSL;
+ public @Value("#{couchdbProperties['relaxedSSLSettings']?:false}") boolean relaxedSSLSettings;
+
+ private SSLSocketFactory sslSocketFactory;
+
+ public HttpClient getObject() throws Exception {
+ LOG.debug("host: {}", host);
+ LOG.debug("port: {}", port);
+ LOG.debug("maxConnections: {}", maxConnections);
+ LOG.debug("connectionTimeout: {}", connectionTimeout);
+ LOG.debug("socketTimeout: {}", socketTimeout);
+ LOG.debug("autoUpdateViewOnChange: {}", autoUpdateViewOnChange);
+ LOG.debug("testConnectionAtStartup: {}", testConnectionAtStartup);
+ LOG.debug("cleanupIdleConnections: {}", cleanupIdleConnections);
+ LOG.debug("enableSSL: {}", enableSSL);
+ LOG.debug("relaxedSSLSettings: {}", relaxedSSLSettings);
+
+ HttpClient client = new StdHttpClient.Builder()
+ .host(host)
+ .port(port)
+ .maxConnections(maxConnections)
+ .connectionTimeout(connectionTimeout)
+ .socketTimeout(socketTimeout)
+ .username(username)
+ .password(password)
+ .cleanupIdleConnections(cleanupIdleConnections)
+ .enableSSL(enableSSL)
+ .relaxedSSLSettings(relaxedSSLSettings)
+ .sslSocketFactory(sslSocketFactory)
+ .build();
+
+ if (testConnectionAtStartup) {
+ testConnect(client);
+ }
+
+ configureAutoUpdateViewOnChange();
+ return client;
+ }
+
+ private void configureAutoUpdateViewOnChange() {
+ if (autoUpdateViewOnChange && !Boolean.getBoolean(CouchDbRepositorySupport.AUTO_UPDATE_VIEW_ON_CHANGE)) {
+ System.setProperty(CouchDbRepositorySupport.AUTO_UPDATE_VIEW_ON_CHANGE, Boolean.TRUE.toString());
+ }
+ }
+
+ private void testConnect(HttpClient client) {
+ try {
+ client.head("/");
+ } catch (Exception e) {
+ throw new BeanCreationException(String.format("Cannot connect to CouchDb@%s:%s", host, port), e);
+ }
+ }
+
+ public Class<? extends HttpClient> getObjectType() {
+ return HttpClient.class;
+ }
+
+ public boolean isSingleton() {
+ return true;
+ }
+
+ public void setAutoUpdateViewOnChange(boolean b) {
+ this.autoUpdateViewOnChange = b;
+ }
+
+ public void setUsername(String user) {
+ this.username = user;
+ }
+
+ public void setPassword(String s) {
+ this.password = s;
+ }
+
+ public void setTestConnectionAtStartup(boolean b) {
+ this.testConnectionAtStartup = b;
+ }
+
+ public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) {
+ this.sslSocketFactory = sslSocketFactory;
+ }
+
+}
View
97 org.ektorp.spring/src/main/java/org/ektorp/spring/InitialDataLoader.java
@@ -0,0 +1,97 @@
+package org.ektorp.spring;
+
+import java.io.*;
+import java.nio.charset.*;
+import java.util.*;
+import java.util.concurrent.*;
+
+import org.ektorp.dataload.*;
+import org.slf4j.*;
+import org.springframework.beans.factory.*;
+import org.springframework.beans.factory.annotation.*;
+import org.springframework.core.io.*;
+import org.springframework.scheduling.concurrent.*;
+import org.springframework.stereotype.*;
+
+/**
+ * Multi-threaded data loader.
+ * Will look up all components in the application context that implements the org.ektorp.dataload.DataLoader interface.
+ *
+ * @author henrik lundgren
+ *
+ */
+@Component("initialDataLoader")
+public class InitialDataLoader implements InitializingBean {
+
+ private final static Charset UTF_8 = Charset.forName("UTF-8");
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ private final List<DataLoader> loaders;
+ private final ResourceLoader resources;
+
+ @Autowired
+ public InitialDataLoader(List<DataLoader> l, ResourceLoader rl) {
+ loaders = l;
+ resources = rl;
+ }
+
+ public void loadData() {
+ ExecutorService es = Executors.newFixedThreadPool(loaders.size(), new CustomizableThreadFactory("initial-dataloader-"));
+ for (final DataLoader l : loaders) {
+ es.submit(new LoaderTask(l));
+ }
+ es.shutdown();
+ try {
+ afterLoad(es);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ private void afterLoad(ExecutorService es) throws InterruptedException {
+ es.awaitTermination(5, TimeUnit.MINUTES);
+ if (es.isTerminated()) {
+ for (DataLoader l : loaders) {
+ l.allDataLoaded();
+ }
+ } else {
+ log.error("The following data loaders did not complete in time: ");
+ for(Runnable r : es.shutdownNow()) {
+ log.error("The following data loaders did not complete in time: {}", r);
+ }
+ }
+ }
+
+ private class LoaderTask implements Runnable {
+
+ final DataLoader loader;
+
+ LoaderTask(DataLoader l) {
+ this.loader = l;
+ }
+
+ public void run() {
+ for (String location: loader.getDataLocations()) {
+ Resource data = resources.getResource(location);
+ if (data.exists()) {
+ try {
+ log.info("loading data from {}", data.getDescription());
+ loader.loadInitialData(new InputStreamReader(data.getInputStream(), UTF_8));
+ } catch (Exception e) {
+ log.error("Failed to load data from : " + location, e);
+ }
+ } else {
+ log.error("Failed to load data from {} does not exists", data.getDescription());
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "LoaderTask: " + loader.getClass().getSimpleName();
+ }
+ }
+
+ public void afterPropertiesSet() throws Exception {
+ loadData();
+ }
+}
View
58 org.ektorp.spring/src/main/java/org/ektorp/spring/RetryAdvice.java
@@ -0,0 +1,58 @@
+package org.ektorp.spring;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+import org.ektorp.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.Ordered;
+
+
+/**
+ *
+ *
+ * @author Henrik Lundgren
+ * created 18 okt 2009
+ *
+ */
+@Aspect
+public class RetryAdvice implements Ordered {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private static final int DEFAULT_MAX_RETRIES = 2;
+ private int maxRetries = DEFAULT_MAX_RETRIES;
+
+ @Pointcut("@annotation(org.ektorp.Retryable)")
+ public void retryableDbOperation() {}
+
+ @Around("org.ektorp.spring.RetryAdvice.retryableDbOperation()")
+ public Object retryAfterUpdateConflict(ProceedingJoinPoint pjp) throws Throwable {
+ int numAttempts = 0;
+ UpdateConflictException conflictException;
+ do {
+ numAttempts++;
+ try {
+ log.debug("proceeding join point: {}", pjp.toShortString());
+ return pjp.proceed();
+ } catch (UpdateConflictException e) {
+ log.warn("{} experienced update conflict. attempt: {}", pjp.toShortString(), numAttempts);
+ conflictException = e;
+ }
+ }
+ while (numAttempts < maxRetries);
+ throw conflictException;
+ }
+
+ public int getOrder() {
+ return 0;
+ }
+
+ public void setMaxRetries(int maxRetries) {
+ this.maxRetries = maxRetries;
+ }
+
+
+}
View
19 org.ektorp.spring/src/main/java/org/ektorp/spring/Retryable.java
@@ -0,0 +1,19 @@
+package org.ektorp.spring;
+
+import java.lang.annotation.*;
+/**
+ * Used to annotate methods that can be retries in case of update conflict.
+ *
+ * Best realized in an aspect. No implementation supplied with Ektorp as this would introduce
+ * unnecessary dependencies.
+ *
+ * @author henrik lundgren
+ *
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+public @interface Retryable {
+
+
+}
View
40 org.ektorp.spring/src/test/java/org/ektorp/spring/RetryAdviceTest.java
@@ -0,0 +1,40 @@
+package org.ektorp.spring;
+
+import static org.mockito.Mockito.*;
+
+import org.aspectj.lang.*;
+import org.ektorp.*;
+import org.junit.*;
+
+/**
+ *
+ * @author Henrik Lundgren
+ * created 30 okt 2009
+ *
+ */
+public class RetryAdviceTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @Test
+ public void testRetryAfterUpdateConflict() throws Throwable {
+ RetryAdvice a = new RetryAdvice();
+ ProceedingJoinPoint jp = mock(ProceedingJoinPoint.class);
+ when(jp.proceed())
+ .thenThrow(new UpdateConflictException("id","rev"))
+ .thenReturn("result");
+ a.retryAfterUpdateConflict(jp);
+ verify(jp, times(2)).proceed();
+ }
+
+ @Test
+ public void testRetryAfterUpdateConflict2() throws Throwable {
+ RetryAdvice a = new RetryAdvice();
+ ProceedingJoinPoint jp = mock(ProceedingJoinPoint.class);
+ when(jp.proceed()).thenReturn("result");
+ a.retryAfterUpdateConflict(jp);
+ verify(jp, times(1)).proceed();
+ }
+}
View
101 org.ektorp/src/main/java/org/ektorp/Attachment.java
@@ -0,0 +1,101 @@
+package org.ektorp;
+
+import java.io.*;
+
+import org.codehaus.jackson.annotate.*;
+import org.codehaus.jackson.map.annotate.*;
+import org.codehaus.jackson.map.annotate.JsonSerialize.*;
+import org.ektorp.util.*;
+
+/**
+ *
+ * @author henrik lundgren
+ *
+ */
+@JsonSerialize(include = Inclusion.NON_NULL)
+public class Attachment implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+ private String id;
+ private String contentType;
+ private long length;
+ private String dataBase64;
+ private boolean stub;
+ private int revpos;
+
+ /**
+ * Constructor that takes data as String.
+ * The data must be base64 encoded single line of characters, so pre-process your data to remove any carriage returns and newlines
+ *
+ * Useful if you want to save the attachment as an inline attachent.
+ *
+ * @param id
+ * @param data base64-encoded
+ * @param contentType
+ * @param contentLength
+ */
+ public Attachment(String id, String data, String contentType) {
+ Assert.hasText(id, "attachmentId must have a value");
+ Assert.hasText(contentType, "contentType must have a value");
+ Assert.notNull(data, "data input stream cannot be null");
+ this.id = id;
+ this.contentType = contentType;
+ this.dataBase64 = data;
+ this.length = data.getBytes().length;
+ }
+
+ Attachment() {}
+
+ @JsonProperty("content_type")
+ public String getContentType() {
+ return contentType;
+ }
+
+ @JsonProperty("content_type")
+ void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+ @JsonIgnore
+ public long getContentLength() {
+ return length;
+ }
+ /**
+ * Only populated if this attachment was created with data as String constructor.
+ * @return
+ */
+ @JsonProperty("data")
+ public String getDataBase64() {
+ return dataBase64;
+ }
+
+ @JsonIgnore
+ public String getId() {
+ return id;
+ }
+
+ @JsonIgnore
+ void setId(String id) {
+ this.id = id;
+ }
+
+ void setLength(int contentLength) {
+ this.length = contentLength;
+ }
+
+ public boolean isStub() {
+ return stub;
+ }
+
+ void setStub(boolean stub) {
+ this.stub = stub;
+ }
+
+ public int getRevpos() {
+ return revpos;
+ }
+
+ public void setRevpos(int revpos) {
+ this.revpos = revpos;
+ }
+
+}
View
42 org.ektorp/src/main/java/org/ektorp/AttachmentInputStream.java
@@ -0,0 +1,42 @@
+package org.ektorp;
+
+import java.io.*;
+
+import org.ektorp.util.*;
+/**
+ * An InputStream that knows what content type is contains.
+ * @author henrik lundgren
+ *
+ */
+public class AttachmentInputStream extends FilterInputStream {
+
+ private final String id;
+ private final String contentType;
+ private final long contentLength;
+
+ public AttachmentInputStream(String id, InputStream data, String contentType) {
+ this(id, data, contentType, -1);
+ }
+
+ public AttachmentInputStream(String id, InputStream data, String contentType, long size) {
+ super(data);
+ Assert.hasText(id, "id may not be null or empty");
+ Assert.hasText(contentType, "contentType not be null or empty");
+ this.id = id;
+ this.contentType = contentType;
+ this.contentLength = size;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ public long getContentLength() {
+ return contentLength;
+ }
+
+}
View
80 org.ektorp/src/main/java/org/ektorp/BulkDeleteDocument.java
@@ -0,0 +1,80 @@
+package org.ektorp;
+
+import java.io.*;
+
+import org.codehaus.jackson.*;
+import org.codehaus.jackson.map.*;
+import org.codehaus.jackson.map.annotate.*;
+import org.ektorp.util.*;
+/**
+ * This class can be used to delete documents in bulk operations.
+ * Add an instance for each document to be deleted to the objects collection.
+ * @author henrik lundgren
+ *
+ */
+@JsonSerialize(using = BulkDeleteDocument.Serializer.class)
+public class BulkDeleteDocument implements Serializable {
+
+ private static final long serialVersionUID = 6517134960185042866L;
+ private final String id;
+ private final String revision;
+ /**
+ * Will create a bulk delete document based on the specified object.
+ * @param o
+ * @return
+ */
+ public static BulkDeleteDocument of(Object o) {
+ return new BulkDeleteDocument(Documents.getId(o), Documents.getRevision(o));
+ }
+
+ public BulkDeleteDocument(String id, String rev) {
+ this.id = id;
+ this.revision = rev;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getRevision() {
+ return revision;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (o instanceof BulkDeleteDocument) {
+ BulkDeleteDocument bd = (BulkDeleteDocument) o;
+ return bd.id.equals(id);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
+ /**
+ * Dummy setter, only exists because the BulkOperationResponseHandler tries to set revision
+ * on all objects, no matter what.
+ * @param s
+ */
+ public void setRevision(String s) {
+ // do nothing
+ }
+
+ public static class Serializer extends JsonSerializer<BulkDeleteDocument> {
+
+ @Override
+ public void serialize(BulkDeleteDocument value, JsonGenerator jgen,
+ SerializerProvider provider) throws IOException,
+ JsonProcessingException {
+ jgen.writeStartObject();
+ jgen.writeStringField("_id", value.id);
+ jgen.writeStringField("_rev", value.revision);
+ jgen.writeBooleanField("_deleted", true);
+ jgen.writeEndObject();
+ }
+
+ }
+}
View
60 org.ektorp/src/main/java/org/ektorp/ComplexKey.java
@@ -0,0 +1,60 @@
+package org.ektorp;
+
+import java.util.*;
+
+import org.codehaus.jackson.*;
+import org.codehaus.jackson.annotate.*;
+import org.codehaus.jackson.map.*;
+import org.codehaus.jackson.node.*;
+/**
+ * Class for creating complex keys for view queries.
+ * The keys's components can consists of any JSON-encodeable objects, but are most likely to be Strings and Integers.
+ * @author henrik lundgren
+ *
+ */
+public class ComplexKey {
+
+ private final static ObjectMapper mapper = new ObjectMapper();
+
+ private final List<Object> components;
+
+ private static final Object EMPTY_OBJECT = new Object();
+ private static final Object[] EMPTY_ARRAY = new Object[0];
+
+ public static ComplexKey of(Object... components) {
+ return new ComplexKey(components);
+ }
+ /**
+ * Add this Object to the key if an empty object definition is desired:
+ * ["foo",{}]
+ * @return an object that will serialize to {}
+ */
+ public static Object emptyObject() {
+ return EMPTY_OBJECT;
+ }
+ /**
+ * Add this array to the key if an empty array definition is desired:
+ * [[],"foo"]
+ * @return an object array that will serialize to []
+ */
+ public static Object[] emptyArray() {
+ return EMPTY_ARRAY;
+ }
+
+ private ComplexKey(Object[] components) {
+ this.components = Arrays.asList(components);
+ }
+
+ @JsonValue
+ public JsonNode toJson() {
+ ArrayNode key = mapper.createArrayNode();
+ for (Object component : components) {
+ if (component == EMPTY_OBJECT) {
+ key.addObject();
+ } else {
+ key.addPOJO(component);
+ }
+ }
+ return key;
+ }
+}
View
344 org.ektorp/src/main/java/org/ektorp/CouchDbConnector.java
@@ -0,0 +1,344 @@
+package org.ektorp;
+
+import java.io.*;
+import java.util.*;
+
+import org.codehaus.jackson.*;
+import org.ektorp.changes.*;
+import org.ektorp.http.*;
+/**
+ * Primary interface for working with Objects mapped as documents in CouchDb.
+ *
+ * Mapped Objects must have getters and setters for id and revision.
+ *
+ * public String getId()
+ * public void setId(String s)
+ * public String getRevision()
+ * public void setRevision(String s)
+ *
+ * Reflection is used to access these methods.
+ *
+ * @author henrik lundgren
+ *
+ */
+public interface CouchDbConnector {
+ /**
+ *
+ * @param id
+ * @param json The document in the form of an Jackson JsonNode.
+ * @throws UpdateConflictException if there was an update conflict.
+ */
+ void create(String id, JsonNode json);
+ /**
+ * Creates the Object as a document in the database.
+ * If the id is not set it will be generated by the database.
+ *
+ * The Object's revision field will be updated through the setRevision(String s) method.
+ * @param o
+ * @throws UpdateConflictException if there was an update conflict.
+ */
+ void create(Object o);
+ /**
+ * Updates the document.
+ *
+ * The Object's revision field will be updated through the setRevision(String s) method.
+ * @param o
+ * @throws UpdateConflictException if there was an update conflict.
+ */
+ void update(Object o);
+ /**
+ * Deletes the Object in the database.
+ * @param o
+ * @return the revision of the deleted document
+ * @throws UpdateConflictException if there was an update conflict.
+ */
+ String delete(Object o);
+ /**
+ * Deletes the document in the database.
+ * @param id
+ * @param revision
+ * @return the revision of the deleted document.
+ * @throws UpdateConflictException if there was an update conflict.
+ */
+ String delete(String id, String revision);
+ /**
+ *
+ * @param <T>
+ * @param c the target class to map to.
+ * @param id the id of the document in the database.
+ * @return the document mapped as the specified class.
+ * @throws DocumentNotFoundException if the document was not found.
+ */
+ <T> T get(Class<T> c, String id);
+ /**
+ *
+ * @param <T>
+ * @param c the target class to map to.
+ * @param id the id of the document in the database.
+ * @param rev of the object.
+ * @return the document mapped as the specified class.
+ * @throws DocumentNotFoundException if the document was not found.
+ */
+ <T> T get(Class<T> c, String id, String rev);
+ /**
+ * Will load the document with any conflicts included.
+ * @param <T>
+ * @param c the target class to map to.
+ * @param id the id of the document in the database.
+ * @return the document mapped as the specified class.
+ * @throws DocumentNotFoundException if the document was not found.
+ */
+ <T> T getWithConflicts(Class<T> c, String id);
+ /**
+ * Check if the database contains a document.
+ * @param id
+ * @return true if a document with the id exists in the database
+ */
+ boolean contains(String id);
+ /**
+ * Please note that the stream has to be closed after usage,
+ * otherwise http connection leaks will occur and the system will eventually hang due
+ * to connection starvation.
+ *
+ * @param id
+ * @return the document as raw json in an InputStream, don't forget to close the stream when finished.
+ * @throws DocumentNotFoundException if the document was not found.
+ */
+ InputStream getAsStream(String id);
+ /**
+ * Please note that the stream has to be closed after usage,
+ * otherwise http connection leaks will occur and the system will eventually hang due
+ * to connection starvation.
+ *
+ * @param id
+ * @param rev
+ * @return the document as raw json in an InputStream, don't forget to close the stream when finished.
+ * @throws DocumentNotFoundException if the document was not found.
+ */
+ InputStream getAsStream(String id, String rev);
+ /**
+ *
+ * @param id
+ * @return
+ * @throws DocumentNotFoundException if the document was not found.
+ */
+ List<Revision> getRevisions(String id);
+ /**
+ * Reads an attachment from the database.
+ *
+ * Please note that the stream has to be closed after usage,
+ * otherwise http connection leaks will occur and the system will eventually hang due
+ * to connection starvation.
+ *
+ * @param id
+ * @param attachmentId
+ * @return the attachment in the form of an AttachmentInputStream.
+ * @throws DocumentNotFoundException if the document was not found.
+ */
+ AttachmentInputStream getAttachment(String id, String attachmentId);
+ /**
+ * Creates both the document and the attachment
+ * @param docId
+ * @param a - the data to be saved as an attachment
+ * @return revision of the created attachment document
+ * @throws UpdateConflictException if there was an update conflict.
+ */
+ String createAttachment(String docId, AttachmentInputStream data);
+ /**
+ * Adds an attachment to the specified document id.
+ * @param docId
+ * @param revision
+ * @param a - the data to be saved as an attachment
+ * @return the new revision of the document
+ * @throws UpdateConflictException if there was an update conflict.
+ */
+ String createAttachment(String docId, String revision, AttachmentInputStream data);
+ /**
+ *
+ * @param docId
+ * @param revision
+ * @param attachmentId
+ * @return the new revision of the document
+ * @throws UpdateConflictException if there was an update conflict.
+ */
+ String deleteAttachment(String docId, String revision, String attachmentId);
+ /**
+ * @return all document ids in the database including design document ids.
+ */
+ List<String> getAllDocIds();
+
+ /**
+ * This method requires the view result values to be document ids or documents :
+ * <ul>
+ * <li>If the value is a document id, then the document is fetched from couchDB.</li>
+ * <li>If the value is a document, then it is used directly for unmarshalling.</li>
+ * </ul>
+ *
+ * {"_id":"_design/ExampleDoc",
+ * "views":{
+ * "all": {"map": "function(doc) { emit(null, doc._id);}"},
+ * "by_name": {"map": "function(doc) { emit(doc.name, doc._id);}"} // emit doc id
+ * "by_author": {"map": "function(doc) { emit(doc.author, doc);}"} // emit doc
+ * }
+ * }
+ *
+ * @param <T>
+ * @param query
+ * @param type the type to map the result to
+ * @return the view result mapped as the specified class.
+ */
+ <T> List<T> queryView(ViewQuery query, Class<T> type);
+
+ /**
+ *
+ * @param query
+ * @return
+ */
+ ViewResult queryView(ViewQuery query);
+ /**
+ *
+ * @param query
+ * @return the view result as a raw InputStream.
+ */
+ InputStream queryForStream(ViewQuery query);
+ /**
+ * Creates a database on the configured path if it does not exists.
+ */
+ void createDatabaseIfNotExists();
+ /**
+ * @return name
+ */
+ String getDatabaseName();
+ /**
+ *
+ * @return
+ */
+ String path();
+ /**
+ * Convenience method for accessing the underlying HttpClient.
+ * Preferably used wrapped in a org.ektorp.http.RestTemplate.
+ * @return
+ */
+ HttpClient getConnection();
+ /**
+ * Provides meta information about this database.
+ * @return
+ */
+ DbInfo getDbInfo();
+ /**
+ * Obtains information about a given design document, including the index,
+ * index size and current status of the design document and associated index information.
+ *
+ * @param designDocId
+ * @return
+ */
+ DesignDocInfo getDesignDocInfo(String designDocId);
+ /**
+ * Compaction compresses the database file by removing unused sections created during updates.
+ * This call is non-blocking, a compaction background task will be created on the CouchDB instance.
+ */
+ void compact();
+ /**
+ * This compacts the view index from the current version of the design document.
+ * This call is non-blocking, a compaction background task will be created on the CouchDB instance.
+ * @param designDocumentId
+ */
+ void compactViews(String designDocumentId);
+ /**
+ * View indexes on disk are named after their MD5 hash of the view definition.
+ * When you change a view, old indexes remain on disk.
+ * To clean up all outdated view indexes (files named after the MD5 representation of views, that does not exist anymore) you can trigger a view cleanup
+ */
+ void cleanupViews();
+ /**
+ * Revision limit defines a upper bound of document revisions which CouchDB keeps track of
+ * @return
+ */
+ int getRevisionLimit();
+
+ void setRevisionLimit(int limit);
+ /**
+ * Replicate the content in the source database into this database.
+ * @param source database
+ * @return ReplicationStatus
+ */
+ ReplicationStatus replicateFrom(String source);
+ /**
+ * Replicate the content in the source database into this database.
+ * Replication is restricted to the specified document ids.
+ * @param source database
+ * @param docIds
+ * @return ReplicationStatus
+ */
+ ReplicationStatus replicateFrom(String source, Collection<String> docIds);
+ /**
+ * Replicate the content in this database into the specified target database.
+ * The target must exist.
+ * @param target database
+ * @return ReplicationStatus
+ */
+ ReplicationStatus replicateTo(String target);
+ /**
+ * Replicate the content in this database into the specified target database.
+ * Replication is restricted to the specified document ids.
+ * The target must exist.
+ * @param target database
+ * @param docIds
+ * @return ReplicationStatus
+ */
+ ReplicationStatus replicateTo(String target, Collection<String> docIds);
+ /**
+ * Add the object to the bulk buffer attached to the executing thread.
+ * A subsequent call to either flushBulkBuffer or clearBulkBuffer is expected.
+ * @param o
+ */
+ void addToBulkBuffer(Object o);
+ /**
+ * Sends the bulk buffer attached the the executing thread to the database (through a executeBulk call).
+ * The bulk buffer will be cleared when this method is finished.
+ */
+ List<DocumentOperationResult> flushBulkBuffer();
+ /**
+ * Clears the bulk buffer attached the the executing thread.
+ */
+ void clearBulkBuffer();
+ /**
+ * Creates, updates or deletes all objects in the supplied collection.
+ *
+ * If the object has no revision set, it will be created, otherwise it will be updated.
+ * If the object's serialized json document contains a "_deleted"=true field it will be deleted.
+ *
+ * org.ektorp.BulkDeleteDocument.of(someObject) is the easiest way to create a delete doc for an instance.
+ *
+ * Some documents may successfully be saved and some may not.
+ * The response will tell the application which documents were saved or not. In the case of a power failure, when the database restarts some may have been saved and some not.
+ * @param objects, all objects will have their id and revision set.
+ * @return The list will only contain entries for documents that has any kind of error code returned from CouchDB. i.e. the list will be empty if everything was completed successfully.
+ */
+ List<DocumentOperationResult> executeBulk(Collection<?> objects);
+ /**
+ * Creates, updates or deletes all objects in the supplied collection.
+ * In the case of a power failure, when the database restarts either all the changes will have been saved or none of them.
+ * However, it does not do conflict checking, so the documents will be committed even if this creates conflicts.
+ * @param objects, all objects will have their id and revision set.
+ * @return The list will only contain entries for documents that has any kind of error code returned from CouchDB. i.e. the list will be empty if everything was completed successfully.
+ */
+ List<DocumentOperationResult> executeAllOrNothing(Collection<?> objects);
+ /**
+ * Queries the database for changes.
+ * This is a one-off operation. To listen to changes continuously @see changesFeed(ChangesCommand cmd).
+ * @param cmd
+ * @return
+ */
+ List<DocumentChange> changes(ChangesCommand cmd);
+ /**
+ * Sets up a continuous changes feed.
+ * The current update sequence in the DB will be used if ChangesCommand does not specify the since parameter.
+ * A heartbeat interval of 10 seconds will be used if ChangesCommand does not specify the heartbeat parameter.
+ *
+ * @param cmd
+ * @return a running changes feed that buffers incoming changes in a unbounded queue (will grow until OutOfMemoryException if not polled).
+ */
+ ChangesFeed changesFeed(ChangesCommand cmd);
+
+}
View
39 org.ektorp/src/main/java/org/ektorp/CouchDbInstance.java
@@ -0,0 +1,39 @@
+package org.ektorp;
+
+import java.util.*;
+
+import org.ektorp.http.*;
+
+
+/**
+ *
+ * @author henrik lundgren
+ *
+ */
+public interface CouchDbInstance {
+ /**
+ *
+ * @return the names of all databases residing in this instance.
+ */
+ List<String> getAllDatabases();
+
+ void createDatabase(DbPath path);
+ void createDatabase(String path);
+
+ void deleteDatabase(String path);
+ /**
+ *
+ * @param path
+ * @param createIfNotExists
+ * @return
+ */
+ CouchDbConnector createConnector(String path, boolean createIfNotExists);
+ /**
+ * Convenience method for accessing the underlying HttpClient.
+ * Preferably used wrapped in a org.ektorp.http.RestTemplate.
+ * @return
+ */
+ HttpClient getConnection();
+
+ ReplicationStatus replicate(ReplicationCommand cmd);
+}
View
22 org.ektorp/src/main/java/org/ektorp/DbAccessException.java
@@ -0,0 +1,22 @@
+package org.ektorp;
+
+
+/**
+ *
+ * @author henrik lundgren
+ *
+ */
+public class DbAccessException extends RuntimeException {
+
+ private static final long serialVersionUID = -1817230646884819428L;
+
+ public DbAccessException(Throwable t) {
+ super(t);
+ }
+
+ public DbAccessException(String message) {
+ super(message);
+ }
+
+ public DbAccessException() {}
+}
View
129 org.ektorp/src/main/java/org/ektorp/DbInfo.java
@@ -0,0 +1,129 @@
+package org.ektorp;
+
+import java.io.*;
+import java.util.*;
+
+import org.codehaus.jackson.annotate.*;
+import org.ektorp.util.*;
+/**
+ *
+ * @author henrik lundgren
+ *
+ */
+public class DbInfo implements Serializable {
+
+ private static final long serialVersionUID = -6511885014968791685L;
+
+ private final String dbName;
+
+ @JsonProperty("compact_running")
+ private boolean compactRunning;
+ @JsonProperty("disk_format_version")
+ private int diskFormatVersion;
+ @JsonProperty("disk_size")
+ private long diskSize;
+ @JsonProperty("doc_count")
+ private long docCount;
+ @JsonProperty("doc_del_count")
+ private int docDelCount;
+ @JsonProperty("instance_start_time")
+ private long instanceStartTime;
+ @JsonProperty("purge_seq")
+ private int purgeSeq;
+ @JsonProperty("update_seq")
+ private int updateSeq;
+ /**
+ * Used to future proof this class, if new fields are added by CouchDb they will be found here.
+ */
+ private Map<String, Object> unknownFields;
+
+ public boolean isCompactRunning() {
+ return compactRunning;
+ }
+ /**
+ * @return Name of the database
+ */
+ public String getDbName() {
+ return dbName;
+ }
+ /**
+ * @return Current version of the internal database format on disk
+ */
+ public int getDiskFormatVersion() {
+ return diskFormatVersion;
+ }
+ /**
+ * @return Current size in Bytes of the database (Note: Size of views indexes on disk are not included)
+ */
+ public long getDiskSize() {
+ return diskSize;
+ }
+ /**
+ * @return Number of documents (including design documents) in the database.
+ */
+ public long getDocCount() {
+ return docCount;
+ }
+ /**
+ * @return
+ */
+ public int getDocDelCount() {
+ return docDelCount;
+ }
+ /**
+ * @return Timestamp of CouchDBs start time (ms)
+ */
+ public long getInstanceStartTime() {
+ return instanceStartTime;
+ }
+ /**
+ * @return Number of purge operations
+ */
+ public int getPurgeSeq() {
+ return purgeSeq;
+ }
+ /**
+ * @return Current number of updates to the database
+ */
+ public int getUpdateSeq() {
+ return updateSeq;
+ }
+
+ @JsonCreator
+ public DbInfo(@JsonProperty("db_name") String dbName) {
+ Assert.hasText(dbName, "dbName may not be null or empty");
+ this.dbName = dbName;
+ }
+
+ @JsonAnySetter
+ public void setUnknown(String key, Object value) {
+ unknownFields().put(key, value);
+ }
+
+ public Map<String, Object> getUnknownFields() {
+ return unknownFields();
+ }
+
+ private Map<String, Object> unknownFields() {
+ if (unknownFields == null) {
+ unknownFields = new HashMap<String, Object>();
+ }
+ return unknownFields;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (o instanceof DbInfo) {
+ DbInfo dbi = (DbInfo) o;
+ return dbName.equals(dbi.dbName);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return dbName.hashCode();
+ }
+
+}
View
85 org.ektorp/src/main/java/org/ektorp/DbPath.java
@@ -0,0 +1,85 @@
+/**
+ *
+ */
+package org.ektorp;
+
+import static java.lang.String.*;
+
+import java.io.*;
+import java.net.*;
+
+import org.ektorp.util.*;
+
+public class DbPath {
+
+ private final static String UTF_8 = "UTF-8";
+ private final static String DB_NAME_PATTERN = "^[\\w+-_\\$()]+(/[\\w+-_\\$()]+)*$";
+ private final static String SPECIAL_DOC_PREFIX = "_";
+
+ private final String dbName;
+ private final String path;
+ private final String allDocs;
+
+ public DbPath(String s) {
+ Assert.notNull(s);
+ checkDbName(s);
+
+ int start = s.startsWith("/") ? 1 : 0;
+ int end = s.endsWith("/") ? s.length() -1 : s.length();
+ dbName = s.substring(start, end).toLowerCase();
+ path = "/" + DbPath.escape(dbName) + "/";
+
+ allDocs = path + "_all_docs";
+ }
+ /**
+ * Appends the string to the dbPath.
+ * The String will be escaped, i.e. dbPath.append("/foo/bar") will become "path/foo%2Fbar"
+ * @param s
+ * @return
+ */
+ public String append(String s) {
+ return path + escape(s);
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public static String escape(String s) {
+ // don't escape design doc ids
+ if (s.startsWith(SPECIAL_DOC_PREFIX)) return s;
+ try {
+ return URLEncoder.encode(s, UTF_8);
+ } catch (UnsupportedEncodingException e) {
+ throw Exceptions.propagate(e);
+ }
+ }
+
+ public static DbPath fromString(String s) {
+ return new DbPath(s);
+ }
+
+ private void checkDbName(String path) {
+ Assert.isTrue(path.matches(DB_NAME_PATTERN), format("Invalid database name: %s", path));
+ }
+
+ public static String normalize(String dbName) {
+ validateDbName(dbName);
+ int start = dbName.startsWith("/") ? 1 : 0;
+ int end = dbName.endsWith("/") ? dbName.length() -1 : dbName.length();
+ dbName = dbName.substring(start, end).toLowerCase();
+ return "/" + DbPath.escape(dbName) + "/";
+ }
+
+ public static void validateDbName(String dbName) {
+ Assert.isTrue(dbName.matches(DB_NAME_PATTERN), format("Invalid database name: %s", dbName));
+ }
+
+ public String getAllDocsPath() {
+ return allDocs;
+ }
+
+ public String getDbName() {
+ return dbName;
+ }
+}
View
117 org.ektorp/src/main/java/org/ektorp/DesignDocInfo.java
@@ -0,0 +1,117 @@
+package org.ektorp;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.ektorp.support.OpenCouchDbDocument;
+
+/**
+ *
+ * @author EronenP
+ *
+ */
+public class DesignDocInfo extends OpenCouchDbDocument {
+
+ private static final long serialVersionUID = 4030630616850588285L;
+
+ public static class ViewIndex extends OpenCouchDbDocument {
+
+ private static final long serialVersionUID = 1164231233089979199L;
+
+ @JsonProperty("compact_running")
+ private boolean compactRunning;
+ @JsonProperty("updater_running")
+ private boolean updaterRunning;
+ @JsonProperty
+ private String language;
+ @JsonProperty("purge_seq")
+ private long purgeSeq;
+ @JsonProperty("waiting_commit")
+ private boolean waitingCommit;
+ @JsonProperty("waiting_clients")
+ private int waitingClients;
+ @JsonProperty
+ private String signature;
+ @JsonProperty("update_seq")
+ private long updateSeq;
+ @JsonProperty("disk_size")
+ private long diskSize;
+ /**
+ * Indicates whether a compaction routine is currently running on the view
+ * @return
+ */
+ public boolean isCompactRunning() {
+ return compactRunning;
+ }
+ /**
+ * Indicates if the view is currently being updated.
+ *
+ * @return
+ */
+ public boolean isUpdaterRunning() {
+ return updaterRunning;
+ }
+ /**
+ * Language for the defined views.
+ * @return
+ */
+ public String getLanguage() {
+ return language;
+ }
+ /**
+ * The purge sequence that has been processed.
+ * @return
+ */
+ public long getPurgeSeq() {
+ return purgeSeq;
+ }
+ /**
+ * Indicates if there are outstanding commits to the underlying database that need to processed.
+ * @return
+ */
+ public boolean isWaitingCommit() {
+ return waitingCommit;
+ }
+ /**
+ * Number of clients waiting on views from this design document.
+ * @return
+ */
+ public int getWaitingClients() {
+ return waitingClients;
+ }
+ /**
+ * MD5 signature of the views for the design document
+ * @return
+ */
+ public String getSignature() {
+ return signature;
+ }
+ /**
+ * The update sequence of the corresponding database that has been indexed.
+ *
+ * @return
+ */
+ public long getUpdateSeq() {
+ return updateSeq;
+ }
+ /**
+ * Size in bytes of the view as stored on disk.
+ * @return
+ */
+ public long getDiskSize() {
+ return diskSize;
+ }
+ }
+
+ @JsonProperty
+ private String name;
+
+ @JsonProperty("view_index")
+ private ViewIndex viewIndex;
+
+ public String getName() {
+ return name;
+ }
+
+ public ViewIndex getViewIndex() {
+ return viewIndex;
+ }
+}
View
17 org.ektorp/src/main/java/org/ektorp/DocumentExistsException.java
@@ -0,0 +1,17 @@
+package org.ektorp;
+
+
+/**
+ *
+ * @author henrik lundgren
+ * @deprecated UpdateConflictException is now thrown if the document already exists.
+ */
+@Deprecated
+public class DocumentExistsException extends DbAccessException {
+
+ private static final long serialVersionUID = 1L;
+
+ public DocumentExistsException(String id) {
+ super(String.format("A document with id %s already exists", id));
+ }
+}
View
44 org.ektorp/src/main/java/org/ektorp/DocumentNotFoundException.java
@@ -0,0 +1,44 @@
+package org.ektorp;
+
+import org.codehaus.jackson.*;
+
+/**
+ *
+ * @author Henrik Lundgren
+ * created 7 nov 2009
+ *
+ */
+public class DocumentNotFoundException extends DbAccessException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -4130993962797968754L;
+
+ private final String path;
+ private final JsonNode body;
+
+ public DocumentNotFoundException(String path, JsonNode responseBody) {
+ super(String.format("nothing found on db path: %s, Response body: %s", path, responseBody));
+ this.path = path;
+ this.body = responseBody;
+ }
+
+ public DocumentNotFoundException(String path) {
+ super(String.format("nothing found on db path: %s", path));
+ this.path = path;
+ this.body = null;
+ }
+
+ public boolean isDocumentDeleted() {
+ if (body == null) {
+ return false;
+ }
+ JsonNode reason = body.findPath("reason");
+ return !reason.isMissingNode() ? reason.getTextValue().equals("deleted") : false;
+ }
+
+ public String getPath() {
+ return path;
+ }
+}
View
82 org.ektorp/src/main/java/org/ektorp/DocumentOperationResult.java
@@ -0,0 +1,82 @@
+package org.ektorp;
+
+import java.io.*;
+
+import org.codehaus.jackson.annotate.*;
+/**
+ * Represents a result of a document operation.
+ * @author henrik lundgren
+ *
+ */
+@JsonIgnoreProperties("ok")
+public class DocumentOperationResult implements Serializable {
+
+ private static final long serialVersionUID = -5107130332464837673L;
+
+ private String id;
+ private String rev;
+ private String error;
+ private String reason;
+
+ public static DocumentOperationResult newInstance(String id, String error, String reason) {
+ DocumentOperationResult r = new DocumentOperationResult();
+ r.setId(id);
+ r.setError(error);
+ r.setReason(reason);
+ return r;
+ }
+
+ public static DocumentOperationResult newInstance(String id, String revision) {
+ DocumentOperationResult r = new DocumentOperationResult();
+ r.setId(id);
+ r.setRev(revision);
+ return r;
+ }
+
+ @JsonProperty
+ void setError(String error) {
+ this.error = error;
+ }
+
+ @JsonProperty
+ void setReason(String reason) {
+ this.reason = reason;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ @JsonProperty("id")
+ void setId(String id) {
+ this.id = id;
+ }
+
+ public String getRevision() {
+ return rev;
+ }
+ @JsonProperty("rev")
+ void setRev(String rev) {
+ this.rev = rev;
+ }
+
+ public String getError() {
+ return error;
+ }
+
+ public String getReason() {
+ return reason;
+ }
+
+ public boolean isErroneous() {
+ return error != null;
+ }
+
+ @Override
+ public String toString() {
+ return "DocumentOperationResult [id=" + id + ", rev=" + rev
+ + ", error=" + error + ", reason=" + reason + "]";
+ }
+
+
+}
View
15 org.ektorp/src/main/java/org/ektorp/InvalidDocumentException.java
@@ -0,0 +1,15 @@
+package org.ektorp;
+/**
+ *
+ * @author henrik lundgren
+ *
+ */
+public class InvalidDocumentException extends DbAccessException {
+
+ private static final long serialVersionUID = 1L;
+
+ public InvalidDocumentException(Class<?> offendingClass, String missingField) {
+ super(String.format("Cannot resolve %s in %s", missingField, offendingClass));
+ }
+
+}
View
159 org.ektorp/src/main/java/org/ektorp/ReplicationCommand.java
@@ -0,0 +1,159 @@
+package org.ektorp;
+
+import java.io.*;
+import java.util.*;
+
+import org.codehaus.jackson.annotate.*;
+import org.codehaus.jackson.map.annotate.*;
+import org.codehaus.jackson.map.annotate.JsonSerialize.*;
+import org.ektorp.util.*;
+
+@JsonSerialize(include = Inclusion.NON_NULL)
+public class ReplicationCommand implements Serializable {
+
+ private static final long serialVersionUID = 6919908757724780784L;
+
+ @JsonProperty
+ public final String source;
+
+ @JsonProperty
+ public final String target;
+
+ @JsonProperty
+ public final String proxy;
+
+ @JsonProperty
+ public final String filter;
+
+ @JsonProperty("doc_ids")
+ public final Collection<String> docIds;
+
+ @JsonProperty
+ public final Boolean continuous;
+
+ @JsonProperty
+ public final Boolean cancel;
+
+ @JsonProperty("query_params")
+ public final Object queryParams;
+
+ @JsonProperty("create_target")
+ public final Boolean createTarget;
+
+ private ReplicationCommand(Builder b) {
+ source = b.source;
+ target = b.target;
+ proxy = b.proxy;
+ filter = b.filter;
+ docIds = b.docIds;
+ continuous = b.continuous ? Boolean.TRUE : null;
+ cancel = b.cancel ? Boolean.TRUE : null;
+ createTarget = b.createTarget ? Boolean.TRUE : null;
+ queryParams = b.queryParams;
+ }
+
+ public static class Builder {
+
+ private String source;
+ private String target;
+ private String proxy;
+ private String filter;
+ private Collection<String> docIds;
+ private boolean continuous;
+ private boolean cancel;
+ private boolean createTarget;
+ private Object queryParams;
+ /**
+ * Source and target can both point at local databases, remote databases and any combination of these.
+ *
+ * If your local CouchDB instance is secured by an admin account, you need to use the full URL format
+ * @param s
+ * @return
+ */
+ public Builder source(String s) {
+ source = s;
+ return this;
+ }
+ /**
+ * Source and target can both point at local databases, remote databases and any combination of these
+ *
+ * If your local CouchDB instance is secured by an admin account, you need to use the full URL format.
+ * @param s
+ * @return
+ */
+ public Builder target(String s) {
+ target = s;
+ return this;
+ }
+ /**
+ * Pass a "proxy" argument in the replication data to have replication go through an HTTP proxy
+ * @param s
+ * @return
+ */
+ public Builder proxy(String s) {
+ proxy = s;
+ return this;
+ }
+ /**
+ * Specify a filter function.
+ * @param s
+ * @return
+ */
+ public Builder filter(String s) {
+ filter = s;
+ return this;
+ }
+ /**
+ * Restricts replication to the specified document ids.
+ * @param docIds
+ * @return
+ */
+ public Builder docIds(Collection<String> docIds) {
+ this.docIds = docIds;
+ return this;
+ }
+ /**
+ * true makes replication continuous
+ * @param b
+ * @return
+ */
+ public Builder continuous(boolean b) {
+ continuous = b;
+ return this;
+ }
+ /**
+ * true cancels a continuous replication task
+ * @param b
+ * @return
+ */
+ public Builder cancel(boolean b) {
+ cancel = b;
+ return this;
+ }
+ /**
+ * Pass parameters to the filter function if specified.
+ * @param o
+ * @return
+ */
+ public Builder queryParams(Object o) {
+ queryParams = o;
+ return this;
+ }
+ /**
+ * To create the target database (remote or local) prior to replication.
+ * The names of the source and target databases do not have to be the same.
+ * @param b
+ * @return
+ */
+ public Builder createTarget(boolean b) {
+ createTarget = b;
+ return this;
+ }
+
+ public ReplicationCommand build() {
+ Assert.hasText(source, "source may not be null or empty");
+ Assert.hasText(target, "target may not be null or empty");
+ return new ReplicationCommand(this);
+ }
+ }
+}
View
169 org.ektorp/src/main/java/org/ektorp/ReplicationStatus.java
@@ -0,0 +1,169 @@
+package org.ektorp;
+
+import java.io.*;
+import java.util.*;
+
+import org.codehaus.jackson.annotate.*;
+/**
+ *
+ * Replication response doc is not very well documented in the CouchDB reference...
+ *
+ * @author henrik lundgren
+ *
+ */
+public class ReplicationStatus implements Serializable {
+
+ private static final long serialVersionUID = 6617269292660336903L;
+
+ @JsonProperty("ok")
+ boolean ok;
+
+ @JsonProperty("no_changes")
+ boolean noChanges;
+
+ @JsonProperty("session_id")
+ String sessionId;
+
+ @JsonProperty("source_last_seq")
+ int sourceLastSequence;
+
+ @JsonProperty("history")
+ List<History> history;
+
+ private Map<String, Object> unknownFields;
+
+ public boolean isOk() {
+ return ok;
+ }
+
+ public boolean isNoChanges() {
+ return noChanges;
+ }
+
+ public String getSessionId() {
+ return sessionId;
+ }
+
+ public int getSourceLastSequence() {
+ return sourceLastSequence;
+ }
+
+ public List<History> getHistory() {
+ return history;
+ }
+
+ private Map<String, Object> unknown() {
+ if (unknownFields == null) {
+ unknownFields = new HashMap<String, Object>();
+ }
+ return unknownFields;
+ }
+
+ @JsonAnySetter
+ public void setUnknown(String key, Object value) {
+ unknown().put(key, value);
+ }
+
+ public Object getField(String key) {
+ return unknown().get(key);
+ }
+
+ public static class History {
+
+ private Map<String, Object> unknownFields;
+
+ @JsonProperty("session_id")
+ String sessionId;
+
+ @JsonProperty("start_time")
+ String startTime;
+
+ @JsonProperty("end_time")
+ String endTime;
+
+ @JsonProperty("start_last_seq")
+ int startLastSeq;
+
+ @JsonProperty("end_last_seq")
+ int endLastSeq;
+
+ @JsonProperty("missing_checked")
+ int missingChecked;
+
+ @JsonProperty("missing_found")
+ int missingFound;
+
+ @JsonProperty("docs_read")
+ int docsRead;
+
+ @JsonProperty("docs_written")
+ int docsWritten;
+