<commit_before>/**
 * junit-rules: JUnit Rules Library
 *
 * Copyright (c) 2009 by <NAME>.
 * This software is made available under the terms of the MIT License.
 *
 * Created Oct 22, 2009
 */
package junit.rules.jpa.hibernate;

import static junit.rules.jpa.hibernate.DerbyHibernateUtil.JDBC_DERBY_URL;
import static junit.rules.util.Reflection.invoke;
import static junit.rules.util.Reflection.set;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;

import junit.rules.dbunit.DbUnitUtil;
import junit.rules.dbunit.FixturesUtil;

import org.apache.derby.jdbc.EmbeddedDriver;
import org.dbunit.JdbcDatabaseTester;
import org.dbunit.dataset.CompositeDataSet;
import org.dbunit.dataset.DataSetException;
import org.dbunit.dataset.IDataSet;
import org.hibernate.ejb.Ejb3Configuration;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author <NAME>
 */
public class DerbyHibernateTestCase {

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

    private static final ThreadLocal<EntityManagerFactory> ENTITY_MANAGER_FACTORY = new ThreadLocal<EntityManagerFactory>();

    private EntityManager entityManager;

    private JdbcDatabaseTester jdbcDatabaseTester;

    /**
     *
     */
    @BeforeClass
    public static void initializeDerbyHibernate() {
        final Ejb3Configuration configuration = DerbyHibernateUtil.configureDerbyHibernateJpa();
        ENTITY_MANAGER_FACTORY.set(configuration.buildEntityManagerFactory());
    }

    /**
     *
     */
    @AfterClass
    public static void closeHibernateDerby() {
        ENTITY_MANAGER_FACTORY.get().close();
        try {
            DriverManager.getConnection(JDBC_DERBY_URL + ";shutdown=true");
        } catch (final SQLException e) {
            if (e.getErrorCode() == 50000 && "XJ015".equals(e.getSQLState())) {
                LOGGER.info("Derby shut down normally");
            } else {
                // if the error code or SQLState is different, we have<commit_msg>Now checks for the correct error code and SQL state for single Derby DB shutdown<commit_after>/**
 * junit-rules: JUnit Rules Library
 *
 * Copyright (c) 2009 by <NAME>.
 * This software is made available under the terms of the MIT License.
 *
 * Created Oct 22, 2009
 */
package junit.rules.jpa.hibernate;

import static junit.rules.jpa.hibernate.DerbyHibernateUtil.JDBC_DERBY_URL;
import static junit.rules.util.Reflection.invoke;
import static junit.rules.util.Reflection.set;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;

import junit.rules.dbunit.DbUnitUtil;
import junit.rules.dbunit.FixturesUtil;

import org.apache.derby.jdbc.EmbeddedDriver;
import org.dbunit.JdbcDatabaseTester;
import org.dbunit.dataset.CompositeDataSet;
import org.dbunit.dataset.DataSetException;
import org.dbunit.dataset.IDataSet;
import org.hibernate.ejb.Ejb3Configuration;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author <NAME>
 */
public class DerbyHibernateTestCase {

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

    private static final ThreadLocal<EntityManagerFactory> ENTITY_MANAGER_FACTORY = new ThreadLocal<EntityManagerFactory>();

    private EntityManager entityManager;

    private JdbcDatabaseTester jdbcDatabaseTester;

    /**
     *
     */
    @BeforeClass
    public static void initializeDerbyHibernate() {
        final Ejb3Configuration configuration = DerbyHibernateUtil.configureDerbyHibernateJpa();
        ENTITY_MANAGER_FACTORY.set(configuration.buildEntityManagerFactory());
    }

    /**
     *
     */
    @AfterClass
    public static void closeHibernateDerby() {
        ENTITY_MANAGER_FACTORY.get().close();
        try {
            DriverManager.getConnection(JDBC_DERBY_URL + ";shutdown=true");
        } catch (final SQLException e) {
            if (e.getErrorCode() == 45000 && "08006".equals(e.getSQLState())) {
                LOGGER.info("Derby shut down normally");
            } else {
                // if the error code or SQLState is different, we have
{'fraction_non_alphanumeric': 0.0955137481910275, 'fraction_numerical': 0.009510026876162911, 'mean_word_length': 4.0553814002089865, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3835533', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1409, 'n_words': 311}