= BlobJpaEmbeddable
:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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.

A utility class to enable the persisting of xref:refguide:applib:index/value/Blob.adoc[Blob] s.

Although JPA supports custom value types, these can only be for simple values; seeeclipse-ee4j/jpa-api/issues/105.

EclipseLink _does_ provide its own extension,Transformation API, but there's a lot of boilerplate involved even so.

This class provides support for an alternative approach, where the Causeway xref:refguide:applib:index/value/Blob.adoc[Blob] is marshalled in and out of this class.

Example usage:

----

    @Embedded
    private BlobJpaEmbeddable pdf;

    @Property()
    @PropertyLayout()
    public Blob getPdf() {
        return BlobJpaEmbeddable.toBlob(pdf);
    }
    public void setPdf(final Blob pdf) {
        this.pdf = BlobJpaEmbeddable.fromBlob(pdf);
    }
   
----

Lastly; note that _javax.persistence.AttributeOverrides_ and _javax.persistence.AttributeOverride_ provide a standardised way of fine-tuning the column definitions.

== API

[source,java]
.BlobJpaEmbeddable.java
----
class BlobJpaEmbeddable {
  BlobJpaEmbeddable fromBlob(Blob blob)     // <.>
  Blob toBlob(BlobJpaEmbeddable blobJpaEmbeddable)     // <.>
  Blob asBlob()
  String toString()
  boolean equals(Object o)
  int hashCode()
}
----

<.> xref:#fromBlob_Blob[fromBlob(Blob)]
+
--
Factory method to marshall a xref:refguide:applib:index/value/Blob.adoc[Blob] into a xref:refguide:persistence:index/jpa/applib/types/BlobJpaEmbeddable.adoc[BlobJpaEmbeddable]
--
<.> xref:#toBlob_BlobJpaEmbeddable[toBlob(BlobJpaEmbeddable)]
+
--
Reciprocal method to marshall a xref:refguide:persistence:index/jpa/applib/types/BlobJpaEmbeddable.adoc[BlobJpaEmbeddable] into a xref:refguide:applib:index/value/Blob.adoc[Blob]
--

== Members

[#fromBlob_Blob]
=== fromBlob(Blob)

Factory method to marshall a xref:refguide:applib:index/value/Blob.adoc[Blob] into a xref:refguide:persistence:index/jpa/applib/types/BlobJpaEmbeddable.adoc[BlobJpaEmbeddable]

[#toBlob_BlobJpaEmbeddable]
=== toBlob(BlobJpaEmbeddable)

Reciprocal method to marshall a xref:refguide:persistence:index/jpa/applib/types/BlobJpaEmbeddable.adoc[BlobJpaEmbeddable] into a xref:refguide:applib:index/value/Blob.adoc[Blob]
