001/*
002 * Stallion Core: A Modern Web Framework
003 *
004 * Copyright (C) 2015 - 2016 Stallion Software LLC.
005 *
006 * This program is free software: you can redistribute it and/or modify it under the terms of the
007 * GNU General Public License as published by the Free Software Foundation, either version 2 of
008 * the License, or (at your option) any later version. This program is distributed in the hope that
009 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
011 * License for more details. You should have received a copy of the GNU General Public License
012 * along with this program.  If not, see <http://www.gnu.org/licenses/gpl-2.0.html>.
013 *
014 *
015 *
016 */
017
018package io.stallion.dataAccess.db;
019
020
021/**
022 * This class is used internally when reflecting over a Java model and converting it into
023 * a table schema.
024 */
025public class Col {
026    private String name = "";
027    private String propertyName = "";
028    private String dbType = null;
029    private Class jType = String.class;
030    private Boolean alternativeKey = false;
031    private Boolean uniqueKey = false;
032    private Boolean updateable = true;
033    private Boolean insertable = true;
034    private String converterClassName = "";
035    private Boolean nullable = true;
036    private int length = 0;
037
038    private Object defaultValue = null;
039    private DbColumnConverter converter = null;
040
041    /**
042     * The name of the column in the database table.
043     * @return
044     */
045    public String getName() {
046        return name;
047    }
048
049    public Col setName(String name) {
050        this.name = name;
051        return this;
052    }
053
054    /**
055     * The database column type for the column
056     * @return
057     */
058    public String getDbType() {
059        return dbType;
060    }
061
062    public Col setDbType(String dbType) {
063        this.dbType = dbType;
064        return this;
065    }
066
067    /**
068     * The Java type of the data
069     * @return
070     */
071    public Class getjType() {
072        return jType;
073    }
074
075    public Col setjType(Class jType) {
076        this.jType = jType;
077        return this;
078    }
079
080    /**
081     * Should the column be included in update queries?
082     * @return
083     */
084    public Boolean getUpdateable() {
085        return updateable;
086    }
087
088    public Col setUpdateable(Boolean updateable) {
089        this.updateable = updateable; return this;
090    }
091
092    /**
093     * Should the column be included in insert queries?
094     * @return
095     */
096    public Boolean getInsertable() {
097        return insertable;
098    }
099
100    public Col setInsertable(Boolean insertable) {
101        this.insertable = insertable;
102        return this;
103    }
104
105    /**
106     * The Java model property name for this column.
107     * @return
108     */
109    public String getPropertyName() {
110        return propertyName;
111    }
112
113    public Col setPropertyName(String propertyName) {
114        this.propertyName = propertyName;
115        return this;
116    }
117
118    /**
119     * The canonical class name for the converter (the converter converts
120     * between the database value type and the java value type for the column)
121     * @return
122     */
123    public String getConverterClassName() {
124        return converterClassName;
125    }
126
127    public Col setConverterClassName(String converterClassName) {
128        this.converterClassName = converterClassName;
129        return this;
130    }
131
132    /**
133     * Is this column indexed or a key?
134     * @return
135     */
136    public Boolean getAlternativeKey() {
137        return alternativeKey;
138    }
139
140    public Col setAlternativeKey(Boolean alternativeKey) {
141        this.alternativeKey = alternativeKey;
142        return this;
143    }
144
145    /**
146     * Is this column a unique key?
147     * @return
148     */
149    public Boolean getUniqueKey() {
150        return uniqueKey;
151    }
152
153    public Col setUniqueKey(Boolean uniqueKey) {
154        this.uniqueKey = uniqueKey;
155        return this;
156    }
157
158    /**
159     * A default value that should be used during insert/updates if null
160     * @return
161     */
162    public Object getDefaultValue() {
163        return defaultValue;
164    }
165
166    public Col setDefaultValue(Object defaultValue) {
167        this.defaultValue = defaultValue;
168        return this;
169    }
170
171    /**
172     * The converter instance that converts to and fro the object type that
173     * the JDBC needs and what the model instance needs.
174     * @return
175     */
176    public DbColumnConverter getConverter() {
177        return converter;
178    }
179
180    public Col setConverter(DbColumnConverter converter) {
181        this.converter = converter;
182        return this;
183    }
184
185    public Boolean getNullable() {
186        return nullable;
187    }
188
189    public Col setNullable(Boolean nullable) {
190        this.nullable = nullable;
191        return this;
192    }
193
194    public int getLength() {
195        return length;
196    }
197
198    public Col setLength(int length) {
199        this.length = length;
200        return this;
201    }
202}