/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.mapping.MessageContextMappingKeys
 *  org.hibernate.HibernateException
 *  org.hibernate.Session
 *  org.hibernate.query.Query
 */
package com.l7tech.server.mapping;

import com.l7tech.gateway.common.mapping.MessageContextMappingKeys;
import com.l7tech.server.mapping.MessageContextMappingKeyManagerImpl;
import com.l7tech.server.util.ReadOnlyHibernateCallback;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.query.Query;

class b
extends ReadOnlyHibernateCallback {
    final String val$digested;
    final MessageContextMappingKeys val$lookupKeys;
    final MessageContextMappingKeyManagerImpl this$0;
    private static final String a = b.a(85, b.a("&0\u0006\u0016B3\\&"));

    b(MessageContextMappingKeyManagerImpl messageContextMappingKeyManagerImpl, String string, MessageContextMappingKeys messageContextMappingKeys) {
        this.this$0 = messageContextMappingKeyManagerImpl;
        this.val$digested = string;
        this.val$lookupKeys = messageContextMappingKeys;
    }

    public Object doInHibernateReadOnly(Session session) throws HibernateException, SQLException {
        block10: {
            Query query = session.createQuery(this.this$0.n);
            query.setParameter(a, (Object)this.val$digested);
            List list = query.list();
            try {
                if (list.size() == 0) {
                    return null;
                }
            }
            catch (HibernateException hibernateException) {
                throw b.a(hibernateException);
            }
            if (list.size() == 1) {
                MessageContextMappingKeys messageContextMappingKeys = (MessageContextMappingKeys)list.iterator().next();
                try {
                    if (messageContextMappingKeys.matches(this.val$lookupKeys)) {
                        return messageContextMappingKeys;
                    }
                    break block10;
                }
                catch (HibernateException hibernateException) {
                    throw b.a(hibernateException);
                }
            }
            for (MessageContextMappingKeys messageContextMappingKeys : list) {
                try {
                    if (!messageContextMappingKeys.matches(this.val$lookupKeys)) continue;
                    return messageContextMappingKeys;
                }
                catch (HibernateException hibernateException) {
                    throw b.a(hibernateException);
                }
            }
        }
        return null;
    }

    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] ^ 0x6C);
        }
        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 -> 23;
                    case 1 -> 12;
                    case 2 -> 52;
                    case 3 -> 38;
                    case 4 -> 100;
                    case 5 -> 18;
                    default -> 108;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

