Skip to content

Commit

Permalink
improve hibernate handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalmer committed Nov 2, 2024
1 parent 60fa5ff commit 0101fd2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
12 changes: 5 additions & 7 deletions java/code/src/com/redhat/rhn/domain/scc/SCCRepositoryAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
Expand All @@ -52,10 +52,8 @@
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "auth_type")
@Table(name = "suseSCCRepositoryAuth")
@NamedNativeQueries({
@NamedNativeQuery(name = "SCCRepositoryAuth.lookupRepoIdWithAuth",
query = "select distinct ra.repo_id from suseSCCRepositoryAuth ra")
})
@NamedNativeQuery(name = "SCCRepositoryAuth.lookupRepoIdWithAuth",
query = "select distinct ra.repo_id from suseSCCRepositoryAuth ra")
public abstract class SCCRepositoryAuth extends BaseDomainHelper {

private Long id;
Expand Down Expand Up @@ -115,7 +113,7 @@ public void setCredentials(RemoteCredentials credentialsIn) {
/**
* @return the contentSource
*/
@OneToOne
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "source_id")
public ContentSource getContentSource() {
return contentSource;
Expand All @@ -131,7 +129,7 @@ public void setContentSource(ContentSource contentSourceIn) {
/**
* @return Returns the products.
*/
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "repo_id", nullable = false)
public SCCRepository getRepo() {
return repo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ private void linkOrphanContentSource(ContentSource cs) {
},
() -> {
LOG.debug("No auth anymore - remove content source: {}", cs.getLabel());
c.getSources().remove(cs);
ChannelFactory.remove(cs);
});
return;
Expand All @@ -662,6 +663,7 @@ else if (cs.getSourceUrl().startsWith("file://")) {
},
() -> {
LOG.debug("No auth anymore - remove content source: {}", cs.getLabel());
c.getSources().remove(cs);
ChannelFactory.remove(cs);
});
return;
Expand Down Expand Up @@ -689,14 +691,14 @@ public void linkAndRefreshContentSource(String mirrorUrl) {
HibernateFactory.getSession().flush();
// find all CountentSource with org id == NULL which do not have a sccrepositoryauth
List<ContentSource> orphan = ChannelFactory.lookupOrphanVendorContentSources();
if (orphan != null) {
if (!orphan.isEmpty()) {
LOG.debug("found orphan vendor content sources: {}", orphan.size());
// find sccrepositoryauth and link or remove the ContentSource
for (ContentSource cs : orphan) {
linkOrphanContentSource(cs);
}
HibernateFactory.getSession().flush();
}
HibernateFactory.getSession().flush();

// find all rhnChannel with org id == null and no or incomplete content sources
List<Channel> incompleteVendorChannels = ChannelFactory.findIncompleteVendorChannels();
Expand All @@ -713,11 +715,12 @@ public void linkAndRefreshContentSource(String mirrorUrl) {

// check if this auth item is the "best" available auth for this repo
// if not, switch it over to the best
if (auth.getRepo().getBestAuth().isEmpty()) {
Optional<SCCRepositoryAuth> bestAuthOpt = auth.getRepo().getBestAuth();
if (bestAuthOpt.isEmpty()) {
LOG.warn("no best auth available for repo {}", auth.getRepo());
continue;
}
SCCRepositoryAuth bestAuth = auth.getRepo().getBestAuth().get();
SCCRepositoryAuth bestAuth = bestAuthOpt.get();
if (!bestAuth.equals(auth)) {
// we are not the "best" available repository auth item.
// remove the content source link and set it to the "best"
Expand Down Expand Up @@ -1009,7 +1012,10 @@ public void refreshRepositoriesAuthentication(
authList.stream()
.filter(repoAuth -> repoAuth.cloudRmtAuth().isEmpty()) // rmtAuth is handled elsewhere (where?)
.filter(repoAuth -> !repoIdsFromCredential.contains(repoAuth.getRepo().getSccId()))
.forEach(SCCCachingFactory::deleteRepositoryAuth);
.forEach(a -> {
a.getRepo().getRepositoryAuth().remove(a);
SCCCachingFactory.deleteRepositoryAuth(a);
});
}

private void generatePtfChannels(List<SCCRepositoryJson> repositories) {
Expand Down

0 comments on commit 0101fd2

Please sign in to comment.