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