FileDocCategorySizeDatePackage
DialectFactory.javaAPI DocHibernate 3.2.55495Fri Jun 08 12:56:06 BST 2007org.hibernate.dialect

DialectFactory

public class DialectFactory extends Object
A factory for generating Dialect instances.
author
Steve Ebersole

Fields Summary
private static final Map
MAPPERS
Constructors Summary
Methods Summary
public static DialectbuildDialect(java.util.Properties props, java.lang.String databaseName, int databaseMajorVersion)
Builds an appropriate Dialect instance.

If a dialect is explicitly named in the incoming properties, it is used. Otherwise, the database name and version (obtained from connection metadata) are used to make the dertemination.

An exception is thrown if a dialect was not explicitly set and the database name is not known.

param
props The configuration properties.
param
databaseName The name of the database product (obtained from metadata).
param
databaseMajorVersion The major version of the database product (obtained from metadata).
return
The appropriate dialect.
throws
HibernateException No dialect specified and database name not known.

		String dialectName = props.getProperty( Environment.DIALECT );
		if ( dialectName == null ) {
			return determineDialect( databaseName, databaseMajorVersion );
		}
		else {
			return buildDialect( dialectName );
		}
	
public static DialectbuildDialect(java.lang.String dialectName)
Returns a dialect instance given the name of the class to use.

param
dialectName The name of the dialect class.
return
The dialect instance.

		try {
			return ( Dialect ) ReflectHelper.classForName( dialectName ).newInstance();
		}
		catch ( ClassNotFoundException cnfe ) {
			throw new HibernateException( "Dialect class not found: " + dialectName );
		}
		catch ( Exception e ) {
			throw new HibernateException( "Could not instantiate dialect class", e );
		}
	
public static DialectdetermineDialect(java.lang.String databaseName, int databaseMajorVersion)
Determine the appropriate Dialect to use given the database product name and major version.

param
databaseName The name of the database product (obtained from metadata).
param
databaseMajorVersion The major version of the database product (obtained from metadata).
return
An appropriate dialect instance.

		if ( databaseName == null ) {
			throw new HibernateException( "Hibernate Dialect must be explicitly set" );
		}

		DatabaseDialectMapper mapper = ( DatabaseDialectMapper ) MAPPERS.get( databaseName );
		if ( mapper == null ) {
			throw new HibernateException( "Hibernate Dialect must be explicitly set for database: " + databaseName );
		}

		String dialectName = mapper.getDialectClass( databaseMajorVersion );
		return buildDialect( dialectName );