mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#778 - ENH: Add support for loading named queries from ebean.xml
This commit is contained in:
@@ -53,6 +53,7 @@ import com.avaje.ebeaninternal.xmlmapping.model.XmAliasMapping;
|
||||
import com.avaje.ebeaninternal.xmlmapping.model.XmColumnMapping;
|
||||
import com.avaje.ebeaninternal.xmlmapping.model.XmEbean;
|
||||
import com.avaje.ebeaninternal.xmlmapping.model.XmEntity;
|
||||
import com.avaje.ebeaninternal.xmlmapping.model.XmNamedQuery;
|
||||
import com.avaje.ebeaninternal.xmlmapping.model.XmRawSql;
|
||||
import com.avaje.ebeanservice.docstore.api.DocStoreBeanAdapter;
|
||||
import com.avaje.ebeanservice.docstore.api.DocStoreFactory;
|
||||
@@ -395,6 +396,10 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
}
|
||||
info.addRawSql(sql.getName(), builder.create());
|
||||
}
|
||||
|
||||
for (XmNamedQuery namedQuery : entityDeploy.getNamedQuery()) {
|
||||
info.addNamedQuery(namedQuery.getName(), namedQuery.getQuery().getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,4 +82,11 @@ public class DeployBeanInfo<T> {
|
||||
public void addRawSql(String name, RawSql rawSql) {
|
||||
descriptor.addRawSql(name, rawSql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the named query.
|
||||
*/
|
||||
public void addNamedQuery(String name, String query) {
|
||||
descriptor.addNamedQuery(name, query);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,4 +77,12 @@ public class ObjectFactory {
|
||||
return new XmEntity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link XmNamedQuery }
|
||||
*
|
||||
*/
|
||||
public XmNamedQuery createNamedQuery() {
|
||||
return new XmNamedQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import javax.xml.bind.annotation.XmlType;
|
||||
* <complexContent>
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||
* <sequence>
|
||||
* <element ref="{http://ebean-orm.github.io/xml/ns/ebean}named-query" maxOccurs="unbounded"/>
|
||||
* <element ref="{http://ebean-orm.github.io/xml/ns/ebean}raw-sql" maxOccurs="unbounded"/>
|
||||
* </sequence>
|
||||
* <attribute name="class" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
|
||||
@@ -33,16 +34,48 @@ import javax.xml.bind.annotation.XmlType;
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"namedQuery",
|
||||
"rawSql"
|
||||
})
|
||||
@XmlRootElement(name = "entity")
|
||||
public class XmEntity {
|
||||
|
||||
@XmlElement(name = "named-query", required = true)
|
||||
protected List<XmNamedQuery> namedQuery;
|
||||
@XmlElement(name = "raw-sql", required = true)
|
||||
protected List<XmRawSql> rawSql;
|
||||
@XmlAttribute(name = "class", required = true)
|
||||
protected String clazz;
|
||||
|
||||
/**
|
||||
* Gets the value of the namedQuery property.
|
||||
*
|
||||
* <p>
|
||||
* 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 <CODE>set</CODE> method for the namedQuery property.
|
||||
*
|
||||
* <p>
|
||||
* For example, to add a new item, do as follows:
|
||||
* <pre>
|
||||
* getNamedQuery().add(newItem);
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Objects of the following type(s) are allowed in the list
|
||||
* {@link XmNamedQuery }
|
||||
*
|
||||
*
|
||||
*/
|
||||
public List<XmNamedQuery> getNamedQuery() {
|
||||
if (namedQuery == null) {
|
||||
namedQuery = new ArrayList<XmNamedQuery>();
|
||||
}
|
||||
return this.namedQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the rawSql property.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
|
||||
package com.avaje.ebeaninternal.xmlmapping.model;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Java class for anonymous complex type.
|
||||
*
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
*
|
||||
* <pre>
|
||||
* <complexType>
|
||||
* <complexContent>
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||
* <sequence>
|
||||
* <element ref="{http://ebean-orm.github.io/xml/ns/ebean}query"/>
|
||||
* </sequence>
|
||||
* <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
|
||||
* </restriction>
|
||||
* </complexContent>
|
||||
* </complexType>
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"query"
|
||||
})
|
||||
@XmlRootElement(name = "named-query")
|
||||
public class XmNamedQuery {
|
||||
|
||||
@XmlElement(required = true)
|
||||
protected XmQuery query;
|
||||
@XmlAttribute(name = "name", required = true)
|
||||
protected String name;
|
||||
|
||||
/**
|
||||
* Gets the value of the query property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link XmQuery }
|
||||
*
|
||||
*/
|
||||
public XmQuery getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the query property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link XmQuery }
|
||||
*
|
||||
*/
|
||||
public void setQuery(XmQuery value) {
|
||||
this.query = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the name property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the name property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public void setName(String value) {
|
||||
this.name = value;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user