Skip to content

Commit

Permalink
fix channel query
Browse files Browse the repository at this point in the history
  • Loading branch information
mbussolotto authored and root committed Nov 26, 2024
1 parent 717d367 commit 6f742e1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
16 changes: 0 additions & 16 deletions java/code/src/com/redhat/rhn/domain/channel/Channel.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,22 +215,6 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
]]>
</query>

<sql-query name="Channel.findByLabelAndUserId">
<![CDATA[SELECT {c.*}
FROM rhnChannel {c}
LEFT OUTER JOIN rhnChannelCloned c_1_ ON c.id = c_1_.id
WHERE c.label = :label AND
EXISTS (SELECT 1
FROM suseChannelUserRoleView scur
WHERE scur.channel_id = c.id AND
scur.user_id = :userId AND
deny_reason IS NULL
)
]]>
<synchronize table="rhnChannel"/>
<return alias="c" class="com.redhat.rhn.domain.channel.Channel" />
</sql-query>

<sql-query name="Channel.findByLabelAndOrgId">
<![CDATA[SELECT c.*, c_1_.original_id, CASE WHEN c_1_.original_id IS NULL THEN 0 ELSE 1 END as clazz_
FROM rhnChannel c
Expand Down
5 changes: 5 additions & 0 deletions java/code/src/com/redhat/rhn/domain/channel/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import jakarta.persistence.ColumnResult;
import jakarta.persistence.EntityResult;
import jakarta.persistence.FieldResult;
import jakarta.persistence.SqlResultSetMapping;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
Expand Down Expand Up @@ -70,6 +74,7 @@
@Entity
@Table(name = "rhnChannel")
@Inheritance(strategy = InheritanceType.JOINED)

public class Channel extends BaseDomainHelper implements Comparable<Channel> {

/**
Expand Down
26 changes: 24 additions & 2 deletions java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.logging.log4j.Logger;
import org.hibernate.CacheMode;
import org.hibernate.Session;
import org.hibernate.query.Query;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -127,8 +128,29 @@ public static Channel lookupByLabelAndUser(String label, User userIn) {
if (label == null || userIn == null) {
return null;
}
return singleton.lookupObjectByNamedQuery("Channel.findByLabelAndUserId",
Map.of(LABEL, label, "userId", userIn.getId()));
Session session = HibernateFactory.getSession();

Query<Channel> query = session.createNativeQuery("""
SELECT c.*, c_1_.original_id,
CASE WHEN c_1_.original_id IS NULL THEN 0 ELSE 1 END as clazz_
FROM rhnChannel c
LEFT OUTER JOIN rhnChannelCloned c_1_ ON c.id = c_1_.id
WHERE c.label = :label AND
EXISTS (SELECT 1
FROM suseChannelUserRoleView scur
WHERE scur.channel_id = c.id AND
scur.user_id = :userId AND
scur.deny_reason IS NULL)
""", Channel.class)
.setCacheable(false)
.addSynchronizedEntityClass(Channel.class)
.addSynchronizedEntityClass(ChannelSyncFlag.class)
.setParameter("label", label)
.setParameter("userId", userIn.getId());
return query.uniqueResult();

// return singleton.lookupObjectByNamedQuery("Channel.findByLabelAndUserId",
// Map.of(LABEL, label, "userId", userIn.getId()));
}

/**
Expand Down

0 comments on commit 6f742e1

Please sign in to comment.