Package mondrian.spi

Interface DialectFactory

  • All Known Implementing Classes:
    JdbcDialectFactory

    public interface DialectFactory
    Factory that creates Dialect objects.

    If you create a class that implements Dialect, you may optionally provide a factory by creating a constant field in that class. For example:

     public class MyDialect implements Dialect {
         public static final DialectFactory FACTORY =
             new JdbcDialectFactory(MyDialect.class, null);
    
         public MyDialect(Connection connection) {
             ...
         }
    
         ...
     }

    (The field must be public, static, final, named "FACTORY", of type DialectFactory or a subclass, and its value must not be null.)

    Explicitly providing a factory gives you more control about how dialects are produced.

    If you do not provide such a field, Mondrian requires that the dialect has a public constructor that takes a Connection as a parameter, and automatically creates a factory that calls the class's public constructor.

    However, an explicit DialectFactory is superior:

    1. When a dialect cannot handle a given connection, a dialect factory can return null, whereas a dialect's constructor can only throw an exception.
    2. A dialect factory can maintain a pool or cache of dialect objects.

    If your dialect is a subclass of JdbcDialectImpl you may wish to use a dialect factory that is a subclass of JdbcDialectFactory.

    Since:
    Jan 13, 2009
    Author:
    jhyde
    • Method Detail

      • createDialect

        Dialect createDialect​(DataSource dataSource,
                              Connection connection)
        Creates a Dialect.

        If the dialect cannot handle this connection, returns null.

        Parameters:
        dataSource - JDBC data source
        connection - JDBC connection
        Returns:
        dialect for this connection, or null if this factory's dialect is not appropriate for the connection
        Throws:
        RuntimeException - if underlying systems give an error