blob: f20bfb8069868da1f25a470f795d0643e7b52e6d [file] [log] [blame]
Madan Jampani619453b2015-07-22 23:47:09 -07001/*
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 Koshibe3a321562015-04-29 13:24:07 -070016package org.onosproject.store.consistent.impl;
17
18import org.onosproject.store.service.TransactionContext;
19import org.onosproject.store.service.TransactionContextBuilder;
20
21/**
22 * The default implementation of a transaction context builder. This builder
23 * generates a {@link DefaultTransactionContext}.
24 */
25public class DefaultTransactionContextBuilder implements TransactionContextBuilder {
26
27 private boolean partitionsEnabled = true;
Madan Jampani50589ac2015-06-08 11:38:46 -070028 private final DatabaseManager manager;
Ayaka Koshibe3a321562015-04-29 13:24:07 -070029 private final long transactionId;
30
Madan Jampani50589ac2015-06-08 11:38:46 -070031 public DefaultTransactionContextBuilder(DatabaseManager manager, long transactionId) {
32 this.manager = manager;
Ayaka Koshibe3a321562015-04-29 13:24:07 -070033 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 Jampani50589ac2015-06-08 11:38:46 -070045 transactionId,
46 partitionsEnabled ? manager.partitionedDatabase : manager.inMemoryDatabase,
47 () -> partitionsEnabled ? manager.consistentMapBuilder()
48 : manager.consistentMapBuilder().withPartitionsDisabled());
Ayaka Koshibe3a321562015-04-29 13:24:07 -070049 }
Ayaka Koshibe3a321562015-04-29 13:24:07 -070050}