Skip to content

Commit

Permalink
QE: Get rid of tools pool repos
Browse files Browse the repository at this point in the history
  • Loading branch information
srbarrios committed Feb 2, 2025
1 parent 3ce7e15 commit e068dfb
Show file tree
Hide file tree
Showing 40 changed files with 537 additions and 512 deletions.
10 changes: 5 additions & 5 deletions java/code/src/com/redhat/rhn/domain/audit/ScapFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.LongType;
import org.hibernate.type.StringType;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -77,8 +78,8 @@ public static void delete(XccdfTestResult tr) {
public static void clearTestResult(long serverId, long actionId) {
List<XccdfTestResult> results = getSession()
.getNamedQuery("XccdfTestResult.findByActionId")
.setParameter("serverId", serverId, StandardBasicTypes.LONG)
.setParameter("actionId", actionId, StandardBasicTypes.LONG)
.setParameter("serverId", serverId, LongType.INSTANCE)
.setParameter("actionId", actionId, LongType.INSTANCE)
.list();
results.forEach(ScapFactory::delete);
}
Expand Down Expand Up @@ -120,8 +121,7 @@ public static Optional<XccdfRuleResultType> lookupRuleResultType(String label) {
String sql = "SELECT * FROM rhnXccdfRuleResultType WHERE label = :label";
XccdfRuleResultType result =
getSession().createNativeQuery(sql, XccdfRuleResultType.class)
.setParameter("label", label, StandardBasicTypes.STRING)
.getResultStream().findFirst().orElse(null);
.setParameter("label", label, StringType.INSTANCE).getResultStream().findFirst().orElse(null);
return Optional.ofNullable(result);
}

Expand Down
46 changes: 29 additions & 17 deletions java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import org.apache.logging.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.query.Query;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.IntegerType;
import org.hibernate.type.LongType;
import org.hibernate.type.StringType;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -395,7 +397,11 @@ public static List<Channel> getAccessibleChannelsByOrg(Long orgid) {
* @return list of channel architectures
*/
public static List<ChannelArch> getChannelArchitectures() {
return getSession().createNativeQuery("SELECT * FROM rhnChannelArch", ChannelArch.class).getResultList();
Session session = getSession();
String sql = "SELECT * FROM rhnChannelArch";
List<ChannelArch> channelArchList
= session.createNativeQuery(sql, ChannelArch.class).getResultList();
return channelArchList;
}

/**
Expand Down Expand Up @@ -430,7 +436,7 @@ public static ChannelArch findArchByLabel(String label) {
Session session = getSession();
String sql = "SELECT * FROM rhnChannelArch WHERE label = :label";
return session.createNativeQuery(sql, ChannelArch.class)
.setParameter(LABEL, label, StandardBasicTypes.STRING)
.setParameter(LABEL, label, StringType.INSTANCE)
.uniqueResult();
}

Expand Down Expand Up @@ -465,7 +471,7 @@ public static Channel lookupByLabel(String label) {
LEFT JOIN rhnChannelCloned cl ON c.id = cl.id
WHERE c.label = :label""";
return session.createNativeQuery(sql, Channel.class)
.setParameter(LABEL, label, StandardBasicTypes.STRING)
.setParameter(LABEL, label, StringType.INSTANCE)
.uniqueResult();
}

Expand Down Expand Up @@ -812,7 +818,7 @@ public static ChannelSyncFlag lookupChannelReposyncFlag(Channel channel) {
return getSession()
.createNativeQuery(
"SELECT * FROM rhnChannelSyncFlag WHERE channel_id = :channel", ChannelSyncFlag.class)
.setParameter("channel", channel.getId(), StandardBasicTypes.LONG)
.setParameter("channel", channel.getId(), LongType.INSTANCE)
.getSingleResult();
}

Expand Down Expand Up @@ -1090,8 +1096,8 @@ public static Package lookupPackageByFilename(Channel channel,

List<Package> pkgs = HibernateFactory.getSession()
.getNamedQuery("Channel.packageByFileName")
.setParameter("pathlike", "%/" + fileName, StandardBasicTypes.STRING)
.setParameter("channel_id", channel.getId(), StandardBasicTypes.LONG)
.setParameter("pathlike", "%/" + fileName, StringType.INSTANCE)
.setParameter("channel_id", channel.getId(), LongType.INSTANCE)
.list();
if (pkgs.isEmpty()) {
return null;
Expand All @@ -1112,10 +1118,10 @@ public static Package lookupPackageByFilenameAndRange(Channel channel,

List<Package> pkgs = HibernateFactory.getSession()
.getNamedQuery("Channel.packageByFileNameAndRange")
.setParameter("pathlike", "%/" + fileName, StandardBasicTypes.STRING)
.setParameter("channel_id", channel.getId(), StandardBasicTypes.LONG)
.setParameter("headerStart", headerStart, StandardBasicTypes.INTEGER)
.setParameter("headerEnd", headerEnd, StandardBasicTypes.INTEGER).list();
.setParameter("pathlike", "%/" + fileName, StringType.INSTANCE)
.setParameter("channel_id", channel.getId(), LongType.INSTANCE)
.setParameter("headerStart", headerStart, IntegerType.INSTANCE)
.setParameter("headerEnd", headerEnd, IntegerType.INSTANCE).list();
if (pkgs.isEmpty()) {
return null;
}
Expand All @@ -1135,7 +1141,7 @@ public static boolean containsDistributions(Channel ch) {
String sql
= "SELECT COUNT(*) FROM rhnKickstartableTree WHERE channel_id = :channelId";
Number count = (Number) session.createNativeQuery(sql)
.setParameter("channelId", ch.getId(), StandardBasicTypes.LONG).getSingleResult();
.setParameter("channelId", ch.getId(), LongType.INSTANCE).getSingleResult();
return count.intValue() > 0;
}

Expand Down Expand Up @@ -1249,8 +1255,11 @@ public static List<Channel> listCustomChannelsWithRepositories() {
*/
@SuppressWarnings("unchecked")
public static List<ContentSource> listVendorContentSources() {
return getSession().createNativeQuery("SELECT * FROM rhnContentSource WHERE org_id IS NULL",
ContentSource.class).getResultList();
Session session = getSession();
String sql = "SELECT * FROM rhnContentSource WHERE org_id IS NULL";
List<ContentSource> contentSources
= session.createNativeQuery(sql, ContentSource.class).getResultList();
return contentSources;
}

/**
Expand Down Expand Up @@ -1324,15 +1333,18 @@ public static ChannelProduct findChannelProduct(String product, String version)
Session session = getSession();
String sql
= "SELECT * FROM rhnChannelProduct WHERE product = :product AND version = :version";
Query<ChannelProduct> query = session.createNativeQuery(sql, ChannelProduct.class);
query.setParameter("product", product, StandardBasicTypes.STRING);
query.setParameter("version", version, StandardBasicTypes.STRING);
Query<ChannelProduct> query = session.createNativeQuery(sql, ChannelProduct.class);
query.setParameter("product", product, StringType.INSTANCE);
query.setParameter("version", version, StringType.INSTANCE);
try {
return query.getSingleResult();
}
catch (NoResultException e) {
return null;
}
catch (Exception e) {
throw new RuntimeException("Error retrieving ChannelProduct", e);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static ChannelFamily lookupByLabel(String label, Org org) {
query.setParameter("org", org.getId());
}
else {
query.setParameter("org", -1);
query.setParameter("org", -1);
}

try {
Expand All @@ -97,6 +97,9 @@ public static ChannelFamily lookupByLabel(String label, Org org) {
catch (NoResultException e) {
return null;
}
catch (Exception e) {
throw new RuntimeException("Error retrieving ChannelFamily", e);
}
}

/**
Expand Down Expand Up @@ -238,9 +241,18 @@ public static List<ChannelFamily> lookupByLabelLike(String label, Org org) {
query.setParameter("org", org.getId());
}
else {
query.setParameter("org", -1);
query.setParameter("org", -1);
}

try {
return query.getResultList();
}
catch (NoResultException e) {
return null;
}
catch (Exception e) {
throw new RuntimeException("Error retrieving ChannelFamily", e);
}
return query.getResultList();
}

/**
Expand Down
13 changes: 7 additions & 6 deletions java/code/src/com/redhat/rhn/domain/common/CommonFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.LongType;
import org.hibernate.type.StringType;

import java.util.Calendar;
import java.util.Date;
Expand Down Expand Up @@ -92,8 +93,8 @@ public static FileList lookupFileList(Long idIn, Org org) {
SELECT * from rhnFileList
WHERE id = :id
and org_id = :org_id """, FileList.class)
.setParameter("id", idIn, StandardBasicTypes.LONG)
.setParameter("org_id", org.getId(), StandardBasicTypes.LONG)
.setParameter("id", idIn, LongType.INSTANCE)
.setParameter("org_id", org.getId(), LongType.INSTANCE)
.uniqueResult();
}

Expand All @@ -108,8 +109,8 @@ public static FileList lookupFileList(String labelIn, Org org) {
//look for Kickstart data by label
session = HibernateFactory.getSession();
return (FileList) session.getNamedQuery("FileList.findByLabelAndOrg")
.setParameter("label", labelIn, StandardBasicTypes.STRING)
.setParameter("org_id", org.getId(), StandardBasicTypes.LONG)
.setParameter("label", labelIn, StringType.INSTANCE)
.setParameter("org_id", org.getId(), LongType.INSTANCE)
.uniqueResult();
}

Expand Down Expand Up @@ -156,7 +157,7 @@ public static void saveTinyUrl(TinyUrl urlIn) {
public static TinyUrl lookupTinyUrl(String tokenIn) {
Session session = HibernateFactory.getSession();
return (TinyUrl) session.getNamedQuery("TinyUrl.findByToken")
.setParameter("token", tokenIn, StandardBasicTypes.STRING)
.setParameter("token", tokenIn, StringType.INSTANCE)
.uniqueResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
import org.apache.logging.log4j.Logger;
import org.hibernate.ObjectNotFoundException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.hibernate.query.Query;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.LongType;
import org.hibernate.type.StringType;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -46,6 +48,10 @@
import java.util.Map;
import java.util.Optional;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

/**
* ConfigurationFactory. For use when dealing with ConfigChannel, ConfigChannelType,
* ConfigFile, ConfigRevision, ConfigFileState, ConfigContent, and ConfigInfo.
Expand Down Expand Up @@ -351,15 +357,11 @@ public static ConfigRevision commit(ConfigRevision revision) {
* @return the list of global config channels
*/
public static List<ConfigChannel> listGlobalChannels() {
return getSession().createNativeQuery("""
SELECT * from rhnConfigChannel
WHERE
confchan_type_id = :confchan_type_id_normal
OR confchan_type_id = :confchan_type_id_state
""", ConfigChannel.class)
.setParameter("confchan_type_id_normal", ConfigChannelType.normal().getId(), StandardBasicTypes.LONG)
.setParameter("confchan_type_id_state", ConfigChannelType.state().getId(), StandardBasicTypes.LONG)
.getResultList();
CriteriaBuilder builder = getSession().getCriteriaBuilder();
CriteriaQuery<ConfigChannel> criteria = builder.createQuery(ConfigChannel.class);
Root<ConfigChannel> root = criteria.from(ConfigChannel.class);
criteria.where(root.get("configChannelType").in(ConfigChannelType.normal(), ConfigChannelType.state()));
return getSession().createQuery(criteria).getResultList();
}

/**
Expand All @@ -383,16 +385,12 @@ public static ConfigChannel lookupConfigChannelById(Long id) {
public static ConfigChannel lookupConfigChannelByLabel(String label,
Org org,
ConfigChannelType cct) {
return getSession().createNativeQuery("""
SELECT * from rhnConfigChannel
WHERE label = :label
AND org_id = :org_id
AND confchan_type_id = :confchan_type_id
""", ConfigChannel.class)
.setParameter("label", label, StandardBasicTypes.STRING)
.setParameter("org_id", org.getId(), StandardBasicTypes.LONG)
.setParameter("confchan_type_id", cct.getId(), StandardBasicTypes.LONG)
.uniqueResult();
Session session = HibernateFactory.getSession();
return (ConfigChannel) session.createCriteria(ConfigChannel.class).
add(Restrictions.eq("org", org)).
add(Restrictions.eq("label", label)).
add(Restrictions.eq("configChannelType", cct)).
uniqueResult();
}

/**
Expand All @@ -404,19 +402,14 @@ public static ConfigChannel lookupConfigChannelByLabel(String label,
*/
public static Optional<ConfigChannel> lookupGlobalConfigChannelByLabel(String label, Org org) {

return getSession().createNativeQuery("""
SELECT * from rhnConfigChannel
WHERE label = :label
AND org_id = :org_id
AND (
confchan_type_id = :confchan_type_id_normal
OR confchan_type_id = :confchan_type_id_state)
""", ConfigChannel.class)
.setParameter("label", label, StandardBasicTypes.STRING)
.setParameter("org_id", org.getId(), StandardBasicTypes.LONG)
.setParameter("confchan_type_id_normal", ConfigChannelType.normal().getId(), StandardBasicTypes.LONG)
.setParameter("confchan_type_id_state", ConfigChannelType.state().getId(), StandardBasicTypes.LONG)
.uniqueResultOptional();
CriteriaBuilder builder = getSession().getCriteriaBuilder();
CriteriaQuery<ConfigChannel> criteria = builder.createQuery(ConfigChannel.class);
Root<ConfigChannel> root = criteria.from(ConfigChannel.class);
criteria.where(builder.and(
builder.equal(root.get("label"), label)),
builder.equal(root.get("org"), org),
root.get("configChannelType").in(ConfigChannelType.normal(), ConfigChannelType.state()));
return getSession().createQuery(criteria).uniqueResultOptional();
}

/**
Expand All @@ -440,9 +433,9 @@ public static ConfigFile lookupConfigFileByChannelAndName(Long channel, Long nam
Session session = HibernateFactory.getSession();
Query<ConfigFile> query =
session.getNamedQuery("ConfigFile.findByChannelAndName")
.setParameter("channel_id", channel, StandardBasicTypes.LONG)
.setParameter("name_id", name, StandardBasicTypes.LONG)
.setParameter("state_id", ConfigFileState.normal().getId(), StandardBasicTypes.LONG);
.setParameter("channel_id", channel, LongType.INSTANCE)
.setParameter("name_id", name, LongType.INSTANCE)
.setParameter("state_id", ConfigFileState.normal().getId(), LongType.INSTANCE);
try {
return query.uniqueResult();
}
Expand Down Expand Up @@ -472,7 +465,7 @@ public static ConfigRevision lookupConfigRevisionById(Long id) {
public static ConfigRevision lookupConfigRevisionByRevId(ConfigFile cf, Long revId) {
Session session = HibernateFactory.getSession();
Query<ConfigRevision> q = session.getNamedQuery("ConfigRevision.findByRevisionAndConfigFile");
q.setParameter("rev", revId, StandardBasicTypes.LONG);
q.setParameter("rev", revId, LongType.INSTANCE);
q.setParameter("cf", cf);
return q.uniqueResult();
}
Expand Down Expand Up @@ -523,7 +516,7 @@ static ConfigChannelType lookupConfigChannelTypeByLabel(String label) {
Session session = HibernateFactory.getSession();
return (ConfigChannelType)
session.getNamedQuery("ConfigChannelType.findByLabel")
.setParameter("label", label, StandardBasicTypes.STRING)
.setParameter("label", label, StringType.INSTANCE)
//Retrieve from cache if there
.setCacheable(true)
.uniqueResult();
Expand All @@ -540,7 +533,7 @@ static ConfigChannelType lookupConfigChannelTypeByLabel(String label) {
static ConfigFileState lookupConfigFileStateByLabel(String label) {
Session session = HibernateFactory.getSession();
return (ConfigFileState)session.getNamedQuery("ConfigFileState.findByLabel")
.setParameter("label", label, StandardBasicTypes.STRING)
.setParameter("label", label, StringType.INSTANCE)
//Retrieve from cache if there
.setCacheable(true)
.uniqueResult();
Expand All @@ -554,7 +547,7 @@ static ConfigFileState lookupConfigFileStateByLabel(String label) {
static ConfigFileType lookupConfigFileTypeByLabel(String label) {
Session session = HibernateFactory.getSession();
return (ConfigFileType)session.getNamedQuery("ConfigFileType.findByLabel")
.setParameter("label", label, StandardBasicTypes.STRING)
.setParameter("label", label, StringType.INSTANCE)
//Retrieve from cache if there
.setCacheable(true)
.uniqueResult();
Expand Down
Loading

0 comments on commit e068dfb

Please sign in to comment.