com.jenkov.mrpersister.impl
Class SqlGenerator

java.lang.Object
  extended by com.jenkov.mrpersister.impl.SqlGenerator
All Implemented Interfaces:
ISqlGenerator

public class SqlGenerator
extends java.lang.Object
implements ISqlGenerator

Author:
Jakob Jenkov, Jenkov Development

Constructor Summary
SqlGenerator()
           
 
Method Summary
 java.lang.String generateDeleteStatement(IObjectMapping mapping)
          Generates a delete SQL string based on the given object mapping.
 java.lang.String generateInsertStatement(IObjectMapping mapping)
          Generates an insert SQL string based on the given object mapping.
 java.lang.String generateReadByPrimaryKeyStatement(IObjectMapping mapping)
          Generates a read-by-primary-key SQL string based on the given object mapping.
 java.lang.String generateReadListByPrimaryKeysStatement(IObjectMapping mapping, int primaryKeyCount)
          Generates a read-by-primary-keys SQL string based on the given object mapping.
 java.lang.String generateUpdateOptimisticStatement(IObjectMapping mapping)
          Generates an update SQL string based on the given object mapping with optimistic locking.
 java.lang.String generateUpdateStatement(IObjectMapping mapping)
          Generates an updateBatch SQL string based on the given object mapping.
protected  void validateObjectMapping(IObjectMapping mapping)
           
protected  void validatePrimaryKey(IObjectMapping mapping)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlGenerator

public SqlGenerator()
Method Detail

generateReadByPrimaryKeyStatement

public java.lang.String generateReadByPrimaryKeyStatement(IObjectMapping mapping)
                                                   throws PersistenceException
Description copied from interface: ISqlGenerator
Generates a read-by-primary-key SQL string based on the given object mapping. The SQL string generated is for use with a PreparedStatement and thus does not contain the value for the primary key itself, but a "?" character instead.

Specified by:
generateReadByPrimaryKeyStatement in interface ISqlGenerator
Parameters:
mapping - The object mapping to generate the read-by-primary-key SQL string for.
Returns:
The String instance containing the generated SQL.
Throws:
PersistenceException - If anything goes wrong during the SQL string generation.

generateReadListByPrimaryKeysStatement

public java.lang.String generateReadListByPrimaryKeysStatement(IObjectMapping mapping,
                                                               int primaryKeyCount)
                                                        throws PersistenceException
Description copied from interface: ISqlGenerator
Generates a read-by-primary-keys SQL string based on the given object mapping. The SQL string generated is for use with a PreparedStatement and thus does not contain the value for the primary key itself, but a "?" character instead.

Specified by:
generateReadListByPrimaryKeysStatement in interface ISqlGenerator
Parameters:
mapping - The object mapping to generate the read-by-primary-key SQL string for.
Returns:
The String instance containing the generated SQL.
Throws:
PersistenceException - If anything goes wrong during the SQL string generation.

generateInsertStatement

public java.lang.String generateInsertStatement(IObjectMapping mapping)
                                         throws PersistenceException
Description copied from interface: ISqlGenerator
Generates an insert SQL string based on the given object mapping. The SQL string generated is for use with a PreparedStatement and thus does not contain the values to be inserted, but a series of "?" characters instead (comma separated).

Specified by:
generateInsertStatement in interface ISqlGenerator
Parameters:
mapping - The object mapping to generate the insert SQL string for.
Returns:
The String instance containing the generated SQL.
Throws:
PersistenceException - If anything goes wrong during the SQL string generation.

generateUpdateStatement

public java.lang.String generateUpdateStatement(IObjectMapping mapping)
                                         throws PersistenceException
Description copied from interface: ISqlGenerator
Generates an updateBatch SQL string based on the given object mapping. The SQL string generated is for use with a PreparedStatement and thus does not contain the values to be updateBatch, but a series of "?" characters instead (comma separated).

Specified by:
generateUpdateStatement in interface ISqlGenerator
Parameters:
mapping - The object mapping to generate the updateBatch SQL string for.
Returns:
The String instance containing the generated SQL.
Throws:
PersistenceException - If anything goes wrong during the SQL string generation.

generateUpdateOptimisticStatement

public java.lang.String generateUpdateOptimisticStatement(IObjectMapping mapping)
                                                   throws PersistenceException
Description copied from interface: ISqlGenerator
Generates an update SQL string based on the given object mapping with optimistic locking. The SQL string generated is for use with a PreparedStatement and thus does not contain the values to be updateBatch, but a series of "?" characters instead (comma separated).

Specified by:
generateUpdateOptimisticStatement in interface ISqlGenerator
Parameters:
mapping - The object mapping to generate the updateBatch SQL string for.
Returns:
The String instance containing the generated SQL.
Throws:
PersistenceException - If anything goes wrong during the SQL string generation.

generateDeleteStatement

public java.lang.String generateDeleteStatement(IObjectMapping mapping)
                                         throws PersistenceException
Description copied from interface: ISqlGenerator
Generates a delete SQL string based on the given object mapping. The SQL string generated is for use with a PreparedStatement and thus does not contain the value for the primary key of the record to delete itself, but a "?" character instead.

Specified by:
generateDeleteStatement in interface ISqlGenerator
Parameters:
mapping - The object mapping to generate the delete SQL string for.
Returns:
The String instance containing the generated SQL.
Throws:
PersistenceException - If anything goes wrong during the SQL string generation.

validateObjectMapping

protected void validateObjectMapping(IObjectMapping mapping)
                              throws PersistenceException
Throws:
PersistenceException

validatePrimaryKey

protected void validatePrimaryKey(IObjectMapping mapping)
                           throws PersistenceException
Throws:
PersistenceException