001    /*
002     * JBoss DNA (http://www.jboss.org/dna)
003     * See the COPYRIGHT.txt file distributed with this work for information
004     * regarding copyright ownership.  Some portions may be licensed
005     * to Red Hat, Inc. under one or more contributor license agreements.
006     * See the AUTHORS.txt file in the distribution for a full listing of 
007     * individual contributors. 
008     *
009     * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
010     * is licensed to you under the terms of the GNU Lesser General Public License as
011     * published by the Free Software Foundation; either version 2.1 of
012     * the License, or (at your option) any later version.
013     *
014     * JBoss DNA is distributed in the hope that it will be useful,
015     * but WITHOUT ANY WARRANTY; without even the implied warranty of
016     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017     * Lesser General Public License for more details.
018     *
019     * You should have received a copy of the GNU Lesser General Public
020     * License along with this software; if not, write to the Free
021     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
022     * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
023     */
024    package org.jboss.dna.connector.store.jpa.util;
025    
026    import javax.persistence.Column;
027    import javax.persistence.Entity;
028    import javax.persistence.Id;
029    import javax.persistence.NamedQueries;
030    import javax.persistence.NamedQuery;
031    import org.hibernate.ejb.Ejb3Configuration;
032    import org.jboss.dna.common.util.CheckArg;
033    import org.jboss.dna.connector.store.jpa.JpaSource;
034    import org.jboss.dna.connector.store.jpa.Model;
035    
036    /**
037     * An option for the store. This is typically used to save store-specific values.
038     * <p>
039     * This JPA entity is always added to the {@link Ejb3Configuration} in the {@link JpaSource#getConnection() JpaSource}, and
040     * therefore should not be {@link Model#configure(Ejb3Configuration) added to the configuration} by a {@link Model}.
041     * </p>
042     * 
043     * @author Randall Hauch
044     */
045    @Entity( name = "DNA_OPTIONS" )
046    @NamedQueries( {@NamedQuery( name = "StoreOptionEntity.findAll", query = "SELECT option FROM DNA_OPTIONS AS option" )} )
047    public class StoreOptionEntity {
048    
049        @Id
050        @Column( name = "NAME", nullable = false, unique = true, length = 512 )
051        private String name;
052    
053        @Column( name = "VALUE", nullable = false, unique = false, length = 512 )
054        private String value;
055    
056        /**
057         * 
058         */
059        protected StoreOptionEntity() {
060        }
061    
062        /**
063         * @param name the name of the option; may not be null or empty
064         * @param value the value of the option; may be null
065         */
066        public StoreOptionEntity( String name,
067                                  String value ) {
068            CheckArg.isNotEmpty(name, "name");
069            setName(name);
070            setValue(value);
071        }
072    
073        /**
074         * @param name the name of the option; may not be null or empty
075         */
076        public StoreOptionEntity( String name ) {
077            CheckArg.isNotEmpty(name, "name");
078            setName(name);
079        }
080    
081        /**
082         * @return name
083         */
084        public String getName() {
085            return name;
086        }
087    
088        /**
089         * @param name Sets name to the specified value.
090         */
091        public void setName( String name ) {
092            this.name = name;
093        }
094    
095        /**
096         * @return value
097         */
098        public String getValue() {
099            return value;
100        }
101    
102        /**
103         * @param value Sets value to the specified value.
104         */
105        public void setValue( String value ) {
106            this.value = value;
107        }
108    
109        /**
110         * {@inheritDoc}
111         * 
112         * @see java.lang.Object#hashCode()
113         */
114        @Override
115        public int hashCode() {
116            return getName().hashCode();
117        }
118    
119        /**
120         * {@inheritDoc}
121         * 
122         * @see java.lang.Object#equals(java.lang.Object)
123         */
124        @Override
125        public boolean equals( Object obj ) {
126            if (obj == this) return true;
127            if (obj instanceof StoreOptionEntity) {
128                StoreOptionEntity that = (StoreOptionEntity)obj;
129                if (!this.getName().equals(that.getName())) return false;
130                if (!this.getValue().equals(that.getValue())) return false;
131                return true;
132            }
133            return false;
134        }
135    
136        /**
137         * {@inheritDoc}
138         * 
139         * @see java.lang.Object#toString()
140         */
141        @Override
142        public String toString() {
143            return "Option " + getName() + " = \"" + getValue() + "\"";
144        }
145    }