private PackageBits loadPackageBitsH2(InputStream packageBitStream, int packageVersionId, String packageName,
String packageVersion, PackageBits existingBits, Map<String, String> contentDetails) {
PackageBits bits = null;
PackageBitsBlob blob = null;
// The blob cannot be updated, so we'll need to create a whole new row.
if (null != existingBits) {
blob = entityManager.find(PackageBitsBlob.class, existingBits.getId());
entityManager.remove(blob);
entityManager.flush();
}
// We have to work backwards to avoid constraint violations. PackageBits requires a PackageBitsBlob,
// so create and persist that first, getting the ID
blob = new PackageBitsBlob();
// just set the blob now, no streaming. The assumption is that H2 (demo) will not be using large blobs
byte[] bytes = StreamUtil.slurp(packageBitStream);
blob.setBits(bytes);
entityManager.persist(blob);
entityManager.flush();
// Now create the PackageBits entity and assign the Id and blob. Note, do not persist the
// entity, the row already exists (due to the blob persist above). Just perform and flush the update.
bits = new PackageBits();
bits.setId(blob.getId());
bits.setBlob(blob);
entityManager.flush();
//locate related packageVersion
PackageVersion pv = entityManager.find(PackageVersion.class, packageVersionId);