Author: danhaywood
Date: Mon May 26 10:31:43 2014
New Revision: 1597553

URL: http://svn.apache.org/r1597553
Log:
mapping blobs

Modified:
    isis/site/trunk/content/components/objectstores/jdo/mapping-blobs.md

Modified: isis/site/trunk/content/components/objectstores/jdo/mapping-blobs.md
URL: 
http://svn.apache.org/viewvc/isis/site/trunk/content/components/objectstores/jdo/mapping-blobs.md?rev=1597553&r1=1597552&r2=1597553&view=diff
==============================================================================
--- isis/site/trunk/content/components/objectstores/jdo/mapping-blobs.md 
(original)
+++ isis/site/trunk/content/components/objectstores/jdo/mapping-blobs.md Mon 
May 26 10:31:43 2014
@@ -6,13 +6,15 @@ Isis configures JDO/DataNucleus so that 
 
 As for [Joda dates](mapping-joda-dates.html), this requires the 
`@javax.jdo.annotations.Persistent` annotation.  However, whereas for dates one 
would always expect this value to be retrieved eagerly, for blobs and clobs it 
is not so clear cut.
 
+### Mapping Blobs
+
 For example, in the `ToDoItem` class (of the [quickstart 
archetype](../../../getting-started/quickstart-archetype.html)) the 
`attachment` property (as of 1.5.0-snapshot) is as follows:
 
 <pre>
   @javax.jdo.annotations.Persistent(defaultFetchGroup="false", columns = {
       @javax.jdo.annotations.Column(name = "attachment_name"),
       @javax.jdo.annotations.Column(name = "attachment_mimetype"),
-      @javax.jdo.annotations.Column(name = "attachment_bytes", sqlType = 
"BLOB")
+      @javax.jdo.annotations.Column(name = "attachment_bytes", 
jdbcType="BLOB", sqlType = "BLOB")
   })
   private Blob attachment;
 
@@ -33,7 +35,7 @@ If the `Blob` or `Clob` is mandatory, th
   @javax.jdo.annotations.Persistent(defaultFetchGroup="false", columns = {
       @javax.jdo.annotations.Column(name = "attachment_name", 
allowsNull="false"),
       @javax.jdo.annotations.Column(name = "attachment_mimetype", 
allowsNull="false"),
-      @javax.jdo.annotations.Column(name = "attachment_bytes", sqlType = 
"BLOB", allowsNull="false")
+      @javax.jdo.annotations.Column(name = "attachment_bytes", 
jdbcType="BLOB", sqlType = "BLOB", allowsNull="false")
   })
   private Blob attachment;
 
@@ -48,23 +50,47 @@ If the `Blob` or `Clob` is mandatory, th
 
 > Instead of `@Mandatory`, using 
 > `@javax.jdo.annotations.Column(allowsNull="false")` will also work.  
 > However, as this last `@Column` annotation is only for Isis' benefit 
 > (DataNucleus ignores it in the presence of the `Persistent#columns` 
 > attribute) we prefer to use `@Mandatory` instead.
 
-Using the `@Column` annotation, you can also specify whether the `Blob` is 
mapped to a `VARBINARY` rather than a `BLOB` column:
+
+### Mapping Clobs
+
+Mapping `Clob`s works in a very similar way, but the `@Column#sqlType` 
attribute will be `CLOB`:
 
 <pre>
-      @javax.jdo.annotations.Column(name = "attachment_bytes", sqlType = 
"VARBINARY", length=2048)
+  @javax.jdo.annotations.Persistent(defaultFetchGroup="false", columns = {
+      @javax.jdo.annotations.Column(name = "attachment_name"),
+      @javax.jdo.annotations.Column(name = "attachment_mimetype"),
+      @javax.jdo.annotations.Column(name = "attachment_chars", sqlType = 
"CLOB")
+  })
+  private Clob doc;
+
+  @Mandatory
+  public Clob getDoc() {
+    return doc;
+  }
+  public void setDoc(final Clob doc) {
+    this.doc = doc;
+  }
+</pre>
+
+or `VARCHAR`:
+
+<pre>
+      @javax.jdo.annotations.Column(name = "attachment_chars", sqlType = 
"VARCHAR", length=2048)
 </pre>
 
-The maximum allowed length for a `VARBINARY` will vary by database vendor.  
Obviously, only do this if you are sure that the data to be mapped fits into 
the smaller size.  
 
-Mapping `Clob`s works the exact same way, but the `@Column#sqlType` attribute 
will either be `CLOB`
+# Mapping to VARBINARY or VARCHAR
+
+Instead of mapping to a `Blob` or `Clob` datatype, you might also specify map 
to a `VARBINARY` or `VARCHAR`.  In this case you will need to specify a length. 
 For example:
 
 <pre>
-      @javax.jdo.annotations.Column(name = "attachment_chars", sqlType = 
"CLOB")
+      @javax.jdo.annotations.Column(name = "attachment_bytes", sqlType = 
"VARBINARY", length=2048)
 </pre>
 
-or `VARCHAR`, 
+or
 
 <pre>
       @javax.jdo.annotations.Column(name = "attachment_chars", sqlType = 
"VARCHAR", length=2048)
 </pre>
 
+Support and maximum allowed length will vary by database vendor.


Reply via email to