// then find the package and architecture, creating them if they do not exist;
// then create the new PV as well as the new PVCS mapping.
// if a repo is associated with the content source, the PV is directly associated with the repo.
for (ContentProviderPackageDetails newDetails : newPackages) {
ContentProviderPackageDetailsKey key = newDetails.getContentProviderPackageDetailsKey();
// find the new package's associated resource type (should already exist)
ResourceType rt = null;
if (key.getResourceTypeName() != null && key.getResourceTypePluginName() != null) {
rt = new ResourceType();
rt.setName(key.getResourceTypeName());
rt.setPlugin(key.getResourceTypePluginName());
if (!knownResourceTypes.containsKey(rt)) {
q = entityManager.createNamedQuery(ResourceType.QUERY_FIND_BY_NAME_AND_PLUGIN);
q.setParameter("name", rt.getName());
q.setParameter("plugin", rt.getPlugin());
try {
rt = (ResourceType) q.getSingleResult();
knownResourceTypes.put(rt, rt); // cache it so we don't have to keep querying the DB
knownProductVersions.put(rt, new HashMap<String, ProductVersion>());
} catch (NoResultException nre) {
log.warn("Content source adapter found a package for an unknown resource type ["
+ key.getResourceTypeName() + "|" + key.getResourceTypePluginName() + "] Skipping it.");
continue; // skip this one but move on to the next
}
} else {
rt = knownResourceTypes.get(rt);
}
}
// find the new package's type (package types should already exist, agent plugin descriptors define them)
PackageType pt = new PackageType(key.getPackageTypeName(), rt);
if (!knownPackageTypes.containsKey(pt)) {
if (rt != null) {
q = entityManager.createNamedQuery(PackageType.QUERY_FIND_BY_RESOURCE_TYPE_ID_AND_NAME);
q.setParameter("typeId", rt.getId());
} else {
q = entityManager.createNamedQuery(PackageType.QUERY_FIND_BY_NAME_AND_NULL_RESOURCE_TYPE);
}
q.setParameter("name", pt.getName());
try {
pt = (PackageType) q.getSingleResult();
pt.setResourceType(rt); // we don't fetch join this, but we already know it, so just set it
knownPackageTypes.put(pt, pt); // cache it so we don't have to keep querying the DB
} catch (NoResultException nre) {
log.warn("Content source adapter found a package of an unknown package type ["
+ key.getPackageTypeName() + "|" + rt + "] Skipping it.");
continue; // skip this one but move on to the next
}
} else {
pt = knownPackageTypes.get(pt);
}