Hvis du bruger MySQL, kræver det en ekstra ExceptionInterceptor
sammen med Blob-implementeringen. Du kan have en tilpasset implementering af ExceptionInterceptor
og brug den til at initialisere Blob-feltet.
Koden til at opnå det ville være som følger
import java.sql.Blob;
import java.sql.Clob;
import java.util.Properties;
import org.apache.olingo.odata2.jpa.processor.api.OnJPAWriteContent;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
import com.mysql.cj.exceptions.ExceptionInterceptor;
import com.mysql.cj.log.Log;
public class CustomOnJPAWriteContent implements OnJPAWriteContent {
@Override
public Blob getJPABlob(byte[] binaryData) throws ODataJPARuntimeException {
return new com.mysql.cj.jdbc.Blob(binaryData, exceptionInterceptor);
}
@Override
public Clob getJPAClob(char[] characterData) throws ODataJPARuntimeException {
return new com.mysql.cj.jdbc.Clob(new String(characterData), exceptionInterceptor);
}
ExceptionInterceptor exceptionInterceptor = new ExceptionInterceptor() {
@Override
public Exception interceptException(Exception sqlEx) {
// TODO Auto-generated method stub
return null;
}
@Override
public ExceptionInterceptor init(Properties props, Log log) {
// TODO Auto-generated method stub
return null;
}
@Override
public void destroy() {
// TODO Auto-generated method stub
}
};
}