Madan Jampani | 619453b | 2015-07-22 23:47:09 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Ayaka Koshibe | 3a32156 | 2015-04-29 13:24:07 -0700 | [diff] [blame] | 16 | package org.onosproject.store.consistent.impl; |
| 17 | |
| 18 | import org.onosproject.store.service.TransactionContext; |
| 19 | import org.onosproject.store.service.TransactionContextBuilder; |
| 20 | |
| 21 | /** |
| 22 | * The default implementation of a transaction context builder. This builder |
| 23 | * generates a {@link DefaultTransactionContext}. |
| 24 | */ |
| 25 | public class DefaultTransactionContextBuilder implements TransactionContextBuilder { |
| 26 | |
| 27 | private boolean partitionsEnabled = true; |
Madan Jampani | 50589ac | 2015-06-08 11:38:46 -0700 | [diff] [blame] | 28 | private final DatabaseManager manager; |
Ayaka Koshibe | 3a32156 | 2015-04-29 13:24:07 -0700 | [diff] [blame] | 29 | private final long transactionId; |
| 30 | |
Madan Jampani | 50589ac | 2015-06-08 11:38:46 -0700 | [diff] [blame] | 31 | public DefaultTransactionContextBuilder(DatabaseManager manager, long transactionId) { |
| 32 | this.manager = manager; |
Ayaka Koshibe | 3a32156 | 2015-04-29 13:24:07 -0700 | [diff] [blame] | 33 | this.transactionId = transactionId; |
| 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public TransactionContextBuilder withPartitionsDisabled() { |
| 38 | partitionsEnabled = false; |
| 39 | return this; |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public TransactionContext build() { |
| 44 | return new DefaultTransactionContext( |
Madan Jampani | 50589ac | 2015-06-08 11:38:46 -0700 | [diff] [blame] | 45 | transactionId, |
| 46 | partitionsEnabled ? manager.partitionedDatabase : manager.inMemoryDatabase, |
| 47 | () -> partitionsEnabled ? manager.consistentMapBuilder() |
| 48 | : manager.consistentMapBuilder().withPartitionsDisabled()); |
Ayaka Koshibe | 3a32156 | 2015-04-29 13:24:07 -0700 | [diff] [blame] | 49 | } |
Ayaka Koshibe | 3a32156 | 2015-04-29 13:24:07 -0700 | [diff] [blame] | 50 | } |