summaryrefslogtreecommitdiffstats
path: root/sandbox/old/contrib/persistence/store.jdbc/src/main/java/org/apache/tuscany/service/persistence/store/jdbc/Record.java
blob: e568481e17cffeb96627f7bda89ad8e914edf270 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.tuscany.service.persistence.store.jdbc;

import java.io.Serializable;

/**
 * Represents a persistent object and its metadata.
 * <p/>
 * Note this class has a natural ordering that is inconsistent with equals.
 *
 * @version $Rev$ $Date$
 */
public class Record implements Comparable {
    public static final int INSERT = 0;
    public static final int UPDATE = 1;

    private String ownerId;
    private String id;
    private Serializable object;
    private long expiration = JDBCStore.NEVER;
    private int operation;

    /**
     * Creates a new record
     *
     * @param ownerId
     * @param id         the unique id of the record
     * @param object     the object to serialize
     * @param expiration the expirary time, {@link org.apache.tuscany.spi.services.store.Store.NEVER} if there is no
     *                   expiration
     * @param operation  an <code>INSERT</code> or <code>UPDATE</code> operation
     */
    public Record(String ownerId, String id, Serializable object, long expiration, int operation) {
        this.id = id;
        this.object = object;
        this.expiration = expiration;
        this.operation = operation;
        this.ownerId = ownerId;
    }

    /**
     * Returns the unique object id
     *
     * @return the unique object id
     */
    public String getId() {
        return id;
    }

    /**
     * Returns the object
     *
     * @return the object
     */
    public Serializable getObject() {
        return object;
    }

    /**
     * Sets the object to serialize
     *
     * @param object the object
     */
    public void setObject(Serializable object) {
        this.object = object;
    }

    /**
     * Returns the expiration time
     *
     * @return the expiration time
     */
    public long getExpiration() {
        return expiration;
    }

    /**
     * Returns the type of operation
     *
     * @return the type of operation
     */
    public int getOperation() {
        return operation;
    }

    public String getOwnerId() {
        return ownerId;
    }

    public void setOwnerId(String ownerId) {
        this.ownerId = ownerId;
    }

    public int compareTo(Object o) {
        assert o instanceof Record;
        Record record = (Record) o;
        if (record.getOperation() == operation) {
            return 0;
        } else if (record.getOperation() == INSERT) {
            return 1;
        } else if (record.getOperation() == UPDATE) {
            return -1;
        } else {
            throw new AssertionError();
        }
    }
}