List<ValueData> vdata = data.getValues();
for (int i = 0; i < vdata.size(); i++)
{
ValueData vd = vdata.get(i);
ValueIOChannel channel = this.containerConfig.valueStorageProvider.getApplicableChannel(data, i);
InputStream stream;
int streamLength;
String storageId;
if (channel == null)
{
// prepare write of Value in database
if (vd.isByteArray())
{
byte[] dataBytes = vd.getAsByteArray();
stream = new ByteArrayInputStream(dataBytes);
streamLength = dataBytes.length;
}
else
{
StreamPersistedValueData streamData = (StreamPersistedValueData)vd;
SwapFile swapFile =
SwapFile.get(this.containerConfig.spoolConfig.tempDirectory,
cid + i + "." + data.getPersistedVersion(),this.containerConfig.spoolConfig.fileCleaner);
try
{
WRITE_VALUE_HELPER.writeStreamedValue(swapFile, streamData);
}
finally
{
swapFile.spoolDone();
}
long vlen = PrivilegedFileHelper.length(swapFile);
if (vlen <= Integer.MAX_VALUE)
{
streamLength = (int)vlen;
}
else
{
throw new RepositoryException("Value data large of allowed by JDBC (Integer.MAX_VALUE) " + vlen
+ ". Property " + data.getQPath().getAsString());
}
stream = streamData.getAsStream();
}
storageId = null;
}
else
{
// write Value in external VS
channel.write(data.getIdentifier(), vd);
valueChanges.add(channel);
storageId = channel.getStorageId();
stream = null;
streamLength = 0;
}
addValueData(cid, i, stream, streamLength, storageId);
}