View Javadoc

1   /*
2    * ModeShape (http://www.modeshape.org)
3    * See the COPYRIGHT.txt file distributed with this work for information
4    * regarding copyright ownership.  Some portions may be licensed
5    * to Red Hat, Inc. under one or more contributor license agreements.
6    * See the AUTHORS.txt file in the distribution for a full listing of 
7    * individual contributors.
8    *
9    * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10   * is licensed to you under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation; either version 2.1 of
12   * the License, or (at your option) any later version.
13   * 
14   * ModeShape is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this software; if not, write to the Free
21   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23   */
24  package org.modeshape.sequencer.ddl.datatype;
25  
26  import org.modeshape.sequencer.ddl.DdlConstants;
27  
28  /**
29   * A representation of SQL data types.
30   */
31  public class DataType {
32      private String name;
33      private int length = -1;
34      private int precision = -1;
35      private int scale = -1;
36      private boolean isKMGLength = false;
37      private String kmgValue = null;
38  
39      /**
40       * The statement source.
41       */
42      private String source = "";
43  
44      public DataType() {
45          super();
46      }
47  
48      public DataType( String theName ) {
49          super();
50          this.name = theName;
51      }
52  
53      public DataType( String name,
54                       int length ) {
55          super();
56          this.name = name;
57          this.length = length;
58      }
59  
60      public DataType( String name,
61                       int precision,
62                       int scale ) {
63          super();
64          this.name = name;
65          this.precision = precision;
66          this.scale = scale;
67      }
68  
69      public String getName() {
70          return this.name;
71      }
72  
73      public void setName( String value ) {
74          this.name = value;
75      }
76  
77      public void setLength( int value ) {
78          this.length = value;
79      }
80  
81      public int getLength() {
82          return this.length;
83      }
84  
85      public void setPrecision( int value ) {
86          this.precision = value;
87      }
88  
89      public int getPrecision() {
90          return this.precision;
91      }
92  
93      public int getScale() {
94          return this.scale;
95      }
96  
97      public void setScale( int value ) {
98          this.scale = value;
99      }
100 
101     @Override
102     public String toString() {
103         StringBuffer result = new StringBuffer(100);
104         result.append("DataType()").append(" ").append(name);
105 
106         return result.toString();
107     }
108 
109     public boolean isKMGLength() {
110         return isKMGLength;
111     }
112 
113     public void setKMGLength( boolean isKMGLength ) {
114         this.isKMGLength = isKMGLength;
115     }
116 
117     public String getKMGValue() {
118         return kmgValue;
119     }
120 
121     public void setKMGValue( String kmgValue ) {
122         this.kmgValue = kmgValue;
123     }
124 
125     /**
126      * @param source
127      */
128     public void setSource( String source ) {
129         if (source == null) {
130             source = "";
131         }
132         this.source = source;
133     }
134 
135     /**
136      * @return source string
137      */
138     public String getSource() {
139         return source;
140     }
141 
142     /**
143      * @param addSpaceBefore
144      * @param value
145      */
146     public void appendSource( boolean addSpaceBefore,
147                               String value ) {
148         if (addSpaceBefore) {
149             this.source = this.source + DdlConstants.SPACE;
150         }
151         this.source = this.source + value;
152     }
153 
154     /**
155      * @param addSpaceBefore
156      * @param value
157      * @param additionalStrs
158      */
159     public void appendSource( boolean addSpaceBefore,
160                               String value,
161                               String... additionalStrs ) {
162         if (addSpaceBefore) {
163             this.source = this.source + DdlConstants.SPACE;
164         }
165         this.source = this.source + value;
166     }
167 
168 }