001    /**
002     * Copyright (c) 2000-2013 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 class TransactionAttribute {
021    
022            public Isolation getIsolation() {
023                    return _isolation;
024            }
025    
026            public Class<?>[] getNoRollbackForClasses() {
027                    return _noRollbackForClasses;
028            }
029    
030            public String[] getNoRollbackForClassNames() {
031                    return _noRollbackForClassNames;
032            }
033    
034            public Propagation getPropagation() {
035                    return _propagation;
036            }
037    
038            public Class<?>[] getRollbackForClasses() {
039                    return _rollbackForClasses;
040            }
041    
042            public String[] getRollbackForClassNames() {
043                    return _rollbackForClassNames;
044            }
045    
046            public int getTimeout() {
047                    return _timeout;
048            }
049    
050            public boolean isReadOnly() {
051                    return _readOnly;
052            }
053    
054            public static class Builder {
055    
056                    public TransactionAttribute build() {
057                            return new TransactionAttribute(this);
058                    }
059    
060                    public Builder setIsolation(Isolation isolation) {
061                            _isolation = isolation;
062    
063                            return this;
064                    }
065    
066                    public Builder setNoRollbackForClasses(
067                            Class<?>... noRollbackForClasses) {
068    
069                            _noRollbackForClasses = noRollbackForClasses;
070    
071                            return this;
072                    }
073    
074                    public Builder setNoRollbackForClassNames(
075                            String... noRollbackForClassNames) {
076    
077                            _noRollbackForClassNames = noRollbackForClassNames;
078    
079                            return this;
080                    }
081    
082                    public Builder setPropagation(Propagation propagation) {
083                            _propagation = propagation;
084    
085                            return this;
086                    }
087    
088                    public Builder setReadOnly(boolean readOnly) {
089                            _readOnly = readOnly;
090    
091                            return this;
092                    }
093    
094                    public Builder setRollbackForClasses(Class<?>... rollbackForClasses) {
095                            _rollbackForClasses = rollbackForClasses;
096    
097                            return this;
098                    }
099    
100                    public Builder setRollbackForClassNames(
101                            String... rollbackForClassNames) {
102    
103                            _rollbackForClassNames = rollbackForClassNames;
104    
105                            return this;
106                    }
107    
108                    private Isolation _isolation = Isolation.DEFAULT;
109                    private Class<?>[] _noRollbackForClasses = {};
110                    private String[] _noRollbackForClassNames = {};
111                    private Propagation _propagation = Propagation.REQUIRED;
112                    private boolean _readOnly;
113                    private Class<?>[] _rollbackForClasses = {};
114                    private String[] _rollbackForClassNames = {};
115                    private int _timeout = TransactionDefinition.TIMEOUT_DEFAULT;
116    
117            }
118    
119            private TransactionAttribute(Builder builder) {
120                    _isolation = builder._isolation;
121                    _noRollbackForClasses = builder._noRollbackForClasses;
122                    _noRollbackForClassNames = builder._noRollbackForClassNames;
123                    _propagation = builder._propagation;
124                    _readOnly = builder._readOnly;
125                    _rollbackForClasses = builder._rollbackForClasses;
126                    _rollbackForClassNames = builder._rollbackForClassNames;
127                    _timeout = builder._timeout;
128            }
129    
130            private final Isolation _isolation;
131            private final Class<?>[] _noRollbackForClasses;
132            private final String[] _noRollbackForClassNames;
133            private final Propagation _propagation;
134            private final boolean _readOnly;
135            private final Class<?>[] _rollbackForClasses;
136            private final String[] _rollbackForClassNames;
137            private final int _timeout;
138    
139    }