blob: 406e901cef2613289764398e8a4ac46ae3bb000a [file] [log] [blame]
Madan Jampanibff6d8f2015-03-31 16:53:47 -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 */
Madan Jampanif4c88502016-01-21 12:35:36 -080016package org.onosproject.store.primitives.impl;
Madan Jampanibff6d8f2015-03-31 16:53:47 -070017
18import java.util.List;
19
20import org.onosproject.store.service.DatabaseUpdate;
21import org.onosproject.store.service.Transaction;
22
23import com.google.common.collect.ImmutableList;
24
25/**
26 * A Default transaction implementation.
27 */
28public class DefaultTransaction implements Transaction {
29
30 private final long transactionId;
31 private final List<DatabaseUpdate> updates;
32 private final State state;
33 private final long lastUpdated;
34
35 public DefaultTransaction(long transactionId, List<DatabaseUpdate> updates) {
36 this(transactionId, updates, State.PREPARING, System.currentTimeMillis());
37 }
38
39 private DefaultTransaction(long transactionId, List<DatabaseUpdate> updates, State state, long lastUpdated) {
40 this.transactionId = transactionId;
41 this.updates = ImmutableList.copyOf(updates);
42 this.state = state;
43 this.lastUpdated = lastUpdated;
44 }
45
46 @Override
47 public long id() {
48 return transactionId;
49 }
50
51 @Override
52 public List<DatabaseUpdate> updates() {
53 return updates;
54 }
55
56 @Override
57 public State state() {
58 return state;
59 }
60
61 @Override
62 public Transaction transition(State newState) {
63 return new DefaultTransaction(transactionId, updates, newState, System.currentTimeMillis());
64 }
65
66 @Override
67 public long lastUpdated() {
68 return lastUpdated;
69 }
70}