/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.audit.SystemAuditRecord
 *  com.l7tech.util.ExceptionUtils
 *  com.l7tech.util.ResourceUtils
 *  org.hibernate.HibernateException
 *  org.hibernate.Session
 *  org.hibernate.internal.SessionImpl
 *  org.springframework.context.ApplicationEvent
 *  org.springframework.transaction.TransactionException
 *  org.springframework.transaction.support.TransactionCallback
 *  org.springframework.transaction.support.TransactionTemplate
 */
package com.l7tech.server.audit;

import com.l7tech.gateway.common.audit.SystemAuditRecord;
import com.l7tech.server.HibernateEntityManager;
import com.l7tech.server.audit.AuditRecordManagerImpl;
import com.l7tech.server.audit.ag;
import com.l7tech.server.audit.ai;
import com.l7tech.server.event.system.AuditPurgeEvent;
import com.l7tech.util.ExceptionUtils;
import com.l7tech.util.ResourceUtils;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.internal.SessionImpl;
import org.springframework.context.ApplicationEvent;
import org.springframework.transaction.TransactionException;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

class ah
implements Runnable {
    private final ag a;
    private final long b;
    final AuditRecordManagerImpl this$0;
    private static final String[] c;

    public ah(AuditRecordManagerImpl auditRecordManagerImpl, long l2) {
        this.this$0 = auditRecordManagerImpl;
        this.a = new ag();
        this.b = l2;
    }

    @Override
    public void run() {
        String[] stringArray;
        int n2;
        int n3 = 0;
        long l2 = System.currentTimeMillis();
        do {
            try {
                int n4 = n3;
                n2 = (Integer)new TransactionTemplate(AuditRecordManagerImpl.access$000(this.this$0)).execute((TransactionCallback)new ai(this, n4));
                n3 += n2;
            }
            catch (TransactionException transactionException) {
                stringArray = c;
                AuditRecordManagerImpl.P.log(Level.WARNING, stringArray[3] + ExceptionUtils.getMessage((Throwable)transactionException), transactionException);
                break;
            }
            try {
                if (n2 <= 0 || !AuditRecordManagerImpl.P.isLoggable(Level.FINE)) continue;
            }
            catch (TransactionException transactionException) {
                throw ah.a((Exception)((Object)transactionException));
            }
            double d10 = (double)(System.currentTimeMillis() - l2) / 1000.0;
            int n5 = n3;
            stringArray = c;
            AuditRecordManagerImpl.P.fine(stringArray[2] + n5 + stringArray[0] + d10 + stringArray[9]);
        } while (n2 != 0);
        if (AuditRecordManagerImpl.P.isLoggable(Level.INFO)) {
            double d11 = (double)(System.currentTimeMillis() - l2) / 1000.0;
            int n6 = n3;
            stringArray = c;
            AuditRecordManagerImpl.P.log(Level.INFO, stringArray[5] + n6 + stringArray[8] + d11 + stringArray[1]);
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private int a(ag ag2, long l2, int n2) throws HibernateException, SQLException {
        int n3;
        block18: {
            Object object;
            Session session = null;
            boolean bl2 = AuditRecordManagerImpl.O.get();
            n3 = 0;
            PreparedStatement preparedStatement = null;
            boolean bl3 = true;
            while (bl3) {
                bl3 = false;
                try {
                    PreparedStatement preparedStatement2;
                    block15: {
                        block14: {
                            session = HibernateEntityManager.useCurrentOrOpenNewSession(this.this$0.getSessionFactory());
                            object = ((SessionImpl)session).connection();
                            try {
                                if (!bl2) break block14;
                                preparedStatement2 = object.prepareStatement(c[4]);
                                break block15;
                            }
                            catch (SQLException sQLException) {
                                throw ah.a(sQLException);
                            }
                        }
                        String[] stringArray = c;
                        preparedStatement2 = object.prepareStatement(stringArray[6]);
                    }
                    preparedStatement = preparedStatement2;
                    preparedStatement.setString(1, Level.SEVERE.getName());
                    preparedStatement.setLong(2, l2);
                    n3 = preparedStatement.executeUpdate();
                }
                catch (SQLException sQLException) {
                    try {
                        try {
                            if (bl2 && c[7].equals(sQLException.getSQLState())) {
                            }
                        }
                        catch (SQLException sQLException2) {
                            throw ah.a(sQLException2);
                        }
                        throw sQLException;
                        bl2 = false;
                        AuditRecordManagerImpl.O.set(false);
                        bl3 = true;
                    }
                    catch (Throwable throwable) {
                        ResourceUtils.closeQuietly(preparedStatement);
                        HibernateEntityManager.closeNewSession(session);
                        throw throwable;
                    }
                    ResourceUtils.closeQuietly((Statement)preparedStatement);
                    HibernateEntityManager.closeNewSession(session);
                    continue;
                }
                ResourceUtils.closeQuietly((Statement)preparedStatement);
                HibernateEntityManager.closeNewSession(session);
            }
            object = ag2.a;
            if (object == null) {
                AuditPurgeEvent auditPurgeEvent = new AuditPurgeEvent((Object)this.this$0, n3);
                AuditRecordManagerImpl.access$100(this.this$0).publishEvent((ApplicationEvent)auditPurgeEvent);
                ag2.a = auditPurgeEvent.getSystemAuditRecord();
            } else {
                block17: {
                    try {
                        if (n3 != 0) break block17;
                        break block18;
                    }
                    catch (SQLException sQLException) {
                        throw ah.a(sQLException);
                    }
                }
                AuditPurgeEvent auditPurgeEvent = new AuditPurgeEvent(this.this$0, (SystemAuditRecord)object, n2 += n3);
                AuditRecordManagerImpl.access$200(this.this$0).publishEvent((ApplicationEvent)auditPurgeEvent);
            }
        }
        return n3;
    }

    private static Exception a(Exception exception) {
        return exception;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[10];
                var3_1 = 0;
                var2_2 = ">j5\u000eE\u0004_{}%\u0004X\u0003_we`\u0005>x%\t\u0002\u0013Zn,\u000fX\u0019\u0010p+0\u0018C\u0017\r{x3P\f&]d5\u0006H\u001eXj+#\u0005A\u001d\u0016j+!\u001fH\u0019\u000b>o%\u0006I\u0004\u0016qe`\bM\u0004\u001cv1`FZN\f/x5_XY\u000f'\f\u0011\nzb45A\u0011\u0016p+\u0017\"i\":>j5\u000eE\u0004 rn6\u000f@PC +\u007fJm>;>\u007f)\u0007IPC>4`&e=6J+qZ\u001c@O\bZn,\u000fX\u0015\u001b>\u00bcZN\f/x5_XY\u000f'\f\u0011\nzb45A\u0011\u0016p+7\u0002I\u0002\u001a>l/\u0003HP\u0016p+h9i<:]_`\rC\u0019\u001b>M\u0012%aPWMN\f/o$_LD\u00175b%2\\N\u0012B\u0005P0HN\u0012B\u0005P\u001em+2\u0005[\u001e\nsi%\u0018\u0000P\u0018qb$Jj\"0S+!\u001fH\u0019\u000bAf!\u0003BP(VN\u0012/\f\u0011\nzb45@\u0015\t{g`V\u0012P@>+!\u0004HP\u000bwf%J\u0010P@7+\u00019\f\u0016\u0010q+\u0017\"i\":>y/\u001dB\u0005\u0012|n2J\u0010M_/;pZ\u001cY\u0005*9\u0018Z\u001d";
                var4_3 = ">j5\u000eE\u0004_{}%\u0004X\u0003_we`\u0005>x%\t\u0002\u0013Zn,\u000fX\u0019\u0010p+0\u0018C\u0017\r{x3P\f&]d5\u0006H\u001eXj+#\u0005A\u001d\u0016j+!\u001fH\u0019\u000b>o%\u0006I\u0004\u0016qe`\bM\u0004\u001cv1`FZN\f/x5_XY\u000f'\f\u0011\nzb45A\u0011\u0016p+\u0017\"i\":>j5\u000eE\u0004 rn6\u000f@PC +\u007fJm>;>\u007f)\u0007IPC>4`&e=6J+qZ\u001c@O\bZn,\u000fX\u0015\u001b>\u00bcZN\f/x5_XY\u000f'\f\u0011\nzb45A\u0011\u0016p+7\u0002I\u0002\u001a>l/\u0003HP\u0016p+h9i<:]_`\rC\u0019\u001b>M\u0012%aPWMN\f/o$_LD\u00175b%2\\N\u0012B\u0005P0HN\u0012B\u0005P\u001em+2\u0005[\u001e\nsi%\u0018\u0000P\u0018qb$Jj\"0S+!\u001fH\u0019\u000bAf!\u0003BP(VN\u0012/\f\u0011\nzb45@\u0015\t{g`V\u0012P@>+!\u0004HP\u000bwf%J\u0010P@7+\u00019\f\u0016\u0010q+\u0017\"i\":>y/\u001dB\u0005\u0012|n2J\u0010M_/;pZ\u001cY\u0005*9\u0018Z\u001d".length();
                var1_4 = 17;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 5;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = ah.a(v0, ah.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "n:e^\u0015T\u000f+-uT\bS\u000f'50\u0004n(uY";
                    var4_3 = "n:e^\u0015T\u000f+-uT\bS\u000f'50\u0004n(uY".length();
                    var1_4 = 17;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 85;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = ah.a(v0, ah.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        ah.c = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x7A);
        }
        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 -> 27;
                    case 1 -> 14;
                    case 2 -> 69;
                    case 3 -> 111;
                    case 4 -> 41;
                    case 5 -> 117;
                    default -> 122;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

