001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.transaction;
016    
017    import java.util.EnumSet;
018    import java.util.HashMap;
019    import java.util.Map;
020    
021    /**
022     * @author Michael Young
023     * @author Shuyang Zhou
024     */
025    public enum Isolation {
026    
027            COUNTER(TransactionDefinition.ISOLATION_COUNTER),
028            DEFAULT(TransactionDefinition.ISOLATION_DEFAULT),
029            PORTAL(TransactionDefinition.ISOLATION_PORTAL),
030            READ_COMMITTED(TransactionDefinition.ISOLATION_READ_COMMITTED),
031            READ_UNCOMMITTED(TransactionDefinition.ISOLATION_READ_UNCOMMITTED),
032            REPEATABLE_READ(TransactionDefinition.ISOLATION_REPEATABLE_READ),
033            SERIALIZABLE(TransactionDefinition.ISOLATION_SERIALIZABLE);
034    
035            public static Isolation getIsolation(int value) {
036                    return _isolations.get(value);
037            }
038    
039            public int value() {
040                    return _value;
041            }
042    
043            private Isolation(int value) {
044                    _value = value;
045            }
046    
047            private static final Map<Integer, Isolation> _isolations = new HashMap<>();
048    
049            static {
050                    for (Isolation isolation : EnumSet.allOf(Isolation.class)) {
051                            _isolations.put(isolation._value, isolation);
052                    }
053            }
054    
055            private final int _value;
056    
057    }