001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2012 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar 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 * Sonar 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 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020 package org.sonar.api.database.model; 021 022 import org.apache.commons.lang.builder.ToStringBuilder; 023 import org.apache.commons.lang.builder.ToStringStyle; 024 import org.sonar.api.database.BaseIdentifiable; 025 026 import javax.persistence.*; 027 028 @Entity 029 @Table(name = "measure_data") 030 public class MeasureData extends BaseIdentifiable { 031 032 @OneToOne(fetch = FetchType.LAZY) 033 @JoinColumn(name = "measure_id") 034 private MeasureModel measure; 035 036 @Column(name = "snapshot_id", updatable = true, nullable = true) 037 private Integer snapshotId; 038 039 @Column(name = "data", updatable = true, nullable = true, length = 167772150) 040 private byte[] data; 041 042 public MeasureData(MeasureModel measure) { 043 this.measure = measure; 044 } 045 046 public MeasureData(MeasureModel measure, byte[] data) { 047 this.measure = measure; 048 this.data = data; 049 } 050 051 public MeasureData(MeasureModel measure, String dataString) { 052 this.measure = measure; 053 this.data = dataString.getBytes(); 054 } 055 056 public MeasureData() { 057 } 058 059 public MeasureModel getMeasure() { 060 return measure; 061 } 062 063 public void setMeasure(MeasureModel measure) { 064 this.measure = measure; 065 } 066 067 public byte[] getData() { 068 return data; 069 } 070 071 public String getText() { 072 if (data != null) { 073 return new String(data); 074 } 075 return null; 076 } 077 078 public void setData(byte[] data) { 079 this.data = data; 080 } 081 082 public Integer getSnapshotId() { 083 return snapshotId; 084 } 085 086 public void setSnapshotId(Integer snapshotId) { 087 this.snapshotId = snapshotId; 088 } 089 090 @Override 091 public String toString() { 092 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) 093 .append("snapshotId", snapshotId) 094 .append("mesasure", measure) 095 .append("data", data) 096 .toString(); 097 } 098 } 099