org.caleigo.core.service
Class SQLToolKitPS

java.lang.Object
  extended byorg.caleigo.core.service.SQLToolKitPS
All Implemented Interfaces:
java.io.Serializable

public class SQLToolKitPS
extends java.lang.Object
implements java.io.Serializable

This class constanis help methods for building valid SQL language statements based on CEL entities, descriptors and qualifiers. The class can be used by any IDataService implementation that connects to SQL based databases.

Version:
1.00 WHEN WHO WHY & WHAT ----------------------------------------------------------------------------- 2001-07-24 Dennis Zikovic Creation
Author:
Dennis Zikovic
See Also:
Serialized Form

Nested Class Summary
static class SQLToolKitPS.BooleanCharTypeConverter
           
static class SQLToolKitPS.BooleanTypeConverter
           
static class SQLToolKitPS.CompositeQualifierParser
          Parser for CompositeQualifiers.
static class SQLToolKitPS.DateTypeConverter
           
static interface SQLToolKitPS.IDataTypeConverter
           
static interface SQLToolKitPS.IQualifierParser
           
static class SQLToolKitPS.NegateQualifierParser
           
 class SQLToolKitPS.RelationQualifierParser
          Class for parsing RelationQualifiers.
static class SQLToolKitPS.StringTypeConverter
           
 
Constructor Summary
SQLToolKitPS()
          Constructs a new SQLToolKitPS and does necessary initialization
 
Method Summary
 void addDataTypeConverter(DataType dataType, SQLToolKitPS.IDataTypeConverter converter)
           
 void addQualifierParser(java.lang.Class qualifierClass, SQLToolKitPS.IQualifierParser parser)
          Adds a qualifierParser for the specified qualifier class.
 java.lang.String buildDataString(DataType type, java.lang.Object data)
           
 java.lang.String buildDeleteCommand(IEntityDescriptor descriptor, Qualifier qualifier, java.util.ArrayList values)
          Build the delete SQL Prepared Statement Query
 java.sql.PreparedStatement buildDeleteStatement(IEntityDescriptor descriptor, Qualifier qualifier, java.sql.Connection connection)
          Build a Delete Prepared Statement from a EntityDescriptor and a Qualifier
 java.lang.String buildFromExpresion(IEntityDescriptor descriptor, Qualifier qualifier)
          This method creates a comma seperated string with the source name of all referenced entity descriptors.
 java.lang.String buildInsertCommand(IEntity entity)
          Build the SQL Insert String for Prepared statements
 java.sql.PreparedStatement buildInsertStatement(IEntity entity, java.sql.Connection connection, boolean generateKeys)
          Build a PreparedStatement for inserting the Entity
 java.lang.String buildSelectCommand(DataQuery query, java.util.ArrayList values)
           
 java.lang.String buildSelectCommand(IEntityDescriptor descriptor, Qualifier qualifier, java.util.ArrayList values)
          Builds the select query to be used by a PreparedStatement
 java.sql.PreparedStatement buildSelectStatement(IEntityDescriptor descriptor, Qualifier qualifier, java.sql.Connection connection)
          Builds a Select PreparedStatement from a IEntityDescriptor and a Qualifier
 java.lang.String buildUpdateCommand(IEntity entity, Qualifier qualifier, java.util.ArrayList values)
          Build the Prepared Statement SQL query for for an update of an entity
 java.sql.PreparedStatement buildUpdateStatement(IEntity entity, Qualifier qualifier, java.sql.Connection connection)
          Build a Update Prepared Statement from a Entity and a Qualifier
 java.lang.String buildWhereExpresion(Qualifier qualifier, java.util.ArrayList values)
          Builds a WHERE Prepared statement from a qualifier
 SQLToolKitPS.IDataTypeConverter getDataTypeConverter(DataType dataType)
           
protected  java.util.Set getQualifierDescriptorSet(Qualifier qualifier)
          Returns a Set containing the entity descriptors meaded for the WHERE statement built by the submited qualifier.
 SQLToolKitPS.IQualifierParser getQualifierParser(java.lang.Class qualifierClass)
           
 boolean isQuotingIdentifiers()
           
 java.lang.String prepareWildcards(java.lang.String dataString)
           
 java.lang.String quoteIdentifier(java.lang.String indentifier)
           
 void setQuotingIdentifiers(boolean allwaysQuote)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLToolKitPS

public SQLToolKitPS()
Constructs a new SQLToolKitPS and does necessary initialization

Method Detail

addDataTypeConverter

public void addDataTypeConverter(DataType dataType,
                                 SQLToolKitPS.IDataTypeConverter converter)

getDataTypeConverter

public SQLToolKitPS.IDataTypeConverter getDataTypeConverter(DataType dataType)

addQualifierParser

public void addQualifierParser(java.lang.Class qualifierClass,
                               SQLToolKitPS.IQualifierParser parser)
Adds a qualifierParser for the specified qualifier class. The Parser is responsible for analysing the qualifier and constructing a SQL query

Parameters:
qualifierClass - The qualifier class that should be handled by the parser
parser - The parser that should handle the qualifier class

getQualifierParser

public SQLToolKitPS.IQualifierParser getQualifierParser(java.lang.Class qualifierClass)

setQuotingIdentifiers

public void setQuotingIdentifiers(boolean allwaysQuote)

isQuotingIdentifiers

public boolean isQuotingIdentifiers()

buildSelectCommand

public java.lang.String buildSelectCommand(DataQuery query,
                                           java.util.ArrayList values)

buildSelectCommand

public java.lang.String buildSelectCommand(IEntityDescriptor descriptor,
                                           Qualifier qualifier,
                                           java.util.ArrayList values)
Builds the select query to be used by a PreparedStatement

Parameters:
descriptor - The Entity type to be queried
qualifier - The qualifier that identies the wanted subset of entities
values - ArrayList that should be populated with the data to be set by the PreparedStatement
Returns:
String Returns a sql query used with a PreparedStatement

buildSelectStatement

public java.sql.PreparedStatement buildSelectStatement(IEntityDescriptor descriptor,
                                                       Qualifier qualifier,
                                                       java.sql.Connection connection)
                                                throws java.sql.SQLException
Builds a Select PreparedStatement from a IEntityDescriptor and a Qualifier

Parameters:
descriptor - IEntityDescriptor that identied the Type of entity wanted
qualifier - Qualifier that is used to limit the result to a wanted subset of entities
connection - SQL Connection that is the link to the database
Returns:
PreparedStatement Returns a fully populated Prepared Statement to be used for querying
Throws:
java.sql.SQLException - throwmn if a database problem occurs

buildUpdateCommand

public java.lang.String buildUpdateCommand(IEntity entity,
                                           Qualifier qualifier,
                                           java.util.ArrayList values)
Build the Prepared Statement SQL query for for an update of an entity

Parameters:
entity - The entity that should be updated
qualifier - The qualifier that uniqely identifies the entity
values - Should be populated with all data to be set in the query and in the correct order.
Returns:
String Returns a SQL query representing the Update

buildUpdateStatement

public java.sql.PreparedStatement buildUpdateStatement(IEntity entity,
                                                       Qualifier qualifier,
                                                       java.sql.Connection connection)
                                                throws java.sql.SQLException
Build a Update Prepared Statement from a Entity and a Qualifier

Parameters:
entity - The entity containing the data to be updated
qualifier - A qualifier that identifies the entity to be updated
connection - A reference to a SQL connection
Returns:
PreparedStatement Returns a fully runnable PreparedStatement
Throws:
java.sql.SQLException - thrown if there was a problem with the sql connection

buildInsertCommand

public java.lang.String buildInsertCommand(IEntity entity)
Build the SQL Insert String for Prepared statements

Parameters:
entity - The entity to be inserted
Returns:
String Returns the string that should be run by the prepared Statement

buildInsertStatement

public java.sql.PreparedStatement buildInsertStatement(IEntity entity,
                                                       java.sql.Connection connection,
                                                       boolean generateKeys)
                                                throws java.sql.SQLException
Build a PreparedStatement for inserting the Entity

Parameters:
entity - The entity to be inserted
connection - The SQL connections that should handle the Statement
generateKeys - Set to true if Generated Keys should be returned
Returns:
PreparedStatement A fully runnable Prepared Statement
Throws:
java.sql.SQLException - Returned if an SQLException occured

buildDeleteCommand

public java.lang.String buildDeleteCommand(IEntityDescriptor descriptor,
                                           Qualifier qualifier,
                                           java.util.ArrayList values)
Build the delete SQL Prepared Statement Query

Parameters:
descriptor - The descriptor that describes the entity/ies being removed
qualifier - The qualifier that identifies the entities to be removed
values - Should be updated with the data that should complement the PreparedStatement
Returns:
String Returns the Prepared Statement query string

buildDeleteStatement

public java.sql.PreparedStatement buildDeleteStatement(IEntityDescriptor descriptor,
                                                       Qualifier qualifier,
                                                       java.sql.Connection connection)
                                                throws java.sql.SQLException
Build a Delete Prepared Statement from a EntityDescriptor and a Qualifier

Parameters:
descriptor - A IEntityDescriptor stating what descriptor type to be deleted
qualifier - A qualifier that identifies the subset of entities to be removed
connection - A reference to a SQL connection
Returns:
PreparedStatement Returns a fully runnable PreparedStatement
Throws:
java.sql.SQLException - thrown if there was a problem with the sql connection

buildFromExpresion

public java.lang.String buildFromExpresion(IEntityDescriptor descriptor,
                                           Qualifier qualifier)
This method creates a comma seperated string with the source name of all referenced entity descriptors.

Parameters:
descriptor - The descriptor that describes the entity/ies
qualifier - The qualifier that identifies the entities
Returns:
Returns a String containing the FROM section of the query

buildWhereExpresion

public java.lang.String buildWhereExpresion(Qualifier qualifier,
                                            java.util.ArrayList values)
Builds a WHERE Prepared statement from a qualifier

Parameters:
qualifier - The qualifier that should be parsed
values - The data stored should be stored in values in the same order it is being added to the generated query
Returns:
String The prepared WHERE statement

buildDataString

public java.lang.String buildDataString(DataType type,
                                        java.lang.Object data)

prepareWildcards

public java.lang.String prepareWildcards(java.lang.String dataString)

getQualifierDescriptorSet

protected java.util.Set getQualifierDescriptorSet(Qualifier qualifier)
Returns a Set containing the entity descriptors meaded for the WHERE statement built by the submited qualifier. Can be used to build the FROM statement of the SQL command. May return null


quoteIdentifier

public java.lang.String quoteIdentifier(java.lang.String indentifier)


Copyright © 2005 Caleigo. All Rights Reserved.