Java 类org.hibernate.engine.jdbc.spi.SqlStatementLogger 实例源码

项目:lams    文件:SchemaExport.java   
/**
 * Create a schema exporter for the given Configuration, with the given
 * database connection properties.
 *
 * @param configuration The configuration from which to build a schema export.
 * @param properties The properties from which to configure connectivity etc.
 * @throws HibernateException Indicates problem preparing for schema export.
 *
 * @deprecated properties may be specified via the Configuration object
 */
@Deprecated
   public SchemaExport(Configuration configuration, Properties properties) throws HibernateException {
    final Dialect dialect = Dialect.getDialect( properties );

    Properties props = new Properties();
    props.putAll( dialect.getDefaultProperties() );
    props.putAll( properties );
    this.connectionHelper = new ManagedProviderConnectionHelper( props );

    this.sqlStatementLogger = new SqlStatementLogger( false, true );
    this.formatter = FormatStyle.DDL.getFormatter();
    this.sqlExceptionHelper = new SqlExceptionHelper();

    this.importFiles = ConfigurationHelper.getString(
            AvailableSettings.HBM2DDL_IMPORT_FILES,
            properties,
            DEFAULT_IMPORT_FILE
    );

    this.dropSQL = configuration.generateDropSchemaScript( dialect );
    this.createSQL = configuration.generateSchemaCreationScript( dialect );
}
项目:lams    文件:SchemaExport.java   
/**
 * Create a schema exporter for the given Configuration, using the supplied connection for connectivity.
 *
 * @param configuration The configuration to use.
 * @param connection The JDBC connection to use.
 * @throws HibernateException Indicates problem preparing for schema export.
 */
public SchemaExport(Configuration configuration, Connection connection) throws HibernateException {
    this.connectionHelper = new SuppliedConnectionHelper( connection );

    this.sqlStatementLogger = new SqlStatementLogger( false, true );
    this.formatter = FormatStyle.DDL.getFormatter();
    this.sqlExceptionHelper = new SqlExceptionHelper();

    this.importFiles = ConfigurationHelper.getString(
            AvailableSettings.HBM2DDL_IMPORT_FILES,
            configuration.getProperties(),
            DEFAULT_IMPORT_FILE
    );

    final Dialect dialect = Dialect.getDialect( configuration.getProperties() );
    this.dropSQL = configuration.generateDropSchemaScript( dialect );
    this.createSQL = configuration.generateSchemaCreationScript( dialect );
}
项目:lams    文件:SchemaExport.java   
public SchemaExport(
        ConnectionHelper connectionHelper,
        String[] dropSql,
        String[] createSql) {
    this.connectionHelper = connectionHelper;
    this.dropSQL = dropSql;
    this.createSQL = createSql;
    this.importFiles = "";
    this.sqlStatementLogger = new SqlStatementLogger( false, true );
    this.sqlExceptionHelper = new SqlExceptionHelper();
    this.formatter = FormatStyle.DDL.getFormatter();
}
项目:lams    文件:SchemaUpdate.java   
public SchemaUpdate(Configuration configuration, Properties properties) throws HibernateException {
    this.configuration = configuration;
    this.dialect = Dialect.getDialect( properties );

    Properties props = new Properties();
    props.putAll( dialect.getDefaultProperties() );
    props.putAll( properties );
    this.connectionHelper = new ManagedProviderConnectionHelper( props );

    this.sqlExceptionHelper = new SqlExceptionHelper();
    this.sqlStatementLogger = new SqlStatementLogger( false, true );
    this.formatter = FormatStyle.DDL.getFormatter();
}
项目:lams    文件:TableGenerator.java   
private PreparedStatement prepareStatement(
        Connection connection,
        String sql,
        SqlStatementLogger statementLogger,
        SessionEventListenerManager statsCollector) throws SQLException {
    statementLogger.logStatement( sql, FormatStyle.BASIC.getFormatter() );
    try {
        statsCollector.jdbcPrepareStatementStart();
        return connection.prepareStatement( sql );
    }
    finally {
        statsCollector.jdbcPrepareStatementEnd();
    }
}
项目:lams    文件:TableStructure.java   
private PreparedStatement prepareStatement(
        Connection connection,
        String sql,
        SqlStatementLogger statementLogger,
        SessionEventListenerManager statsCollector) throws SQLException {
    statementLogger.logStatement( sql, FormatStyle.BASIC.getFormatter() );
    try {
        statsCollector.jdbcPrepareStatementStart();
        return connection.prepareStatement( sql );
    }
    finally {
        statsCollector.jdbcPrepareStatementEnd();
    }
}
项目:lams    文件:TableGenerator.java   
private PreparedStatement prepareStatement(
        Connection connection,
        String sql,
        SqlStatementLogger statementLogger,
        SessionEventListenerManager statsCollector) throws SQLException {
    statementLogger.logStatement( sql, FormatStyle.BASIC.getFormatter() );
    try {
        statsCollector.jdbcPrepareStatementStart();
        return connection.prepareStatement( sql );
    }
    finally {
        statsCollector.jdbcPrepareStatementEnd();
    }
}
项目:lams    文件:MultipleHiLoPerTableGenerator.java   
private PreparedStatement prepareStatement(
        Connection connection,
        String sql,
        SqlStatementLogger statementLogger,
        SessionEventListenerManager statsCollector) throws SQLException {
    statementLogger.logStatement( sql, FormatStyle.BASIC.getFormatter() );
    try {
        statsCollector.jdbcPrepareStatementStart();
        return connection.prepareStatement( sql );
    }
    finally {
        statsCollector.jdbcPrepareStatementEnd();
    }
}
项目:lightmare    文件:TableGeneratorExt.java   
/**
    * Updates (or inserts) table column value with existing id
    * 
    * @param session
    * @param currentValue
    * @return {@link Serializable}
    */
   public Serializable generateIncrementally(final SessionImplementor session,
    final long currentValue) {

final SqlStatementLogger statementLogger = session.getFactory()
    .getServiceRegistry().getService(JdbcServices.class)
    .getSqlStatementLogger();
final AccessCallback callback = new AccessCallbackImpl(session,
    currentValue, statementLogger);

return optimizer.generate(callback);
   }
项目:lams    文件:JdbcServicesImpl.java   
@Override
public SqlStatementLogger getSqlStatementLogger() {
    return sqlStatementLogger;
}
项目:lams    文件:TableStructure.java   
@Override
public AccessCallback buildCallback(final SessionImplementor session) {
    final SqlStatementLogger statementLogger = session.getFactory().getServiceRegistry()
            .getService( JdbcServices.class )
            .getSqlStatementLogger();
    final SessionEventListenerManager statsCollector = session.getEventListenerManager();

    return new AccessCallback() {
        @Override
        public IntegralDataTypeHolder getNextValue() {
            return session.getTransactionCoordinator().getTransaction().createIsolationDelegate().delegateWork(
                    new AbstractReturningWork<IntegralDataTypeHolder>() {
                        @Override
                        public IntegralDataTypeHolder execute(Connection connection) throws SQLException {
                            final IntegralDataTypeHolder value = makeValue();
                            int rows;
                            do {
                                final PreparedStatement selectStatement = prepareStatement( connection, selectQuery, statementLogger, statsCollector );
                                try {
                                    final ResultSet selectRS = executeQuery( selectStatement, statsCollector );
                                    if ( !selectRS.next() ) {
                                        final String err = "could not read a hi value - you need to populate the table: " + tableName;
                                        LOG.error( err );
                                        throw new IdentifierGenerationException( err );
                                    }
                                    value.initialize( selectRS, 1 );
                                    selectRS.close();
                                }
                                catch (SQLException sqle) {
                                    LOG.error( "could not read a hi value", sqle );
                                    throw sqle;
                                }
                                finally {
                                    selectStatement.close();
                                }


                                final PreparedStatement updatePS = prepareStatement( connection, updateQuery, statementLogger, statsCollector );
                                try {
                                    final int increment = applyIncrementSizeToSourceValues ? incrementSize : 1;
                                    final IntegralDataTypeHolder updateValue = value.copy().add( increment );
                                    updateValue.bind( updatePS, 1 );
                                    value.bind( updatePS, 2 );
                                    rows = executeUpdate( updatePS, statsCollector );
                                }
                                catch (SQLException e) {
                                    LOG.unableToUpdateQueryHiValue( tableName, e );
                                    throw e;
                                }
                                finally {
                                    updatePS.close();
                                }
                            } while ( rows == 0 );

                            accessCounter++;

                            return value;
                        }
                    },
                    true
            );
        }

        @Override
        public String getTenantIdentifier() {
            return session.getTenantIdentifier();
        }
    };
}
项目:lams    文件:TableGenerator.java   
protected IntegralDataTypeHolder generateHolder(final SessionImplementor session) {
    final SqlStatementLogger statementLogger = session.getFactory().getServiceRegistry()
            .getService( JdbcServices.class )
            .getSqlStatementLogger();
    final SessionEventListenerManager listeners = session.getEventListenerManager();

    return session.getTransactionCoordinator().getTransaction().createIsolationDelegate().delegateWork(
            new AbstractReturningWork<IntegralDataTypeHolder>() {
                @Override
                public IntegralDataTypeHolder execute(Connection connection) throws SQLException {
                    IntegralDataTypeHolder value = buildHolder();
                    int rows;

                    // The loop ensures atomicity of the select + update even for no transaction or
                    // read committed isolation level
                    do {
                        final PreparedStatement qps = prepareStatement( connection, query, statementLogger, listeners );
                        try {
                            ResultSet rs = executeQuery( qps, listeners );
                            if ( !rs.next() ) {
                                String err = "could not read a hi value - you need to populate the table: " + tableName;
                                LOG.error(err);
                                throw new IdentifierGenerationException(err);
                            }
                            value.initialize( rs, 1 );
                            rs.close();
                        }
                        catch (SQLException e) {
                            LOG.error("Could not read a hi value", e);
                            throw e;
                        }
                        finally {
                            qps.close();
                        }

                        final PreparedStatement ups = prepareStatement( connection, update, statementLogger, listeners );
                        try {
                            value.copy().increment().bind( ups, 1 );
                            value.bind( ups, 2 );
                            rows = executeUpdate( ups, listeners );
                        }
                        catch (SQLException sqle) {
                            LOG.error(LOG.unableToUpdateHiValue(tableName), sqle);
                            throw sqle;
                        }
                        finally {
                            ups.close();
                        }
                    }
                    while (rows==0);
                    return value;
                }
            },
            true
    );
}
项目:lightmare    文件:TableGeneratorExt.java   
public ReturningWork(SqlStatementLogger statementLogger,
    long currentValue) {
    this.statementLogger = statementLogger;
    this.currentValue = currentValue;
}
项目:lightmare    文件:TableGeneratorExt.java   
public AccessCallbackImpl(SessionImplementor session,
    long currentValue, SqlStatementLogger statementLogger) {
    this.session = session;
    this.currentValue = currentValue;
    this.statementLogger = statementLogger;
}
项目:lams    文件:AbstractBatchImpl.java   
/**
 * Convenience access to the SQL statement logger.
 *
 * @return The underlying JDBC services.
 */
protected SqlStatementLogger sqlStatementLogger() {
    return sqlStatementLogger;
}