// which would cause our tx to rollback. the next sync should help us survive this failure.
pkg = this.contentManager.persistOrMergePackageSafely(pkg);
}
// find and, if necessary create, the architecture
Architecture arch = new Architecture(newDetails.getArchitectureName());
if (!knownArchitectures.containsKey(arch)) {
q = entityManager.createNamedQuery(Architecture.QUERY_FIND_BY_NAME);
q.setParameter("name", arch.getName());
try {
arch = (Architecture) q.getSingleResult();
knownArchitectures.put(arch, arch); // cache it so we don't have to keep querying the DB
} catch (NoResultException nre) {
log.info("Content source adapter found a previously unknown architecture [" + arch
+ "] - it will be added to the list of known architectures");
}
} else {
arch = knownArchitectures.get(arch);
}
// now finally create the new package version - this cascade-persists down several levels
// note that other content sources might already be previously defined this, so only
// persist it if it does not yet exist
PackageVersion pv = new PackageVersion(pkg, newDetails.getVersion(), arch);
pv.setDisplayName(newDetails.getDisplayName());
pv.setDisplayVersion(newDetails.getDisplayVersion());
pv.setExtraProperties(newDetails.getExtraProperties());
pv.setFileCreatedDate(newDetails.getFileCreatedDate());
pv.setFileName(newDetails.getFileName());
pv.setFileSize(newDetails.getFileSize());
pv.setLicenseName(newDetails.getLicenseName());
pv.setLicenseVersion(newDetails.getLicenseVersion());
pv.setLongDescription(newDetails.getLongDescription());
pv.setMD5(newDetails.getMD5());
pv.setMetadata(newDetails.getMetadata());
pv.setSHA256(newDetails.getSHA256());
pv.setShortDescription(newDetails.getShortDescription());
q = entityManager.createNamedQuery(PackageVersion.QUERY_FIND_BY_PACKAGE_DETAILS_KEY);
q.setParameter("packageName", newDetails.getName());
q.setParameter("packageTypeName", pt.getName());
q.setParameter("resourceType", rt);
q.setParameter("architectureName", arch.getName());
q.setParameter("version", newDetails.getVersion());
try {
PackageVersion pvExisting = (PackageVersion) q.getSingleResult();