JPA entities can have properties that are of type java.sql.Blob
or java.sql.Clob
. Internally, JPA entities can instantiate a JPA provider (Eclipse Link or Hibernate or ...) specific implementation
of the above two interfaces and bind them to the properties. To enable write on such properties using OData JPA Processor Library, an additional access modifier is required to be added to the JPA
entities. Following is the proposal on how OData JPA Processor Library handles java.sql.Blob
and java.sql.Clob
during metadata generation and runtime processing.
Based on the JPA entity property type, the pseudocode for generating the EDM is as below.
For java.sql.Blob
:
For java.sql.Clob
:
java.sql.Clob
and annotated with @Lob annotation.Edm.String
(with no max length unless a max length is specified).Prerequisites:
org.apache.olingo.odata2.jpa.processor.api.OnJPAWriteContent
.setOnJPAWriteContent
part of ODataJPAServiceFactory
.Following is the pseudocode for handling the java.sql.Blob
and java.sql.Clob
during runtime.
/* Callback Implementation */
public class OnDBWriteContent implements OnJPAWriteContent {
@Override
public Blob getJPABlob(byte[] binaryData) throws ODataJPARuntimeException {
try {
return new JDBCBlob(binaryData);
} catch (SerialException e) {
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
} catch (SQLException e) {
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
}
return null;
}
@Override
public Clob getJPAClob(char[] characterData) throws ODataJPARuntimeException {
try {
return new JDBCClob(new String(characterData));
} catch (SQLException e) {
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
}
return null;
}
}
/* Call Back registration in Service Factory */
public class JPAReferenceServiceFactory extends ODataJPAServiceFactory {
public static final OnJPAWriteContent onDBWriteContent = new OnDBWriteContent();
@Override
public ODataJPAContext initializeODataJPAContext()
throws ODataJPARuntimeException {
....
........
..............
setOnWriteJPAContent(onDBWriteContent); //Register Call Back
return oDataJPAContext;
}
}
OData JPA Processor Library internally does the following:
java.sql.Blob
or java.sql.Clob
.getJPABlob
or getJPAClob
respectively.Note: Step 3 is needed because the OData JPA Processor Library is not bound to any specific implementation of BLOB or CLOB interface.
Copyright © 2013-2023, The Apache Software Foundation
Apache Olingo, Olingo, Apache, the Apache feather, and
the Apache Olingo project logo are trademarks of the Apache Software
Foundation.