001package org.apache.maven.scm.provider.accurev;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.Collection;
023import java.util.Date;
024import java.util.HashSet;
025
026/**
027 * 
028 */
029public class Transaction
030{
031
032    /**
033     * 
034     */
035    public class Version
036    {
037
038        private String realSpec;
039
040        private String virtualSpec;
041
042        private String ancestorSpec;
043
044        private Long elementId;
045
046        private String elementName;
047
048        private Version( Long id, String elementName, String virtualSpec, String realSpec, String ancestor )
049        {
050            this.elementId = id;
051            this.virtualSpec = virtualSpec;
052            this.realSpec = realSpec;
053            this.ancestorSpec = ancestor;
054            this.elementName = elementName;
055        }
056
057        public String getVirtualSpec()
058        {
059            return virtualSpec;
060        }
061
062        public void setVirtualSpec( String virtualSpec )
063        {
064            this.virtualSpec = virtualSpec;
065        }
066
067        public String getAncestorSpec()
068        {
069            return ancestorSpec;
070        }
071
072        public void setAncestorSpec( String ancestorSpec )
073        {
074            this.ancestorSpec = ancestorSpec;
075        }
076
077        public void setRealSpec( String realSpec )
078        {
079            this.realSpec = realSpec;
080        }
081
082        public void setElementId( Long elementId )
083        {
084            this.elementId = elementId;
085        }
086
087        public String getRealSpec()
088        {
089            return realSpec;
090        }
091
092        public Long getElementId()
093        {
094            return elementId;
095        }
096
097        public Transaction getTransaction()
098        {
099            return getOuterTransaction();
100        }
101
102        public String getElementName()
103        {
104            return elementName;
105        }
106
107        @Override
108        public String toString()
109        {
110            return String.format( "Version: %s (%d) %s (%s) anc=%s", elementName, elementId, virtualSpec, realSpec,
111                                  ancestorSpec );
112        }
113
114    }
115
116    private Collection<Version> versions = new HashSet<Version>();
117
118    private long id;
119
120    public Transaction( Long id, Date when, String tranType, String user )
121    {
122        this.id = id;
123        this.tranType = tranType;
124        this.when = when;
125        this.author = user;
126    }
127
128    public long getId()
129    {
130        return id;
131    }
132
133    public String getTranType()
134    {
135        return tranType;
136    }
137
138    public String getComment()
139    {
140        return comment;
141    }
142
143    public void setComment( String comment )
144    {
145        this.comment = comment;
146    }
147
148    private Date when;
149
150    private String tranType;
151
152    private String author;
153
154    private String comment;
155
156    public long getTranId()
157    {
158        return id;
159    }
160
161    private Transaction getOuterTransaction()
162    {
163        return this;
164    }
165
166    public Collection<Version> getVersions()
167    {
168        return versions;
169    }
170
171    public Date getWhen()
172    {
173        return when;
174    }
175
176    public String getType()
177    {
178        return tranType;
179    }
180
181    public String getAuthor()
182    {
183        return author;
184    }
185
186    public void addVersion( Long id, String name, String virtualSpec, String realSpec, String ancestor )
187    {
188        Transaction.Version v = new Version( id, name, virtualSpec, realSpec, ancestor );
189        versions.add( v );
190
191    }
192
193    public String toString()
194    {
195        return String.format( "Transaction: %d, %s at %tc by %s -'%s'", this.getId(), this.getTranType(),
196                              this.getWhen(), this.getAuthor(), this.getComment() );
197    }
198}