Example usage for javax.persistence Parameter getName

List of usage examples for javax.persistence Parameter getName

Introduction

In this page you can find the example usage for javax.persistence Parameter getName.

Prototype

String getName();

Source Link

Document

Return the parameter name, or null if the parameter is not a named parameter or no name has been assigned.

Usage

From source file:org.eclipse.emf.teneo.hibernate.HbEntityDataStore.java

@SuppressWarnings({ "rawtypes", "unchecked" })
protected QueryImpl<?> repairParameterJavaType(QueryImpl<?> query) {
    try {/*from w  w w. j a v  a  2s.c  o  m*/
        final Set<Parameter<?>> repairedParameters = new HashSet<Parameter<?>>();
        final Object parametersObject = getQueryParametersField().get(query);
        final AbstractQueryImpl queryImpl = AbstractQueryImpl.class.cast(query.getHibernateQuery());
        for (Parameter<?> parameter : (Collection<Parameter>) parametersObject) {
            if (Map.class == parameter.getParameterType()) {
                final Type type;
                if (parameter.getName() != null) {
                    // repair these ones
                    final NamedParameterDescriptor descriptor = queryImpl.getParameterMetadata()
                            .getNamedParameterDescriptor(parameter.getName());
                    type = descriptor.getExpectedType();
                } else {
                    type = queryImpl.getParameterMetadata()
                            .getOrdinalParameterExpectedType(parameter.getPosition());
                }
                if (type instanceof EntityType) {
                    final Parameter<?> param = new ParameterImpl(parameter.getName(), parameter.getPosition(),
                            Object.class);
                    repairedParameters.add(param);
                    // final EntityType entityType = (EntityType) type;
                    // final String entityName = entityType
                    // .getAssociatedEntityName();
                    // final EClass eClass = HbEntityDataStore.this
                    // .getEntityNameStrategy().toEClass(entityName);

                } else {
                    repairedParameters.add(parameter);
                }
            } else {
                repairedParameters.add(parameter);
            }
        }
        getQueryParametersField().set(query, repairedParameters);
        return query;
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.springframework.integration.jpa.core.DefaultJpaOperations.java

/**
 * Given a JPQL query, this method gets all parameters defined in this query and
 * use the {@link ParameterSource} to find their values and set them.
 *
 *//*from www. j a  v a 2s .co  m*/
private void setParametersIfRequired(String queryString, ParameterSource source, Query query) {
    Set<Parameter<?>> parameters = query.getParameters();

    if (parameters != null && !parameters.isEmpty()) {
        if (source != null) {
            for (Parameter<?> param : parameters) {
                String paramName = param.getName();
                Integer position = param.getPosition();

                final Object paramValue;

                if (position != null) {

                    if (source instanceof PositionSupportingParameterSource) {
                        paramValue = ((PositionSupportingParameterSource) source).getValueByPosition(position);
                        query.setParameter(position, paramValue);
                    } else {
                        throw new JpaOperationFailedException("Positional Parameters are only support "
                                + "for PositionSupportingParameterSources.", queryString);
                    }

                } else {

                    if (StringUtils.hasText(paramName)) {
                        paramValue = source.getValue(paramName);
                        query.setParameter(paramName, paramValue);
                    } else {
                        throw new JpaOperationFailedException(
                                "This parameter does not contain a parameter name. "
                                        + "Additionally it is not a positional parameter, neither.",
                                queryString);
                    }
                }

            }
        } else {
            throw new IllegalArgumentException("Query has parameters but no parameter source provided");
        }

    }
}

From source file:org.squashtest.tm.domain.testcase.TestCase.java

/**
 * If the given parameter doesn't already exists in this.parameters, and, if the given parameter's name is not found
 * in this.parmeters : will add the given parameter to this.parameters.
 *
 * @throws NameAlreadyInUseException/*from   ww w.ja  v a 2s . co  m*/
 * @param parameter
 */
protected void addParameter(@NotNull Parameter parameter) {
    Parameter homonyme = findParameterByName(parameter.getName());
    if (homonyme != null && !homonyme.equals(parameter)) {
        throw new NameAlreadyInUseException(Parameter.class.getSimpleName(), parameter.getName());
    }
    this.parameters.add(parameter);

}

From source file:org.squashtest.tm.domain.testcase.TestCase.java

/**
 * Will go through this.parameters and return the Parameter matching the given name
 *
 * @param name//from ww  w . j  av  a  2 s .  c  om
 *            : the name of the parameter to return
 * @return the parameter matching the given name or <code>null</code>
 */
public Parameter findParameterByName(String name) {
    for (Parameter parameter : this.parameters) {
        if (parameter.getName().equals(name)) {
            return parameter;
        }
    }
    return null;
}