<commit_before>/**
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 *
 * Copyright 2012-2014 the original author or authors.
 */
package org.assertj.db.common;

import java.lang.reflect.Constructor;
import java.util.List;

import javax.sql.DataSource;

import org.assertj.db.configuration.TestsConfiguration;
import org.assertj.db.type.Row;
import org.assertj.db.type.Source;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

/**
 * Parent for all the tests. It contains the variables like a {@code DataSource} and a {@code Source}.
 * 
 * @author <NAME>
 * 
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { TestsConfiguration.class })
@Transactional
public abstract class AbstractTest {

  @Autowired(required = true)
  protected DataSource dataSource;

  protected Source source = new Source("jdbc:h2:mem:test", "sa", "");

  /**
   * Returns an instance of a Row.
   * 
   * @param pksNameList The list of the primary keys name.
   * @param columnsNameList The list of the columns name.
   * @param valuesList The values in the row.
   * @return An instance.
   * @throws Exception Exception
   */
  protected static Row getRow(List<String> pksNameList, List<String> columnsNameList, List<Object> valuesList) throws Exception {
    Constructor<Row> constructor = Row.class.getDeclaredConstructor(List.class, List.class, List.class);
    constructor.setAccessible(true);
    return constructor.newInstance(pksNameList, columnsNameList, valuesList);
  }
}
<commit_msg>Add a method to update the database<commit_after>/**
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 *
 * Copyright 2012-2014 the original author or authors.
 */
package org.assertj.db.common;

import java.lang.reflect.Constructor;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.List;

import javax.sql.DataSource;

import org.assertj.db.configuration.TestsConfiguration;
import org.assertj.db.type.Row;
import org.assertj.db.type.Source;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.Transactional;

/**
 * Parent for all the tests. It contains the variables like a {@code DataSource} and a {@code Source}.
 * 
 * @author <NAME>
 * 
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { TestsConfiguration.class })
@Transactional
public abstract class AbstractTest {

  @Autowired(required = true)
  protected DataSource dataSource;
  @Autowired(required = true)
  protected PlatformTransactionManager transactionManager;

  protected Source source = new Source("jdbc:h2:mem:test", "sa", "");

  /**
   * Returns an instance of a Row.
   * 
   * @param pksNameList The list of the primary keys name.
   * @param columnsNameList The list of the columns name.
   * @param valuesList The values in the row.
   * @return An instance.
   * @throws Exception Exception
   */
  protected static Row getRow(List<String> pksNameList, List<String> columnsNameList, List<Object> valuesList) throws Exception {
    Constructor<Row> constructor = Row.class.getDeclaredConstructor(List.class, List.class, List.class);
    constructor.setAccessible(true);
    return constructor.newInstance(pksNameList, columnsNameList, valuesList);
  }

  /**
   * Update the database.
   * @param request Request to update.
   * @param parameters The parameters of the request.
   */
  protected void update(String request, Object... parameters) {
    try (Connection connection = dataSource.getConnection()) {
      try (PreparedStatement statement = connection.prepareStatement(request)) {
        for (int i = 0; i < parameters.length; i++) {
          statement.setObject(i + 1, parameters[i]);
        }
        statement.executeUpdate();
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}

{'fraction_non_alphanumeric': 0.09515701853953841, 'fraction_numerical': 0.006432084752175558, 'mean_word_length': 4.36751269035533, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6884534', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1405, 'n_words': 471}