Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
net.sourceforge.jtds.jdbc.Support
public class Support
extends java.lang.Object
Field Summary | |
private static BigDecimal | |
private static BigDecimal | |
private static java.sql.Date | |
private static Double | |
private static Double | |
private static Float | |
private static Float | |
private static Integer | |
private static Integer | |
private static Long | |
private static Long | |
private static BigInteger | |
private static BigInteger | |
private static java.sql.Time | |
private static GregorianCalendar |
|
private static char[] |
|
private static HashMap |
|
Constructor Summary | |
|
Method Summary | |
(package private) static int |
|
(package private) static Object |
|
static Object |
|
static int |
|
(package private) static void |
|
(package private) static byte[] |
|
(package private) static String |
|
private static ConnectionJDBC2 |
|
(package private) static int |
|
(package private) static int |
|
(package private) static String |
|
(package private) static String |
|
(package private) static String |
|
static boolean |
|
static Throwable |
|
static SQLException |
|
static SQLWarning |
|
(package private) static BigDecimal |
|
(package private) static String |
|
(package private) static String |
|
static long |
|
static long |
|
static String |
|
private static final BigDecimal BIG_DECIMAL_ONE
private static final BigDecimal BIG_DECIMAL_ZERO
private static final java.sql.Date DATE_ZERO
private static final Double DOUBLE_ONE
private static final Double DOUBLE_ZERO
private static final Float FLOAT_ONE
private static final Float FLOAT_ZERO
private static final Integer INTEGER_ONE
private static final Integer INTEGER_ZERO
private static final Long LONG_ONE
private static final Long LONG_ZERO
private static final BigInteger MAX_VALUE_28
private static final BigInteger MAX_VALUE_38
private static final java.sql.Time TIME_ZERO
private static final GregorianCalendar cal
Static utility Calendar object.
private static final char[] hex
Hex constants to use in conversion routines.
private static final HashMap typeMap
Convert java clases to java.sql.Type constant.
(package private) static int calculateNamedPipeBufferSize(int tdsVersion, int packetSize)
Calculate the buffer size to use when buffering theInputStream
for named pipes. The buffer size is tied directly to the packet size because each request to theSmbNamedPipe
will send a request for a particular size of packet. In other words, if you only request 1 byte, theSmbNamedPipe
will send a request out and only ask for 1 byte back. Buffering the expected packet size ensures that all of the data will be returned in the buffer without wasting any space.
- Parameters:
tdsVersion
- the TDS version for the connectionpacketSize
- requested packet size for the connection
- Returns:
- minimum default packet size if
packetSize == 0
, elsepacketSize
(package private) static Object convert(Object callerReference, Object x, int jdbcType, String charSet) throws SQLException
Convert an existing data object to the specified JDBC type.
- Parameters:
callerReference
- an object reference to the caller of this method; must be aConnection
,Statement
orResultSet
x
- the data object to convertjdbcType
- the required type constant fromjava.sql.Types
- Returns:
- the converted data object
public static Object convertLOB(Object value) throws SQLException
Converts a LOB to the equivalent Java type, i.e.Clob
toString
andBlob
tobyte[]
. If the value passed is not a LOB object, it is left unchanged and no exception is thrown; the idea is to transparently convert only LOBs.
- Parameters:
value
- an object that may be a LOB
- Returns:
- if the value was a LOB, the equivalent Java object, otherwise the original value
public static int convertLOBType(int type)
Converts a LOB type constant to the equivalent Java type constant, i.e.Types.CLOB
toTypes.LONGVARCHAR
andTypes.BLOB
toTypes.LONGVARBINARY
. If the type passed is not that of a LOB, it is left unchanged and no exception is thrown; the idea is to transparently convert only LOB types.
- Parameters:
type
- aTypes
constant defining a JDBC type, possibly a LOB
- Returns:
- if the type was that of a LOB, the equivalent Java object type, otherwise the original type
(package private) static void embedData(StringBuffer buf, Object value, boolean isUnicode, ConnectionJDBC2 connection) throws SQLException
Embed the data object as a string literal in the buffer supplied.
- Parameters:
buf
- The buffer in which the data will be embeded.value
- The data object.isUnicode
- Set totrue
if Unicode strings should be used, elsefalse
.connection
- TheConnectionJDBC2
object.
(package private) static byte[] encodeString(String cs, String value)
Encode a string into a byte array using the specified character set.
- Parameters:
cs
- The Charset name.value
- The value to encode.
- Returns:
- The value of the String as a
byte[]
.
(package private) static String getClassName(int jdbcType)
Retrieve the fully qualified java class name for the supplied JDBC Types constant.
- Parameters:
jdbcType
- The JDBC Types constant.
- Returns:
- The fully qualified java class name as a
String
.
private static ConnectionJDBC2 getConnection(Object callerReference)
Returns the connection for a givenResultSet
,Statement
orConnection
object.
- Parameters:
callerReference
- an object reference to the caller of this method; must be aConnection
,Statement
orResultSet
- Returns:
- a connection
(package private) static int getJdbcType(Class typeClass)
Get the JDBC type constant which matches the suppliedClass
.
- Parameters:
typeClass
- theClass
to analyse
- Returns:
- the JDBC type constant as an
int
(package private) static int getJdbcType(Object value)
Get the JDBC type constant which matches the supplied Object type.
- Parameters:
value
- The object to analyse.
- Returns:
- The JDBC type constant as an
int
.
(package private) static String getJdbcTypeName(int jdbcType)
Get a String describing the supplied JDBC type constant.
- Parameters:
jdbcType
- The constant to be decoded.
- Returns:
- The text decode of the type constant as a
String
.
(package private) static String getParameterDefinitions(ParamInfo[] parameters)
Constructs a parameter definition string for use with sp_executesql, sp_prepare, sp_prepexec, sp_cursoropen, sp_cursorprepare and sp_cursorprepexec.
- Parameters:
parameters
- Parameters to construct the definition for
- Returns:
- a parameter definition string
(package private) static String getStatementKey(String sql, ParamInfo[] params, int serverType, String catalog, boolean autoCommit, boolean cursor)
Generates a unique statement key for a given SQL statement.
- Parameters:
sql
- the sql statment to generate the key forparams
- the statement parametersserverType
- the type of server to generate the key forcatalog
- the catalog is required for uniqueness on Microsoft SQL ServerautoCommit
- true if in auto commit modecursor
- true if this is a prepared cursor
- Returns:
- the unique statement key
public static boolean isWindowsOS()
Checks theos.name
system property to see if it starts with "windows".
- Returns:
true
ifos.name
starts with "windows", elsefalse
.
public static Throwable linkException(Exception exception, Throwable cause)
Link the original cause to anException
. If running under JVM 1.4+ theThrowable.initCause(Throwable)
method will be invoked to chain the exception, else the exception is logged via theLogger
class. Modeled after the code written by Brian Heineman.
- Parameters:
exception
- TheException
to enhance.cause
- TheThrowable
to link.
- Returns:
- The original
Exception
object.
public static SQLException linkException(SQLException sqle, Throwable cause)
Link the original cause to anSQLException
. This convenience method callslinkException(Exception,Throwable)
and casts the result for cleaner code elsewhere.
- Parameters:
sqle
- TheSQLException
to enhance.cause
- TheThrowable
to link.
- Returns:
- The original
SQLException
object.
public static SQLWarning linkException(SQLWarning sqle, Throwable cause)
Link the original cause to anSQLWarning
. This convenience method callslinkException(Exception,Throwable)
and casts the result for cleaner code elsewhere.
- Parameters:
sqle
- TheSQLWarning
to enhance.cause
- TheThrowable
to link.
- Returns:
- The original
SQLWarning
object.
(package private) static BigDecimal normalizeBigDecimal(BigDecimal value, int maxPrecision) throws SQLException
Normalize a BigDecimal value so that it fits within the available precision.
- Parameters:
value
- The decimal value to normalize.maxPrecision
- The decimal precision supported by the server (assumed to be a value of either 28 or 38).
- Returns:
- The possibly normalized decimal value as a
BigDecimal
.
(package private) static String substituteParamMarkers(String sql, ParamInfo[] list)
Update the SQL string and replace the ? markers with parameter names eg @P0, @P1 etc.
- Parameters:
sql
- the SQL containing markers to substitutelist
- the parameter list
- Returns:
- the modified SQL as a
String
(package private) static String substituteParameters(String sql, ParamInfo[] list, ConnectionJDBC2 connection) throws SQLException
Substitute actual data for the parameter markers to simulate parameter substitution in a PreparedStatement.
- Parameters:
sql
- The SQL containing parameter markers to substitute.list
- The parameter descriptors.connection
- The current connection.
- Returns:
- The modified SQL statement.
public static long timeFromZone(java.util.Date value, Calendar target)
Convert a timestamp from a different Timezone.
- Parameters:
value
- the timestamp value.target
- the Calendar containing the TimeZone.
- Returns:
- The new timestamp value as a
long
.
public static long timeToZone(java.util.Date value, Calendar target)
Convert a timestamp to a different Timezone.
- Parameters:
value
- the timestamp valuetarget
- theCalendar
containing the TimeZone
- Returns:
- the new timestamp value as a
long
public static String toHex(byte[] bytes)
Convert a byte[] object to a hex string.
- Parameters:
bytes
- The byte array to convert.
- Returns:
- The hex equivalent as a
String
.