<commit_before>package org.jboss.pnc.datastore.configuration;

import java.lang.invoke.MethodHandles;

import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;

import org.jboss.pnc.datastore.repositories.SequenceHandlerRepository;
import org.jboss.pnc.model.BuildConfigSetRecord;
import org.jboss.pnc.model.BuildRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Singleton
@Startup
public class CustomSequenceConfiguration {

    public static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    @Inject
    private SequenceHandlerRepository sequenceHandlerRepository;

    @PostConstruct
    public void initialize() {

        String hbm2ddlAutoValue = sequenceHandlerRepository.getEntityManagerFactoryProperty("hibernate.hbm2ddl.auto");
        logger.info("Found hibernate.hbm2ddl.auto {} ...", hbm2ddlAutoValue);

        if ("create".equalsIgnoreCase(hbm2ddlAutoValue) || "create-drop".equalsIgnoreCase(hbm2ddlAutoValue)) {

            try {
                logger.info("Dropping sequence {} ...", BuildRecord.SEQUENCE_NAME);
                sequenceHandlerRepository.dropSequence(BuildRecord.SEQUENCE_NAME);
            } catch (Exception e) {
                logger.error(e.getMessage());
            }

            try {
                logger.info("Dropping sequence {} ...", BuildConfigSetRecord.SEQUENCE_NAME);
                sequenceHandlerRepository.dropSequence(BuildConfigSetRecord.SEQUENCE_NAME);
            } catch (Exception e) {
                logger.error(e.getMessage());
            }

            try {
                logger.info("Creating sequence {} ...", BuildRecord.SEQUENCE_NAME);
                sequenceHandlerRepository.createSequence(BuildRecord.SEQUENCE_NAME);
            } catch (Exception e) {
                logger.error(e.getMessage());
            }

            try {
                logger.info("Creating sequence {} ...", BuildConfigSetRecord.SEQUENCE_NAME);
                sequenceHandlerRepository.createSequence(BuildConfigSetRecord.SEQUENCE_NAME);
            } catch (Exception e) {
                logger.error(e.getMessage());
            }
        }
    }

}
<commit_msg>Handling of hibernate.hbm2ddl.auto = update<commit_after>package org.jboss.pnc.datastore.configuration;

import java.lang.invoke.MethodHandles;

import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;

import org.jboss.pnc.datastore.repositories.SequenceHandlerRepository;
import org.jboss.pnc.model.BuildConfigSetRecord;
import org.jboss.pnc.model.BuildRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Singleton
@Startup
public class CustomSequenceConfiguration {

    public static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    @Inject
    private SequenceHandlerRepository sequenceHandlerRepository;

    @PostConstruct
    public void initialize() {

        String hbm2ddlAutoValue = sequenceHandlerRepository.getEntityManagerFactoryProperty("hibernate.hbm2ddl.auto");
        logger.info("Found hibernate.hbm2ddl.auto {} ...", hbm2ddlAutoValue);
        // Possible values: validate | update | create | create-drop

        // I need to drop and re-create model
        if ("create".equalsIgnoreCase(hbm2ddlAutoValue) || "create-drop".equalsIgnoreCase(hbm2ddlAutoValue)) {

            try {
                logger.info("Dropping sequence {} ...", BuildRecord.SEQUENCE_NAME);
                sequenceHandlerRepository.dropSequence(BuildRecord.SEQUENCE_NAME);
            } catch (Exception e) {
                logger.error(e.getMessage());
            }

            try {
                logger.info("Dropping sequence {} ...", BuildConfigSetRecord.SEQUENCE_NAME);
                sequenceHandlerRepository.dropSequence(BuildConfigSetRecord.SEQUENCE_NAME);
            } catch (Exception e) {
                logger.error(e.getMessage());
            }

            try {
                logger.info("Creating sequence {} ...", BuildRecord.SEQUENCE_NAME);
                sequenceHandlerRepository.createSequence(BuildRecord.SEQUENCE_NAME);
            } catch (Exception e) {
                logger.error(e.getMessage());
            }

            try {
                logger.info("Creating sequence {} ...", BuildConfigSetRecord.SEQUENCE_NAME);
                sequenceHandlerRepository.createSequence(BuildConfigSetRecord.SEQUENCE_NAME);
            } catch (Exception e) {
                logger.error(e.getMessage());
            }
        }

        // If I need to update the model them I can safely ignore any "sequence already-existing" error
        if ("update".equalsIgnoreCase(hbm2ddlAutoValue)) {

            try {
                logger.info("Updating sequence {} ...", BuildRecord.SEQUENCE_NAME);
                sequenceHandlerRepository.createSequence(BuildRecord.SEQUENCE_NAME);
            } catch (Exception e) {
            }

            try {
                logger.info("Updating sequence {} ...", BuildConfigSetRecord.SEQUENCE_NAME);
                sequenceHandlerRepository.createSequence(BuildConfigSetRecord.SEQUENCE_NAME);
            } catch (Exception e) {
            }
        }
    }

}

{'fraction_non_alphanumeric': 0.10152571105669618, 'fraction_numerical': 0.0033904690148803917, 'mean_word_length': 2.5470941883767537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5568186', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1372, 'n_words': 222}