Ayaka Koshibe | 3a32156 | 2015-04-29 13:24:07 -0700 | [diff] [blame^] | 1 | package org.onosproject.store.consistent.impl; |
| 2 | |
| 3 | import org.onosproject.store.service.TransactionContext; |
| 4 | import org.onosproject.store.service.TransactionContextBuilder; |
| 5 | |
| 6 | /** |
| 7 | * The default implementation of a transaction context builder. This builder |
| 8 | * generates a {@link DefaultTransactionContext}. |
| 9 | */ |
| 10 | public class DefaultTransactionContextBuilder implements TransactionContextBuilder { |
| 11 | |
| 12 | private boolean partitionsEnabled = true; |
| 13 | private final Database partitionedDatabase; |
| 14 | private final Database inMemoryDatabase; |
| 15 | private final long transactionId; |
| 16 | |
| 17 | public DefaultTransactionContextBuilder( |
| 18 | Database inMemoryDatabase, Database partitionedDatabase, long transactionId) { |
| 19 | this.partitionedDatabase = partitionedDatabase; |
| 20 | this.inMemoryDatabase = inMemoryDatabase; |
| 21 | this.transactionId = transactionId; |
| 22 | } |
| 23 | |
| 24 | @Override |
| 25 | public TransactionContextBuilder withPartitionsDisabled() { |
| 26 | partitionsEnabled = false; |
| 27 | return this; |
| 28 | } |
| 29 | |
| 30 | @Override |
| 31 | public TransactionContext build() { |
| 32 | return new DefaultTransactionContext( |
| 33 | partitionsEnabled ? partitionedDatabase : inMemoryDatabase, |
| 34 | transactionId); |
| 35 | } |
| 36 | |
| 37 | } |