The Data Access Accelerator Library
You can use the methods in the Data Access Accelerator (DAA) library to improve performance when your Java™ code manipulates native data.
For an overview of this library, see Native data operations.
For information about the classes that are available, see the API documentation.
Example: Converting a packed decimal to a BigDecimal object
In this example, a signed packed decimal of 100 digits (not including the sign), is stored in a
byte array called pdarray
.
Normal code:
...
String pdsb = new StringBuffer();
int precision = 100;
if (isNegative(pdarray, precision))
pdsb.append('-');
for (int i = 0; i < precision; ++i)
pdsb.append(getDigit(pdarray, i) + '0');
return new BigDecimal(pdsb.toString());
...
Equivalent code, which uses the DAA API:
...
return com.ibm.dataaccess.DecimalData.convertPackedDecimalToBigDecimal(pdarray, 0, precision, 0, false);
...
Example: Adding two packed decimal types
In this example, two packed decimals, pdarray1
and pdarray2
,
are added, and the result, pdarrayResult
, is returned. The packed decimals, and the
result, are stored as byte arrays. The precision (the number of decimal digits in the decimal value,
not including the sign) of the two initial arrays is 100.
Without using the Data Access Accelerator API, you have to write your own methods to convert
between packed decimal and BigDecimal formats (for example, by using an intermediate String object):
...
BigDecimal operand1 = myPackedDecimalToBigDecimalMethod(pdarray1, 100);
BigDecimal operand2 = myPackedDecimalToBigDecimalMethod(pdarray2, 100);
BigDecimal result = operand1.add(operand2);
myBigDecimalToPackedDecimalMethod(result, pdarrayResult);
return pdarrayResult;
...
Equivalent code, which uses the DAA API. The precision of the result is 1 greater than the
precision of the two initial decimals. All the packed decimals have an offset (where the packed
decimal begins) of 0:
...
com.ibm.dataaccess.DecimalData.addPackedDecimal(pdrrayResult, 0, 101, pdarray1, 0, 100, pdarray2, 0, 100, false);
return pdarrayResult;
...