Beispiel #1
0
  public String getString(Column storeColumn) {
    int index = storeColumn.getColumnId();
    NdbRecAttr ndbRecAttr = ndbRecAttrs[index];
    if (ndbRecAttr.isNULL() == 1) return null;
    int prefixLength = storeColumn.getPrefixLength();
    int actualLength;
    int offset = offsets[index];
    byteBuffer.limit(byteBuffer.capacity());
    switch (prefixLength) {
      case 0:
        actualLength = lengths[index];
        break;
      case 1:
        actualLength = (byteBuffer.get(offset) + 256) % 256;
        offset += 1;
        break;
      case 2:
        actualLength = (byteBuffer.get(offset) + 256) % 256;
        int length2 = (byteBuffer.get(offset + 1) + 256) % 256;
        actualLength += 256 * length2;
        offset += 2;
        break;
      default:
        throw new ClusterJFatalInternalException(
            local.message("ERR_Invalid_Prefix_Length", prefixLength));
    }

    byteBuffer.position(offset);
    byteBuffer.limit(offset + actualLength);

    String result = Utility.decode(byteBuffer, storeColumn.getCharsetNumber(), bufferManager);
    byteBuffer.clear();
    return result;
  }
Beispiel #2
0
 public byte[] getBytes(Column storeColumn) {
   int index = storeColumn.getColumnId();
   NdbRecAttr ndbRecAttr = ndbRecAttrs[index];
   if (ndbRecAttr.isNULL() == 1) return null;
   int prefixLength = storeColumn.getPrefixLength();
   int actualLength = lengths[index];
   int offset = offsets[index];
   switch (prefixLength) {
     case 0:
       break;
     case 1:
       actualLength = (byteBuffer.get(offset) + 256) % 256;
       offset += 1;
       break;
     case 2:
       actualLength = (byteBuffer.get(offset) + 256) % 256;
       int length2 = (byteBuffer.get(offset + 1) + 256) % 256;
       actualLength += 256 * length2;
       offset += 2;
       break;
     default:
       throw new ClusterJFatalInternalException(
           local.message("ERR_Invalid_Prefix_Length", prefixLength));
   }
   byteBuffer.position(offset);
   byte[] result = new byte[actualLength];
   byteBuffer.get(result);
   return result;
 }
Beispiel #3
0
 public BigDecimal getDecimal(Column storeColumn) {
   int index = storeColumn.getColumnId();
   int offset = offsets[index];
   int precision = storeColumn.getPrecision();
   int scale = storeColumn.getScale();
   int length = Utility.getDecimalColumnSpace(precision, scale);
   byteBuffer.position(offset);
   return Utility.getDecimal(byteBuffer, length, precision, scale);
 }
 public void setBytes(Column storeColumn, byte[] value) {
   // TODO use the string storage buffer instead of allocating a new buffer for each value
   int length = value.length;
   if (length > storeColumn.getLength()) {
     throw new ClusterJUserException(
         local.message(
             "ERR_Data_Too_Long", storeColumn.getName(), storeColumn.getLength(), length));
   }
   ByteBuffer buffer = Utility.convertValue(storeColumn, value);
   int returnCode = ndbOperation.setValue(storeColumn.getColumnId(), buffer);
   handleError(returnCode, ndbOperation);
 }
 public void setString(Column storeColumn, String value) {
   ByteBuffer stringStorageBuffer = Utility.encode(value, storeColumn, bufferManager);
   int length = stringStorageBuffer.remaining() - storeColumn.getPrefixLength();
   if (length > storeColumn.getLength()) {
     throw new ClusterJUserException(
         local.message(
             "ERR_Data_Too_Long", storeColumn.getName(), storeColumn.getLength(), length));
   }
   int returnCode = ndbOperation.setValue(storeColumn.getColumnId(), stringStorageBuffer);
   bufferManager.clearStringStorageBuffer();
   handleError(returnCode, ndbOperation);
 }
 public void equalBytes(Column storeColumn, byte[] value) {
   if (logger.isDetailEnabled())
     logger.detail(
         "Column: "
             + storeColumn.getName()
             + " columnId: "
             + storeColumn.getColumnId()
             + " data length: "
             + value.length);
   ByteBuffer buffer = Utility.convertValue(storeColumn, value);
   int returnCode = ndbOperation.equal(storeColumn.getName(), buffer);
   handleError(returnCode, ndbOperation);
 }
 public void equalByte(Column storeColumn, byte b) {
   try {
     ndbOperation.equalInt(storeColumn.getName(), (int) b);
   } catch (NdbApiException ndbApiException) {
     throw new ClusterJDatastoreException(local.message("ERR_Datastore"), ndbApiException);
   }
 }
 public void setDatetime(Column storeColumn, Timestamp value) {
   try {
     ndbOperation.setDatetime(storeColumn.getName(), value);
   } catch (NdbApiException ndbApiException) {
     throw new ClusterJDatastoreException(local.message("ERR_Datastore"), ndbApiException);
   }
 }
 public void setNull(Column storeColumn) {
   try {
     ndbOperation.setNull(storeColumn.getName());
   } catch (NdbApiException ndbApiException) {
     throw new ClusterJDatastoreException(local.message("ERR_Datastore"), ndbApiException);
   }
 }
 public void setByte(Column storeColumn, byte value) {
   try {
     ndbOperation.setInt(storeColumn.getName(), (int) value);
   } catch (NdbApiException ndbApiException) {
     throw new ClusterJDatastoreException(local.message("ERR_Datastore"), ndbApiException);
   }
 }
 public Blob getBlobHandle(Column storeColumn) {
   try {
     return new BlobImpl(ndbOperation.getBlobHandle(storeColumn.getName()));
   } catch (NdbApiException ndbApiException) {
     throw new ClusterJDatastoreException(local.message("ERR_Datastore"), ndbApiException);
   }
 }
Beispiel #12
0
 public Long getObjectLong(Column storeColumn) {
   int index = storeColumn.getColumnId();
   NdbRecAttr ndbRecAttr = ndbRecAttrs[index];
   return (ndbRecAttr.isNULL() == 1)
       ? null
       : Utility.getLong(storeColumn, ndbRecAttr.int64_value());
 }
 public void equalLong(Column storeColumn, long value) {
   try {
     ndbOperation.equalLong(storeColumn.getName(), value);
   } catch (NdbApiException ndbApiException) {
     throw new ClusterJDatastoreException(local.message("ERR_Datastore"), ndbApiException);
   }
 }
 public void equalTime(Column storeColumn, Time value) {
   try {
     Timestamp timestamp = new Timestamp(((Time) value).getTime());
     ndbOperation.equalDatetime(storeColumn.getName(), timestamp);
   } catch (NdbApiException ndbApiException) {
     throw new ClusterJDatastoreException(local.message("ERR_Datastore"), ndbApiException);
   }
 }
 public void setBoundFloat(Column storeColumn, BoundType type, Float value) {
   int returnCode =
       ndbIndexScanOperation.setBound(
           storeColumn.getName(),
           convertBoundType(type),
           Utility.convertValue(storeColumn, value));
   handleError(returnCode, ndbIndexScanOperation);
 }
Beispiel #16
0
 public Boolean getObjectBoolean(Column storeColumn) {
   int index = storeColumn.getColumnId();
   NdbRecAttr ndbRecAttr = ndbRecAttrs[index];
   if (ndbRecAttr.isNULL() == 1) {
     return null;
   } else {
     byte value = ndbRecAttr.int8_value();
     Boolean result = (Boolean.valueOf((value & 0x01) == 0x01));
     return result;
   }
 }
Beispiel #17
0
 /**
  * Construct the ResultDataImpl based on an NdbOperation, a list of columns to include in the
  * result, and the pre-computed buffer layout for the result.
  *
  * @param ndbOperation the NdbOperation
  * @param storeColumns the columns in the result
  * @param maximumColumnId the largest column id
  * @param bufferSize the size of the buffer needed
  * @param offsets the array of offsets indexed by column id
  * @param lengths the array of lengths indexed by column id
  * @param bufferManager the buffer manager
  * @param allocateNew true to allocate a new (unshared) result buffer
  */
 public ResultDataImpl(
     NdbOperation ndbOperation,
     List<Column> storeColumns,
     int maximumColumnId,
     int bufferSize,
     int[] offsets,
     int[] lengths,
     BufferManager bufferManager,
     boolean allocateNew) {
   this.ndbOperation = ndbOperation;
   this.bufferManager = bufferManager;
   // save the column list
   this.storeColumns = storeColumns.toArray(new Column[storeColumns.size()]);
   this.offsets = offsets;
   this.lengths = lengths;
   if (allocateNew) {
     byteBuffer = ByteBuffer.allocateDirect(bufferSize);
   } else {
     byteBuffer = bufferManager.getResultDataBuffer(bufferSize);
   }
   byteBuffer.order(ByteOrder.nativeOrder());
   // iterate the list of store columns and allocate an NdbRecAttr (via getValue) for each
   ndbRecAttrs = new NdbRecAttr[maximumColumnId + 1];
   for (Column storeColumn : storeColumns) {
     NdbRecAttr ndbRecAttr = null;
     int columnId = storeColumn.getColumnId();
     byteBuffer.position(offsets[columnId]);
     if (lengths[columnId] == 0) {
       // TODO: to help profiling
       ndbRecAttr = ndbOperation.getValue(columnId, null);
       //                ndbRecAttr = getValue(ndbOperation, columnId, null);
     } else {
       ndbRecAttr = ndbOperation.getValue(columnId, byteBuffer);
       //                ndbRecAttr = getValue(ndbOperation, columnId, byteBuffer);
     }
     handleError(ndbRecAttr, ndbOperation);
     ndbRecAttrs[columnId] = ndbRecAttr;
   }
 }
 public void equalBoolean(Column storeColumn, boolean booleanValue) {
   byte value = (booleanValue ? (byte) 0x01 : (byte) 0x00);
   int returnCode = ndbOperation.equal(storeColumn.getName(), value);
   handleError(returnCode, ndbOperation);
 }
 public void setShort(Column storeColumn, Short value) {
   int storeValue = Utility.convertShortValueForStorage(storeColumn, value);
   int returnCode = ndbOperation.setValue(storeColumn.getName(), storeValue);
   handleError(returnCode, ndbOperation);
 }
 public void setNull(Column storeColumn) {
   int returnCode = ndbOperation.setValue(storeColumn.getColumnId(), null);
   handleError(returnCode, ndbOperation);
 }
 public void setLong(Column storeColumn, long value) {
   long storeValue = Utility.convertLongValueForStorage(storeColumn, value);
   int returnCode = ndbOperation.setValue(storeColumn.getColumnId(), storeValue);
   handleError(returnCode, ndbOperation);
 }
 public void setInt(Column storeColumn, Integer value) {
   int returnCode = ndbOperation.setValue(storeColumn.getColumnId(), value);
   handleError(returnCode, ndbOperation);
 }
 public void setDecimal(Column storeColumn, BigDecimal value) {
   ByteBuffer buffer = Utility.convertValue(storeColumn, value);
   int returnCode = ndbOperation.setValue(storeColumn.getColumnId(), buffer);
   handleError(returnCode, ndbOperation);
 }
 public void setByte(Column storeColumn, byte value) {
   int storeValue = Utility.convertByteValueForStorage(storeColumn, value);
   int returnCode = ndbOperation.setValue(storeColumn.getColumnId(), storeValue);
   handleError(returnCode, ndbOperation);
 }
 public Blob getBlobHandle(Column storeColumn) {
   NdbBlob blobHandle = ndbOperation.getBlobHandleM(storeColumn.getColumnId());
   handleError(blobHandle, ndbOperation);
   return new BlobImpl(blobHandle);
 }
 public void getBlob(Column storeColumn) {
   NdbBlob ndbBlob = ndbOperation.getBlobHandleM(storeColumn.getColumnId());
   handleError(ndbBlob, ndbOperation);
 }
 public void equalString(Column storeColumn, String value) {
   ByteBuffer stringStorageBuffer = Utility.encode(value, storeColumn, bufferManager);
   int returnCode = ndbOperation.equal(storeColumn.getName(), stringStorageBuffer);
   bufferManager.clearStringStorageBuffer();
   handleError(returnCode, ndbOperation);
 }
 public void equalInt(Column storeColumn, int value) {
   int returnCode = ndbOperation.equal(storeColumn.getName(), value);
   handleError(returnCode, ndbOperation);
 }
 public void equalFloat(Column storeColumn, float value) {
   ByteBuffer buffer = Utility.convertValue(storeColumn, value);
   int returnCode = ndbOperation.equal(storeColumn.getName(), buffer);
   handleError(returnCode, ndbOperation);
 }
Beispiel #30
0
 public Double getObjectDouble(Column storeColumn) {
   int index = storeColumn.getColumnId();
   NdbRecAttr ndbRecAttr = ndbRecAttrs[index];
   return (ndbRecAttr.isNULL() == 1) ? null : getDouble(storeColumn);
 }