Package org.hibernate.engine.jdbc.dialect.internal

Source Code of org.hibernate.engine.jdbc.dialect.internal.DialectResolverSet

/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors.  All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA  02110-1301  USA
*/
package org.hibernate.engine.jdbc.dialect.internal;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolver;
import org.hibernate.exception.JDBCConnectionException;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;

/**
* A {@link DialectResolver} implementation which coordinates resolution by delegating to sub-resolvers.
*
* @author Tomoto Shimizu Washio
* @author Steve Ebersole
*/
public class DialectResolverSet implements DialectResolver {
  private static final CoreMessageLogger LOG = CoreLogging.messageLogger( DialectResolverSet.class );

  private List<DialectResolver> resolvers;

  public DialectResolverSet() {
    this( new ArrayList<DialectResolver>() );
  }

  public DialectResolverSet(List<DialectResolver> resolvers) {
    this.resolvers = resolvers;
  }

  public DialectResolverSet(DialectResolver... resolvers) {
    this( Arrays.asList( resolvers ) );
  }

  @Override
  public Dialect resolveDialect(DialectResolutionInfo info) {
    for ( DialectResolver resolver : resolvers ) {
      try {
        final Dialect dialect = resolver.resolveDialect( info );
        if ( dialect != null ) {
          return dialect;
        }
      }
      catch ( JDBCConnectionException e ) {
        throw e;
      }
      catch ( Exception e ) {
        LOG.exceptionInSubResolver( e.getMessage() );
      }
    }

    return null;
  }

  /**
   * Add a resolver at the end of the underlying resolver list.  The resolver added by this method is at lower
   * priority than any other existing resolvers.
   *
   * @param resolver The resolver to add.
   */
  public void addResolver(DialectResolver resolver) {
    resolvers.add( resolver );
  }

  /**
   * Add a resolver at the beginning of the underlying resolver list.  The resolver added by this method is at higher
   * priority than any other existing resolvers.
   *
   * @param resolver The resolver to add.
   */
  public void addResolverAtFirst(DialectResolver resolver) {
    resolvers.add( 0, resolver );
  }
}
TOP

Related Classes of org.hibernate.engine.jdbc.dialect.internal.DialectResolverSet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.