@@ -28,6 +28,14 @@ public enum Signedness {
2828 SIGNED , UNSIGNED
2929 }
3030
31+ public enum TypeModifier {
32+ SIGNED , UNSIGNED , ZEROFILL
33+ }
34+
35+ public enum NationalCharacterType {
36+ CHAR , VARCHAR
37+ }
38+
3139 private String dataType ;
3240 private List <String > argumentsStringList ;
3341 private String characterSet ;
@@ -37,6 +45,8 @@ public enum Signedness {
3745 private boolean zerofill ;
3846 private Integer precision ;
3947 private Integer scale ;
48+ private List <TypeModifier > typeModifiers ;
49+ private NationalCharacterType nationalCharacterType ;
4050
4151 public ColDataType () {
4252 // empty constructor
@@ -120,6 +130,58 @@ public void setZerofill(boolean zerofill) {
120130 this .zerofill = zerofill ;
121131 }
122132
133+ /** Returns MySQL numeric modifiers in their original order, including repetitions. */
134+ public List <TypeModifier > getTypeModifiers () {
135+ return typeModifiers ;
136+ }
137+
138+ public void setTypeModifiers (List <TypeModifier > typeModifiers ) {
139+ this .typeModifiers = typeModifiers ;
140+ signedness = null ;
141+ zerofill = false ;
142+ if (typeModifiers != null ) {
143+ for (TypeModifier modifier : typeModifiers ) {
144+ updateEffectiveModifier (modifier );
145+ }
146+ }
147+ }
148+
149+ public void addTypeModifier (TypeModifier typeModifier ) {
150+ if (typeModifiers == null ) {
151+ typeModifiers = new ArrayList <>();
152+ }
153+ typeModifiers .add (typeModifier );
154+ updateEffectiveModifier (typeModifier );
155+ }
156+
157+ private void updateEffectiveModifier (TypeModifier modifier ) {
158+ switch (modifier ) {
159+ case SIGNED :
160+ signedness = Signedness .SIGNED ;
161+ break ;
162+ case UNSIGNED :
163+ signedness = Signedness .UNSIGNED ;
164+ break ;
165+ case ZEROFILL :
166+ zerofill = true ;
167+ break ;
168+ default :
169+ break ;
170+ }
171+ }
172+
173+ public NationalCharacterType getNationalCharacterType () {
174+ return nationalCharacterType ;
175+ }
176+
177+ public void setNationalCharacterType (NationalCharacterType nationalCharacterType ) {
178+ this .nationalCharacterType = nationalCharacterType ;
179+ }
180+
181+ public boolean isNational () {
182+ return nationalCharacterType != null ;
183+ }
184+
123185 /**
124186 * The first numeric type parameter, e.g. {@code 255} for {@code VARCHAR(255)} or {@code 10} for
125187 * {@code DECIMAL(10, 2)}. {@code MAX} is reported as {@link Integer#MAX_VALUE}. Returns
@@ -161,8 +223,10 @@ public String toString() {
161223 + (argumentsStringList != null
162224 ? " " + PlainSelect .getStringList (argumentsStringList , true , true )
163225 : "" )
164- + (signedness != null ? " " + signedness : "" )
165- + (zerofill ? " ZEROFILL" : "" )
226+ + (typeModifiers != null && !typeModifiers .isEmpty ()
227+ ? " " + PlainSelect .getStringList (typeModifiers , false , false )
228+ : (signedness != null ? " " + signedness : "" )
229+ + (zerofill ? " ZEROFILL" : "" ))
166230 + arraySpec .toString ()
167231 + (characterSet != null ? " CHARACTER SET " + characterSet : "" );
168232 }
@@ -202,6 +266,16 @@ public ColDataType withZerofill(boolean zerofill) {
202266 return this ;
203267 }
204268
269+ public ColDataType withTypeModifiers (List <TypeModifier > typeModifiers ) {
270+ setTypeModifiers (typeModifiers );
271+ return this ;
272+ }
273+
274+ public ColDataType withNationalCharacterType (NationalCharacterType nationalCharacterType ) {
275+ setNationalCharacterType (nationalCharacterType );
276+ return this ;
277+ }
278+
205279 public ColDataType withPrecision (Integer precision ) {
206280 this .setPrecision (precision );
207281 return this ;
@@ -254,7 +328,9 @@ public final boolean equals(Object o) {
254328 && Objects .equals (intervalQualifier , that .intervalQualifier )
255329 && Objects .equals (arrayData , that .arrayData )
256330 && signedness == that .signedness
257- && zerofill == that .zerofill ;
331+ && zerofill == that .zerofill
332+ && Objects .equals (typeModifiers , that .typeModifiers )
333+ && nationalCharacterType == that .nationalCharacterType ;
258334 }
259335
260336 @ Override
@@ -266,6 +342,8 @@ public int hashCode() {
266342 result = 31 * result + Objects .hashCode (arrayData );
267343 result = 31 * result + Objects .hashCode (signedness );
268344 result = 31 * result + Boolean .hashCode (zerofill );
345+ result = 31 * result + Objects .hashCode (typeModifiers );
346+ result = 31 * result + Objects .hashCode (nationalCharacterType );
269347 return result ;
270348 }
271349}
0 commit comments