<commit_before>package com.github.ledoyen.winter.stepdef;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import javax.inject.Provider;

import org.assertj.core.util.Lists;
import org.springframework.beans.factory.annotation.Autowired;

import com.github.ledoyen.automocker.extension.sql.Connections;
import com.github.ledoyen.automocker.extension.sql.DataSources;
import com.github.ledoyen.automocker.extension.sql.DatasourceLocator;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;

import cucumber.api.DataTable;
import cucumber.api.java.After;
import cucumber.api.java.en.Given;

public class SqlStepDefs {

	@Autowired
	private Provider<DatasourceLocator> datasourceLocator;

	private final ListMultimap<String, String> tablesToClean = ArrayListMultimap.create();

	@Given("^an SQL table (\\S+) containing$")
	public void a_call_on_service_method_is_made(String tableName, DataTable data) throws Exception {
		DataSources.populateTable(datasourceLocator.get()
				.getDataSource(), tableName, data.topCells(), data.cells(1));
		tablesToClean.put(datasourceLocator.get()
				.getName(), tableName);
	}

	@After
	public void afterScenario() {
		tablesToClean.asMap()
				.forEach((dsName, names) -> DataSources.doInConnection(datasourceLocator.get()
						.getDataSource(dsName), c -> {
							// TODO fix this, not working
							List<String> copy = Lists.newArrayList(names);
							Collections.sort(copy, Comparator.reverseOrder());
							names.forEach(name -> Connections.truncate(c, name));
						}));
		tablesToClean.clear();
	}
}
<commit_msg>fix truncate operation in SQL @After hook<commit_after>package com.github.ledoyen.winter.stepdef;

import java.util.stream.Collectors;

import javax.inject.Provider;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.github.ledoyen.automocker.extension.sql.Connections;
import com.github.ledoyen.automocker.extension.sql.DataSources;
import com.github.ledoyen.automocker.extension.sql.DatasourceLocator;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;

import cucumber.api.DataTable;
import cucumber.api.java.After;
import cucumber.api.java.en.Given;

public class SqlStepDefs {

	private static final Logger LOGGER = LoggerFactory.getLogger(SqlStepDefs.class);

	@Autowired
	private Provider<DatasourceLocator> datasourceLocator;

	private final ListMultimap<String, String> tablesToClean = ArrayListMultimap.create();

	@Given("^an SQL table (\\S+) containing$")
	public void a_call_on_service_method_is_made(String tableName, DataTable data) throws Exception {
		DataSources.populateTable(datasourceLocator.get()
				.getDataSource(), tableName, data.topCells(), data.cells(1));
		tablesToClean.put(datasourceLocator.get()
				.getName(), tableName);
	}

	@After
	public void afterScenario() {
		tablesToClean.asMap()
				.forEach((dsName, names) -> DataSources.doInConnection(datasourceLocator.get()
						.getDataSource(dsName), c -> {
							Connections.execute(c, "SET REFERENTIAL_INTEGRITY FALSE");
							names.forEach(name -> Connections.truncate(c, name));
							Connections.execute(c, "SET REFERENTIAL_INTEGRITY TRUE");
							LOGGER.info("[" + dsName + "] Tables (" + names.stream()
									.collect(Collectors.joining(", ")) + ") truncated");
						}));
		tablesToClean.clear();
	}
}

{'fraction_non_alphanumeric': 0.11898096304591266, 'fraction_numerical': 0.0011198208286674132, 'mean_word_length': 4.405446293494705, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 14, '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': '1892103', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1125, 'n_words': 190}