org.clazzes.jdbc2xml.helper
Class SQLHelper

java.lang.Object
  extended by org.clazzes.jdbc2xml.helper.SQLHelper

public abstract class SQLHelper
extends Object

Helper functions common for many SQL engines.

Author:
wglas

Constructor Summary
SQLHelper()
           
 
Method Summary
static void appendTypePrec(StringBuffer sb, String type, Integer prec)
          Append an SQL type name together with a precision to a string buffer.
static void appendTypePrecScale(StringBuffer sb, String type, Integer prec, Integer scale)
          Append an SQL type name together with a precision and a scale to a string buffer.
static void copyResultField(PreparedStatement ps, int pc, ResultSet rs, int rc)
          Copies a column from a result set to a placeholder of a PreparedStatment.
static void executeUpdate(Connection connection, String sql)
          Perform an SQL update statement.
static String joinIdentifiers(Collection<String> strings, SqlIdentifierMapper mapper)
          Simply concatenate a collection of SQL identifiers by using a comma as separator.
static void joinIdentifiers(StringBuffer sb, Collection<String> strings, SqlIdentifierMapper mapper)
          Simply concatenate a collection of SQL identifiers by using a comma as separator.
static void quoteISOSqlString(StringBuffer sb, String s)
          Quote the given string as defined by ISO SQL by doubling single quotes.
static String unquoteISOSqlString(String s)
          Unquote the given string as defined by ISO SQL by doubling single quotes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLHelper

public SQLHelper()
Method Detail

quoteISOSqlString

public static void quoteISOSqlString(StringBuffer sb,
                                     String s)
Quote the given string as defined by ISO SQL by doubling single quotes.

Parameters:
sb - The buffer to put the result to.
s - The String to quote.
See Also:
unquoteISOSqlString

unquoteISOSqlString

public static String unquoteISOSqlString(String s)
Unquote the given string as defined by ISO SQL by doubling single quotes.

Parameters:
s - The String to unquote.
Returns:
the unquoted String.
See Also:
quoteISOSqlString

appendTypePrec

public static void appendTypePrec(StringBuffer sb,
                                  String type,
                                  Integer prec)
Append an SQL type name together with a precision to a string buffer.

Parameters:
sb - The buffer to put the result to.
type - The SQL name of the type.
prec - The optional precision (field width).

appendTypePrecScale

public static void appendTypePrecScale(StringBuffer sb,
                                       String type,
                                       Integer prec,
                                       Integer scale)
Append an SQL type name together with a precision and a scale to a string buffer.

Parameters:
sb - The buffer to put the result to.
type - The SQL name of the type.
prec - The optional precision (field width).
scale - The optional scale (fractional digits).

executeUpdate

public static void executeUpdate(Connection connection,
                                 String sql)
                          throws SQLException
Perform an SQL update statement.

Parameters:
connection - The JDBC connection to use.
sql - The SQL update statement.
Throws:
SQLException - Upon database errors
See Also:
Statement.executeUpdate(String)

copyResultField

public static void copyResultField(PreparedStatement ps,
                                   int pc,
                                   ResultSet rs,
                                   int rc)
                            throws SQLException
Copies a column from a result set to a placeholder of a PreparedStatment.

Parameters:
ps - The prepared statement.
pc - The column number of the column to be filled.
rs - The result set from which to retrieve the data.
rc - The column of the result set to be evaluated.
Throws:
SQLException

joinIdentifiers

public static void joinIdentifiers(StringBuffer sb,
                                   Collection<String> strings,
                                   SqlIdentifierMapper mapper)
Simply concatenate a collection of SQL identifiers by using a comma as separator. No quoting is undertaken, as this function is usually used for SQL column names.

Parameters:
sb - The string buffer to write the concatenated list of string to.
strings - A collection of strings.
mapper - A mapper for transforming SQL identifiers to their external form.

joinIdentifiers

public static String joinIdentifiers(Collection<String> strings,
                                     SqlIdentifierMapper mapper)
Simply concatenate a collection of SQL identifiers by using a comma as separator. No quoting is undertaken, as this function is usually used for SQL column names.

Parameters:
strings - A collection of strings.
mapper - A mapper for transforming SQL identifiers to their external form.
Returns:
A string containing all strings delimited by a comma.


Copyright © 2011. All Rights Reserved.