<commit_before>package com.github.ferstl.spring.jdbc.oracle;

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

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
import org.springframework.jdbc.support.nativejdbc.OracleJdbc4NativeJdbcExtractor;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@PropertySource({
  "classpath:database.properties",
  "classpath:database_${user.name}.properties",
  "connectionpool.properties"})
@Import({
  SingleConnectionDataSourceConfiguration.class,
  TomcatPoolDataSourceConfiguration.class,
  CommonsDbcpDataSourceConfiguration.class})
@EnableTransactionManagement
public class DatabaseConfiguration {

  private static final int NUMBER_OF_ROWS = 10000;
  private static final String INSERT_SQL = "INSERT INTO test_table(id, val) VALUES(seq_test_table.nextval, ?)";

  @Autowired
  private DataSource dataSource;

  @Bean
  public JdbcTemplate jdbcTemplate() throws Exception {
    prepareDatabase(this.dataSource);

    JdbcTemplate jdbcTemplate = new OracleJdbcTemplate(10, this.dataSource);
    jdbcTemplate.setNativeJdbcExtractor(nativeJdbcExtractor());
    initDatabase(jdbcTemplate);

    return jdbcTemplate;
  }

  @Bean
  public NamedParameterJdbcTemplate namedParameterJdbcTemplate() throws Exception {
    return new NamedParameterJdbcTemplate(jdbcTemplate());
  }

  @Bean
  NativeJdbcExtractor nativeJdbcExtractor() {
    return new OracleJdbc4NativeJdbcExtractor();
  }

  private static void prepareDatabase(DataSource dataSource) {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(new ClassPathResource("prepare-database.sql"));
    populator.setIgnoreFailedDrops(true);
    DatabasePopulatorUtils.execute(populator, dataSource);
  }

  private static void initDatabase(JdbcTemplate jdbcTemplate) {
    List<Object[]> batchArgs = new ArrayList<>(NUMBER_OF_ROWS);
    for (int i = 0; i < NUMBER_OF_ROWS; i++) {
      batchArgs.add(new Object[] {String.format("Value_%05d", i + 1)});
    }
    jdbcTemplate.batchUpdate(INSERT_SQL, batchArgs);
  }
}<commit_msg>Setup test data in transaction<commit_after>package com.github.ferstl.spring.jdbc.oracle;

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

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
import org.springframework.jdbc.support.nativejdbc.OracleJdbc4NativeJdbcExtractor;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

@Configuration
@PropertySource({
  "classpath:database.properties",
  "classpath:database_${user.name}.properties",
  "connectionpool.properties"})
@Import({
  SingleConnectionDataSourceConfiguration.class,
  TomcatPoolDataSourceConfiguration.class,
  CommonsDbcpDataSourceConfiguration.class})
@EnableTransactionManagement
public class DatabaseConfiguration {

  private static final int NUMBER_OF_ROWS = 10000;
  private static final String INSERT_SQL = "INSERT INTO test_table(id, val) VALUES(seq_test_table.nextval, ?)";

  @Autowired
  private DataSource dataSource;

  @Bean
  public JdbcTemplate jdbcTemplate() throws Exception {
    prepareDatabase();

    JdbcTemplate jdbcTemplate = new OracleJdbcTemplate(10, this.dataSource);
    jdbcTemplate.setNativeJdbcExtractor(nativeJdbcExtractor());
    initDatabase(jdbcTemplate);

    return jdbcTemplate;
  }

  @Bean
  public NamedParameterJdbcTemplate namedParameterJdbcTemplate() throws Exception {
    return new NamedParameterJdbcTemplate(jdbcTemplate());
  }

  @Bean
  NativeJdbcExtractor nativeJdbcExtractor() {
    return new OracleJdbc4NativeJdbcExtractor();
  }

  @Bean
  PlatformTransactionManager transactionManager() {
    return new DataSourceTransactionManager(this.dataSource);
  }

  private void prepareDatabase() {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(new ClassPathResource("prepare-database.sql"));
    populator.setIgnoreFailedDrops(true);

    TransactionTemplate trxTemplate = new TransactionTemplate(transactionManager());
    trxTemplate.execute(new TransactionCallback<Void>() {

      @Override
      public Void doInTransaction(TransactionStatus status) {
        DatabasePopulatorUtils.execute(populator, DatabaseConfiguration.this.dataSource);
        return null;
      }
    });
  }

  private void initDatabase(final JdbcTemplate jdbcTemplate) {
    TransactionTemplate trxTemplate = new TransactionTemplate(transactionManager());
    trxTemplate.execute(new TransactionCallback<int[]>() {

      @Override
      public int[] doInTransaction(TransactionStatus status) {
        List<Object[]> batchArgs = new ArrayList<>(NUMBER_OF_ROWS);
        for (int i = 0; i < NUMBER_OF_ROWS; i++) {
          batchArgs.add(new Object[] {String.format("Value_%05d", i + 1)});
        }
        return jdbcTemplate.batchUpdate(INSERT_SQL, batchArgs);
      }
    });
  }
}
{'fraction_non_alphanumeric': 0.09021639743980493, 'fraction_numerical': 0.003962206644315757, 'mean_word_length': 6.095135135135135, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1095213', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1713, 'n_words': 314}