/*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
*
* The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
* Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
*
* Contributor(s):
* Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
*
* If you didn't download this code from the following link, you should check
* if you aren't using an obsolete version: http://www.isqlviewer.com
*/
package org.isqlviewer;
/**
* Represents parameterized data for bookmarks and historical items that are to be executed as a prepared statement.
* <p>
* Each parameter has an optional index to specify the order in the prepared statement to bound in. If the order is not
* specified it will be automatically set based on the order it was added to the bookmark.
* <p>
* Each parameter has the user data to be transformed into a specific object in the form of a string, the format options
* will represent a string of commands to transform the user data into the specific type.
*
* @author Mark A. Kobold <mkobold at isqlviewer dot com>
* @version 1.0
*/
public class BindVariable implements Comparable<BindVariable> {
private int index = 0;
private int type = 1;
private String userData = null;
private String formatOptions = null;
/**
* Compares this parameter data to another for ordering by the index of the parameter.
* <p>
*
* @param o other bookmark parameter data to be comparaed against.
* @return number indicating relative value as specificed by comparable.
* @see Comparable
*/
public int compareTo(BindVariable o) {
if (o == null) {
return 1;
}
return index > o.index ? 1 : (index == o.index ? 0 : -1);
}
/**
* Returns the formatting options to be applied to the user data.
* <p>
* These commands are semi-colon ';' seperated commands that will be applied to the user data field of this object
* in order to transfor the user data in to the proper data type.
*
* @return formatting options and commands for the user data; can be <tt>null</tt>.
*/
public String getFormatOptions() {
return formatOptions;
}
/**
* Sets the formatting options and commands for the user data.
* <p>
*
* @param formatOptions The formatOptions for the user data to set; use <tt>null</tt> to disable.
*/
public void setFormatOptions(String formatOptions) {
this.formatOptions = formatOptions;
}
/**
* Gets the index of this parameter as part of the prepared statement.
* <p>
* This value will be a number of 1..n where n is total number of parameters for a bookmark. if the value is
* anything else like 0 or less then actual index will be determined automatically by the bookmark this instance is
* added to.
*
* @return index of this parameter for order within a prepared statement.
*/
public int getIndex() {
return index;
}
/**
* Sets the parameter index for determining order for a prepared statement.
* <p>
*
* @param index order of the parameter binding. within a prepared statement; use 0 or less to make index automatic.
*/
public void setIndex(int index) {
this.index = index;
}
/**
* Get the SQL type that represents the intended data type for this parameter.
* <p>
* This should always be a value that is defined within the java.sql.Types interface. The Types interface defines
* the domain of inteded values for this field.
*
* @return the intended SQL data type for this parameter.
* @see java.sql.Types
*/
public int getType() {
return type;
}
/**
* Sets the SQL data-type for the parameter.
* <p>
*
* @param type data-type identifier as defined by java.sql.Types.
* @see java.sql.Types
*/
public void setType(int type) {
this.type = type;
}
/**
* Gets the user data that represents the actual data to be bound to the prepared statement.
* <p>
* If there are formatting options those commands will be applied to this content to transform it to the target
* data-type.
* <p>
* This value can be null if not specified. It is not recommended to use the NULL Type for null values as that is
* not actually what the NULL type is for, so if a null date is needed that still use the DATE data-type.
*
* @return user data that represents the data to be bound to a prepared statement.
*/
public String getUserData() {
return userData;
}
/**
* Sets the user data to be bound to a prepared statement.
* <p>
*
* @param userData that represents the data-type; can be null.
*/
public void setUserData(String userData) {
this.userData = userData;
}
}
|