Search in sources :

Example 1 with JaxbHbmQueryParamType

use of org.hibernate.boot.jaxb.hbm.spi.JaxbHbmQueryParamType in project hibernate-orm by hibernate.

the class NamedQueryBinder method processNamedQueryContentItem.

private static boolean processNamedQueryContentItem(Object content, NamedSQLQueryDefinitionBuilder builder, ImplicitResultSetMappingDefinition.Builder implicitResultSetMappingBuilder, JaxbHbmNamedNativeQueryType namedQueryBinding, HbmLocalMetadataBuildingContext context) {
    if (String.class.isInstance(content)) {
        // Especially when the query string is wrapped in CDATA we will get
        // "extra" Strings here containing just spaces and/or newlines.  This
        // bit tries to account for them.
        final String contentString = StringHelper.nullIfEmpty(((String) content).trim());
        if (contentString != null) {
            builder.setQuery((String) content);
            return true;
        } else {
            return false;
        }
    } else if (JAXBElement.class.isInstance(content)) {
        return processNamedQueryContentItem(((JAXBElement) content).getValue(), builder, implicitResultSetMappingBuilder, namedQueryBinding, context);
    }
    if (JaxbHbmQueryParamType.class.isInstance(content)) {
        final JaxbHbmQueryParamType paramTypeBinding = (JaxbHbmQueryParamType) content;
        builder.addParameterType(paramTypeBinding.getName(), paramTypeBinding.getType());
    } else if (JaxbHbmSynchronizeType.class.isInstance(content)) {
        final JaxbHbmSynchronizeType synchronizedSpace = (JaxbHbmSynchronizeType) content;
        builder.addSynchronizedQuerySpace(synchronizedSpace.getTable());
    } else if (JaxbHbmNativeQueryScalarReturnType.class.isInstance(content)) {
        implicitResultSetMappingBuilder.addReturn((JaxbHbmNativeQueryScalarReturnType) content);
    } else if (JaxbHbmNativeQueryReturnType.class.isInstance(content)) {
        implicitResultSetMappingBuilder.addReturn((JaxbHbmNativeQueryReturnType) content);
    } else if (JaxbHbmNativeQueryJoinReturnType.class.isInstance(content)) {
        implicitResultSetMappingBuilder.addReturn((JaxbHbmNativeQueryJoinReturnType) content);
    } else if (JaxbHbmNativeQueryCollectionLoadReturnType.class.isInstance(content)) {
        implicitResultSetMappingBuilder.addReturn((JaxbHbmNativeQueryCollectionLoadReturnType) content);
    } else {
        throw new org.hibernate.boot.MappingException(String.format(Locale.ENGLISH, "Encountered unexpected content type [%s] for named native query [%s] : [%s]", content.getClass().getName(), namedQueryBinding.getName(), content.toString()), context.getOrigin());
    }
    return false;
}
Also used : JaxbHbmQueryParamType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmQueryParamType) JaxbHbmNativeQueryCollectionLoadReturnType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNativeQueryCollectionLoadReturnType) JAXBElement(javax.xml.bind.JAXBElement) JaxbHbmSynchronizeType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSynchronizeType) JaxbHbmNativeQueryReturnType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNativeQueryReturnType)

Example 2 with JaxbHbmQueryParamType

use of org.hibernate.boot.jaxb.hbm.spi.JaxbHbmQueryParamType in project hibernate-orm by hibernate.

the class NamedQueryBinder method processNamedQuery.

public static void processNamedQuery(HbmLocalMetadataBuildingContext context, JaxbHbmNamedQueryType namedQueryBinding, String prefix) {
    String query = null;
    java.util.Map<String, String> parameterTypeMap = null;
    for (Object content : namedQueryBinding.getContent()) {
        if (String.class.isInstance(content)) {
            String trimmed = ((String) content).trim();
            if (!"".equals(trimmed)) {
                query = trimmed;
            }
        } else {
            final JaxbHbmQueryParamType paramTypeBinding = (JaxbHbmQueryParamType) ((JAXBElement) content).getValue();
            if (parameterTypeMap == null) {
                parameterTypeMap = new HashMap<String, String>();
            }
            parameterTypeMap.put(paramTypeBinding.getName(), paramTypeBinding.getType());
        }
    }
    if (query == null) {
        throw new org.hibernate.boot.MappingException(String.format("Named query [%s] did not specify query string", namedQueryBinding.getName()), context.getOrigin());
    }
    context.getMetadataCollector().addNamedQuery(new NamedQueryDefinitionBuilder().setName(prefix + namedQueryBinding.getName()).setQuery(query).setComment(namedQueryBinding.getComment()).setCacheable(namedQueryBinding.isCacheable()).setCacheMode(namedQueryBinding.getCacheMode()).setCacheRegion(namedQueryBinding.getCacheRegion()).setTimeout(namedQueryBinding.getTimeout()).setReadOnly(namedQueryBinding.isReadOnly()).setFlushMode(namedQueryBinding.getFlushMode()).setFetchSize(namedQueryBinding.getFetchSize()).setParameterTypes(parameterTypeMap).createNamedQueryDefinition());
}
Also used : JaxbHbmQueryParamType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmQueryParamType) NamedQueryDefinitionBuilder(org.hibernate.engine.spi.NamedQueryDefinitionBuilder) MappingException(org.hibernate.MappingException)

Aggregations

JaxbHbmQueryParamType (org.hibernate.boot.jaxb.hbm.spi.JaxbHbmQueryParamType)2 JAXBElement (javax.xml.bind.JAXBElement)1 MappingException (org.hibernate.MappingException)1 JaxbHbmNativeQueryCollectionLoadReturnType (org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNativeQueryCollectionLoadReturnType)1 JaxbHbmNativeQueryReturnType (org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNativeQueryReturnType)1 JaxbHbmSynchronizeType (org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSynchronizeType)1 NamedQueryDefinitionBuilder (org.hibernate.engine.spi.NamedQueryDefinitionBuilder)1