View Javadoc

1   /*
2    * ModeShape (http://www.modeshape.org)
3    * See the COPYRIGHT.txt file distributed with this work for information
4    * regarding copyright ownership.  Some portions may be licensed
5    * to Red Hat, Inc. under one or more contributor license agreements.
6    * See the AUTHORS.txt file in the distribution for a full listing of 
7    * individual contributors. 
8    *
9    * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10   * is licensed to you under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation; either version 2.1 of
12   * the License, or (at your option) any later version.
13   *
14   * ModeShape is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this software; if not, write to the Free
21   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23   */
24  package org.modeshape.connector.store.jpa.util;
25  
26  import javax.persistence.Column;
27  import javax.persistence.Entity;
28  import javax.persistence.Id;
29  import javax.persistence.NamedQueries;
30  import javax.persistence.NamedQuery;
31  import org.hibernate.ejb.Ejb3Configuration;
32  import org.modeshape.common.util.CheckArg;
33  import org.modeshape.connector.store.jpa.JpaSource;
34  import org.modeshape.connector.store.jpa.Model;
35  
36  /**
37   * An option for the store. This is typically used to save store-specific values.
38   * <p>
39   * This JPA entity is always added to the {@link Ejb3Configuration} in the {@link JpaSource#getConnection() JpaSource}, and
40   * therefore should not be {@link Model#configure(Ejb3Configuration) added to the configuration} by a {@link Model}.
41   * </p>
42   */
43  @Entity( name = "MODE_OPTIONS" )
44  @NamedQueries( {@NamedQuery( name = "StoreOptionEntity.findAll", query = "SELECT option FROM MODE_OPTIONS AS option" )} )
45  public class StoreOptionEntity {
46  
47      @Id
48      @Column( name = "NAME", nullable = false, length = 512 )
49      private String name;
50  
51      @Column( name = "VALUE", nullable = false, length = 512 )
52      private String value;
53  
54      /**
55       * 
56       */
57      protected StoreOptionEntity() {
58      }
59  
60      /**
61       * @param name the name of the option; may not be null or empty
62       * @param value the value of the option; may be null
63       */
64      public StoreOptionEntity( String name,
65                                String value ) {
66          CheckArg.isNotEmpty(name, "name");
67          setName(name);
68          setValue(value);
69      }
70  
71      /**
72       * @param name the name of the option; may not be null or empty
73       */
74      public StoreOptionEntity( String name ) {
75          CheckArg.isNotEmpty(name, "name");
76          setName(name);
77      }
78  
79      /**
80       * @return name
81       */
82      public String getName() {
83          return name;
84      }
85  
86      /**
87       * @param name Sets name to the specified value.
88       */
89      public void setName( String name ) {
90          this.name = name;
91      }
92  
93      /**
94       * @return value
95       */
96      public String getValue() {
97          return value;
98      }
99  
100     /**
101      * @param value Sets value to the specified value.
102      */
103     public void setValue( String value ) {
104         this.value = value;
105     }
106 
107     /**
108      * {@inheritDoc}
109      * 
110      * @see java.lang.Object#hashCode()
111      */
112     @Override
113     public int hashCode() {
114         return getName().hashCode();
115     }
116 
117     /**
118      * {@inheritDoc}
119      * 
120      * @see java.lang.Object#equals(java.lang.Object)
121      */
122     @Override
123     public boolean equals( Object obj ) {
124         if (obj == this) return true;
125         if (obj instanceof StoreOptionEntity) {
126             StoreOptionEntity that = (StoreOptionEntity)obj;
127             if (!this.getName().equals(that.getName())) return false;
128             if (!this.getValue().equals(that.getValue())) return false;
129             return true;
130         }
131         return false;
132     }
133 
134     /**
135      * {@inheritDoc}
136      * 
137      * @see java.lang.Object#toString()
138      */
139     @Override
140     public String toString() {
141         return "Option " + getName() + " = \"" + getValue() + "\"";
142     }
143 }