summaryrefslogtreecommitdiffstats
path: root/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/TrackingId.java
blob: 7df7619df391fda99099e307e1e85a8ce1197054 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright (C) 2010 The Android Open Source Project
//
// Licensed 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 com.google.gerrit.reviewdb;

import com.google.gwtorm.client.Column;
import com.google.gwtorm.client.CompoundKey;
import com.google.gwtorm.client.StringKey;

/** External tracking id associated with a {@link Change} */
public final class TrackingId {
  public static final int TRACKING_ID_MAX_CHAR = 20;
  public static final int TRACKING_SYSTEM_MAX_CHAR = 10;

  /** External tracking id */
  public static class Id extends StringKey<com.google.gwtorm.client.Key<?>> {
    private static final long serialVersionUID = 1L;

    @Column(id = 1, length = TrackingId.TRACKING_ID_MAX_CHAR)
    protected String id;

    protected Id() {
    }

    public Id(final String id) {
      this.id = id;
    }

    @Override
    public String get() {
      return id;
    }

    @Override
    protected void set(String newValue) {
      id = newValue;
    }
  }

  /** Name of external tracking system */
  public static class System extends StringKey<com.google.gwtorm.client.Key<?>> {
    private static final long serialVersionUID = 1L;

    @Column(id = 1, length = TrackingId.TRACKING_SYSTEM_MAX_CHAR)
    protected String system;

    protected System() {
    }

    public System(final String s) {
      this.system = s;
    }

    @Override
    public String get() {
      return system;
    }

    @Override
    protected void set(String newValue) {
      system = newValue;
    }
  }

  public static class Key extends CompoundKey<Change.Id> {
    private static final long serialVersionUID = 1L;

    @Column(id = 1)
    protected Change.Id changeId;

    @Column(id = 2)
    protected Id trackingId;

    @Column(id = 3)
    protected System trackingSystem;

    protected Key() {
      changeId = new Change.Id();
      trackingId = new Id();
      trackingSystem = new System();
    }

    protected Key(final Change.Id ch, final Id id, final System s) {
      changeId = ch;
      trackingId = id;
      trackingSystem = s;
    }

    @Override
    public Change.Id getParentKey() {
      return changeId;
    }

    @Override
    public com.google.gwtorm.client.Key<?>[] members() {
      return new com.google.gwtorm.client.Key<?>[] {trackingId, trackingSystem};
    }
  }

  @Column(id = 1, name = Column.NONE)
  protected Key key;

  protected TrackingId() {
  }

  public TrackingId(final Change.Id ch, final TrackingId.Id id,
      final TrackingId.System s) {
    key = new Key(ch, id, s);
  }

  public TrackingId(final Change.Id ch, final String id, final String s) {
    key = new Key(ch, new TrackingId.Id(id), new TrackingId.System(s));
  }

  public Change.Id getChangeId() {
    return key.changeId;
  }

  public String getTrackingId() {
    return key.trackingId.get();
  }

  public String getSystem() {
    return key.trackingSystem.get();
  }

  @Override
  public int hashCode() {
    return key.hashCode();
  }

  @Override
  public boolean equals(final Object obj) {
    if (obj instanceof TrackingId) {
      final TrackingId tr = (TrackingId) obj;
      return tr.key.equals(tr.key);
    }
    return false;
  }
}