<commit_before>package br.com.six2six.fixturefactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.Session;

import br.com.six2six.fixturefactory.util.ReflectionUtils;

public class PersistentObjectFactory extends ObjectFactory {

	private final Session session;
	
	public PersistentObjectFactory(TemplateHolder templateHolder, Object owner, Session session) {
		super(templateHolder, owner);
		this.session = session;
	}
	
	public PersistentObjectFactory(TemplateHolder templateHolder, Session session) {
		super(templateHolder);
		this.session = session;
	}

	@Override
	protected Object createObject(Rule rule) {
		Map<String, Object> constructorArguments = new HashMap<String, Object>();
		List<Property> deferredProperties = new ArrayList<Property>();
		Class<?> clazz = templateHolder.getClazz();
		
		List<String> parameterNames = !ReflectionUtils.hasDefaultConstructor(clazz) ? 
										lookupConstructorParameterNames(clazz, rule.getProperties()) : new ArrayList<String>();
		
		for (Property property : rule.getProperties()) {
			if (parameterNames.contains(property.getRootAttribute())) {
				if(property.hasRelationFunction()) {
					constructorArguments.put(property.getName(), property.getValue(session));
				} else {
					constructorArguments.put(property.getName(), property.getValue());
				}
			} else {
				deferredProperties.add(property);
			}
		}
		
		Object result = ReflectionUtils.newInstance(clazz, processConstructorArguments(parameterNames, constructorArguments));
		
		for (Property property : deferredProperties) {
			ReflectionUtils.invokeRecursiveSetter(result, property.getName(), processPropertyValue(result, property));
		}
		
		session.save(result);
		
		return result;
	}<commit_msg>little refactoring<commit_after>package br.com.six2six.fixturefactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.Session;

import br.com.six2six.fixturefactory.util.ReflectionUtils;

public class PersistentObjectFactory extends ObjectFactory {

	private final Session session;
	
	public PersistentObjectFactory(TemplateHolder templateHolder, Object owner, Session session) {
		super(templateHolder, owner);
		this.session = session;
	}
	
	public PersistentObjectFactory(TemplateHolder templateHolder, Session session) {
		super(templateHolder);
		this.session = session;
	}

	@Override
	protected Object createObject(Rule rule) {
		Map<String, Object> constructorArguments = new HashMap<String, Object>();
		List<Property> deferredProperties = new ArrayList<Property>();
		Class<?> clazz = templateHolder.getClazz();
		
		List<String> parameterNames = !ReflectionUtils.hasDefaultConstructor(clazz) ? 
										lookupConstructorParameterNames(clazz, rule.getProperties()) : new ArrayList<String>();
		
		for (Property property : rule.getProperties()) {
			if (parameterNames.contains(property.getRootAttribute())) {
				constructorArguments.put(property.getName(), generateConstructorParamValue(property));
			} else {
				deferredProperties.add(property);
			}
		}
		
		Object result = ReflectionUtils.newInstance(clazz, processConstructorArguments(parameterNames, constructorArguments));
		
		for (Property property : deferredProperties) {
			ReflectionUtils.invokeRecursiveSetter(result, property.getName(), processPropertyValue(result, property));
		}
		
		session.save(result);
		
		return result;
	}
	
	private Object generateConstructorParamValue(Property property) {
		if(property.hasRelationFunction()) {
			return property.getValue(session);
		} else {
			return property.getValue();
		}
	}
{'fraction_non_alphanumeric': 0.10380434782608695, 'fraction_numerical': 0.0010869565217391304, 'mean_word_length': 5.526595744680851, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4232035', 'n_tokens_mistral': 1106, 'n_tokens_neox': 950, 'n_words': 201}