org.midao.jdbc.core.handlers.type
Class TypeHandlerUtils

java.lang.Object
  extended by org.midao.jdbc.core.handlers.type.TypeHandlerUtils

public class TypeHandlerUtils
extends java.lang.Object

Utility classes used by TypeHandlers


Constructor Summary
TypeHandlerUtils()
           
 
Method Summary
static void closeQuietly(java.io.InputStream input)
          Closes InputStream while catching any exceptions
static void closeQuietly(java.io.OutputStream output)
          Closes OutputStream while catching any exceptions
static java.lang.Object convertArray(java.sql.Connection conn, java.util.Collection<?> array)
          Converts Collection into sql.Array
static java.lang.Object convertArray(java.sql.Connection conn, java.lang.Object[] array)
          Converts array of Object into sql.Array
static java.lang.Object convertBlob(java.sql.Connection conn, byte[] value)
          Transfers data from byte[] into sql.Blob
static java.lang.Object convertBlob(java.sql.Connection conn, java.io.InputStream input)
          Transfers data from InputStream into sql.Blob
static java.lang.Object convertBlob(java.sql.Connection conn, java.lang.String value)
          Transfers data from String into sql.Blob
static java.lang.Object convertBlob(java.lang.Object blob, byte[] value)
          Transfers data from byte[] into sql.Blob
static java.lang.Object convertBlob(java.lang.Object blob, java.io.InputStream input)
          Transfers data from InputStream into sql.Blob
static java.lang.Object convertBlob(java.lang.Object blob, java.lang.String value)
          Transfers data from String into sql.Blob
static java.lang.Object convertClob(java.sql.Connection conn, byte[] value)
          Transfers data from byte[] into sql.Clob
static java.lang.Object convertClob(java.sql.Connection conn, java.io.InputStream input)
          Transfers data from InputStream into sql.Clob Using default locale.
static java.lang.Object convertClob(java.sql.Connection conn, java.lang.String value)
          Transfers data from String into sql.Blob
static java.lang.Object convertClob(java.lang.Object clob, byte[] value)
          Transfers data from byte[] into sql.Clob
static java.lang.Object convertClob(java.lang.Object clob, java.io.InputStream input)
          Transfers data from InputStream into sql.Clob Using default locale.
static java.lang.Object convertClob(java.lang.Object clob, java.lang.String value)
          Transfers data from String into sql.Clob
static java.lang.String convertJavaClassToSqlType(java.lang.String simpleClassName)
          Converts Java Class name into SQL Type name
static java.lang.Object convertSqlXml(java.sql.Connection conn, byte[] value)
          Transfers data from byte[] into sql.SQLXML
static java.lang.Object convertSqlXml(java.sql.Connection conn, java.io.InputStream input)
          Transfers data from InputStream into sql.SQLXML Using default locale.
static java.lang.Object convertSqlXml(java.sql.Connection conn, java.lang.String value)
          Transfers data from String into sql.SQLXML
static java.lang.Object convertSqlXml(java.lang.Object sqlXml, byte[] value)
          Transfers data from byte[] into sql.SQLXML
static java.lang.Object convertSqlXml(java.lang.Object sqlXml, java.io.InputStream input)
          Transfers data from InputStream into sql.SQLXML Using default locale.
static java.lang.Object convertSqlXml(java.lang.Object sqlXml, java.lang.String value)
          Transfers data from String into sql.SQLXML
static long copy(java.io.InputStream input, java.io.OutputStream output)
          Transfers data from InputStream into OutputStream Uses DEFAULT_BUFFER_SIZE to define buffer size
static long copy(java.io.Reader input, java.lang.StringBuilder output)
          Transfers data from Reader into StringBuilder Uses DEFAULT_BUFFER_SIZE to define buffer size
static java.lang.Object createArrayOf(java.sql.Connection conn, java.lang.String typeName, java.lang.Object[] elements)
          Creates new Array instance.
static java.lang.Object createBlob(java.sql.Connection conn)
          Creates new Blob instance.
static java.lang.Object createClob(java.sql.Connection conn)
          Creates new Clob instance.
static java.lang.Object createSQLXML(java.sql.Connection conn)
          /** Creates new SQLXML instance.
static boolean isJDBC3(Overrider overrider)
          Returns if JDBC3 driver is used.
static byte[] readBlob(java.lang.Object blob)
          Transfers data from sql.Blob into byte[] sql.Blob is closed after read
static byte[] readBlob(java.lang.Object blob, boolean close)
          Transfers data from sql.Blob into byte[]
static byte[] readClob(java.lang.Object clob)
          Transfers data from sql.Clob into byte[] sql.Clob is closed after read
static byte[] readClob(java.lang.Object clob, boolean close)
          Transfers data from sql.Clob into byte[]
static byte[] readSqlXml(java.lang.Object sqlXml)
          Transfers data from sql.SQLXML into byte[] sql.SQLXML is closed after read
static byte[] readSqlXml(java.lang.Object sqlXml, boolean close)
          Transfers data from sql.SQLXML into byte[]
static byte[] toByteArray(java.io.InputStream input)
          Transfers data from InputStream into byte array
static java.lang.String toString(java.io.Reader reader)
          Reads Reader and converts it contents into String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeHandlerUtils

public TypeHandlerUtils()
Method Detail

convertArray

public static java.lang.Object convertArray(java.sql.Connection conn,
                                            java.lang.Object[] array)
                                     throws java.sql.SQLException
Converts array of Object into sql.Array

Parameters:
conn - connection for which sql.Array object would be created
array - array of objects
Returns:
sql.Array from array of Object
Throws:
java.sql.SQLException

convertArray

public static java.lang.Object convertArray(java.sql.Connection conn,
                                            java.util.Collection<?> array)
                                     throws java.sql.SQLException
Converts Collection into sql.Array

Parameters:
conn - connection for which sql.Array object would be created
array - Collection
Returns:
sql.Array from Collection
Throws:
java.sql.SQLException

convertBlob

public static java.lang.Object convertBlob(java.sql.Connection conn,
                                           byte[] value)
                                    throws java.sql.SQLException
Transfers data from byte[] into sql.Blob

Parameters:
conn - connection for which sql.Blob object would be created
value - array of bytes
Returns:
sql.Blob from array of bytes
Throws:
java.sql.SQLException

convertBlob

public static java.lang.Object convertBlob(java.sql.Connection conn,
                                           java.io.InputStream input)
                                    throws java.sql.SQLException
Transfers data from InputStream into sql.Blob

Parameters:
conn - connection for which sql.Blob object would be created
input - InputStream
Returns:
sql.Blob from InputStream
Throws:
java.sql.SQLException

convertBlob

public static java.lang.Object convertBlob(java.sql.Connection conn,
                                           java.lang.String value)
                                    throws java.sql.SQLException
Transfers data from String into sql.Blob

Parameters:
conn - connection for which sql.Blob object would be created
value - String
Returns:
sql.Blob from String
Throws:
java.sql.SQLException

convertBlob

public static java.lang.Object convertBlob(java.lang.Object blob,
                                           byte[] value)
                                    throws java.sql.SQLException
Transfers data from byte[] into sql.Blob

Parameters:
blob - sql.Blob which would be filled
value - array of bytes
Returns:
sql.Blob from array of bytes
Throws:
java.sql.SQLException

convertBlob

public static java.lang.Object convertBlob(java.lang.Object blob,
                                           java.io.InputStream input)
                                    throws java.sql.SQLException
Transfers data from InputStream into sql.Blob

Parameters:
blob - sql.Blob which would be filled
input - InputStream
Returns:
sql.Blob from InputStream
Throws:
java.sql.SQLException

convertBlob

public static java.lang.Object convertBlob(java.lang.Object blob,
                                           java.lang.String value)
                                    throws java.sql.SQLException
Transfers data from String into sql.Blob

Parameters:
blob - sql.Blob which would be filled
value - String
Returns:
sql.Blob from String
Throws:
java.sql.SQLException

convertClob

public static java.lang.Object convertClob(java.sql.Connection conn,
                                           byte[] value)
                                    throws java.sql.SQLException
Transfers data from byte[] into sql.Clob

Parameters:
conn - connection for which sql.Clob object would be created
value - array of bytes
Returns:
sql.Clob from array of bytes
Throws:
java.sql.SQLException

convertClob

public static java.lang.Object convertClob(java.sql.Connection conn,
                                           java.lang.String value)
                                    throws java.sql.SQLException
Transfers data from String into sql.Blob

Parameters:
conn - connection for which sql.Blob object would be created
value - String
Returns:
sql.Clob from String
Throws:
java.sql.SQLException

convertClob

public static java.lang.Object convertClob(java.sql.Connection conn,
                                           java.io.InputStream input)
                                    throws java.sql.SQLException
Transfers data from InputStream into sql.Clob Using default locale. If different locale is required see convertClob(java.sql.Connection, String)

Parameters:
conn - connection for which sql.Clob object would be created
input - InputStream
Returns:
sql.Clob from InputStream
Throws:
java.sql.SQLException

convertClob

public static java.lang.Object convertClob(java.lang.Object clob,
                                           byte[] value)
                                    throws java.sql.SQLException
Transfers data from byte[] into sql.Clob

Parameters:
clob - sql.Clob which would be filled
value - array of bytes
Returns:
sql.Clob from array of bytes
Throws:
java.sql.SQLException

convertClob

public static java.lang.Object convertClob(java.lang.Object clob,
                                           java.lang.String value)
                                    throws java.sql.SQLException
Transfers data from String into sql.Clob

Parameters:
clob - sql.Clob which would be filled
value - String
Returns:
sql.Clob from String
Throws:
java.sql.SQLException

convertClob

public static java.lang.Object convertClob(java.lang.Object clob,
                                           java.io.InputStream input)
                                    throws java.sql.SQLException
Transfers data from InputStream into sql.Clob Using default locale. If different locale is required see convertClob(java.sql.Connection, String)

Parameters:
clob - sql.Clob which would be filled
input - InputStream
Returns:
sql.Clob from InputStream
Throws:
java.sql.SQLException

convertJavaClassToSqlType

public static java.lang.String convertJavaClassToSqlType(java.lang.String simpleClassName)
                                                  throws java.sql.SQLException
Converts Java Class name into SQL Type name

Parameters:
simpleClassName - Java Class name
Returns:
SQL Type name
Throws:
java.sql.SQLException

convertSqlXml

public static java.lang.Object convertSqlXml(java.sql.Connection conn,
                                             byte[] value)
                                      throws java.sql.SQLException
Transfers data from byte[] into sql.SQLXML

Parameters:
conn - connection for which sql.SQLXML object would be created
value - array of bytes
Returns:
sql.SQLXML from array of bytes
Throws:
java.sql.SQLException

convertSqlXml

public static java.lang.Object convertSqlXml(java.sql.Connection conn,
                                             java.lang.String value)
                                      throws java.sql.SQLException
Transfers data from String into sql.SQLXML

Parameters:
conn - connection for which sql.SQLXML object would be created
value - String
Returns:
sql.SQLXML from String
Throws:
java.sql.SQLException

convertSqlXml

public static java.lang.Object convertSqlXml(java.sql.Connection conn,
                                             java.io.InputStream input)
                                      throws java.sql.SQLException
Transfers data from InputStream into sql.SQLXML Using default locale. If different locale is required see convertSqlXml(java.sql.Connection, String)

Parameters:
conn - connection for which sql.SQLXML object would be created
input - InputStream
Returns:
sql.SQLXML from InputStream
Throws:
java.sql.SQLException

convertSqlXml

public static java.lang.Object convertSqlXml(java.lang.Object sqlXml,
                                             byte[] value)
                                      throws java.sql.SQLException
Transfers data from byte[] into sql.SQLXML

Parameters:
sqlXml - sql.SQLXML which would be filled
value - array of bytes
Returns:
sql.SQLXML from array of bytes
Throws:
java.sql.SQLException

convertSqlXml

public static java.lang.Object convertSqlXml(java.lang.Object sqlXml,
                                             java.lang.String value)
                                      throws java.sql.SQLException
Transfers data from String into sql.SQLXML

Parameters:
sqlXml - sql.SQLXML which would be filled
value - array of bytes
Returns:
sql.SQLXML from String
Throws:
java.sql.SQLException

convertSqlXml

public static java.lang.Object convertSqlXml(java.lang.Object sqlXml,
                                             java.io.InputStream input)
                                      throws java.sql.SQLException
Transfers data from InputStream into sql.SQLXML Using default locale. If different locale is required see convertSqlXml(Object, String)

Parameters:
sqlXml - sql.SQLXML which would be filled
input - InputStream
Returns:
sql.SQLXML from InputStream
Throws:
java.sql.SQLException

readBlob

public static byte[] readBlob(java.lang.Object blob,
                              boolean close)
                       throws java.sql.SQLException
Transfers data from sql.Blob into byte[]

Parameters:
blob - sql.Blob which would be read
close - informs if sql.Blob should be closed after a read
Returns:
array of bytes from sql.Blob
Throws:
java.sql.SQLException

readBlob

public static byte[] readBlob(java.lang.Object blob)
                       throws java.sql.SQLException
Transfers data from sql.Blob into byte[] sql.Blob is closed after read

Parameters:
blob - sql.Blob which would be read
Returns:
array of bytes from sql.Blob
Throws:
java.sql.SQLException

readClob

public static byte[] readClob(java.lang.Object clob,
                              boolean close)
                       throws java.sql.SQLException
Transfers data from sql.Clob into byte[]

Parameters:
clob - sql.Clob which would be read
close - informs if sql.Clob should be closed after a read
Returns:
array of bytes from sql.Clob
Throws:
java.sql.SQLException

readClob

public static byte[] readClob(java.lang.Object clob)
                       throws java.sql.SQLException
Transfers data from sql.Clob into byte[] sql.Clob is closed after read

Parameters:
clob - sql.Clob which would be read
Returns:
array of bytes from sql.Clob
Throws:
java.sql.SQLException

readSqlXml

public static byte[] readSqlXml(java.lang.Object sqlXml,
                                boolean close)
                         throws java.sql.SQLException
Transfers data from sql.SQLXML into byte[]

Parameters:
sqlXml - sql.SQLXML which would be read
close - informs if sql.Clob should be closed after a read
Returns:
array of bytes from sql.SQLXML
Throws:
java.sql.SQLException

readSqlXml

public static byte[] readSqlXml(java.lang.Object sqlXml)
                         throws java.sql.SQLException
Transfers data from sql.SQLXML into byte[] sql.SQLXML is closed after read

Parameters:
sqlXml - sql.SQLXML which would be read
Returns:
array of bytes from sql.SQLXML
Throws:
java.sql.SQLException

toByteArray

public static byte[] toByteArray(java.io.InputStream input)
                          throws java.sql.SQLException
Transfers data from InputStream into byte array

Parameters:
input - InputStream
Returns:
array of bytes from InputStream
Throws:
java.sql.SQLException

toString

public static java.lang.String toString(java.io.Reader reader)
                                 throws java.sql.SQLException
Reads Reader and converts it contents into String

Parameters:
reader - Reader instance
Returns:
contents of Reader as string
Throws:
java.sql.SQLException

closeQuietly

public static void closeQuietly(java.io.InputStream input)
Closes InputStream while catching any exceptions

Parameters:
input - InputStream
Throws:
java.sql.SQLException

closeQuietly

public static void closeQuietly(java.io.OutputStream output)
Closes OutputStream while catching any exceptions

Parameters:
output - OutputStream

copy

public static long copy(java.io.InputStream input,
                        java.io.OutputStream output)
                 throws java.io.IOException
Transfers data from InputStream into OutputStream Uses DEFAULT_BUFFER_SIZE to define buffer size

Parameters:
input - InputStream which would be read
output - OutputStream which would be filled
Returns:
amount of bytes transferred
Throws:
java.io.IOException

copy

public static long copy(java.io.Reader input,
                        java.lang.StringBuilder output)
                 throws java.io.IOException
Transfers data from Reader into StringBuilder Uses DEFAULT_BUFFER_SIZE to define buffer size

Parameters:
input - Reader which would be read
output - StringBuilder which would be filled
Returns:
amount of bytes transferred
Throws:
java.io.IOException

createBlob

public static java.lang.Object createBlob(java.sql.Connection conn)
                                   throws MidaoSQLException
Creates new Blob instance. Can be invoked only for JDBC4 driver

Parameters:
conn - SQL connection
Returns:
new Blob instance
Throws:
MidaoSQLException

createClob

public static java.lang.Object createClob(java.sql.Connection conn)
                                   throws MidaoSQLException
Creates new Clob instance. Can be invoked only for JDBC4 driver

Parameters:
conn - SQL connection
Returns:
new Clob instance
Throws:
MidaoSQLException

createSQLXML

public static java.lang.Object createSQLXML(java.sql.Connection conn)
                                     throws MidaoSQLException
/** Creates new SQLXML instance. Can be invoked only for JDBC4 driver

Parameters:
conn - SQL connection
Returns:
new SQLXML instance
Throws:
MidaoSQLException

createArrayOf

public static java.lang.Object createArrayOf(java.sql.Connection conn,
                                             java.lang.String typeName,
                                             java.lang.Object[] elements)
                                      throws MidaoSQLException
Creates new Array instance. Can be invoked only for JDBC4 driver

Parameters:
conn - SQL connection
typeName - array type name
elements - array of elements
Returns:
new Array instance
Throws:
MidaoSQLException

isJDBC3

public static boolean isJDBC3(Overrider overrider)
Returns if JDBC3 driver is used. Actual check is done during QueryRunner instance initialization.

Returns:
true if JDBC3 Driver is used


Copyright © 2013. All Rights Reserved.