All Downloads are FREE. Search and download functionalities are using the official Maven repository.

testdata_builder.ObjectBuilder_persistable.ftl Maven / Gradle / Ivy

There is a newer version: 2.4.3
Show newest version
<#include '/makros.ftl'>
package ${variables.rootPackage}.common.builders;

import java.util.LinkedList;
import java.util.List;

import javax.persistence.EntityManager;

import ${pojo.package}.${pojo.name};
import ${variables.rootPackage}.common.builders.P;

/**
 * Test data builder for ${pojo.name} generated with cobigen.
 */
public class ${pojo.name}Builder {

  /**
   * @param em the {@link EntityManager}
   * @return the ${pojo.name}
   */
   public ${pojo.name} persist(EntityManager em) {
        ${pojo.name} ${pojo.name?lower_case} = createNew();
        em.persist(${pojo.name?lower_case});
        return ${pojo.name?lower_case};
    }
    
  /**
   * @param em the {@link EntityManager}
   * @param quantity the quantity
   * @return a list of ${pojo.name}
   */
    public List<${pojo.name}> persistAndDuplicate(EntityManager em, int quantity) {

        List<${pojo.name}> ${pojo.name?lower_case}List = new LinkedList<>();
        for (int i = 0; i < quantity; i++) {
            ${pojo.name} ${pojo.name?lower_case} = createNew();
            // TODO alter at least values with unique key constraints to prevent from exceptions while persisting
            em.persist(${pojo.name?lower_case});
            ${pojo.name?lower_case}List.add(${pojo.name?lower_case});
        }

        return ${pojo.name?lower_case}List;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy