Package org.hibernate.engine.jdbc.spi

Examples of org.hibernate.engine.jdbc.spi.JdbcServices


  public SettingsFactory() {
  }

  public Settings buildSettings(Properties props, ServiceRegistry serviceRegistry) {
    final boolean debugEnabled =  LOG.isDebugEnabled();
    final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
    Settings settings = new Settings();

    //SessionFactory name:

    String sessionFactoryName = props.getProperty(Environment.SESSION_FACTORY_NAME);
    settings.setSessionFactoryName(sessionFactoryName);

    //JDBC and connection settings:

    //Interrogate JDBC metadata
    ExtractedDatabaseMetaData meta = jdbcServices.getExtractedMetaDataSupport();

    settings.setDataDefinitionImplicitCommit( meta.doesDataDefinitionCauseTransactionCommit() );
    settings.setDataDefinitionInTransactionSupported( meta.supportsDataDefinitionInTransaction() );

    //use dialect default properties
    final Properties properties = new Properties();
    properties.putAll( jdbcServices.getDialect().getDefaultProperties() );
    properties.putAll( props );

    // Transaction settings:
    settings.setJtaPlatform( serviceRegistry.getService( JtaPlatform.class ) );

    boolean flushBeforeCompletion = ConfigurationHelper.getBoolean(Environment.FLUSH_BEFORE_COMPLETION, properties);
    if ( debugEnabled ) {
      LOG.debugf( "Automatic flush during beforeCompletion(): %s", enabledDisabled(flushBeforeCompletion) );
    }
    settings.setFlushBeforeCompletionEnabled(flushBeforeCompletion);

    boolean autoCloseSession = ConfigurationHelper.getBoolean(Environment.AUTO_CLOSE_SESSION, properties);
    if ( debugEnabled ) {
      LOG.debugf( "Automatic session close at end of transaction: %s", enabledDisabled(autoCloseSession) );
    }
    settings.setAutoCloseSessionEnabled(autoCloseSession);

    //JDBC and connection settings:

    int batchSize = ConfigurationHelper.getInt(Environment.STATEMENT_BATCH_SIZE, properties, 0);
    if ( !meta.supportsBatchUpdates() ) {
      batchSize = 0;
    }
    if ( batchSize > 0 && debugEnabled ) {
      LOG.debugf( "JDBC batch size: %s", batchSize );
    }
    settings.setJdbcBatchSize(batchSize);

    boolean jdbcBatchVersionedData = ConfigurationHelper.getBoolean(Environment.BATCH_VERSIONED_DATA, properties, false);
    if ( batchSize > 0 && debugEnabled ) {
      LOG.debugf( "JDBC batch updates for versioned data: %s", enabledDisabled(jdbcBatchVersionedData) );
    }
    settings.setJdbcBatchVersionedData(jdbcBatchVersionedData);

    boolean useScrollableResultSets = ConfigurationHelper.getBoolean(
        Environment.USE_SCROLLABLE_RESULTSET,
        properties,
        meta.supportsScrollableResults()
    );
    if ( debugEnabled ) {
      LOG.debugf( "Scrollable result sets: %s", enabledDisabled(useScrollableResultSets) );
    }
    settings.setScrollableResultSetsEnabled(useScrollableResultSets);

    boolean wrapResultSets = ConfigurationHelper.getBoolean(Environment.WRAP_RESULT_SETS, properties, false);
    if ( debugEnabled ) {
      LOG.debugf( "Wrap result sets: %s", enabledDisabled(wrapResultSets) );
    }
    settings.setWrapResultSetsEnabled(wrapResultSets);

    boolean useGetGeneratedKeys = ConfigurationHelper.getBoolean(Environment.USE_GET_GENERATED_KEYS, properties, meta.supportsGetGeneratedKeys());
    if ( debugEnabled ) {
      LOG.debugf( "JDBC3 getGeneratedKeys(): %s", enabledDisabled(useGetGeneratedKeys) );
    }
    settings.setGetGeneratedKeysEnabled(useGetGeneratedKeys);

    Integer statementFetchSize = ConfigurationHelper.getInteger(Environment.STATEMENT_FETCH_SIZE, properties);
    if ( statementFetchSize != null && debugEnabled ) {
      LOG.debugf( "JDBC result set fetch size: %s", statementFetchSize );
    }
    settings.setJdbcFetchSize(statementFetchSize);

    String releaseModeName = ConfigurationHelper.getString( Environment.RELEASE_CONNECTIONS, properties, "auto" );
    if ( debugEnabled ) {
      LOG.debugf( "Connection release mode: %s", releaseModeName );
    }
    ConnectionReleaseMode releaseMode;
    if ( "auto".equals(releaseModeName) ) {
      releaseMode = serviceRegistry.getService( TransactionFactory.class ).getDefaultReleaseMode();
    }
    else {
      releaseMode = ConnectionReleaseMode.parse( releaseModeName );
      if ( releaseMode == ConnectionReleaseMode.AFTER_STATEMENT &&
          ! jdbcServices.getConnectionProvider().supportsAggressiveRelease() ) {
        LOG.unsupportedAfterStatement();
        releaseMode = ConnectionReleaseMode.AFTER_TRANSACTION;
      }
    }
    settings.setConnectionReleaseMode( releaseMode );
View Full Code Here


    connectionHelper = new ManagedProviderConnectionHelper( props );
  }

  public SchemaValidator(ServiceRegistry serviceRegistry, Configuration cfg ) throws HibernateException {
    this.configuration = cfg;
    final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
    this.dialect = jdbcServices.getDialect();
    this.connectionHelper = new SuppliedConnectionProviderConnectionHelper( jdbcServices.getConnectionProvider() );
  }
View Full Code Here

  public SchemaExport(MetadataImplementor metadata) {
    ServiceRegistry serviceRegistry = metadata.getServiceRegistry();
    this.connectionHelper = new SuppliedConnectionProviderConnectionHelper(
        serviceRegistry.getService( ConnectionProvider.class )
    );
        JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
    this.sqlStatementLogger = jdbcServices.getSqlStatementLogger();
    this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter();
    this.sqlExceptionHelper = jdbcServices.getSqlExceptionHelper();

    this.importFiles = ConfigurationHelper.getString(
        AvailableSettings.HBM2DDL_IMPORT_FILES,
        serviceRegistry.getService( ConfigurationService.class ).getSettings(),
        DEFAULT_IMPORT_FILE
    );

    final Dialect dialect = jdbcServices.getDialect();
    this.dropSQL = metadata.getDatabase().generateDropSchemaScript( dialect );
    this.createSQL = metadata.getDatabase().generateSchemaCreationScript( dialect );
  }
View Full Code Here

  }

  public SchemaUpdate(ServiceRegistry serviceRegistry, Configuration cfg) throws HibernateException {
    this.configuration = cfg;

    final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
    this.dialect = jdbcServices.getDialect();
    this.connectionHelper = new SuppliedConnectionProviderConnectionHelper( jdbcServices.getConnectionProvider() );

    this.sqlExceptionHelper = new SqlExceptionHelper();
    this.sqlStatementLogger = jdbcServices.getSqlStatementLogger();
    this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter();
  }
View Full Code Here

    }
    this.key = key;
    this.jdbcCoordinator = jdbcCoordinator;

    this.transactionContext = jdbcCoordinator.getTransactionCoordinator().getTransactionContext();
    final JdbcServices jdbcServices = transactionContext.getTransactionEnvironment().getJdbcServices();
    this.sqlStatementLogger = jdbcServices.getSqlStatementLogger();
    this.sqlExceptionHelper = jdbcServices.getSqlExceptionHelper();
  }
View Full Code Here

    connectionHelper = new ManagedProviderConnectionHelper( props );
  }

  public SchemaValidator(ServiceRegistry serviceRegistry, Configuration cfg ) throws HibernateException {
    this.configuration = cfg;
    final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
    this.dialect = jdbcServices.getDialect();
    this.connectionHelper = new SuppliedConnectionProviderConnectionHelper( jdbcServices.getConnectionProvider() );
  }
View Full Code Here

  public SchemaExport(MetadataImplementor metadata) {
    ServiceRegistry serviceRegistry = metadata.getServiceRegistry();
    this.connectionHelper = new SuppliedConnectionProviderConnectionHelper(
        serviceRegistry.getService( ConnectionProvider.class )
    );
        JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
    this.sqlStatementLogger = jdbcServices.getSqlStatementLogger();
    this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter();
    this.sqlExceptionHelper = jdbcServices.getSqlExceptionHelper();

    this.importFiles = ConfigurationHelper.getString(
        AvailableSettings.HBM2DDL_IMPORT_FILES,
        serviceRegistry.getService( ConfigurationService.class ).getSettings(),
        DEFAULT_IMPORT_FILE
    );

    final Dialect dialect = jdbcServices.getDialect();
    this.dropSQL = metadata.getDatabase().generateDropSchemaScript( dialect );
    this.createSQL = metadata.getDatabase().generateSchemaCreationScript( dialect );
  }
View Full Code Here

  }

  public SchemaUpdate(ServiceRegistry serviceRegistry, Configuration cfg) throws HibernateException {
    this.configuration = cfg;

    final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
    this.dialect = jdbcServices.getDialect();
    this.connectionHelper = new SuppliedConnectionProviderConnectionHelper( jdbcServices.getConnectionProvider() );

    this.sqlExceptionHelper = new SqlExceptionHelper();
    this.sqlStatementLogger = jdbcServices.getSqlStatementLogger();
    this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter();
  }
View Full Code Here

      }
  );

  protected JDBCException convertSqlException(String message, SQLException e) {
    // if JdbcServices#getSqlExceptionHelper is available, use it...
    final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
    if ( jdbcServices != null && jdbcServices.getSqlExceptionHelper() != null ) {
      return jdbcServices.getSqlExceptionHelper().convert( e, message, null );
    }

    // likely we are still in the process of initializing the ServiceRegistry, so use the simplified
    // SQLException conversion
    return simpleConverterAccess.getValue().convert( e, message, null );
View Full Code Here

   * @param jdbcCoordinator The JdbcCoordinator
   */
  public ResultSetReturnImpl(JdbcCoordinator jdbcCoordinator) {
    this.jdbcCoordinator = jdbcCoordinator;

    final JdbcServices jdbcServices = jdbcCoordinator.getTransactionCoordinator().getTransactionContext()
        .getTransactionEnvironment()
        .getJdbcServices();

    this.dialect = jdbcServices.getDialect();
    this.sqlStatementLogger = jdbcServices.getSqlStatementLogger();
    this.sqlExceptionHelper = jdbcServices.getSqlExceptionHelper();
  }
View Full Code Here

TOP

Related Classes of org.hibernate.engine.jdbc.spi.JdbcServices

Copyright © 2018 www.massapicom. 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.