001/* 002 * ModeShape (http://www.modeshape.org) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.modeshape.sequencer.ddl.datatype; 017 018import org.modeshape.sequencer.ddl.DdlConstants; 019 020/** 021 * A representation of SQL data types. 022 */ 023public class DataType { 024 025 public static final long DEFAULT_LENGTH = -1; 026 public static final int DEFAULT_PRECISION = -1; 027 public static final int DEFAULT_SCALE = -1; 028 public static final int DEFAULT_ARRAY_DIMENSIONS = 0; 029 030 private String name; 031 private long length = DEFAULT_LENGTH; 032 private int precision = DEFAULT_PRECISION; 033 private int scale = DEFAULT_SCALE; 034 private int arrayDimensions = DEFAULT_ARRAY_DIMENSIONS; 035 private boolean autoIncrement = false; 036 private boolean notNull = false; 037 038 /** 039 * The statement source. 040 */ 041 private String source = ""; 042 043 public DataType() { 044 super(); 045 } 046 047 public DataType( String theName ) { 048 super(); 049 this.name = theName; 050 } 051 052 public DataType( String name, 053 int length ) { 054 super(); 055 this.name = name; 056 this.length = length; 057 } 058 059 public DataType( String name, 060 int precision, 061 int scale ) { 062 super(); 063 this.name = name; 064 this.precision = precision; 065 this.scale = scale; 066 } 067 068 public String getName() { 069 return this.name; 070 } 071 072 public void setName( String value ) { 073 this.name = value; 074 } 075 076 public void setLength( long value ) { 077 this.length = value; 078 } 079 080 public long getLength() { 081 return this.length; 082 } 083 084 public void setPrecision( int value ) { 085 this.precision = value; 086 } 087 088 public int getPrecision() { 089 return this.precision; 090 } 091 092 public int getScale() { 093 return this.scale; 094 } 095 096 public void setScale( int value ) { 097 this.scale = value; 098 } 099 100 /** 101 * @return array dimensions 102 */ 103 public int getArrayDimensions() { 104 return arrayDimensions; 105 } 106 107 /** 108 * @param arrayDimensions 109 */ 110 public void setArrayDimensions(int arrayDimensions) { 111 this.arrayDimensions = arrayDimensions; 112 } 113 /** 114 * @return auto increment 115 */ 116 public boolean isAutoIncrement() { 117 return this.autoIncrement; 118 } 119 120 /** 121 * @param autoIncrement the autoIncrement flag to set 122 */ 123 public void setAutoIncrement(boolean autoIncrement) { 124 this.autoIncrement = autoIncrement; 125 } 126 127 /** 128 * @return not null flag 129 */ 130 public boolean isNotNull() { 131 return this.notNull; 132 } 133 134 /** 135 * @param notNull the notNull flag to set 136 */ 137 public void setNotNull(boolean notNull) { 138 this.notNull = notNull; 139 } 140 @Override 141 public String toString() { 142 StringBuilder result = new StringBuilder(100); 143 result.append("DataType()").append(" ").append(name); 144 145 return result.toString(); 146 } 147 148 /** 149 * @param source 150 */ 151 public void setSource( String source ) { 152 if (source == null) { 153 source = ""; 154 } 155 this.source = source; 156 } 157 158 /** 159 * @return source string 160 */ 161 public String getSource() { 162 return source; 163 } 164 165 /** 166 * @param addSpaceBefore 167 * @param value 168 */ 169 public void appendSource( boolean addSpaceBefore, 170 String value ) { 171 if (addSpaceBefore) { 172 this.source = this.source + DdlConstants.SPACE; 173 } 174 this.source = this.source + value; 175 } 176 177 /** 178 * @param addSpaceBefore 179 * @param value 180 * @param additionalStrs 181 */ 182 public void appendSource( boolean addSpaceBefore, 183 String value, 184 String... additionalStrs ) { 185 if (addSpaceBefore) { 186 this.source = this.source + DdlConstants.SPACE; 187 } 188 this.source = this.source + value; 189 } 190 191}