001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/io/datastore/schema/content/MappingField.java $
002    /*----------------------------------------------------------------------------
003     This file is part of deegree, http://deegree.org/
004     Copyright (C) 2001-2009 by:
005       Department of Geography, University of Bonn
006     and
007       lat/lon GmbH
008    
009     This library is free software; you can redistribute it and/or modify it under
010     the terms of the GNU Lesser General Public License as published by the Free
011     Software Foundation; either version 2.1 of the License, or (at your option)
012     any later version.
013     This library is distributed in the hope that it will be useful, but WITHOUT
014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016     details.
017     You should have received a copy of the GNU Lesser General Public License
018     along with this library; if not, write to the Free Software Foundation, Inc.,
019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020    
021     Contact information:
022    
023     lat/lon GmbH
024     Aennchenstr. 19, 53177 Bonn
025     Germany
026     http://lat-lon.de/
027    
028     Department of Geography, University of Bonn
029     Prof. Dr. Klaus Greve
030     Postfach 1147, 53001 Bonn
031     Germany
032     http://www.geographie.uni-bonn.de/deegree/
033    
034     e-mail: info@deegree.org
035    ----------------------------------------------------------------------------*/
036    package org.deegree.io.datastore.schema.content;
037    
038    /**
039     * Encapsulates a field of the backend (e.g. an SQL table column).
040     *
041     * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
042     * @author last edited by: $Author: mschneider $
043     *
044     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
045     */
046    public class MappingField implements SimpleContent {
047    
048        private String table;
049    
050        private String field;
051    
052        private int type;
053    
054        private boolean auto;
055    
056        /**
057         * Creates a new instance of <code>MappingField</code> from the given parameters.
058         *
059         * @param table
060         * @param field
061         * @param type
062         *            type code
063         * @param auto
064         *
065         * @see java.sql.Types
066         */
067        public MappingField( String table, String field, int type, boolean auto ) {
068            this.table = table;
069            this.field = field;
070            this.type = type;
071            this.auto = auto;
072        }
073    
074        /**
075         * Creates a new instance of <code>MappingField</code> from the given parameters with no automatic generation of
076         * values.
077         *
078         * @param table
079         * @param field
080         * @param type
081         *
082         * @see java.sql.Types
083         */
084        public MappingField( String table, String field, int type ) {
085            this.table = table;
086            this.field = field;
087            this.type = type;
088        }
089    
090        /**
091         * Returns true, because a db field may be updated.
092         *
093         * @return true, because a db field may be updated
094         */
095        public boolean isUpdateable() {
096            return true;
097        }
098    
099        /**
100         * Returns true, because a db field is (in general) suitable as a sort criterion.
101         *
102         * @return true, because a db field is (in general) suitable as a sort criterion
103         */
104        public boolean isSortable() {
105            return true;
106        }
107    
108        /**
109         * Returns the name of the backend's (e.g. database) table.
110         *
111         * @return the table name
112         */
113        public String getTable() {
114            return this.table;
115        }
116    
117        /**
118         * Sets the table to the given table name. This is currently needed, as <code>MappedGMLSchema</code> must be able to
119         * resolve unspecified (null) table names.
120         *
121         * @param table
122         *            table name to set
123         */
124        public void setTable( String table ) {
125            this.table = table;
126        }
127    
128        /**
129         * Returns the name of the backend's (e.g. database) field.
130         *
131         * @return the field name
132         */
133        public String getField() {
134            return this.field;
135        }
136    
137        /**
138         * Returns the SQL type code of the field.
139         *
140         * @return the SQL type code
141         * @see java.sql.Types
142         */
143        public int getType() {
144            return this.type;
145        }
146    
147        /**
148         * Returns whether the backend generates the value automatically on insert.
149         *
150         * @return true, if a value for this field is generated automatically, false otherwise
151         */
152        public boolean isAuto() {
153            return this.auto;
154        }
155    
156        /**
157         * Returns <code>true</code> if the field has a numerical type.
158         *
159         * @see java.sql.Types
160         *
161         * @return <code>true</code> if the field has a numerical type, false otherwise
162         */
163        public boolean isNumeric() {
164            switch ( getType() ) {
165            case java.sql.Types.BIT:
166            case java.sql.Types.BIGINT:
167            case java.sql.Types.INTEGER:
168            case java.sql.Types.FLOAT:
169            case java.sql.Types.DOUBLE:
170            case java.sql.Types.DECIMAL:
171            case java.sql.Types.NUMERIC:
172            case java.sql.Types.REAL:
173            case java.sql.Types.SMALLINT:
174                return true;
175            }
176            return false;
177        }
178    
179        @Override
180        public String toString() {
181            return this.table + "." + this.field;
182        }
183    
184        @Override
185        public boolean equals( Object other ) {
186            if ( other == this ) {
187                return true;
188            }
189            if ( other instanceof MappingField ) {
190                MappingField f = (MappingField) other;
191                return f.table.equals( table ) && f.field.equals( field ) && f.type == type;
192            }
193            return super.equals( other );
194        }
195    
196    }