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

io.github.jeddict.jpa.spec.NamedQuery Maven / Gradle / Ivy

Go to download

Jeddict is an open source Jakarta EE application development platform that accelerates developers productivity and simplifies development tasks of creating complex entity relationship models.

There is a newer version: 6.6.0
Show newest version
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2014.01.21 at 01:52:19 PM IST
//
package io.github.jeddict.jpa.spec;

import io.github.jeddict.jcode.util.StringHelper;
import io.github.jeddict.jpa.spec.extend.Attribute;
import io.github.jeddict.jpa.spec.extend.QueryMapping;
import io.github.jeddict.source.AnnotatedMember;
import io.github.jeddict.source.AnnotationExplorer;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static java.util.stream.Collectors.toList;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlType;

/**
 *
 *
 * @Target({TYPE}) @Retention(RUNTIME) public @interface NamedQuery { String
 * name(); String query(); LockModeType lockMode() default NONE; QueryHint[]
 * hints() default {}; }
 *
 *
 *
 * 

* Java class for named-query complex type. * *

* The following schema fragment specifies the expected content contained within * this class. * *

 * <complexType name="named-query">
 *   <complexContent>
 *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       <sequence>
 *         <element name="description" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         <element name="query" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         <element name="lock-mode" type="{http://java.sun.com/xml/ns/persistence/orm}lock-mode-type" minOccurs="0"/>
 *         <element name="hint" type="{http://java.sun.com/xml/ns/persistence/orm}query-hint" maxOccurs="unbounded" minOccurs="0"/>
 *       </sequence>
 *       <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
 *     </restriction>
 *   </complexContent>
 * </complexType>
 * 
* * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "named-query", propOrder = { // "description", // "query", "lockMode", "hint" }) public class NamedQuery extends QueryMapping { public static final String FIND_BY = "findBy"; public static final String FIND_ALL = "findAll"; @XmlElement(name = "lock-mode") protected LockModeType lockMode; protected List hint; public static NamedQuery load(AnnotationExplorer annotation) { NamedQuery namedQuery = new NamedQuery(); annotation.getString("name").ifPresent(namedQuery::setName); annotation.getString("query").ifPresent(namedQuery::setQuery); annotation.getEnum("lockMode").map(LockModeType::valueOf).ifPresent(namedQuery::setLockMode); namedQuery.hint = annotation.getAnnotationList("hints") .map(hint -> QueryHint.load(hint)) .collect(toList()); return namedQuery; } public static List load(AnnotatedMember member) { List namedQueries = new ArrayList<>(); Optional namedQueriesOpt = member.getAnnotation(jakarta.persistence.NamedQueries.class); if (namedQueriesOpt.isPresent()) { namedQueries.addAll( namedQueriesOpt.get() .getAnnotationList("value") .map(NamedQuery::load) .collect(toList()) ); } namedQueries.addAll( member.getRepeatableAnnotations(jakarta.persistence.NamedQuery.class) .map(NamedQuery::load) .collect(toList()) ); return namedQueries; } /** * Gets the value of the lockMode property. * * @return possible object is {@link LockModeType } * */ public LockModeType getLockMode() { return lockMode; } /** * Sets the value of the lockMode property. * * @param value allowed object is {@link LockModeType } * */ public void setLockMode(LockModeType value) { this.lockMode = value; } /** * Gets the value of the hint property. * *

* This accessor method returns a reference to the live list, not a * snapshot. Therefore any modification you make to the returned list will * be present inside the JAXB object. This is why there is not a * set method for the hint property. * *

* For example, to add a new item, do as follows: *

     *    getHint().add(newItem);
     * 
* * *

* Objects of the following type(s) are allowed in the list * {@link QueryHint } * * */ public List getHint() { if (hint == null) { hint = new ArrayList<>(); } return this.hint; } public static NamedQuery getTemplate(IdentifiableClass identifiableClass, Attribute attribute){ NamedQuery namedQuery = new NamedQuery(); namedQuery.setName(identifiableClass.getClazz() + '.' +FIND_BY + StringHelper.firstUpper(attribute.getName())); StringBuilder builder = new StringBuilder(); char var = Character.toLowerCase(identifiableClass.getClazz().charAt(0)); builder.append("Select ").append(var).append(" from ") .append(identifiableClass.getClazz()).append(" ").append(var) .append(" where ") .append(var).append(".").append(attribute.getName()).append("=:").append(attribute.getName()); namedQuery.setQuery(builder.toString()); return namedQuery; } public static NamedQuery getTemplate(IdentifiableClass identifiableClass){ NamedQuery namedQuery = new NamedQuery(); namedQuery.setName(identifiableClass.getClazz() + '.' +FIND_ALL); StringBuilder builder = new StringBuilder(); char var = Character.toLowerCase(identifiableClass.getClazz().charAt(0)); builder.append("Select ").append(var).append(" from ") .append(identifiableClass.getClazz()).append(" ").append(var); namedQuery.setQuery(builder.toString()); return namedQuery; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy