001: /*
002: * The contents of this file are subject to the Mozilla Public License
003: * Version 1.1 (the "License"); you may not use this file except in
004: * compliance with the License. You may obtain a copy of the License at
005: * http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
009: * License for the specific language governing rights and limitations
010: * under the License.
011: *
012: * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
013: *
014: * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
015: * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
016: *
017: * Contributor(s):
018: * Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
019: *
020: * If you didn't download this code from the following link, you should check
021: * if you aren't using an obsolete version: http://www.isqlviewer.com
022: */
023: package org.isqlviewer;
024:
025: /**
026: * Represents parameterized data for bookmarks and historical items that are to be executed as a prepared statement.
027: * <p>
028: * Each parameter has an optional index to specify the order in the prepared statement to bound in. If the order is not
029: * specified it will be automatically set based on the order it was added to the bookmark.
030: * <p>
031: * Each parameter has the user data to be transformed into a specific object in the form of a string, the format options
032: * will represent a string of commands to transform the user data into the specific type.
033: *
034: * @author Mark A. Kobold <mkobold at isqlviewer dot com>
035: * @version 1.0
036: */
037: public class BindVariable implements Comparable<BindVariable> {
038:
039: private int index = 0;
040: private int type = 1;
041: private String userData = null;
042: private String formatOptions = null;
043:
044: /**
045: * Compares this parameter data to another for ordering by the index of the parameter.
046: * <p>
047: *
048: * @param o other bookmark parameter data to be comparaed against.
049: * @return number indicating relative value as specificed by comparable.
050: * @see Comparable
051: */
052: public int compareTo(BindVariable o) {
053:
054: if (o == null) {
055: return 1;
056: }
057: return index > o.index ? 1 : (index == o.index ? 0 : -1);
058: }
059:
060: /**
061: * Returns the formatting options to be applied to the user data.
062: * <p>
063: * These commands are semi-colon ';' seperated commands that will be applied to the user data field of this object
064: * in order to transfor the user data in to the proper data type.
065: *
066: * @return formatting options and commands for the user data; can be <tt>null</tt>.
067: */
068: public String getFormatOptions() {
069:
070: return formatOptions;
071: }
072:
073: /**
074: * Sets the formatting options and commands for the user data.
075: * <p>
076: *
077: * @param formatOptions The formatOptions for the user data to set; use <tt>null</tt> to disable.
078: */
079: public void setFormatOptions(String formatOptions) {
080:
081: this .formatOptions = formatOptions;
082: }
083:
084: /**
085: * Gets the index of this parameter as part of the prepared statement.
086: * <p>
087: * This value will be a number of 1..n where n is total number of parameters for a bookmark. if the value is
088: * anything else like 0 or less then actual index will be determined automatically by the bookmark this instance is
089: * added to.
090: *
091: * @return index of this parameter for order within a prepared statement.
092: */
093: public int getIndex() {
094:
095: return index;
096: }
097:
098: /**
099: * Sets the parameter index for determining order for a prepared statement.
100: * <p>
101: *
102: * @param index order of the parameter binding. within a prepared statement; use 0 or less to make index automatic.
103: */
104: public void setIndex(int index) {
105:
106: this .index = index;
107: }
108:
109: /**
110: * Get the SQL type that represents the intended data type for this parameter.
111: * <p>
112: * This should always be a value that is defined within the java.sql.Types interface. The Types interface defines
113: * the domain of inteded values for this field.
114: *
115: * @return the intended SQL data type for this parameter.
116: * @see java.sql.Types
117: */
118: public int getType() {
119:
120: return type;
121: }
122:
123: /**
124: * Sets the SQL data-type for the parameter.
125: * <p>
126: *
127: * @param type data-type identifier as defined by java.sql.Types.
128: * @see java.sql.Types
129: */
130: public void setType(int type) {
131:
132: this .type = type;
133: }
134:
135: /**
136: * Gets the user data that represents the actual data to be bound to the prepared statement.
137: * <p>
138: * If there are formatting options those commands will be applied to this content to transform it to the target
139: * data-type.
140: * <p>
141: * This value can be null if not specified. It is not recommended to use the NULL Type for null values as that is
142: * not actually what the NULL type is for, so if a null date is needed that still use the DATE data-type.
143: *
144: * @return user data that represents the data to be bound to a prepared statement.
145: */
146: public String getUserData() {
147:
148: return userData;
149: }
150:
151: /**
152: * Sets the user data to be bound to a prepared statement.
153: * <p>
154: *
155: * @param userData that represents the data-type; can be null.
156: */
157: public void setUserData(String userData) {
158:
159: this.userData = userData;
160: }
161: }
|