19 package com.mysql.clusterj.tie;
21 import java.nio.ByteBuffer;
23 import com.mysql.ndbjtie.ndbapi.NdbBlob;
25 import com.mysql.clusterj.ClusterJFatalInternalException;
27 import com.mysql.clusterj.core.store.Blob;
29 import com.mysql.clusterj.core.util.I18NHelper;
30 import com.mysql.clusterj.core.util.Logger;
31 import com.mysql.clusterj.core.util.LoggerFactoryService;
36 class BlobImpl
implements Blob {
39 static final I18NHelper local = I18NHelper
40 .getInstance(BlobImpl.class);
43 static final Logger logger = LoggerFactoryService.getFactory()
44 .getInstance(BlobImpl.class);
52 public Long getLength() {
53 long[] length =
new long[1];
54 int returnCode = ndbBlob.
getLength(length);
55 handleError(returnCode, ndbBlob);
59 public void readData(byte[] array,
int length) {
61 int[] lengthRead =
new int[] {length};
62 ByteBuffer buffer = ByteBuffer.allocateDirect(array.length);
63 int returnCode = ndbBlob.readData(buffer, lengthRead);
64 handleError(returnCode, ndbBlob);
65 if (lengthRead[0] != length) {
66 throw new ClusterJFatalInternalException(
67 local.message(
"ERR_Blob_Read_Data", length, lengthRead[0]));
73 public void writeData(byte[] array) {
75 if (array.length == 0)
return;
76 ByteBuffer buffer = null;
77 if (array.length > 0) {
78 buffer = ByteBuffer.allocateDirect(array.length);
82 int returnCode = ndbBlob.writeData(buffer, array.length);
83 handleError(returnCode, ndbBlob);
86 public void setValue(byte[] array) {
88 if (array.length == 0)
return;
89 ByteBuffer buffer = null;
90 if (array.length > 0) {
91 buffer = ByteBuffer.allocateDirect(array.length);
95 int returnCode = ndbBlob.setValue(buffer, array.length);
96 handleError(returnCode, ndbBlob);
99 public void setNull() {
100 int returnCode = ndbBlob.setNull();
101 handleError(returnCode, ndbBlob);
104 public void close() {
105 int returnCode = ndbBlob.close(
true);
106 handleError(returnCode, ndbBlob);
109 protected static void handleError(
int returnCode,
NdbBlob ndbBlob) {
110 if (returnCode == 0) {
113 Utility.throwError(returnCode, ndbBlob.
getNdbError());