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    /**
018     * @author Shuyang Zhou
019     */
020    public interface TransactionAttribute {
021    
022            public Isolation getIsolation();
023    
024            public Propagation getPropagation();
025    
026            public boolean isReadOnly();
027    
028            public static class Builder {
029    
030                    public TransactionAttribute build() {
031                            return new DefaultTransactionAttribute(this);
032                    }
033    
034                    public Builder setIsolation(Isolation isolation) {
035                            _isolation = isolation;
036    
037                            return this;
038                    }
039    
040                    public Builder setPropagation(Propagation propagation) {
041                            _propagation = propagation;
042    
043                            return this;
044                    }
045    
046                    public Builder setReadOnly(boolean readOnly) {
047                            _readOnly = readOnly;
048    
049                            return this;
050                    }
051    
052                    private Isolation _isolation = Isolation.DEFAULT;
053                    private Propagation _propagation = Propagation.REQUIRED;
054                    private boolean _readOnly;
055    
056            }
057    
058            public static class DefaultTransactionAttribute
059                    implements TransactionAttribute {
060    
061                    @Override
062                    public Isolation getIsolation() {
063                            return _isolation;
064                    }
065    
066                    @Override
067                    public Propagation getPropagation() {
068                            return _propagation;
069                    }
070    
071                    @Override
072                    public boolean isReadOnly() {
073                            return _readOnly;
074                    }
075    
076                    private DefaultTransactionAttribute(Builder builder) {
077                            _isolation = builder._isolation;
078                            _propagation = builder._propagation;
079                            _readOnly = builder._readOnly;
080                    }
081    
082                    private final Isolation _isolation;
083                    private final Propagation _propagation;
084                    private final boolean _readOnly;
085    
086            }
087    
088    }