/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.PersistentEntity
 *  com.l7tech.objectmodel.imp.PersistentEntityUtil
 *  com.l7tech.util.RandomUtil
 *  org.hibernate.HibernateException
 *  org.hibernate.engine.spi.SharedSessionContractImplementor
 *  org.hibernate.id.IdentifierGenerator
 *  org.springframework.orm.hibernate5.LocalSessionFactoryBean
 */
package com.l7tech.server.util;

import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.PersistentEntity;
import com.l7tech.objectmodel.imp.PersistentEntityUtil;
import com.l7tech.util.RandomUtil;
import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;

public class ConfiguredSessionFactoryBean
extends LocalSessionFactoryBean {

    public static final class ConfiguredGOIDGenerator
    implements IdentifierGenerator {
        private static AtomicLong a;
        private static AtomicLong b;
        private static final int c = 65536;

        public ConfiguredGOIDGenerator() {
            long l2;
            while ((l2 = RandomUtil.nextLong()) >= 0L && l2 < 65536L) {
            }
            a = new AtomicLong(l2);
            b = new AtomicLong(RandomUtil.nextLong());
        }

        public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object object) throws HibernateException {
            block6: {
                try {
                    try {
                        try {
                            if (!(object instanceof PersistentEntity) || ((PersistentEntity)object).getGoid() == null) break block6;
                        }
                        catch (HibernateException hibernateException) {
                            throw ConfiguredGOIDGenerator.a(hibernateException);
                        }
                        if (!PersistentEntityUtil.isPreserveId((PersistentEntity)((PersistentEntity)object))) break block6;
                    }
                    catch (HibernateException hibernateException) {
                        throw ConfiguredGOIDGenerator.a(hibernateException);
                    }
                    return ((PersistentEntity)object).getGoid();
                }
                catch (HibernateException hibernateException) {
                    throw ConfiguredGOIDGenerator.a(hibernateException);
                }
            }
            return new Goid(a.get(), b.getAndIncrement());
        }

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

