001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2009 SonarSource SA
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.configuration;
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.Column;
027 import javax.persistence.Entity;
028 import javax.persistence.Lob;
029 import javax.persistence.Table;
030
031 /**
032 * @since 1.10
033 */
034 @Entity
035 @Table(name = "properties")
036 public class Property extends BaseIdentifiable {
037
038 @Column(name = "prop_key", updatable = true, nullable = true)
039 private String key;
040
041 @Column(name = "text_value", updatable = true, nullable = true, length = 167772150)
042 @Lob
043 private char[] value;
044
045 @Column(name = "resource_id", updatable = true, nullable = true)
046 private Integer resourceId;
047
048 @Column(name = "user_id", updatable = true, nullable = true)
049 private Integer userId;
050
051 public Property(String key, String value) {
052 this(key, value, null);
053 }
054
055 public Property(String key, String value, Integer resourceId) {
056 this.key = key;
057 if (value != null) {
058 this.value = value.toCharArray();
059
060 } else {
061 this.value = null;
062 }
063 this.resourceId = resourceId;
064 }
065
066 public Property() {
067 }
068
069 public String getKey() {
070 return key;
071 }
072
073 public void setKey(String key) {
074 this.key = key;
075 }
076
077 public String getValue() {
078 if (value != null) {
079 return new String(value);
080 }
081 return null;
082 }
083
084 public void setValue(String value) {
085 if (value != null) {
086 this.value = value.toCharArray();
087 } else {
088 this.value = null;
089 }
090 }
091
092 public Integer getResourceId() {
093 return resourceId;
094 }
095
096 public void setResourceId(Integer resourceId) {
097 this.resourceId = resourceId;
098 }
099
100 public Integer getUserId() {
101 return userId;
102 }
103
104 public Property setUserId(Integer userId) {
105 this.userId = userId;
106 return this;
107 }
108
109 @Override
110 public boolean equals(Object o) {
111 if (this == o) {
112 return true;
113 }
114 if (o == null || getClass() != o.getClass()) {
115 return false;
116 }
117
118 Property property = (Property) o;
119 if (!key.equals(property.key)) {
120 return false;
121 }
122 if (resourceId != null ? !resourceId.equals(property.resourceId) : property.resourceId != null) {
123 return false;
124 }
125 return !(userId != null ? !userId.equals(property.userId) : property.userId != null);
126
127 }
128
129 @Override
130 public int hashCode() {
131 int result = key.hashCode();
132 result = 31 * result + (resourceId != null ? resourceId.hashCode() : 0);
133 result = 31 * result + (userId != null ? userId.hashCode() : 0);
134 return result;
135 }
136
137 @Override
138 public String toString() {
139 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
140 .append("key", key)
141 .append("resource", resourceId)
142 .append("user", userId)
143 .append("value", value)
144 .toString();
145 }
146 }