/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.objectmodel.PersistentEntity
 *  com.l7tech.util.Functions
 *  com.l7tech.util.Functions$Binary
 *  jakarta.persistence.criteria.CriteriaBuilder
 *  jakarta.persistence.criteria.CriteriaQuery
 *  jakarta.persistence.criteria.Expression
 *  jakarta.persistence.criteria.Order
 *  jakarta.persistence.criteria.Path
 *  jakarta.persistence.criteria.Predicate
 *  jakarta.persistence.criteria.Root
 *  jakarta.persistence.criteria.Selection
 *  org.hibernate.HibernateException
 *  org.hibernate.Session
 */
package com.l7tech.server;

import com.l7tech.objectmodel.PersistentEntity;
import com.l7tech.server.HibernateEntityManager;
import com.l7tech.server.ak;
import com.l7tech.server.util.ReadOnlyHibernateCallback;
import com.l7tech.util.Functions;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Order;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import jakarta.persistence.criteria.Selection;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.Session;

class bx
extends ReadOnlyHibernateCallback<List<ET>> {
    final Map val$matchProperties;
    final String val$sortProperty;
    final Boolean val$ascending;
    final int val$offset;
    final int val$count;
    final HibernateEntityManager this$0;
    private static final String a = bx.a(89, bx.a("C\u000b\u0011=ME\u007fI\u000b\u0018rQI3J\u001c\u0002pM\u007ftV\u001c"));

    bx(HibernateEntityManager hibernateEntityManager, Map map, String string, Boolean bl2, int n2, int n3) {
        this.this$0 = hibernateEntityManager;
        this.val$matchProperties = map;
        this.val$sortProperty = string;
        this.val$ascending = bl2;
        this.val$offset = n2;
        this.val$count = n3;
    }

    @Override
    protected List<ET> doInHibernateReadOnly(Session session) throws HibernateException, SQLException {
        Path path;
        CriteriaQuery criteriaQuery;
        block14: {
            Predicate predicate;
            Root root;
            CriteriaBuilder criteriaBuilder;
            block12: {
                criteriaBuilder = session.getCriteriaBuilder();
                criteriaQuery = criteriaBuilder.createQuery(this.this$0.getImpClass());
                root = criteriaQuery.from(this.this$0.getImpClass());
                predicate = this.this$0.addFindAllPredicate(criteriaBuilder.conjunction(), criteriaBuilder, root);
                try {
                    if (this.val$matchProperties == null || this.val$matchProperties.isEmpty()) break block12;
                }
                catch (HibernateException hibernateException) {
                    throw bx.a(hibernateException);
                }
                predicate = (Predicate)Functions.reduce(this.val$matchProperties.entrySet(), (Object)predicate, (Functions.Binary)new ak(this, criteriaBuilder, root));
            }
            if (this.val$sortProperty != null) {
                block13: {
                    path = HibernateEntityManager.expandNestedAttribute(root, this.val$sortProperty, true);
                    try {
                        try {
                            if (this.val$ascending != null && !this.val$ascending.booleanValue()) break block13;
                        }
                        catch (HibernateException hibernateException) {
                            throw bx.a(hibernateException);
                        }
                        criteriaQuery.select((Selection)root).where((Expression)predicate).orderBy(new Order[]{criteriaBuilder.asc((Expression)path)});
                        break block14;
                    }
                    catch (HibernateException hibernateException) {
                        throw bx.a(hibernateException);
                    }
                }
                criteriaQuery.select((Selection)root).where((Expression)predicate).orderBy(new Order[]{criteriaBuilder.desc((Expression)path)});
            } else {
                criteriaQuery.select((Selection)root).where((Expression)predicate);
            }
        }
        path = session.createQuery(criteriaQuery);
        try {
            path.setFirstResult(this.val$offset);
            if (this.val$count >= 0) {
                path.setHint(a, (Object)this.val$count);
                path.setMaxResults(this.val$count);
            }
        }
        catch (HibernateException hibernateException) {
            throw bx.a(hibernateException);
        }
        List list = path.getResultList();
        for (PersistentEntity persistentEntity : list) {
            this.this$0.initializeLazilyLoaded(persistentEntity);
        }
        return list;
    }

    private static HibernateException a(HibernateException hibernateException) {
        return hibernateException;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x44);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 117;
                    case 1 -> 32;
                    case 2 -> 47;
                    case 3 -> 74;
                    case 4 -> 124;
                    case 5 -> 117;
                    default -> 68;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

