Skip to content

Commit

Permalink
refactor VirtualHostManagerFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
mbussolotto committed Jan 10, 2025
1 parent 621f2dc commit 9337e37
Showing 1 changed file with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.hibernate.type.LongType;
import org.hibernate.type.StringType;

import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -103,9 +102,11 @@ protected Logger getLogger() {
* exist
*/
public VirtualHostManager lookupByLabel(String label) {
return (VirtualHostManager) getSession()
.createCriteria(VirtualHostManager.class)
.add(Restrictions.eq("label", label))
return getSession().createNativeQuery("""
SELECT * from suseVirtualHostManager
WHERE label = :label
""", VirtualHostManager.class)
.setParameter("label", label, StringType.INSTANCE)
.uniqueResult();
}

Expand All @@ -127,10 +128,13 @@ public Optional<VirtualHostManager> lookupById(Long id) {
* exist
*/
public VirtualHostManager lookupByIdAndOrg(Long id, Org org) {
return (VirtualHostManager) getSession()
.createCriteria(VirtualHostManager.class)
.add(Restrictions.eq("org", org))
.add(Restrictions.eq("id", id))
return getSession().createNativeQuery("""
SELECT * from suseVirtualHostManager
WHERE id = :id
AND org_id = :org
""", VirtualHostManager.class)
.setParameter("id", id, LongType.INSTANCE)
.setParameter("org_id", org.getId(), LongType.INSTANCE)
.uniqueResult();
}

Expand Down Expand Up @@ -160,10 +164,13 @@ WHERE id IN (:ids)
* exist
*/
public VirtualHostManager lookupByLabelAndOrg(String label, Org org) {
return (VirtualHostManager) getSession()
.createCriteria(VirtualHostManager.class)
.add(Restrictions.eq("org", org))
.add(Restrictions.eq("label", label))
return getSession().createNativeQuery("""
SELECT * from suseVirtualHostManager
WHERE label = :label
AND org_id = :org
""", VirtualHostManager.class)
.setParameter("label", label, StringType.INSTANCE)
.setParameter("org_id", org.getId(), LongType.INSTANCE)
.uniqueResult();
}

Expand All @@ -189,9 +196,10 @@ public List<VirtualHostManager> listVirtualHostManagers(Org org) {
*/
@SuppressWarnings("unchecked")
public List<VirtualHostManager> listVirtualHostManagers() {
return getSession()
.createCriteria(VirtualHostManager.class)
.list();
return getSession().createNativeQuery("""
SELECT * from suseVirtualHostManager
""", VirtualHostManager.class)
.getResultList();
}

/**
Expand Down Expand Up @@ -472,12 +480,14 @@ private VHMCredentials createCredentialsFromParams(Map<String, String> params) {
*/
public Optional<VirtualHostManagerNodeInfo> lookupNodeInfoByIdentifier(
String identifier) {
return Optional.ofNullable(getSession().createNativeQuery("""
SELECT * from suseVirtualHostManagerNodeInfo
WHERE identifier = :identifier
""", VirtualHostManagerNodeInfo.class)
.setParameter("identifier", identifier, StringType.INSTANCE)
.getSingleResult());
==== BASE ====
VirtualHostManagerNodeInfo result = (VirtualHostManagerNodeInfo) getSession()
.createCriteria(VirtualHostManagerNodeInfo.class)
.add(Restrictions.eq("identifier", identifier))
.uniqueResult();

return Optional.ofNullable(result);
==== BASE ====
}

}

0 comments on commit 9337e37

Please sign in to comment.