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.EqualsBuilder;
023    import org.apache.commons.lang.builder.HashCodeBuilder;
024    import org.apache.commons.lang.builder.ToStringBuilder;
025    import org.sonar.api.database.BaseIdentifiable;
026    
027    import javax.persistence.Column;
028    import javax.persistence.Entity;
029    import javax.persistence.Lob;
030    import javax.persistence.Table;
031    
032    /**
033     * @since 1.10
034     */
035    @Entity
036    @Table(name = "properties")
037    public class Property extends BaseIdentifiable {
038    
039      @Column(name = "prop_key", updatable = true, nullable = true)
040      private String key;
041    
042      @Column(name = "text_value", updatable = true, nullable = true, length = 167772150)
043      @Lob
044      private char[] value;
045    
046      @Column(name = "resource_id", updatable = true, nullable = true)
047      private Integer resourceId;
048    
049      public Property(String key, String value) {
050        this(key, value, null);
051      }
052    
053      public Property(String key, String value, Integer resourceId) {
054        this.key = key;
055        if (value != null) {
056          this.value = value.toCharArray();
057    
058        } else {
059          this.value = null;
060        }
061        this.resourceId = resourceId;
062      }
063    
064      public Property() {
065      }
066    
067      public String getKey() {
068        return key;
069      }
070    
071      public void setKey(String key) {
072        this.key = key;
073      }
074    
075      public String getValue() {
076        if (value != null) {
077          return new String(value);
078        }
079        return null;
080      }
081    
082      public void setValue(String value) {
083        if (value != null) {
084          this.value = value.toCharArray();
085        } else {
086          this.value = null;
087        }
088      }
089    
090      public Integer getResourceId() {
091        return resourceId;
092      }
093    
094      public void setResourceId(Integer resourceId) {
095        this.resourceId = resourceId;
096      }
097    
098      @Override
099      public boolean equals(Object obj) {
100        if (!(obj instanceof Property)) {
101          return false;
102        }
103        if (this == obj) {
104          return true;
105        }
106        Property other = (Property) obj;
107        return new EqualsBuilder()
108            .append(key, other.getKey())
109            .append(resourceId, other.getResourceId())
110            .isEquals();
111      }
112    
113      @Override
114      public int hashCode() {
115        return new HashCodeBuilder(17, 37)
116            .append(key)
117            .append(resourceId)
118            .toHashCode();
119      }
120    
121      @Override
122      public String toString() {
123        return new ToStringBuilder(this)
124            .append("key", key)
125            .append("resource", resourceId)
126            .append("value", value)
127            .toString();
128      }
129    }