<commit_before>/* DO NOT EDIT: File is auto-generated */
package <%= to_package(dao.jpa.qualified_dao_name) %>;

@java.lang.SuppressWarnings( { "UnusedDeclaration" } )
@javax.annotation.Generated( "Domgen" )
@javax.enterprise.context.ApplicationScoped
@javax.transaction.Transactional( javax.transaction.Transactional.TxType.<%= Domgen::Naming.uppercase_constantize(dao.jpa.transaction_type.to_s) %> )
@javax.enterprise.inject.Typed( <%= dao.jpa.qualified_dao_service_name %>.class )
public class <%= dao.jpa.dao_name %>
  implements <%= dao.jpa.qualified_dao_service_name %>
{
<% unless dao.repository? -%>
<% dao.queries.each do |query| -%>
  private static final String <%= Domgen::Naming.uppercase_constantize(query.name) %> = "<%= query.qualified_name %>";
<% end %>
<% end -%>
  @javax.persistence.PersistenceContext( unitName = <%= dao.data_module.repository.jpa.qualified_unit_descriptor_name %>.NAME )
  private javax.persistence.EntityManager em;

<% dao.queries.each do |query| -%>
  @java.lang.Override
  public <%= query_result_type(query) %> <%= Domgen::Naming.camelize(query.name) %>(<%= (query.parameters.collect {|p| "final #{p.jpa.primitive? ? '' : nullability_annotation(p.nullable?)} #{p.jpa.java_type} #{p.name}"} + [query.jpa.limit ? 'final int limit': nil] + [query.jpa.offset ? 'final int offset': nil]).compact.join(', ') %>)
  {
    final javax.persistence.TypedQuery<<%= query_component_result_type(query) %>> query =
      em.createNamedQuery( <%= dao.repository? ? "#{query.entity.jpa.qualified_name}." : '' %><%= Domgen::Naming.uppercase_constantize(query.name) %>, <%= query_component_result_type(query) %>.class );
<%
   if !query.jpa.native?
    query.parameters.each do |p|
%>    query.setParameter( <%= "\"#{p.name}\"" %>, <%= p.name %> );
<%  end
   else -%>
<%  query.parameters.each_with_index do |p, index|
    param_suffix = nil
    if p.reference?
      param_suffix = ".#{getter_for(p.referenced_entity.primary_key)}"
    elsif p.enumeration? && p.enumeration.textual_values?
      param_suffix = ".name()"
    elsif p.enumeration? && p.enumeration.numeric_value?
      param_suffix = ".ordinal()"
    end
    param_value = "#{p.name}#{param_suffix}"
    if param_suffix && p.nullable?
      param_value = "null == #{p.name} ? null : #{param_value}"
    end
%>
    query.setParameter( <%= index + 1 %>, <%= param_value %> );
<%  end
   end -%>
<% if query.jpa.offset -%>
    query.setFirstResult( offset );
<% end -%>
<% if query.jpa.limit -%>
    query.setMaxResults( limit );
<% end -%>
<% if query.query_type == :select -%>
<% if query.multiplicity == :many -%>
    return query.getResultList();
<% elsif query.multiplicity == :one -%>
    return query.getSingleResult();
<% else -%>
    query.setMaxResults( 1 );
    final java.util.List<<%= query_component_result_type(query) %>> resultList = query.getResultList();
    if ( resultList.size() > 0 )
    {
      return resultList.get( 0 );
    }<commit_msg>Fix crash when query parameters are numeric enums<commit_after>/* DO NOT EDIT: File is auto-generated */
package <%= to_package(dao.jpa.qualified_dao_name) %>;

@java.lang.SuppressWarnings( { "UnusedDeclaration" } )
@javax.annotation.Generated( "Domgen" )
@javax.enterprise.context.ApplicationScoped
@javax.transaction.Transactional( javax.transaction.Transactional.TxType.<%= Domgen::Naming.uppercase_constantize(dao.jpa.transaction_type.to_s) %> )
@javax.enterprise.inject.Typed( <%= dao.jpa.qualified_dao_service_name %>.class )
public class <%= dao.jpa.dao_name %>
  implements <%= dao.jpa.qualified_dao_service_name %>
{
<% unless dao.repository? -%>
<% dao.queries.each do |query| -%>
  private static final String <%= Domgen::Naming.uppercase_constantize(query.name) %> = "<%= query.qualified_name %>";
<% end %>
<% end -%>
  @javax.persistence.PersistenceContext( unitName = <%= dao.data_module.repository.jpa.qualified_unit_descriptor_name %>.NAME )
  private javax.persistence.EntityManager em;

<% dao.queries.each do |query| -%>
  @java.lang.Override
  public <%= query_result_type(query) %> <%= Domgen::Naming.camelize(query.name) %>(<%= (query.parameters.collect {|p| "final #{p.jpa.primitive? ? '' : nullability_annotation(p.nullable?)} #{p.jpa.java_type} #{p.name}"} + [query.jpa.limit ? 'final int limit': nil] + [query.jpa.offset ? 'final int offset': nil]).compact.join(', ') %>)
  {
    final javax.persistence.TypedQuery<<%= query_component_result_type(query) %>> query =
      em.createNamedQuery( <%= dao.repository? ? "#{query.entity.jpa.qualified_name}." : '' %><%= Domgen::Naming.uppercase_constantize(query.name) %>, <%= query_component_result_type(query) %>.class );
<%
   if !query.jpa.native?
    query.parameters.each do |p|
%>    query.setParameter( <%= "\"#{p.name}\"" %>, <%= p.name %> );
<%  end
   else -%>
<%  query.parameters.each_with_index do |p, index|
    param_suffix = nil
    if p.reference?
      param_suffix = ".#{getter_for(p.referenced_entity.primary_key)}"
    elsif p.enumeration? && p.enumeration.textual_values?
      param_suffix = ".name()"
    elsif p.enumeration? && p.enumeration.numeric_values?
      param_suffix = ".ordinal()"
    end
    param_value = "#{p.name}#{param_suffix}"
    if param_suffix && p.nullable?
      param_value = "null == #{p.name} ? null : #{param_value}"
    end
%>
    query.setParameter( <%= index + 1 %>, <%= param_value %> );
<%  end
   end -%>
<% if query.jpa.offset -%>
    query.setFirstResult( offset );
<% end -%>
<% if query.jpa.limit -%>
    query.setMaxResults( limit );
<% end -%>
<% if query.query_type == :select -%>
<% if query.multiplicity == :many -%>
    return query.getResultList();
<% elsif query.multiplicity == :one -%>
    return query.getSingleResult();
<% else -%>
    query.setMaxResults( 1 );
    final java.util.List<<%= query_component_result_type(query) %>> resultList = query.getResultList();
    if ( resultList.size() > 0 )
    {
      return resultList.get( 0 );
    }
{'fraction_non_alphanumeric': 0.18576476527006563, 'fraction_numerical': 0.0013461214874642437, 'mean_word_length': 4.223198594024605, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 83, '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': '6422849', 'n_tokens_mistral': 2188, 'n_tokens_neox': 2071, 'n_words': 335}