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 long length = -1;
34      private int precision = -1;
35      private int scale = -1;
36  
37      /**
38       * The statement source.
39       */
40      private String source = "";
41  
42      public DataType() {
43          super();
44      }
45  
46      public DataType( String theName ) {
47          super();
48          this.name = theName;
49      }
50  
51      public DataType( String name,
52                       int length ) {
53          super();
54          this.name = name;
55          this.length = length;
56      }
57  
58      public DataType( String name,
59                       int precision,
60                       int scale ) {
61          super();
62          this.name = name;
63          this.precision = precision;
64          this.scale = scale;
65      }
66  
67      public String getName() {
68          return this.name;
69      }
70  
71      public void setName( String value ) {
72          this.name = value;
73      }
74  
75      public void setLength( long value ) {
76          this.length = value;
77      }
78  
79      public long getLength() {
80          return this.length;
81      }
82  
83      public void setPrecision( int value ) {
84          this.precision = value;
85      }
86  
87      public int getPrecision() {
88          return this.precision;
89      }
90  
91      public int getScale() {
92          return this.scale;
93      }
94  
95      public void setScale( int value ) {
96          this.scale = value;
97      }
98  
99      @Override
100     public String toString() {
101         StringBuffer result = new StringBuffer(100);
102         result.append("DataType()").append(" ").append(name);
103 
104         return result.toString();
105     }
106 
107     /**
108      * @param source
109      */
110     public void setSource( String source ) {
111         if (source == null) {
112             source = "";
113         }
114         this.source = source;
115     }
116 
117     /**
118      * @return source string
119      */
120     public String getSource() {
121         return source;
122     }
123 
124     /**
125      * @param addSpaceBefore
126      * @param value
127      */
128     public void appendSource( boolean addSpaceBefore,
129                               String value ) {
130         if (addSpaceBefore) {
131             this.source = this.source + DdlConstants.SPACE;
132         }
133         this.source = this.source + value;
134     }
135 
136     /**
137      * @param addSpaceBefore
138      * @param value
139      * @param additionalStrs
140      */
141     public void appendSource( boolean addSpaceBefore,
142                               String value,
143                               String... additionalStrs ) {
144         if (addSpaceBefore) {
145             this.source = this.source + DdlConstants.SPACE;
146         }
147         this.source = this.source + value;
148     }
149 
150 }