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