<commit_before>package org.lightmare.deploy;

import java.io.IOException;
import java.net.URL;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.persistence.Entity;

import org.lightmare.annotations.UnitName;
import org.lightmare.config.Configuration;
import org.lightmare.jpa.JpaManager;
import org.lightmare.scannotation.AnnotationDB;
import org.lightmare.utils.AbstractIOUtils;
import org.lightmare.utils.CollectionUtils;
import org.lightmare.utils.ObjectUtils;
import org.lightmare.utils.reflect.MetaUtils;

public class OrmCreator {

    private MetaCreator creator;

    private AnnotationDB annotationDB;

    private OrmCreator(MetaCreator creator) {

	this.creator = creator;
	this.annotationDB = creator.getAnnotationDB();
    }

    /**
     * Checks weather {@link javax.persistence.Entity} annotated classes is need
     * to be filtered by {@link org.lightmare.annotations.UnitName} value
     * 
     * @param className
     * @return boolean
     * @throws IOException
     */
    private boolean checkForUnitName(String className, Configuration cloneConfig)
	    throws IOException {

	boolean isValid;

	Class<?> entityClass;
	entityClass = MetaUtils.initClassForName(className);
	UnitName annotation = entityClass.getAnnotation(UnitName.class);
	isValid = annotation.value().equals(cloneConfig.getAnnotatedUnitName());

	return isValid;
    }

    /**
     * Defines belongs or not of {@link javax.persistence.Entity} annotated
     * classes to jar file
     * 
     * @param classSet
     * @return {@link List}<String>
     */
    private void filterEntitiesForJar(Set<String> classSet,
	    String fileNameForBean) {

	Map<String, String> classOwnersFiles = annotationDB
		.getClassOwnersFiles();

	String fileNameForEntity;
	for (String entityName : classSet) {
	    fileNameForEntity = classOwnersFiles.get(entityName);
	    if (ObjectUtils
		    .notNullNotEquals(fileNameForEntity, fileNameForBean)) {
		classSet.remove(entityName);
	    }
	}
    }

    /**
     * Filters {@link javax.persistence.Entity} annotated classes by name or by
     * {@link org.lightmare.annotations.UnitName} by configuration
     * 
     * @param classSet
     * @return {@link List}<String>
     * @throws IOException
     */
    private List<String> filterEntities(Set<String> classSet,
	    Configuration configClone) throws IOException {

	List<String> classes;

	if (configClone.getAnnotatedUnitName() == null) {
	    classes = CollectionUtils.translateToList(classSet);
	} else {
	    Set<String> filtereds = new HashSet<String>();
	    boolean valid;
	    for (String className : classSet) {
		valid = checkForUnitName(className, configClone);
		if (valid) {
		    filtereds.add(className);
		}
	    }
	    classes = CollectionUtils.translateToList(filtereds);
	}

	return classes;
    }

    /**
     * Creates connection associated with unit name if such does not exists
     * 
     * @param unitName
     * @param beanName
     * @throws IOException
     */
    protected void configureConnection(String unitName, String beanName,
	    ClassLoader loader, Configuration configClone) throws IOException {

	JpaManager.Builder builder = new JpaManager.Builder();
	Map<String, String> classOwnersFiles = annotationDB
		.getClassOwnersFiles();
	AbstractIOUtils ioUtils = creator.getAggregateds().get(beanName);

	if (ObjectUtils.notNull(ioUtils)) {
	    URL jarURL = ioUtils.getAppropriatedURL(classOwnersFiles, beanName);
	    builder.setURL(jarURL);
	}

	if (configClone.isScanForEntities()) {
	    Set<String> classSet;
	    Map<String, Set<String>> annotationIndex = annotationDB
		    .getAnnotationIndex();
	    classSet = annotationIndex.get(Entity.class.getName());
	    String annotatedUnitName = configClone.getAnnotatedUnitName();
	    if (annotatedUnitName == null) {
		classSet = annotationIndex.get(Entity.class.getName());
	    } else if (annotatedUnitName.equals(unitName)) {
		Set<String> unitNamedSet = annotationIndex.get(UnitName.class
			.getName());
		// Intersects entities with unit name annotated classes
		classSet.retainAll(unitNamedSet);
	    }
	    if (ObjectUtils.notNull(ioUtils)) {
		String fileNameForBean = classOwnersFiles.get(beanName);
		filterEntitiesForJar(classSet, fileNameForBean);
	    }
	    List<String> classes = filterEntities(classSet, configClone);
	    builder.setClasses(classes);
	}

	// Builds connection for appropriated persistence unit name
	builder.configure(configClone).setClassLoader(loader).build()
		.create(unitName);
    }

    protected static OrmCreator get(MetaCreator creator) {

	return new OrmCreator(creator);
    }
}<commit_msg>improved code and comments in deployment utility classes<commit_after>package org.lightmare.deploy;

import java.io.IOException;
import java.net.URL;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.persistence.Entity;

import org.lightmare.annotations.UnitName;
import org.lightmare.config.Configuration;
import org.lightmare.jpa.JpaManager;
import org.lightmare.scannotation.AnnotationDB;
import org.lightmare.utils.AbstractIOUtils;
import org.lightmare.utils.CollectionUtils;
import org.lightmare.utils.ObjectUtils;
import org.lightmare.utils.reflect.MetaUtils;

public class OrmCreator {

    private MetaCreator creator;

    private AnnotationDB annotationDB;

    private OrmCreator(MetaCreator creator) {

	this.creator = creator;
	this.annotationDB = creator.getAnnotationDB();
    }

    /**
     * Checks weather {@link javax.persistence.Entity} annotated classes is need
     * to be filtered by {@link org.lightmare.annotations.UnitName} value
     * 
     * @param className
     * @return boolean
     * @throws IOException
     */
    private boolean checkForUnitName(String className, Configuration cloneConfig)
	    throws IOException {

	boolean isValid;

	Class<?> entityClass;
	entityClass = MetaUtils.initClassForName(className);
	UnitName annotation = entityClass.getAnnotation(UnitName.class);
	isValid = annotation.value().equals(cloneConfig.getAnnotatedUnitName());

	return isValid;
    }

    /**
     * Defines belongs or not of {@link javax.persistence.Entity} annotated
     * classes to jar file
     * 
     * @param classSet
     * @return {@link List}<String>
     */
    private void filterEntitiesForJar(Set<String> classSet,
	    String fileNameForBean) {

	Map<String, String> classOwnersFiles = annotationDB
		.getClassOwnersFiles();

	String fileNameForEntity;
	for (String entityName : classSet) {
	    fileNameForEntity = classOwnersFiles.get(entityName);
	    if (ObjectUtils
		    .notNullNotEquals(fileNameForEntity, fileNameForBean)) {
		classSet.remove(entityName);
	    }
	}
    }

    /**
     * Filters {@link javax.persistence.Entity} annotated classes by name or by
     * {@link org.lightmare.annotations.UnitName} by configuration
     * 
     * @param classSet
     * @return {@link List}<String>
     * @throws IOException
     */
    private List<String> filterEntities(Set<String> classSet,
	    Configuration configClone) throws IOException {

	List<String> classes;

	if (configClone.getAnnotatedUnitName() == null) {
	    classes = CollectionUtils.translateToList(classSet);
	} else {
	    Set<String> filtereds = new HashSet<String>();
	    boolean valid;
	    for (String className : classSet) {
		valid = checkForUnitName(className, configClone);
		if (valid) {
		    filtereds.add(className);
		}
	    }
	    classes = CollectionUtils.translateToList(filtereds);
	}

	return classes;
    }

    /**
     * Creates connection associated with unit name if such does not exists
     * 
     * @param unitName
     * @param beanName
     * @throws IOException
     */
    protected void configureConnection(String unitName, String beanName,
	    ClassLoader loader, Configuration configClone) throws IOException {

	JpaManager.Builder builder = new JpaManager.Builder();
	Map<String, String> classOwnersFiles = annotationDB
		.getClassOwnersFiles();
	AbstractIOUtils ioUtils = creator.getAggregateds().get(beanName);

	if (ObjectUtils.notNull(ioUtils)) {
	    URL jarURL = ioUtils.getAppropriatedURL(classOwnersFiles, beanName);
	    builder.setURL(jarURL);
	}

	if (configClone.isScanForEntities()) {
	    Set<String> classSet;
	    Map<String, Set<String>> annotationIndex = annotationDB
		    .getAnnotationIndex();
	    classSet = annotationIndex.get(Entity.class.getName());
	    String annotatedUnitName = configClone.getAnnotatedUnitName();
	    if (annotatedUnitName == null) {
		classSet = annotationIndex.get(Entity.class.getName());
	    } else if (annotatedUnitName.equals(unitName)) {
		Set<String> unitNamedSet = annotationIndex.get(UnitName.class
			.getName());
		// Intersects entities with unit name annotated classes
		classSet.retainAll(unitNamedSet);
	    }
	    if (ObjectUtils.notNull(ioUtils)) {
		String fileNameForBean = classOwnersFiles.get(beanName);
		filterEntitiesForJar(classSet, fileNameForBean);
	    }

	    List<String> classes = filterEntities(classSet, configClone);
	    builder.setClasses(classes);
	}

	// Builds connection for appropriated persistence unit name
	builder.configure(configClone).setClassLoader(loader).build()
		.create(unitName);
    }

    protected static OrmCreator get(MetaCreator creator) {

	return new OrmCreator(creator);
    }
}
{'fraction_non_alphanumeric': 0.0995099083741743, 'fraction_numerical': 0.0, 'mean_word_length': 3.979840848806366, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '820552', 'n_tokens_mistral': 2837, 'n_tokens_neox': 2703, 'n_words': 603}