nl.gx.webmanager.services.seo.dao.impl
Class SEODatabaseUtil

java.lang.Object
  extended by nl.gx.webmanager.services.seo.dao.impl.SEODatabaseUtil

public final class SEODatabaseUtil
extends java.lang.Object

SEO related database utility class.

Author:
Sander Dahlberg

Constructor Summary
SEODatabaseUtil(InternalSEOService seoService)
          Constructor.
 
Method Summary
protected static void close(java.sql.Connection connection, java.sql.Statement stmt, java.sql.ResultSet rs)
          Convenience method to close resources in a safe way.
protected  int executeInsert(java.lang.String query, java.util.List<java.lang.Object> arguments)
          Executes updates the given query with its arguments.
protected  java.lang.String[] executeStringSelectColumns(java.lang.String query, java.util.List<java.lang.Object> arguments, int numberOfColumns)
          Executes a query returning an array of string values.
protected  void executeUpdate(java.lang.String query, java.util.List<java.lang.Object> arguments)
          Execute updates the given query with its arguments.
protected  java.sql.Connection getConnection()
          Returns a new connection to this database.
protected static java.lang.String getCurrentDateFunctionReplacement()
          Returns the current date function string replacement.
protected  java.lang.String getSEODataSourceName()
          Returns the datasource name of SEO.
protected static java.lang.String getStringLengthFunctionReplacement()
          Returns the string length function name string replacement.
static void logSQL(java.util.logging.Logger log, java.lang.String methodName, java.lang.String query, java.util.List<java.lang.Object> arguments, long start)
          Logs an SQL message on level FINEST.
protected static void setArguments(java.sql.PreparedStatement stmt, java.util.List<java.lang.Object> arguments)
          Convenience method to set an array of arguments on the prepared statement.
protected static java.lang.String setDatabaseSpecificFunctions(java.sql.Connection connection, java.lang.String query)
          Sets database specific functions.
static long startLogSQL(java.util.logging.Logger log)
          Returns current time in milliseconds if FINEST messages are loggable on the given log.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SEODatabaseUtil

public SEODatabaseUtil(InternalSEOService seoService)
Constructor.

Parameters:
seoService - Reference to the SEO service.
Method Detail

startLogSQL

public static long startLogSQL(java.util.logging.Logger log)
Returns current time in milliseconds if FINEST messages are loggable on the given log.

Parameters:
log - Log.
Returns:
Current time in milliseconds.

logSQL

public static void logSQL(java.util.logging.Logger log,
                          java.lang.String methodName,
                          java.lang.String query,
                          java.util.List<java.lang.Object> arguments,
                          long start)
Logs an SQL message on level FINEST.

Parameters:
log - Log.
methodName - Method name.
query - SQL query.
arguments - Arguments.
start - Time in milliseconds the query was about to be executed.

getConnection

protected java.sql.Connection getConnection()
                                     throws java.sql.SQLException
Returns a new connection to this database.

Returns:
A new connection to this database
Throws:
java.sql.SQLException - If a connection to this database could not be returned.

getSEODataSourceName

protected java.lang.String getSEODataSourceName()
Returns the datasource name of SEO.

Returns:
The data source name for SEO data.

executeUpdate

protected void executeUpdate(java.lang.String query,
                             java.util.List<java.lang.Object> arguments)
                      throws java.sql.SQLException
Execute updates the given query with its arguments. Calls setDatabaseSpecificFunctions(Connection, String) before preparing the query.

Parameters:
query - Execute this CUD query.
arguments - The arguments for the given query.
Throws:
java.sql.SQLException - If a database access error occurs.

executeInsert

protected int executeInsert(java.lang.String query,
                            java.util.List<java.lang.Object> arguments)
                     throws java.sql.SQLException
Executes updates the given query with its arguments. Assumes an insert query is passed, of which the generated ID is returned.

Parameters:
query - Execute this insert query.
arguments - The arguments for the given query.
Returns:
The ID of the newly inserted row.
Throws:
java.sql.SQLException - If a database access error occurs.

executeStringSelectColumns

protected java.lang.String[] executeStringSelectColumns(java.lang.String query,
                                                        java.util.List<java.lang.Object> arguments,
                                                        int numberOfColumns)
                                                 throws java.sql.SQLException
Executes a query returning an array of string values. Specify the number of columns to retrieve from the result set. Calls setDatabaseSpecificFunctions(Connection, String) before preparing the query.

Parameters:
query - Query to execute.
arguments - The arguments for the given query.
numberOfColumns - Number of columns to retrieve string values from.
Returns:
Array of strings.
Throws:
java.sql.SQLException - If a database access error occurs.

setArguments

protected static void setArguments(java.sql.PreparedStatement stmt,
                                   java.util.List<java.lang.Object> arguments)
                            throws java.sql.SQLException
Convenience method to set an array of arguments on the prepared statement.

Parameters:
stmt - Set the arguments on this statement.
arguments - Array of arguments.
Throws:
java.sql.SQLException - If a database access error occurs.

close

protected static void close(java.sql.Connection connection,
                            java.sql.Statement stmt,
                            java.sql.ResultSet rs)
                     throws java.sql.SQLException
Convenience method to close resources in a safe way.

Parameters:
connection - Close this connection. Can be null.
stmt - Close this statement. Can be null.
rs - Close this result set. Can be null.
Throws:
java.sql.SQLException - Occurs If a database access error occurs.

getCurrentDateFunctionReplacement

protected static java.lang.String getCurrentDateFunctionReplacement()
Returns the current date function string replacement. Use this string instead of the database dependent current date functions. Before preparing the query, call setDatabaseSpecificFunctions(Connection, String) so that this replacement string is replaced with the correct current date function.

Returns:
Current date function string: getdate()

getStringLengthFunctionReplacement

protected static java.lang.String getStringLengthFunctionReplacement()
Returns the string length function name string replacement. Use this string instead of the database dependent string length function names. Before preparing the query, call setDatabaseSpecificFunctions(Connection, String) so that this replacement string is replaced with the correct string length function name.

Returns:
String length function string: len()

setDatabaseSpecificFunctions

protected static java.lang.String setDatabaseSpecificFunctions(java.sql.Connection connection,
                                                               java.lang.String query)
                                                        throws java.sql.SQLException
Sets database specific functions. Assumes given query contains Microsoft functions.

Parameters:
connection - Connection to invest database product name.
query - Input query.
Returns:
Output query.
Throws:
java.sql.SQLException - If database product name could not be determined.


Copyright © 2007-2011 GX Software BV. All Rights Reserved.