Search in sources :

Example 1 with NamedStoredProcedureQuery

use of jakarta.persistence.NamedStoredProcedureQuery in project hibernate-orm by hibernate.

the class JPAXMLOverriddenAnnotationReader method addNamedStoredProcedureQueryIfNeeded.

private void addNamedStoredProcedureQueryIfNeeded(NamedStoredProcedureQuery annotation, List<NamedStoredProcedureQuery> queries) {
    if (annotation != null) {
        String queryName = annotation.name();
        boolean present = false;
        for (NamedStoredProcedureQuery current : queries) {
            if (current.name().equals(queryName)) {
                present = true;
                break;
            }
        }
        if (!present) {
            queries.add(annotation);
        }
    }
}
Also used : JaxbNamedStoredProcedureQuery(org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQuery) NamedStoredProcedureQuery(jakarta.persistence.NamedStoredProcedureQuery)

Example 2 with NamedStoredProcedureQuery

use of jakarta.persistence.NamedStoredProcedureQuery in project hibernate-orm by hibernate.

the class JPAXMLOverriddenAnnotationReader method getNamedStoredProcedureQueries.

private NamedStoredProcedureQueries getNamedStoredProcedureQueries(ManagedType root, XMLContext.Default defaults) {
    List<NamedStoredProcedureQuery> queries = root instanceof JaxbEntity ? buildNamedStoreProcedureQueries(((JaxbEntity) root).getNamedStoredProcedureQuery(), defaults, classLoaderAccess) : new ArrayList<>();
    if (defaults.canUseJavaAnnotations()) {
        NamedStoredProcedureQuery annotation = getPhysicalAnnotation(NamedStoredProcedureQuery.class);
        addNamedStoredProcedureQueryIfNeeded(annotation, queries);
        NamedStoredProcedureQueries annotations = getPhysicalAnnotation(NamedStoredProcedureQueries.class);
        if (annotations != null) {
            for (NamedStoredProcedureQuery current : annotations.value()) {
                addNamedStoredProcedureQueryIfNeeded(current, queries);
            }
        }
    }
    if (queries.size() > 0) {
        AnnotationDescriptor ad = new AnnotationDescriptor(NamedStoredProcedureQueries.class);
        ad.setValue("value", queries.toArray(new NamedStoredProcedureQuery[queries.size()]));
        return AnnotationFactory.create(ad);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) NamedStoredProcedureQueries(jakarta.persistence.NamedStoredProcedureQueries) JaxbNamedStoredProcedureQuery(org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQuery) NamedStoredProcedureQuery(jakarta.persistence.NamedStoredProcedureQuery) JaxbEntity(org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)

Example 3 with NamedStoredProcedureQuery

use of jakarta.persistence.NamedStoredProcedureQuery in project hibernate-orm by hibernate.

the class JPAXMLOverriddenAnnotationReader method buildNamedStoreProcedureQueries.

public static List<NamedStoredProcedureQuery> buildNamedStoreProcedureQueries(List<JaxbNamedStoredProcedureQuery> elements, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
    List<NamedStoredProcedureQuery> namedStoredProcedureQueries = new ArrayList<>();
    for (JaxbNamedStoredProcedureQuery element : elements) {
        AnnotationDescriptor ann = new AnnotationDescriptor(NamedStoredProcedureQuery.class);
        copyAttribute(ann, "name", element.getName(), true);
        copyAttribute(ann, "procedure-name", element.getProcedureName(), true);
        List<StoredProcedureParameter> storedProcedureParameters = new ArrayList<>();
        for (JaxbStoredProcedureParameter parameterElement : element.getParameter()) {
            AnnotationDescriptor parameterDescriptor = new AnnotationDescriptor(StoredProcedureParameter.class);
            copyAttribute(parameterDescriptor, "name", parameterElement.getName(), false);
            ParameterMode modeValue = parameterElement.getMode();
            if (modeValue == null) {
                parameterDescriptor.setValue("mode", ParameterMode.IN);
            } else {
                parameterDescriptor.setValue("mode", modeValue);
            }
            String clazzName = parameterElement.getClazz();
            Class<?> clazz;
            try {
                clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(clazzName, defaults));
            } catch (ClassLoadingException e) {
                throw new AnnotationException("Unable to find entity-class: " + clazzName, e);
            }
            parameterDescriptor.setValue("type", clazz);
            storedProcedureParameters.add(AnnotationFactory.create(parameterDescriptor));
        }
        ann.setValue("parameters", storedProcedureParameters.toArray(new StoredProcedureParameter[storedProcedureParameters.size()]));
        List<Class<?>> returnClasses = new ArrayList<>();
        for (String clazzName : element.getResultClass()) {
            Class<?> clazz;
            try {
                clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(clazzName, defaults));
            } catch (ClassLoadingException e) {
                throw new AnnotationException("Unable to find entity-class: " + clazzName, e);
            }
            returnClasses.add(clazz);
        }
        ann.setValue("resultClasses", returnClasses.toArray(new Class[returnClasses.size()]));
        ann.setValue("resultSetMappings", element.getResultSetMapping().toArray(new String[0]));
        buildQueryHints(element.getHint(), ann);
        namedStoredProcedureQueries.add(AnnotationFactory.create(ann));
    }
    return namedStoredProcedureQueries;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) ArrayList(java.util.ArrayList) JaxbStoredProcedureParameter(org.hibernate.boot.jaxb.mapping.spi.JaxbStoredProcedureParameter) JaxbStoredProcedureParameter(org.hibernate.boot.jaxb.mapping.spi.JaxbStoredProcedureParameter) StoredProcedureParameter(jakarta.persistence.StoredProcedureParameter) ParameterMode(jakarta.persistence.ParameterMode) AnnotationException(org.hibernate.AnnotationException) IdClass(jakarta.persistence.IdClass) MapKeyClass(jakarta.persistence.MapKeyClass) JaxbIdClass(org.hibernate.boot.jaxb.mapping.spi.JaxbIdClass) JaxbMapKeyClass(org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyClass) JaxbNamedStoredProcedureQuery(org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQuery) JaxbNamedStoredProcedureQuery(org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQuery) NamedStoredProcedureQuery(jakarta.persistence.NamedStoredProcedureQuery)

Example 4 with NamedStoredProcedureQuery

use of jakarta.persistence.NamedStoredProcedureQuery in project hibernate-orm by hibernate.

the class JPAXMLOverriddenMetadataProvider method getDefaults.

@Override
public Map<Object, Object> getDefaults() {
    if (!xmlMappingEnabled) {
        return Collections.emptyMap();
    } else {
        if (defaults == null) {
            defaults = new HashMap<>();
            XMLContext.Default xmlDefaults = xmlContext.getDefaultWithGlobalCatalogAndSchema();
            defaults.put("schema", xmlDefaults.getSchema());
            defaults.put("catalog", xmlDefaults.getCatalog());
            defaults.put("delimited-identifier", xmlDefaults.getDelimitedIdentifier());
            defaults.put("cascade-persist", xmlDefaults.getCascadePersist());
            List<Class> entityListeners = new ArrayList<Class>();
            for (String className : xmlContext.getDefaultEntityListeners()) {
                try {
                    entityListeners.add(classLoaderAccess.classForName(className));
                } catch (ClassLoadingException e) {
                    throw new IllegalStateException("Default entity listener class not found: " + className);
                }
            }
            defaults.put(EntityListeners.class, entityListeners);
            for (JaxbEntityMappings entityMappings : xmlContext.getAllDocuments()) {
                List<JaxbSequenceGenerator> jaxbSequenceGenerators = entityMappings.getSequenceGenerator();
                List<SequenceGenerator> sequenceGenerators = (List<SequenceGenerator>) defaults.get(SequenceGenerator.class);
                if (sequenceGenerators == null) {
                    sequenceGenerators = new ArrayList<>();
                    defaults.put(SequenceGenerator.class, sequenceGenerators);
                }
                for (JaxbSequenceGenerator element : jaxbSequenceGenerators) {
                    sequenceGenerators.add(JPAXMLOverriddenAnnotationReader.buildSequenceGeneratorAnnotation(element));
                }
                List<JaxbTableGenerator> jaxbTableGenerators = entityMappings.getTableGenerator();
                List<TableGenerator> tableGenerators = (List<TableGenerator>) defaults.get(TableGenerator.class);
                if (tableGenerators == null) {
                    tableGenerators = new ArrayList<>();
                    defaults.put(TableGenerator.class, tableGenerators);
                }
                for (JaxbTableGenerator element : jaxbTableGenerators) {
                    tableGenerators.add(JPAXMLOverriddenAnnotationReader.buildTableGeneratorAnnotation(element, xmlDefaults));
                }
                List<NamedQuery> namedQueries = (List<NamedQuery>) defaults.get(NamedQuery.class);
                if (namedQueries == null) {
                    namedQueries = new ArrayList<>();
                    defaults.put(NamedQuery.class, namedQueries);
                }
                List<NamedQuery> currentNamedQueries = JPAXMLOverriddenAnnotationReader.buildNamedQueries(entityMappings.getNamedQuery(), xmlDefaults, classLoaderAccess);
                namedQueries.addAll(currentNamedQueries);
                List<NamedNativeQuery> namedNativeQueries = (List<NamedNativeQuery>) defaults.get(NamedNativeQuery.class);
                if (namedNativeQueries == null) {
                    namedNativeQueries = new ArrayList<>();
                    defaults.put(NamedNativeQuery.class, namedNativeQueries);
                }
                List<NamedNativeQuery> currentNamedNativeQueries = JPAXMLOverriddenAnnotationReader.buildNamedNativeQueries(entityMappings.getNamedNativeQuery(), xmlDefaults, classLoaderAccess);
                namedNativeQueries.addAll(currentNamedNativeQueries);
                List<SqlResultSetMapping> sqlResultSetMappings = (List<SqlResultSetMapping>) defaults.get(SqlResultSetMapping.class);
                if (sqlResultSetMappings == null) {
                    sqlResultSetMappings = new ArrayList<>();
                    defaults.put(SqlResultSetMapping.class, sqlResultSetMappings);
                }
                List<SqlResultSetMapping> currentSqlResultSetMappings = JPAXMLOverriddenAnnotationReader.buildSqlResultsetMappings(entityMappings.getSqlResultSetMapping(), xmlDefaults, classLoaderAccess);
                sqlResultSetMappings.addAll(currentSqlResultSetMappings);
                List<NamedStoredProcedureQuery> namedStoredProcedureQueries = (List<NamedStoredProcedureQuery>) defaults.get(NamedStoredProcedureQuery.class);
                if (namedStoredProcedureQueries == null) {
                    namedStoredProcedureQueries = new ArrayList<>();
                    defaults.put(NamedStoredProcedureQuery.class, namedStoredProcedureQueries);
                }
                List<NamedStoredProcedureQuery> currentNamedStoredProcedureQueries = JPAXMLOverriddenAnnotationReader.buildNamedStoreProcedureQueries(entityMappings.getNamedStoredProcedureQuery(), xmlDefaults, classLoaderAccess);
                namedStoredProcedureQueries.addAll(currentNamedStoredProcedureQueries);
            }
        }
        return defaults;
    }
}
Also used : JaxbSequenceGenerator(org.hibernate.boot.jaxb.mapping.spi.JaxbSequenceGenerator) NamedNativeQuery(jakarta.persistence.NamedNativeQuery) ArrayList(java.util.ArrayList) JaxbEntityMappings(org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings) JaxbTableGenerator(org.hibernate.boot.jaxb.mapping.spi.JaxbTableGenerator) ArrayList(java.util.ArrayList) List(java.util.List) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) JaxbSequenceGenerator(org.hibernate.boot.jaxb.mapping.spi.JaxbSequenceGenerator) SequenceGenerator(jakarta.persistence.SequenceGenerator) JaxbTableGenerator(org.hibernate.boot.jaxb.mapping.spi.JaxbTableGenerator) TableGenerator(jakarta.persistence.TableGenerator) NamedQuery(jakarta.persistence.NamedQuery) SqlResultSetMapping(jakarta.persistence.SqlResultSetMapping) NamedStoredProcedureQuery(jakarta.persistence.NamedStoredProcedureQuery)

Aggregations

NamedStoredProcedureQuery (jakarta.persistence.NamedStoredProcedureQuery)4 JaxbNamedStoredProcedureQuery (org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQuery)3 ArrayList (java.util.ArrayList)2 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)2 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)2 IdClass (jakarta.persistence.IdClass)1 MapKeyClass (jakarta.persistence.MapKeyClass)1 NamedNativeQuery (jakarta.persistence.NamedNativeQuery)1 NamedQuery (jakarta.persistence.NamedQuery)1 NamedStoredProcedureQueries (jakarta.persistence.NamedStoredProcedureQueries)1 ParameterMode (jakarta.persistence.ParameterMode)1 SequenceGenerator (jakarta.persistence.SequenceGenerator)1 SqlResultSetMapping (jakarta.persistence.SqlResultSetMapping)1 StoredProcedureParameter (jakarta.persistence.StoredProcedureParameter)1 TableGenerator (jakarta.persistence.TableGenerator)1 List (java.util.List)1 AnnotationException (org.hibernate.AnnotationException)1 JaxbEntity (org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)1 JaxbEntityMappings (org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings)1 JaxbIdClass (org.hibernate.boot.jaxb.mapping.spi.JaxbIdClass)1