diff --git a/java/code/src/com/redhat/rhn/common/hibernate/EmptyVarcharInterceptor.java b/java/code/src/com/redhat/rhn/common/hibernate/EmptyVarcharInterceptor.java index bbc7dac81e34..233b3801cd48 100644 --- a/java/code/src/com/redhat/rhn/common/hibernate/EmptyVarcharInterceptor.java +++ b/java/code/src/com/redhat/rhn/common/hibernate/EmptyVarcharInterceptor.java @@ -17,7 +17,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.hibernate.EmptyInterceptor; -import org.hibernate.type.StringType; import org.hibernate.type.Type; import java.io.Serializable; @@ -59,8 +58,7 @@ protected static boolean emptyStringToNull(Object entity, Serializable id, boolean modified = false; for (int i = 0; i < types.length; i++) { - // type is string (VARCHAR) and state is empty string - if ((types[i] instanceof StringType) && "".equals(state[i])) { + if ("".equals(state[i])) { if (LOG.isDebugEnabled()) { LOG.debug("Object {} is setting empty string {}", entity.getClass().getCanonicalName(), propertyNames[i]); diff --git a/java/code/src/com/redhat/rhn/domain/BaseDomainHelper.java b/java/code/src/com/redhat/rhn/domain/BaseDomainHelper.java index 76dbefcc1223..9b4615b9fc03 100644 --- a/java/code/src/com/redhat/rhn/domain/BaseDomainHelper.java +++ b/java/code/src/com/redhat/rhn/domain/BaseDomainHelper.java @@ -20,6 +20,7 @@ import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.UpdateTimestamp; +import java.io.Serializable; import java.util.Date; import javax.persistence.Column; @@ -31,7 +32,7 @@ * DB table: web_contact */ @MappedSuperclass -public abstract class BaseDomainHelper { +public abstract class BaseDomainHelper implements Serializable { private Date created = new Date(); private Date modified; diff --git a/java/code/src/com/redhat/rhn/domain/action/test/ActionTypeTest.java b/java/code/src/com/redhat/rhn/domain/action/test/ActionTypeTest.java index aba0cade5c78..41dd04532dff 100644 --- a/java/code/src/com/redhat/rhn/domain/action/test/ActionTypeTest.java +++ b/java/code/src/com/redhat/rhn/domain/action/test/ActionTypeTest.java @@ -22,6 +22,7 @@ import com.redhat.rhn.testing.RhnBaseTestCase; import org.hibernate.Session; +import org.hibernate.type.StringType; import org.junit.jupiter.api.Test; /** @@ -70,7 +71,7 @@ public void testFindByLabel() throws Exception { private ActionType lookupByLabel(String label) { Session session = HibernateFactory.getSession(); return (ActionType) session.getNamedQuery("ActionType.findByLabel") - .setString("label", label) + .setParameter("label", label, StringType.INSTANCE) //Retrieve from cache if there .setCacheable(true) .uniqueResult(); diff --git a/java/code/src/com/redhat/rhn/domain/audit/ScapFactory.java b/java/code/src/com/redhat/rhn/domain/audit/ScapFactory.java index 172fe46e9098..2023aec492f0 100644 --- a/java/code/src/com/redhat/rhn/domain/audit/ScapFactory.java +++ b/java/code/src/com/redhat/rhn/domain/audit/ScapFactory.java @@ -20,7 +20,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.hibernate.criterion.Restrictions; +import org.hibernate.type.LongType; +import org.hibernate.type.StringType; import java.util.List; import java.util.Map; @@ -77,8 +78,8 @@ public static void delete(XccdfTestResult tr) { public static void clearTestResult(long serverId, long actionId) { List results = getSession() .getNamedQuery("XccdfTestResult.findByActionId") - .setLong("serverId", serverId) - .setLong("actionId", actionId) + .setParameter("serverId", serverId, LongType.INSTANCE) + .setParameter("actionId", actionId, LongType.INSTANCE) .list(); results.forEach(ScapFactory::delete); } @@ -89,8 +90,7 @@ public static void clearTestResult(long serverId, long actionId) { * @return the {@link XccdfBenchmark} if any */ public static Optional lookupBenchmarkById(long benchmarkId) { - return Optional.ofNullable( - (XccdfBenchmark)getSession().get(XccdfBenchmark.class, benchmarkId)); + return Optional.ofNullable(getSession().get(XccdfBenchmark.class, benchmarkId)); } /** @@ -99,7 +99,7 @@ public static Optional lookupBenchmarkById(long benchmarkId) { * @return the {@link XccdfIdent} if any */ public static Optional lookupIdentById(long identId) { - return Optional.ofNullable((XccdfIdent)getSession().get(XccdfIdent.class, identId)); + return Optional.ofNullable(getSession().get(XccdfIdent.class, identId)); } /** @@ -108,20 +108,21 @@ public static Optional lookupIdentById(long identId) { * @return the {@link XccdfProfile} if any */ public static Optional lookupProfileById(long profileId) { - return Optional.ofNullable( - (XccdfProfile)getSession().get(XccdfProfile.class, profileId)); + return Optional.ofNullable(getSession().get(XccdfProfile.class, profileId)); } /** - * Find a {@link XccdfRuleResultType} by id. - * @param label label id - * @return the {@link XccdfRuleResultType} if any + * Queries an XccdfRuleResultType by its label. + * + * @param label the label of the XccdfRuleResultType + * @return optional of XccdfRuleResultType */ public static Optional lookupRuleResultType(String label) { - return getSession().createCriteria(XccdfRuleResultType.class) - .add(Restrictions.eq("label", label)) - .list() - .stream().findFirst(); + String sql = "SELECT * FROM rhnXccdfRuleResultType WHERE label = :label"; + XccdfRuleResultType result = + getSession().createNativeQuery(sql, XccdfRuleResultType.class) + .setParameter("label", label, StringType.INSTANCE).getResultStream().findFirst().orElse(null); + return Optional.ofNullable(result); } /** diff --git a/java/code/src/com/redhat/rhn/domain/common/CommonFactory.java b/java/code/src/com/redhat/rhn/domain/common/CommonFactory.java index bb26abb21209..f1b72a7c3c54 100644 --- a/java/code/src/com/redhat/rhn/domain/common/CommonFactory.java +++ b/java/code/src/com/redhat/rhn/domain/common/CommonFactory.java @@ -22,6 +22,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.hibernate.Session; +import org.hibernate.type.LongType; +import org.hibernate.type.StringType; import java.util.Calendar; import java.util.Date; @@ -87,9 +89,12 @@ public static FileList lookupFileList(Long idIn, Org org) { Session session = null; //look for Kickstart data by id session = HibernateFactory.getSession(); - return (FileList) session.getNamedQuery("FileList.findByIdAndOrg") - .setLong("id", idIn) - .setLong("org_id", org.getId()) + return session.createNativeQuery(""" + SELECT * from rhnFileList + WHERE id = :id + and org_id = :org_id """, FileList.class) + .setParameter("id", idIn, LongType.INSTANCE) + .setParameter("org_id", org.getId(), LongType.INSTANCE) .uniqueResult(); } @@ -103,8 +108,10 @@ public static FileList lookupFileList(String labelIn, Org org) { Session session = null; //look for Kickstart data by label session = HibernateFactory.getSession(); - return (FileList) session.getNamedQuery("FileList.findByLabelAndOrg").setString("label", labelIn) - .setLong("org_id", org.getId()).uniqueResult(); + return (FileList) session.getNamedQuery("FileList.findByLabelAndOrg") + .setParameter("label", labelIn, StringType.INSTANCE) + .setParameter("org_id", org.getId(), LongType.INSTANCE) + .uniqueResult(); } /** @@ -150,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") - .setString("token", tokenIn) - .uniqueResult(); + .setParameter("token", tokenIn, StringType.INSTANCE) + .uniqueResult(); } } diff --git a/java/code/src/com/redhat/rhn/domain/common/FileList.hbm.xml b/java/code/src/com/redhat/rhn/domain/common/FileList.hbm.xml index bcf59d0ecd5f..8f20591bb346 100644 --- a/java/code/src/com/redhat/rhn/domain/common/FileList.hbm.xml +++ b/java/code/src/com/redhat/rhn/domain/common/FileList.hbm.xml @@ -34,10 +34,6 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" - - - diff --git a/java/code/src/com/redhat/rhn/domain/config/ConfigChannelListProcessor.java b/java/code/src/com/redhat/rhn/domain/config/ConfigChannelListProcessor.java index 3ccf6cc04221..fb978075f012 100644 --- a/java/code/src/com/redhat/rhn/domain/config/ConfigChannelListProcessor.java +++ b/java/code/src/com/redhat/rhn/domain/config/ConfigChannelListProcessor.java @@ -20,13 +20,14 @@ import com.redhat.rhn.domain.user.User; import com.redhat.rhn.manager.configuration.ConfigurationManager; +import java.io.Serializable; import java.util.List; /** * * ConfigChannelListProcessor */ -public class ConfigChannelListProcessor { +public class ConfigChannelListProcessor implements Serializable { private void check(ConfigChannel cc) { if (cc == null) { diff --git a/java/code/src/com/redhat/rhn/domain/config/ConfigurationFactory.java b/java/code/src/com/redhat/rhn/domain/config/ConfigurationFactory.java index 972987cee09a..42321210a151 100644 --- a/java/code/src/com/redhat/rhn/domain/config/ConfigurationFactory.java +++ b/java/code/src/com/redhat/rhn/domain/config/ConfigurationFactory.java @@ -36,6 +36,8 @@ import org.hibernate.Session; import org.hibernate.criterion.Restrictions; import org.hibernate.query.Query; +import org.hibernate.type.LongType; +import org.hibernate.type.StringType; import java.io.IOException; import java.io.InputStream; @@ -431,10 +433,9 @@ public static ConfigFile lookupConfigFileByChannelAndName(Long channel, Long nam Session session = HibernateFactory.getSession(); Query query = session.getNamedQuery("ConfigFile.findByChannelAndName") - .setLong("channel_id", channel) - .setLong("name_id", name) - .setLong("state_id", ConfigFileState.normal(). - getId()); + .setParameter("channel_id", channel, LongType.INSTANCE) + .setParameter("name_id", name, LongType.INSTANCE) + .setParameter("state_id", ConfigFileState.normal().getId(), LongType.INSTANCE); try { return query.uniqueResult(); } @@ -464,7 +465,7 @@ public static ConfigRevision lookupConfigRevisionById(Long id) { public static ConfigRevision lookupConfigRevisionByRevId(ConfigFile cf, Long revId) { Session session = HibernateFactory.getSession(); Query q = session.getNamedQuery("ConfigRevision.findByRevisionAndConfigFile"); - q.setLong("rev", revId); + q.setParameter("rev", revId, LongType.INSTANCE); q.setParameter("cf", cf); return q.uniqueResult(); } @@ -515,7 +516,7 @@ static ConfigChannelType lookupConfigChannelTypeByLabel(String label) { Session session = HibernateFactory.getSession(); return (ConfigChannelType) session.getNamedQuery("ConfigChannelType.findByLabel") - .setString("label", label) + .setParameter("label", label, StringType.INSTANCE) //Retrieve from cache if there .setCacheable(true) .uniqueResult(); @@ -532,7 +533,7 @@ static ConfigChannelType lookupConfigChannelTypeByLabel(String label) { static ConfigFileState lookupConfigFileStateByLabel(String label) { Session session = HibernateFactory.getSession(); return (ConfigFileState)session.getNamedQuery("ConfigFileState.findByLabel") - .setString("label", label) + .setParameter("label", label, StringType.INSTANCE) //Retrieve from cache if there .setCacheable(true) .uniqueResult(); @@ -546,7 +547,7 @@ static ConfigFileState lookupConfigFileStateByLabel(String label) { static ConfigFileType lookupConfigFileTypeByLabel(String label) { Session session = HibernateFactory.getSession(); return (ConfigFileType)session.getNamedQuery("ConfigFileType.findByLabel") - .setString("label", label) + .setParameter("label", label, StringType.INSTANCE) //Retrieve from cache if there .setCacheable(true) .uniqueResult(); diff --git a/java/code/src/com/redhat/rhn/domain/errata/ErrataFactory.java b/java/code/src/com/redhat/rhn/domain/errata/ErrataFactory.java index 1f8d1a196735..947ff381e4df 100644 --- a/java/code/src/com/redhat/rhn/domain/errata/ErrataFactory.java +++ b/java/code/src/com/redhat/rhn/domain/errata/ErrataFactory.java @@ -50,6 +50,8 @@ import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.query.Query; +import org.hibernate.type.LongType; +import org.hibernate.type.StringType; import java.util.ArrayList; import java.util.Collection; @@ -396,7 +398,8 @@ public static ErrataFileType lookupErrataFileType(String label) { ErrataFileType retval; try { retval = (ErrataFileType) getSession().getNamedQuery("ErrataFileType.findByLabel") - .setString("label", label).setCacheable(true).uniqueResult(); + .setParameter("label", label, StringType.INSTANCE) + .setCacheable(true).uniqueResult(); } catch (HibernateException e) { throw new HibernateRuntimeException(e.getMessage(), e); @@ -413,9 +416,9 @@ public static ErrataFileType lookupErrataFileType(String label) { public static List lookupErrataFilesByErrataAndFileType(Long errataId, String fileType) { List retval; try { - Query q = getSession().getNamedQuery("ErrataFile.listByErrataAndFileType"); - q.setLong("errata_id", errataId); - q.setString("file_type", fileType.toUpperCase()); + Query q = getSession().getNamedQuery("ErrataFile.listByErrataAndFileType") + .setParameter("errata_id", errataId, LongType.INSTANCE) + .setParameter("file_type", fileType.toUpperCase(), StringType.INSTANCE); retval = q.list(); } catch (HibernateException e) { @@ -446,7 +449,7 @@ public static List lookupErratasByAdvisoryType(String advisoryType) { List retval; try { retval = getSession().getNamedQuery("Errata.findByAdvisoryType") - .setString("type", advisoryType) + .setParameter("type", advisoryType, StringType.INSTANCE) //Retrieve from cache if there .setCacheable(true).list(); } @@ -466,7 +469,8 @@ public static Errata lookupErrataById(Long id) { Errata retval; try { retval = (Errata) getSession().getNamedQuery("Errata.findById") - .setLong("id", id).uniqueResult(); + .setParameter("id", id, LongType.INSTANCE) + .uniqueResult(); } catch (HibernateException he) { log.error("Error loading ActionArchTypes from DB", he); @@ -485,7 +489,7 @@ public static Errata lookupErrataById(Long id) { public static List lookupVendorAndUserErrataByAdvisoryAndOrg(String advisory, Org org) { Session session = HibernateFactory.getSession(); return session.getNamedQuery("Errata.findVendorAnUserErrataByAdvisoryNameAndOrg") - .setParameter("advisory", advisory) + .setParameter("advisory", advisory, StringType.INSTANCE) .setParameter("org", org) .getResultList(); } @@ -499,7 +503,7 @@ public static List lookupVendorAndUserErrataByAdvisoryAndOrg(String advi public static Errata lookupByAdvisoryAndOrg(String advisory, Org org) { return (Errata) HibernateFactory.getSession() .getNamedQuery("Errata.findByAdvisoryNameAndOrg") - .setParameter("advisory", advisory) + .setParameter("advisory", advisory, StringType.INSTANCE) .setParameter("org", org) .uniqueResult(); } @@ -515,7 +519,7 @@ public static List lookupByAdvisoryId(String advisoryId, Org org) { List retval; try { retval = getSession().getNamedQuery("Errata.findByAdvisory") - .setParameter("advisory", advisoryId) + .setParameter("advisory", advisoryId, StringType.INSTANCE) .setParameter("org", org) .getResultList(); } @@ -712,8 +716,8 @@ public static List lookupByChannelBetweenDates(Org org, Channel channel, getNamedQuery("Errata.lookupByChannelBetweenDates") .setParameter("org", org) .setParameter("channel", channel) - .setParameter("start_date", startDate) - .setParameter("end_date", endDate) + .setParameter("start_date", startDate, StringType.INSTANCE) + .setParameter("end_date", endDate, StringType.INSTANCE) .list(); } @@ -731,8 +735,9 @@ public static List lookupByChannelBetweenDates(Org org, Channel channel, public static Optional lookupErrataFile(Long errataId, String filename) { Session session = HibernateFactory.getSession(); return session.getNamedQuery("ErrataFile.lookupByErrataAndPackage") - .setParameter("errata_id", errataId) - .setParameter("filename", filename).uniqueResultOptional(); + .setParameter("errata_id", errataId, LongType.INSTANCE) + .setParameter("filename", filename, StringType.INSTANCE) + .uniqueResultOptional(); } /** diff --git a/java/code/src/com/redhat/rhn/domain/image/ProfileCustomDataValue.java b/java/code/src/com/redhat/rhn/domain/image/ProfileCustomDataValue.java index 47eeb5709113..6b0f089ef6bc 100644 --- a/java/code/src/com/redhat/rhn/domain/image/ProfileCustomDataValue.java +++ b/java/code/src/com/redhat/rhn/domain/image/ProfileCustomDataValue.java @@ -15,6 +15,7 @@ package com.redhat.rhn.domain.image; import com.redhat.rhn.common.util.StringUtil; +import com.redhat.rhn.domain.BaseDomainHelper; import com.redhat.rhn.domain.org.CustomDataKey; import com.redhat.rhn.domain.user.User; import com.redhat.rhn.domain.user.legacy.UserImpl; @@ -22,8 +23,6 @@ import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; -import java.util.Date; - import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -41,7 +40,7 @@ @Entity @Table(name = "suseProfileCustomDataValue") -public class ProfileCustomDataValue { +public class ProfileCustomDataValue extends BaseDomainHelper { private Long id; private ImageProfile profile; @@ -49,8 +48,6 @@ public class ProfileCustomDataValue { private String value; private User creator; private User lastModifier; - private Date created; - private Date modified; /** * @return Returns the Id @@ -101,20 +98,6 @@ public User getCreator() { public User getLastModifier() { return lastModifier; } - /** - * @return Returns the created. - */ - @Column(insertable = false, updatable = false) - public Date getCreated() { - return created; - } - /** - * @return Returns the modified. - */ - @Column(insertable = false, updatable = false) - public Date getModified() { - return modified; - } /** * @param idIn the id to set @@ -152,18 +135,6 @@ public void setCreator(User creatorIn) { public void setLastModifier(User lastModifierIn) { this.lastModifier = lastModifierIn; } - /** - * @param createdIn The created to set. - */ - public void setCreated(Date createdIn) { - this.created = createdIn; - } - /** - * @param modifiedIn The modified to set. - */ - public void setModified(Date modifiedIn) { - this.modified = modifiedIn; - } /** * {@inheritDoc} diff --git a/java/code/src/com/redhat/rhn/domain/kickstart/KickstartFactory.java b/java/code/src/com/redhat/rhn/domain/kickstart/KickstartFactory.java index d5a9c4b0007a..6b6f002be548 100644 --- a/java/code/src/com/redhat/rhn/domain/kickstart/KickstartFactory.java +++ b/java/code/src/com/redhat/rhn/domain/kickstart/KickstartFactory.java @@ -484,12 +484,12 @@ public static CryptoKey lookupCryptoKey(String description, Org org) { Query query = null; if (org != null) { query = session.getNamedQuery("CryptoKey.findByDescAndOrg") - .setParameter("description", description) + .setParameter("description", description, StringType.INSTANCE) .setParameter(ORG_ID, org.getId(), LongType.INSTANCE); } else { query = session.getNamedQuery("CryptoKey.findByDescAndNullOrg") - .setParameter("description", description); + .setParameter("description", description, StringType.INSTANCE); } return query.uniqueResult(); } @@ -545,7 +545,8 @@ public static SslCryptoKey lookupSslCryptoKeyById(Long keyId, Org org) { //look for Kickstart data by id Session session = HibernateFactory.getSession(); Query query = session.getNamedQuery("SslCryptoKey.findByIdAndOrg"); - return query.setParameter("key_id", keyId, LongType.INSTANCE) + return query + .setParameter("key_id", keyId, LongType.INSTANCE) .setParameter(ORG_ID, org.getId(), LongType.INSTANCE) .uniqueResult(); } @@ -575,7 +576,7 @@ public static KickstartableTree lookupKickstartTreeByLabel(String label, Org org Session session = HibernateFactory.getSession(); KickstartableTree retval = (KickstartableTree) session.getNamedQuery("KickstartableTree.findByLabelAndOrg") - .setParameter(LABEL, label) + .setParameter(LABEL, label, StringType.INSTANCE) .setParameter(ORG_ID, org.getId(), LongType.INSTANCE) .uniqueResult(); // If we don't find by label + org then diff --git a/java/code/src/com/redhat/rhn/domain/org/usergroup/UserGroup.java b/java/code/src/com/redhat/rhn/domain/org/usergroup/UserGroup.java index a81b379b7ac0..4587d35bc281 100644 --- a/java/code/src/com/redhat/rhn/domain/org/usergroup/UserGroup.java +++ b/java/code/src/com/redhat/rhn/domain/org/usergroup/UserGroup.java @@ -17,6 +17,7 @@ import com.redhat.rhn.domain.role.Role; +import java.io.Serializable; import java.util.Date; /** @@ -26,7 +27,7 @@ * * DB table: RHNUSERGROUP */ -public interface UserGroup { +public interface UserGroup extends Serializable { /** * Getter for id diff --git a/java/code/src/com/redhat/rhn/domain/recurringactions/RecurringAction.java b/java/code/src/com/redhat/rhn/domain/recurringactions/RecurringAction.java index bd70ea85bf74..e697119bdb39 100644 --- a/java/code/src/com/redhat/rhn/domain/recurringactions/RecurringAction.java +++ b/java/code/src/com/redhat/rhn/domain/recurringactions/RecurringAction.java @@ -23,6 +23,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; +import org.hibernate.annotations.Type; import java.util.List; @@ -204,7 +205,7 @@ public void setCronExpr(String cronExprIn) { * @return active - if action is active */ @Column - @org.hibernate.annotations.Type(type = "yes_no") + @Type(type = "yes_no") public boolean isActive() { return active; } diff --git a/java/code/src/com/redhat/rhn/domain/rhnpackage/PackageEvrFactory.java b/java/code/src/com/redhat/rhn/domain/rhnpackage/PackageEvrFactory.java index b3e1c1399918..01acda7555a7 100644 --- a/java/code/src/com/redhat/rhn/domain/rhnpackage/PackageEvrFactory.java +++ b/java/code/src/com/redhat/rhn/domain/rhnpackage/PackageEvrFactory.java @@ -19,6 +19,8 @@ import com.redhat.rhn.common.hibernate.HibernateFactory; import org.hibernate.Session; +import org.hibernate.type.LongType; +import org.hibernate.type.StringType; import java.sql.Types; import java.util.HashMap; @@ -95,8 +97,9 @@ public static PackageEvr lookupOrCreatePackageEvr(String e, String v, String r, */ public static PackageEvr lookupPackageEvrById(Long id) { Session session = HibernateFactory.getSession(); - return (PackageEvr) session.getNamedQuery("PackageEvr.findById").setLong( - "id", id).uniqueResult(); + return (PackageEvr) session.getNamedQuery("PackageEvr.findById") + .setParameter("id", id, LongType.INSTANCE) + .uniqueResult(); } /** @@ -111,10 +114,10 @@ public static Optional lookupPackageEvrByEvr( String epoch, String version, String release, PackageType type) { Session session = HibernateFactory.getSession(); return (Optional) session.getNamedQuery("PackageEvr.lookupByEvr") - .setString("e_in", epoch) - .setString("v_in", version) - .setString("r_in", release) - .setString("t_in", type.getDbString()) + .setParameter("e_in", epoch, StringType.INSTANCE) + .setParameter("v_in", version, StringType.INSTANCE) + .setParameter("r_in", release, StringType.INSTANCE) + .setParameter("t_in", type.getDbString(), StringType.INSTANCE) .uniqueResultOptional(); } diff --git a/java/code/src/com/redhat/rhn/domain/rhnpackage/PackageFactory.java b/java/code/src/com/redhat/rhn/domain/rhnpackage/PackageFactory.java index 196bd19a81c2..d65896e104ee 100644 --- a/java/code/src/com/redhat/rhn/domain/rhnpackage/PackageFactory.java +++ b/java/code/src/com/redhat/rhn/domain/rhnpackage/PackageFactory.java @@ -33,6 +33,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.hibernate.Session; +import org.hibernate.type.LongType; +import org.hibernate.type.StringType; import java.sql.Types; import java.util.ArrayList; @@ -300,7 +302,8 @@ public static long lookupOrCreatePackageNameId(String name) { */ public static PackageName lookupPackageName(Long id) { return (PackageName) HibernateFactory.getSession().getNamedQuery("PackageName.findById") - .setLong("id", id).uniqueResult(); + .setParameter("id", id, LongType.INSTANCE) + .uniqueResult(); } /** @@ -313,7 +316,8 @@ public static PackageName lookupPackageName(Long id) { */ public static PackageName lookupPackageName(String pn) { return (PackageName) HibernateFactory.getSession().getNamedQuery("PackageName.findByName") - .setString("name", pn).uniqueResult(); + .setParameter("name", pn, StringType.INSTANCE) + .uniqueResult(); } /** @@ -325,7 +329,8 @@ public static PackageName lookupPackageName(String pn) { @SuppressWarnings("unchecked") public static List lookupOrphanPackages(Org org) { return HibernateFactory.getSession().getNamedQuery("Package.listOrphans") - .setParameter("org", org).list(); + .setParameter("org", org) + .list(); } /** @@ -342,9 +347,13 @@ public static List lookupByNevra(Org org, String name, String version, String release, String epoch, PackageArch arch) { List packages = HibernateFactory.getSession().getNamedQuery( - "Package.lookupByNevra").setParameter("org", org).setString("name", name) - .setString("version", version).setString("release", release).setParameter( - "arch", arch).list(); + "Package.lookupByNevra") + .setParameter("org", org) + .setParameter("name", name, StringType.INSTANCE) + .setParameter("version", version, StringType.INSTANCE) + .setParameter("release", release, StringType.INSTANCE) + .setParameter("arch", arch) + .list(); if (epoch == null || packages.size() < 2) { return packages; @@ -365,9 +374,9 @@ public static List lookupByNevraIds(Org org, long nameId, long evrId, l return HibernateFactory.getSession().createNamedQuery("Package.lookupByNevraIds", Package.class) .setParameter("org", org) - .setParameter("nameId", nameId) - .setParameter("evrId", evrId) - .setParameter("archId", archId) + .setParameter("nameId", nameId, LongType.INSTANCE) + .setParameter("evrId", evrId, LongType.INSTANCE) + .setParameter("archId", archId, LongType.INSTANCE) .list(); } @@ -388,12 +397,12 @@ public static Package lookupByChannelLabelNevraCs(String channel, String name, @SuppressWarnings("unchecked") List packages = HibernateFactory.getSession() .getNamedQuery("Package.lookupByChannelLabelNevraCs") - .setString("channel", channel) - .setString("name", name) - .setString("version", version) - .setString("release", release) - .setString("arch", arch) - .setString("checksum", checksum.orElse(null)) + .setParameter("channel", channel, StringType.INSTANCE) + .setParameter("name", name, StringType.INSTANCE) + .setParameter("version", version, StringType.INSTANCE) + .setParameter("release", release, StringType.INSTANCE) + .setParameter("arch", arch, StringType.INSTANCE) + .setParameter("checksum", checksum.orElse(null), StringType.INSTANCE) .list(); if (packages.isEmpty()) { diff --git a/java/code/src/com/redhat/rhn/domain/rhnpackage/profile/test/ProfileTest.java b/java/code/src/com/redhat/rhn/domain/rhnpackage/profile/test/ProfileTest.java index 9c7dcd4bb866..da175648a306 100644 --- a/java/code/src/com/redhat/rhn/domain/rhnpackage/profile/test/ProfileTest.java +++ b/java/code/src/com/redhat/rhn/domain/rhnpackage/profile/test/ProfileTest.java @@ -80,8 +80,8 @@ public void testProfileEquals() throws Exception { public static Profile lookupByIdAndOrg(Long id, Org org) { Session session = HibernateFactory.getSession(); return (Profile) session.getNamedQuery("Profile.findByIdAndOrg") - .setLong("id", id) - .setLong("org_id", org.getId()) + .setParameter("id", id) + .setParameter("org_id", org.getId()) .uniqueResult(); } @@ -126,8 +126,8 @@ public void testCompatibleServer() throws Exception { session.flush(); Query qry = session.getNamedQuery("Profile.compatibleWithServer"); - qry.setLong("sid", server.getId()); - qry.setLong("org_id", user.getOrg().getId()); + qry.setParameter("sid", server.getId()); + qry.setParameter("org_id", user.getOrg().getId()); List list = qry.list(); assertNotNull(list, "List is null"); assertFalse(list.isEmpty(), "List is empty"); diff --git a/java/code/src/com/redhat/rhn/domain/rhnpackage/profile/test/ProfileTypeTest.java b/java/code/src/com/redhat/rhn/domain/rhnpackage/profile/test/ProfileTypeTest.java index 5ab04b4044ad..a813bee16b5d 100644 --- a/java/code/src/com/redhat/rhn/domain/rhnpackage/profile/test/ProfileTypeTest.java +++ b/java/code/src/com/redhat/rhn/domain/rhnpackage/profile/test/ProfileTypeTest.java @@ -23,6 +23,7 @@ import com.redhat.rhn.testing.RhnBaseTestCase; import org.hibernate.Session; +import org.hibernate.type.StringType; import org.junit.jupiter.api.Test; /** @@ -73,7 +74,7 @@ public void testFindByLabel() throws Exception { public static ProfileType lookupByLabel(String label) { Session session = HibernateFactory.getSession(); return (ProfileType) session.getNamedQuery("ProfileType.findByLabel") - .setString("label", label) + .setParameter("label", label, StringType.INSTANCE) //Retrieve from cache if there .setCacheable(true) .uniqueResult(); diff --git a/java/code/src/com/redhat/rhn/domain/role/RoleFactory.java b/java/code/src/com/redhat/rhn/domain/role/RoleFactory.java index 6f4ad8e277b5..9be5cdf19589 100644 --- a/java/code/src/com/redhat/rhn/domain/role/RoleFactory.java +++ b/java/code/src/com/redhat/rhn/domain/role/RoleFactory.java @@ -19,6 +19,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.hibernate.Session; +import org.hibernate.type.LongType; +import org.hibernate.type.StringType; /** * RoleFactory @@ -56,7 +58,7 @@ protected Logger getLogger() { public static Role lookupById(Long id) { Session session = HibernateFactory.getSession(); return (Role) session.getNamedQuery("Role.findById") - .setLong("id", id) + .setParameter("id", id, LongType.INSTANCE) //Retrieve from cache if there .setCacheable(true) .uniqueResult(); @@ -70,7 +72,7 @@ public static Role lookupById(Long id) { public static Role lookupByLabel(String name) { Session session = HibernateFactory.getSession(); return (Role) session.getNamedQuery("Role.findByLabel") - .setString("label", name) + .setParameter("label", name, StringType.INSTANCE) //Retrieve from cache if there .setCacheable(true) .uniqueResult(); diff --git a/java/code/src/com/redhat/rhn/domain/scc/SCCRegCacheItem.java b/java/code/src/com/redhat/rhn/domain/scc/SCCRegCacheItem.java index 8f1785b38f66..81dbcfac9c92 100644 --- a/java/code/src/com/redhat/rhn/domain/scc/SCCRegCacheItem.java +++ b/java/code/src/com/redhat/rhn/domain/scc/SCCRegCacheItem.java @@ -25,6 +25,7 @@ import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; +import org.hibernate.annotations.Type; import java.security.SecureRandom; import java.util.Date; @@ -178,7 +179,7 @@ public Optional getOptCredentials() { * @return true when updating the registration at SCC is required, otherwise false */ @Column(name = "scc_reg_required") - @org.hibernate.annotations.Type(type = "yes_no") + @Type(type = "yes_no") public boolean isSccRegistrationRequired() { return sccRegistrationRequired; } diff --git a/java/code/src/com/redhat/rhn/domain/server/PinnedSubscriptionFactory.java b/java/code/src/com/redhat/rhn/domain/server/PinnedSubscriptionFactory.java index 7330cdaac2d0..24d7008545b6 100644 --- a/java/code/src/com/redhat/rhn/domain/server/PinnedSubscriptionFactory.java +++ b/java/code/src/com/redhat/rhn/domain/server/PinnedSubscriptionFactory.java @@ -21,6 +21,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.hibernate.criterion.Restrictions; +import org.hibernate.type.LongType; import java.util.List; @@ -96,7 +97,7 @@ public void remove(PinnedSubscription subscription) { public void cleanStalePins() { getSession() .getNamedQuery("PinnedSubscription.cleanStalePins") - .setLong("selfSystemId", MatcherJsonIO.SELF_SYSTEM_ID) + .setParameter("selfSystemId", MatcherJsonIO.SELF_SYSTEM_ID, LongType.INSTANCE) .executeUpdate(); } diff --git a/java/code/src/com/redhat/rhn/domain/server/ServerFactory.java b/java/code/src/com/redhat/rhn/domain/server/ServerFactory.java index 0b5213380b03..49d05dffb701 100644 --- a/java/code/src/com/redhat/rhn/domain/server/ServerFactory.java +++ b/java/code/src/com/redhat/rhn/domain/server/ServerFactory.java @@ -62,7 +62,9 @@ import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Subqueries; import org.hibernate.query.Query; +import org.hibernate.type.LongType; import org.hibernate.type.StandardBasicTypes; +import org.hibernate.type.StringType; import java.util.ArrayList; import java.util.Arrays; @@ -115,10 +117,11 @@ protected static CustomDataValue getCustomDataValue(CustomDataKey key, Session session = HibernateFactory.getSession(); return (CustomDataValue) session.getNamedQuery( - "CustomDataValue.findByServerAndKey").setParameter("server", - server).setParameter("key", key) - // Retrieve from cache if there - .setCacheable(true).uniqueResult(); + "CustomDataValue.findByServerAndKey") + .setParameter("server", server) + .setParameter("key", key) + .setCacheable(true) + .uniqueResult(); } /** @@ -793,9 +796,9 @@ public static List lookupByServerIds(List ids, Strin */ public static ServerGroupType lookupServerGroupTypeByLabel(String label) { return (ServerGroupType) HibernateFactory.getSession().getNamedQuery("ServerGroupType.findByLabel") - .setString("label", label) - // Retrieve from cache if there - .setCacheable(true).uniqueResult(); + .setParameter("label", label, StringType.INSTANCE) + .setCacheable(true) + .uniqueResult(); } @@ -897,9 +900,9 @@ private static void updateServerPerms(Server server) { public static ServerArch lookupServerArchByLabel(String label) { Session session = HibernateFactory.getSession(); return (ServerArch) session.getNamedQuery("ServerArch.findByLabel") - .setString("label", label) - // Retrieve from cache if there - .setCacheable(true).uniqueResult(); + .setParameter("label", label, StringType.INSTANCE) + .setCacheable(true) + .uniqueResult(); } /** @@ -923,8 +926,7 @@ public static ServerArch lookupServerArchByName(String name) { public static CPUArch lookupCPUArchByName(String name) { Session session = HibernateFactory.getSession(); return (CPUArch) session.getNamedQuery("CPUArch.findByName") - .setString("name", name) - // Retrieve from cache if there + .setParameter("name", name, StringType.INSTANCE) .setCacheable(true).uniqueResult(); } @@ -1299,7 +1301,7 @@ public static void removeTagFromSnapshot(Long serverId, SnapshotTag tag) { */ public static SnapshotTag lookupSnapshotTagbyName(String tagName) { return (SnapshotTag) HibernateFactory.getSession().getNamedQuery("SnapshotTag.lookupByTagName") - .setString("tag_name", tagName) + .setParameter("tag_name", tagName, StringType.INSTANCE) // Do not use setCacheable(true), as tag deletion will // usually end up making this query's output out of date .uniqueResult(); @@ -1311,7 +1313,7 @@ public static SnapshotTag lookupSnapshotTagbyName(String tagName) { */ public static SnapshotTag lookupSnapshotTagbyId(Long tagId) { return (SnapshotTag) HibernateFactory.getSession().getNamedQuery("SnapshotTag.lookupById") - .setLong("id", tagId) + .setParameter("id", tagId, LongType.INSTANCE) // Do not use setCacheable(true), as tag deletion will // usually end up making this query's output out of date .uniqueResult(); diff --git a/java/code/src/com/redhat/rhn/domain/server/VirtualInstanceFactory.java b/java/code/src/com/redhat/rhn/domain/server/VirtualInstanceFactory.java index 87d9707e0a5b..58b8afb70341 100644 --- a/java/code/src/com/redhat/rhn/domain/server/VirtualInstanceFactory.java +++ b/java/code/src/com/redhat/rhn/domain/server/VirtualInstanceFactory.java @@ -20,6 +20,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.hibernate.Session; +import org.hibernate.type.LongType; +import org.hibernate.type.StringType; import java.util.ArrayList; import java.util.HashSet; @@ -83,7 +85,9 @@ public VirtualInstance lookupByGuestId(Org org, Long id) { Session session = HibernateFactory.getSession(); return (VirtualInstance) session.getNamedQuery("VirtualInstance.lookupGuestBySidAndOrg") - .setParameter("org", org).setParameter("sid", id).uniqueResult(); + .setParameter("org", org) + .setParameter("sid", id, LongType.INSTANCE) + .uniqueResult(); } @@ -96,8 +100,9 @@ public VirtualInstance lookupByGuestId(Org org, Long id) { public VirtualInstance lookupByGuestId(Long id) { Session session = HibernateFactory.getSession(); return (VirtualInstance) session.getNamedQuery( - "VirtualInstance.lookupGuestBySid"). - setParameter("sid", id).uniqueResult(); + "VirtualInstance.lookupGuestBySid") + .setParameter("sid", id, LongType.INSTANCE) + .uniqueResult(); } /** @@ -111,7 +116,8 @@ public boolean isOutdated(VirtualInstance guest) { Session session = HibernateFactory.getSession(); VirtualInstance results = (VirtualInstance) session.getNamedQuery( "VirtualInstance.isOutdatedVirtualInstance"). - setParameter("guest", guest).uniqueResult(); + setParameter("guest", guest) + .uniqueResult(); return results != null; } @@ -165,7 +171,8 @@ public Set findGuestsWithNonVirtHostByOrg(Org org) { Session session = HibernateFactory.getSession(); List results = session.getNamedQuery( "VirtualInstance.findGuestsWithNonVirtHostByOrg"). - setParameter("org_id", org.getId()).list(); + setParameter("org_id", org.getId(), LongType.INSTANCE) + .list(); return new HashSet<>(convertToView(results)); } @@ -251,7 +258,8 @@ public Set findGuestsWithoutAHostByOrg(Org org) { */ public VirtualInstanceType getParaVirtType() { return (VirtualInstanceType)getSession().getNamedQuery( - "VirtualInstanceType.findByLabel").setString("label", "para_virtualized") + "VirtualInstanceType.findByLabel") + .setParameter("label", "para_virtualized", StringType.INSTANCE) .setCacheable(true).uniqueResult(); } @@ -262,7 +270,8 @@ public VirtualInstanceType getParaVirtType() { */ public VirtualInstanceType getFullyVirtType() { return (VirtualInstanceType)getSession().getNamedQuery( - "VirtualInstanceType.findByLabel").setString("label", "fully_virtualized") + "VirtualInstanceType.findByLabel") + .setParameter("label", "fully_virtualized", StringType.INSTANCE) .setCacheable(true).uniqueResult(); } @@ -274,7 +283,8 @@ public VirtualInstanceType getFullyVirtType() { */ public VirtualInstanceType getVirtualInstanceType(String label) { return (VirtualInstanceType)getSession().getNamedQuery( - "VirtualInstanceType.findByLabel").setString("label", label) + "VirtualInstanceType.findByLabel") + .setParameter("label", label, StringType.INSTANCE) .setCacheable(true).uniqueResult(); } @@ -285,7 +295,8 @@ public VirtualInstanceType getVirtualInstanceType(String label) { */ public VirtualInstanceState getRunningState() { return (VirtualInstanceState)getSession().getNamedQuery( - "VirtualInstanceState.findByLabel").setString("label", "running") + "VirtualInstanceState.findByLabel") + .setParameter("label", "running", StringType.INSTANCE) .uniqueResult(); } @@ -296,8 +307,9 @@ public VirtualInstanceState getRunningState() { */ public VirtualInstanceState getStoppedState() { return (VirtualInstanceState)getSession().getNamedQuery( - "VirtualInstanceState.findByLabel").setString("label", "stopped") - .uniqueResult(); + "VirtualInstanceState.findByLabel") + .setParameter("label", "stopped", StringType.INSTANCE) + .uniqueResult(); } /** @@ -307,8 +319,9 @@ public VirtualInstanceState getStoppedState() { */ public VirtualInstanceState getPausedState() { return (VirtualInstanceState)getSession().getNamedQuery( - "VirtualInstanceState.findByLabel").setString("label", "paused") - .uniqueResult(); + "VirtualInstanceState.findByLabel") + .setParameter("label", "paused", StringType.INSTANCE) + .uniqueResult(); } /** @@ -318,8 +331,9 @@ public VirtualInstanceState getPausedState() { */ public VirtualInstanceState getCrashedState() { return (VirtualInstanceState)getSession().getNamedQuery( - "VirtualInstanceState.findByLabel").setString("label", "crashed") - .uniqueResult(); + "VirtualInstanceState.findByLabel") + .setParameter("label", "crashed", StringType.INSTANCE) + .uniqueResult(); } /** @@ -329,7 +343,8 @@ public VirtualInstanceState getCrashedState() { */ public VirtualInstanceState getUnknownState() { return (VirtualInstanceState)getSession().getNamedQuery( - "VirtualInstanceState.findByLabel").setString("label", "unknown") + "VirtualInstanceState.findByLabel") + .setParameter("label", "unknown", StringType.INSTANCE) .uniqueResult(); } @@ -341,7 +356,8 @@ public VirtualInstanceState getUnknownState() { */ public Optional getState(String label) { return Optional.ofNullable((VirtualInstanceState)getSession().getNamedQuery( - "VirtualInstanceState.findByLabel").setString("label", label) + "VirtualInstanceState.findByLabel") + .setParameter("label", label, StringType.INSTANCE) .uniqueResult()); } @@ -353,8 +369,8 @@ public Optional getState(String label) { public List lookupVirtualInstanceByUuid(String uuid) { return getSession() .getNamedQuery("VirtualInstance.lookupVirtualInstanceByUuid") - .setParameter("uuid", uuid) - .list(); + .setParameter("uuid", uuid, StringType.INSTANCE) + .list(); } /** @@ -365,7 +381,7 @@ public List lookupVirtualInstanceByUuid(String uuid) { public VirtualInstance lookupHostVirtInstanceByHostId(Long hostId) { return (VirtualInstance) getSession() .getNamedQuery("VirtualInstance.lookupHostVirtInstanceByHostId") - .setParameter("hostId", hostId) + .setParameter("hostId", hostId, LongType.INSTANCE) .uniqueResult(); } @@ -378,8 +394,8 @@ public VirtualInstance lookupHostVirtInstanceByHostId(Long hostId) { public VirtualInstance lookupVirtualInstanceByHostIdAndUuid(Long hostId, String uuid) { return (VirtualInstance) getSession() .getNamedQuery("VirtualInstance.lookupHostVirtInstanceByHostIdAndUuid") - .setParameter("hostId", hostId) - .setParameter("uuid", uuid) + .setParameter("hostId", hostId, LongType.INSTANCE) + .setParameter("uuid", uuid, StringType.INSTANCE) .uniqueResult(); } } diff --git a/java/code/src/com/redhat/rhn/domain/server/test/LocationTest.java b/java/code/src/com/redhat/rhn/domain/server/test/LocationTest.java index 9b2b2c6f1b35..5adfff8bf44d 100644 --- a/java/code/src/com/redhat/rhn/domain/server/test/LocationTest.java +++ b/java/code/src/com/redhat/rhn/domain/server/test/LocationTest.java @@ -28,6 +28,7 @@ import com.redhat.rhn.testing.UserTestUtils; import org.hibernate.Session; +import org.hibernate.type.LongType; import org.junit.jupiter.api.Test; import java.util.Date; @@ -57,7 +58,7 @@ public void testLocation() throws Exception { Session session = HibernateFactory.getSession(); loc2 = (Location) session.getNamedQuery("Location.findById") - .setLong("id", loc1.getId()) + .setParameter("id", loc1.getId(), LongType.INSTANCE) .uniqueResult(); assertEquals(loc1, loc2); } diff --git a/java/code/src/com/redhat/rhn/domain/server/test/NoteTest.java b/java/code/src/com/redhat/rhn/domain/server/test/NoteTest.java index 0b1634a518a1..ff26e4ef8ddb 100644 --- a/java/code/src/com/redhat/rhn/domain/server/test/NoteTest.java +++ b/java/code/src/com/redhat/rhn/domain/server/test/NoteTest.java @@ -27,6 +27,7 @@ import com.redhat.rhn.testing.UserTestUtils; import org.hibernate.Session; +import org.hibernate.type.LongType; import org.junit.jupiter.api.Test; import java.util.Date; @@ -50,7 +51,7 @@ public void testEquals() throws Exception { Session session = HibernateFactory.getSession(); note2 = (Note) session.getNamedQuery("Note.findById") - .setLong("id", note1.getId()) + .setParameter("id", note1.getId(), LongType.INSTANCE) .uniqueResult(); assertEquals(note1, note2); diff --git a/java/code/src/com/redhat/rhn/domain/token/ActivationKeyFactory.java b/java/code/src/com/redhat/rhn/domain/token/ActivationKeyFactory.java index c827113065a4..9f533f757909 100644 --- a/java/code/src/com/redhat/rhn/domain/token/ActivationKeyFactory.java +++ b/java/code/src/com/redhat/rhn/domain/token/ActivationKeyFactory.java @@ -33,6 +33,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.hibernate.type.StringType; import java.util.HashMap; import java.util.List; @@ -60,7 +61,7 @@ public static ActivationKey lookupByKey(String key) { return (ActivationKey) HibernateFactory.getSession() .getNamedQuery("ActivationKey.findByKey") - .setString("key", key) + .setParameter("key", key, StringType.INSTANCE) .uniqueResult(); } diff --git a/java/code/src/com/redhat/rhn/domain/token/test/TokenTest.java b/java/code/src/com/redhat/rhn/domain/token/test/TokenTest.java index 05faf1c891bb..1ce39c078a36 100644 --- a/java/code/src/com/redhat/rhn/domain/token/test/TokenTest.java +++ b/java/code/src/com/redhat/rhn/domain/token/test/TokenTest.java @@ -41,6 +41,7 @@ import com.redhat.rhn.testing.UserTestUtils; import org.hibernate.Session; +import org.hibernate.type.LongType; import org.junit.jupiter.api.Test; import java.util.ArrayList; @@ -64,7 +65,7 @@ public void testEquals() throws Exception { Session session = HibernateFactory.getSession(); token2 = (Token) session.getNamedQuery("Token.findById") - .setLong("id", token1.getId()) + .setParameter("id", token1.getId(), LongType.INSTANCE) .uniqueResult(); assertEquals(token1, token2); diff --git a/java/code/src/com/redhat/rhn/domain/user/User.java b/java/code/src/com/redhat/rhn/domain/user/User.java index 305029ef921a..a99ebedf2613 100644 --- a/java/code/src/com/redhat/rhn/domain/user/User.java +++ b/java/code/src/com/redhat/rhn/domain/user/User.java @@ -20,6 +20,7 @@ import com.redhat.rhn.domain.server.Server; import com.redhat.rhn.domain.server.ServerGroup; +import java.io.Serializable; import java.util.Date; import java.util.Set; @@ -28,7 +29,7 @@ * and ancillary tables. * DB table: web_contact */ -public interface User { +public interface User extends Serializable { /** * Gets the current value of id * @return long the current value diff --git a/java/code/src/com/redhat/rhn/domain/user/UserFactory.java b/java/code/src/com/redhat/rhn/domain/user/UserFactory.java index 7e152051ed73..7c9fff4be5b4 100644 --- a/java/code/src/com/redhat/rhn/domain/user/UserFactory.java +++ b/java/code/src/com/redhat/rhn/domain/user/UserFactory.java @@ -37,6 +37,8 @@ import org.apache.logging.log4j.Logger; import org.hibernate.Session; import org.hibernate.query.Query; +import org.hibernate.type.IntegerType; +import org.hibernate.type.StringType; import java.sql.Types; import java.util.Arrays; @@ -446,7 +448,7 @@ public void syncServerGroupPerms(User usr) { public static RhnTimeZone getTimeZone(int id) { Session session = HibernateFactory.getSession(); return (RhnTimeZone) session.getNamedQuery("RhnTimeZone.loadTimeZoneById") - .setInteger("tid", id) + .setParameter("tid", id, IntegerType.INSTANCE) //Retrieve from cache if there .setCacheable(true) .uniqueResult(); @@ -461,7 +463,7 @@ public static RhnTimeZone getTimeZone(String olsonName) { Session session = HibernateFactory.getSession(); return (RhnTimeZone) session .getNamedQuery("RhnTimeZone.loadTimeZoneByOlsonName") - .setString("ton", olsonName) + .setParameter("ton", olsonName, StringType.INSTANCE) //Retrieve from cache if there .setCacheable(true) .uniqueResult(); diff --git a/java/code/src/com/redhat/rhn/frontend/action/kickstart/test/KickstartDeleteActionTest.java b/java/code/src/com/redhat/rhn/frontend/action/kickstart/test/KickstartDeleteActionTest.java index a92e4119bcb8..f4365dca5755 100644 --- a/java/code/src/com/redhat/rhn/frontend/action/kickstart/test/KickstartDeleteActionTest.java +++ b/java/code/src/com/redhat/rhn/frontend/action/kickstart/test/KickstartDeleteActionTest.java @@ -23,6 +23,7 @@ import com.redhat.rhn.frontend.struts.RequestContext; import org.hibernate.Session; +import org.hibernate.type.LongType; import org.junit.jupiter.api.Test; public class KickstartDeleteActionTest extends BaseKickstartEditTestCase { @@ -63,8 +64,8 @@ public void testSubmit() throws Exception { private KickstartData lookupById(Long id) { Session session = HibernateFactory.getSession(); return (KickstartData) session.getNamedQuery("KickstartData.findByIdAndOrg") - .setLong("id", id) - .setLong("org_id", user.getOrg().getId()) + .setParameter("id", id, LongType.INSTANCE) + .setParameter("org_id", user.getOrg().getId(), LongType.INSTANCE) .uniqueResult(); } } diff --git a/java/code/src/com/redhat/rhn/manager/rhnpackage/PackageManager.java b/java/code/src/com/redhat/rhn/manager/rhnpackage/PackageManager.java index 364a050b2f57..d6d51c65f8a0 100644 --- a/java/code/src/com/redhat/rhn/manager/rhnpackage/PackageManager.java +++ b/java/code/src/com/redhat/rhn/manager/rhnpackage/PackageManager.java @@ -68,6 +68,7 @@ import org.apache.logging.log4j.Logger; import org.hibernate.HibernateException; import org.hibernate.Session; +import org.hibernate.type.StringType; import java.io.File; import java.util.ArrayList; @@ -636,7 +637,7 @@ public static PackageName lookupPackageName(String name) { try { session = HibernateFactory.getSession(); return (PackageName)session.getNamedQuery("PackageName.findByName") - .setString("name", name) + .setParameter("name", name, StringType.INSTANCE) .uniqueResult(); } catch (HibernateException e) { diff --git a/java/code/src/com/redhat/rhn/taskomatic/task/test/KickstartCleanupTest.java b/java/code/src/com/redhat/rhn/taskomatic/task/test/KickstartCleanupTest.java index 04c658e7aa3e..25367449acbc 100644 --- a/java/code/src/com/redhat/rhn/taskomatic/task/test/KickstartCleanupTest.java +++ b/java/code/src/com/redhat/rhn/taskomatic/task/test/KickstartCleanupTest.java @@ -38,6 +38,7 @@ import com.redhat.rhn.testing.UserTestUtils; import org.hibernate.Session; +import org.hibernate.type.StringType; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -156,7 +157,7 @@ private static KickstartSessionState lookupByLabel(String label) { Session session = HibernateFactory.getSession(); return (KickstartSessionState) session .getNamedQuery("KickstartSessionState.findByLabel") - .setString("label", label) + .setParameter("label", label, StringType.INSTANCE) .uniqueResult(); } diff --git a/java/code/src/com/redhat/rhn/testing/TestUtils.java b/java/code/src/com/redhat/rhn/testing/TestUtils.java index 7c8dbf06e35e..9ed442e690c5 100644 --- a/java/code/src/com/redhat/rhn/testing/TestUtils.java +++ b/java/code/src/com/redhat/rhn/testing/TestUtils.java @@ -42,6 +42,8 @@ import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.query.Query; +import org.hibernate.type.LongType; +import org.hibernate.type.StringType; import java.io.BufferedReader; import java.io.File; @@ -267,7 +269,7 @@ public static List lookupTestObjects(String query) { public static Object lookupFromCacheById(Long id, String queryname) { Session session = HibernateFactory.getSession(); return session.getNamedQuery(queryname) - .setLong("id", id) + .setParameter("id", id, LongType.INSTANCE) //Retrieve from cache if there .setCacheable(true) .uniqueResult(); @@ -284,7 +286,7 @@ public static Object lookupFromCacheByLabel(String label, String queryname) { Session session = HibernateFactory.getSession(); return session.getNamedQuery(queryname) - .setString("label", label) + .setParameter("label", label, StringType.INSTANCE) //Retrieve from cache if there .setCacheable(true) .uniqueResult(); diff --git a/java/spacewalk-java.changes.mbussolotto.hibernate_factory_refactoring b/java/spacewalk-java.changes.mbussolotto.hibernate_factory_refactoring new file mode 100644 index 000000000000..5462af59f5df --- /dev/null +++ b/java/spacewalk-java.changes.mbussolotto.hibernate_factory_refactoring @@ -0,0 +1 @@ +- Use setParameter in Hibernate queries