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.configuration;
021
022 import org.apache.commons.lang.builder.ReflectionToStringBuilder;
023 import org.apache.commons.lang.builder.ToStringStyle;
024 import org.sonar.api.database.BaseIdentifiable;
025
026 import javax.persistence.Column;
027 import javax.persistence.Entity;
028 import javax.persistence.Lob;
029 import javax.persistence.Table;
030
031 /**
032 * IMPORTANT : This class can't be moved to org.sonar.jpa.dao for backward-compatibility reasons.
033 * This class is still used in some plugins.
034 *
035 * @since 1.10
036 */
037 @Entity
038 @Table(name = "properties")
039 public class Property extends BaseIdentifiable {
040
041 @Column(name = "prop_key", updatable = true, nullable = true)
042 private String key;
043
044 @Column(name = "text_value", updatable = true, nullable = true, length = 167772150)
045 @Lob
046 private char[] value;
047
048 @Column(name = "resource_id", updatable = true, nullable = true)
049 private Integer resourceId;
050
051 @Column(name = "user_id", updatable = true, nullable = true)
052 private Integer userId;
053
054 public Property(String key, String value) {
055 this(key, value, null);
056 }
057
058 public Property(String key, String value, Integer resourceId) {
059 this.key = key;
060 if (value != null) {
061 this.value = value.toCharArray();
062
063 } else {
064 this.value = null;
065 }
066 this.resourceId = resourceId;
067 }
068
069 public Property() {
070 }
071
072 public String getKey() {
073 return key;
074 }
075
076 public void setKey(String key) {
077 this.key = key;
078 }
079
080 public String getValue() {
081 if (value != null) {
082 return new String(value);
083 }
084 return null;
085 }
086
087 public void setValue(String value) {
088 if (value != null) {
089 this.value = value.toCharArray();
090 } else {
091 this.value = null;
092 }
093 }
094
095 public Integer getResourceId() {
096 return resourceId;
097 }
098
099 public void setResourceId(Integer resourceId) {
100 this.resourceId = resourceId;
101 }
102
103 public Integer getUserId() {
104 return userId;
105 }
106
107 public Property setUserId(Integer userId) {
108 this.userId = userId;
109 return this;
110 }
111
112 @Override
113 public boolean equals(Object o) {
114 if (this == o) {
115 return true;
116 }
117 if (o == null || getClass() != o.getClass()) {
118 return false;
119 }
120
121 Property property = (Property) o;
122 if (!key.equals(property.key)) {
123 return false;
124 }
125 if (resourceId != null ? !resourceId.equals(property.resourceId) : property.resourceId != null) {
126 return false;
127 }
128 return !(userId != null ? !userId.equals(property.userId) : property.userId != null);
129
130 }
131
132 @Override
133 public int hashCode() {
134 int result = key.hashCode();
135 result = 31 * result + (resourceId != null ? resourceId.hashCode() : 0);
136 result = 31 * result + (userId != null ? userId.hashCode() : 0);
137 return result;
138 }
139
140 @Override
141 public String toString() {
142 return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
143 }
144 }