001 /*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * SonarQube is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
019 */
020 package org.sonar.api.database.model;
021
022 import org.apache.commons.lang.StringUtils;
023 import org.apache.commons.lang.builder.ToStringBuilder;
024 import org.apache.commons.lang.builder.ToStringStyle;
025 import org.sonar.api.database.BaseIdentifiable;
026 import org.sonar.api.database.DatabaseProperties;
027
028 import javax.persistence.Column;
029 import javax.persistence.Entity;
030 import javax.persistence.Lob;
031 import javax.persistence.Table;
032
033 @Entity
034 @Table(name = "snapshot_sources")
035 public class SnapshotSource extends BaseIdentifiable {
036
037 @Column(name = "snapshot_id")
038 private Integer snapshotId;
039
040 @Lob
041 @Column(name = "data", updatable = true, nullable = true, length = DatabaseProperties.MAX_TEXT_SIZE)
042 private String data;
043
044 public SnapshotSource() {
045 }
046
047 public SnapshotSource(Snapshot snapshot, String source) {
048 this.snapshotId = snapshot.getId();
049 this.data = source;
050 }
051
052 public SnapshotSource(Integer snapshotId, String source) {
053 this.snapshotId = snapshotId;
054 this.data = source;
055 }
056
057 public void setSnapshot(Snapshot snapshot) {
058 this.snapshotId = snapshot.getId();
059 }
060
061 public String getData() {
062 return data;
063 }
064
065 public void setData(String data) {
066 this.data = data;
067 }
068
069 @Override
070 public boolean equals(Object obj) {
071 if (!(obj instanceof SnapshotSource)) {
072 return false;
073 }
074 if (this == obj) {
075 return true;
076 }
077 SnapshotSource other = (SnapshotSource) obj;
078 return snapshotId.equals(other.snapshotId);
079 }
080
081 @Override
082 public int hashCode() {
083 return snapshotId.hashCode();
084 }
085
086 @Override
087 public String toString() {
088 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
089 .append("snapshot_id", snapshotId)
090 .append("data", StringUtils.abbreviate(data, 1000))
091 .toString();
092 }
093 }