001: package liquibase.database.template;
002:
003: /**
004: * Object to represent a SQL parameter definition.
005: * <p/>
006: * <p>Parameters may be anonymous, in which case "name" is <code>null</code>.
007: * However, all parameters must define a SQL type according to {@link java.sql.Types}.
008: *
009: * @author Spring Framework
010: * @see java.sql.Types
011: */
012: class SqlParameter {
013:
014: /**
015: * The name of the parameter, if any
016: */
017: private String name;
018:
019: /**
020: * SQL type constant from <code>java.sql.Types</code>
021: */
022: private final int sqlType;
023:
024: /**
025: * Used for types that are user-named like: STRUCT, DISTINCT, JAVA_OBJECT, named array types
026: */
027: private String typeName;
028:
029: /**
030: * The scale to apply in case of a NUMERIC or DECIMAL type, if any
031: */
032: private Integer scale;
033:
034: /**
035: * Create a new anonymous SqlParameter, supplying the SQL type.
036: *
037: * @param sqlType SQL type of the parameter according to <code>java.sql.Types</code>
038: */
039: public SqlParameter(int sqlType) {
040: this .sqlType = sqlType;
041: }
042:
043: /**
044: * Create a new anonymous SqlParameter, supplying the SQL type.
045: *
046: * @param sqlType SQL type of the parameter according to <code>java.sql.Types</code>
047: * @param typeName the type name of the parameter (optional)
048: */
049: public SqlParameter(int sqlType, String typeName) {
050: this .sqlType = sqlType;
051: this .typeName = typeName;
052: }
053:
054: /**
055: * Create a new anonymous SqlParameter, supplying the SQL type.
056: *
057: * @param sqlType SQL type of the parameter according to <code>java.sql.Types</code>
058: * @param scale the number of digits after the decimal point
059: * (for DECIMAL and NUMERIC types)
060: */
061: public SqlParameter(int sqlType, int scale) {
062: this .sqlType = sqlType;
063: this .scale = scale;
064: }
065:
066: /**
067: * Create a new SqlParameter, supplying name and SQL type.
068: *
069: * @param name name of the parameter, as used in input and output maps
070: * @param sqlType SQL type of the parameter according to <code>java.sql.Types</code>
071: */
072: public SqlParameter(String name, int sqlType) {
073: this .name = name;
074: this .sqlType = sqlType;
075: }
076:
077: /**
078: * Create a new SqlParameter, supplying name and SQL type.
079: *
080: * @param name name of the parameter, as used in input and output maps
081: * @param sqlType SQL type of the parameter according to <code>java.sql.Types</code>
082: * @param typeName the type name of the parameter (optional)
083: */
084: public SqlParameter(String name, int sqlType, String typeName) {
085: this .name = name;
086: this .sqlType = sqlType;
087: this .typeName = typeName;
088: }
089:
090: /**
091: * Create a new SqlParameter, supplying name and SQL type.
092: *
093: * @param name name of the parameter, as used in input and output maps
094: * @param sqlType SQL type of the parameter according to <code>java.sql.Types</code>
095: * @param scale the number of digits after the decimal point
096: * (for DECIMAL and NUMERIC types)
097: */
098: public SqlParameter(String name, int sqlType, int scale) {
099: this .name = name;
100: this .sqlType = sqlType;
101: this .scale = scale;
102: }
103:
104: /**
105: * Copy constructor.
106: *
107: * @param otherParam the SqlParameter object to copy from
108: */
109: public SqlParameter(SqlParameter otherParam) {
110: this .name = otherParam.name;
111: this .sqlType = otherParam.sqlType;
112: this .typeName = otherParam.typeName;
113: this .scale = otherParam.scale;
114: }
115:
116: /**
117: * Return the name of the parameter.
118: */
119: public String getName() {
120: return this .name;
121: }
122:
123: /**
124: * Return the SQL type of the parameter.
125: */
126: public int getSqlType() {
127: return this .sqlType;
128: }
129:
130: /**
131: * Return the type name of the parameter, if any.
132: */
133: public String getTypeName() {
134: return this .typeName;
135: }
136:
137: /**
138: * Return the scale of the parameter, if any.
139: */
140: public Integer getScale() {
141: return this .scale;
142: }
143:
144: /**
145: * Return whether this parameter holds input values that should be set
146: * before execution even if they are <code>null</code>.
147: * <p>This implementation always returns <code>true</code>.
148: */
149: public boolean isInputValueProvided() {
150: return true;
151: }
152:
153: /**
154: * Return whether this parameter is an implicit return parameter used during the
155: * reults preocessing of the CallableStatement.getMoreResults/getUpdateCount.
156: * <p>This implementation always returns <code>false</code>.
157: */
158: public boolean isResultsParameter() {
159: return false;
160: }
161: }
|