#2075 - Refactor external mapping (i.e. named queries from ebean.xml etc) - extract api and separate module

This commit is contained in:
rob bygrave committed 2020-10-12 14:54:25 +13:00
1 parent f57db28f1c
commit 49b1bd54c3
52 files changed
+817 -259

No files matched your search

+8 -2
View File
@@ -47,18 +47,24 @@
</profiles>
<dependencies>
<!-- keep testing in core using ebean-ddlgen -->
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-ddlgen</artifactId>
<version>12.4.1</version>
<scope>provided</scope>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-externalmapping-api</artifactId>
<version>${project.version}</version>
</dependency>
<!--
@@ -1,23 +0,0 @@
package io.ebeaninternal.xmapping.api;
import java.util.ArrayList;
import java.util.List;
public class XmapDto {
protected final String clazz;
protected final List<XmapRawSql> rawSql = new ArrayList<>();
public XmapDto(String clazz) {
this.clazz = clazz;
}
public String getClazz() {
return clazz;
}
public List<XmapRawSql> getRawSql() {
return rawSql;
}
}
@@ -1,19 +0,0 @@
package io.ebeaninternal.xmapping.api;
import java.util.ArrayList;
import java.util.List;
public class XmapEbean {
protected final List<XmapEntity> entity = new ArrayList<>();
protected final List<XmapDto> dto = new ArrayList<>();
public List<XmapEntity> getEntity() {
return entity;
}
public List<XmapDto> getDto() {
return dto;
}
}
@@ -1,27 +0,0 @@
package io.ebeaninternal.xmapping.api;
import java.util.ArrayList;
import java.util.List;
public class XmapEntity {
protected final String clazz;
protected final List<XmapNamedQuery> namedQuery = new ArrayList<>();
protected final List<XmapRawSql> rawSql = new ArrayList<>();
public XmapEntity(String clazz) {
this.clazz = clazz;
}
public String getClazz() {
return clazz;
}
public List<XmapNamedQuery> getNamedQuery() {
return namedQuery;
}
public List<XmapRawSql> getRawSql() {
return rawSql;
}
}
@@ -1,20 +0,0 @@
package io.ebeaninternal.xmapping.api;
public class XmapNamedQuery {
protected final String name;
protected final String query;
public XmapNamedQuery(String name, String query) {
this.name = name;
this.query = query;
}
public String getName() {
return name;
}
public String getQuery() {
return query;
}
}
@@ -1,42 +0,0 @@
package io.ebeaninternal.xmapping.api;
import java.util.LinkedHashMap;
import java.util.Map;
public class XmapRawSql {
protected final String name;
protected final String query;
protected final Map<String, String> columnMapping = new LinkedHashMap<>();
protected final Map<String, String> aliasMapping = new LinkedHashMap<>();
public XmapRawSql(String name, String query) {
this.name = name;
this.query = query;
}
public void addColumnMapping(String column, String property) {
columnMapping.put(column, property);
}
public void addAliasMapping(String alias, String property) {
aliasMapping.put(alias, property);
}
public String getName() {
return name;
}
public String getQuery() {
return query;
}
public Map<String, String> getColumnMapping() {
return columnMapping;
}
public Map<String, String> getAliasMapping() {
return aliasMapping;
}
}
@@ -1,15 +0,0 @@
package io.ebeaninternal.xmapping.api;
import java.util.List;
/**
* Read and return external mapping for named queries etc.
*/
public interface XmapService {
/**
* Read and return external named queries etc.
*/
List<XmapEbean> read(ClassLoader classLoader, List<String> mappingLocations);
}
@@ -1,66 +0,0 @@
package io.ebeaninternal.xmlmapping;
import io.avaje.classpath.scanner.ClassPathScanner;
import io.avaje.classpath.scanner.ClassPathScannerFactory;
import io.avaje.classpath.scanner.Resource;
import io.ebeaninternal.xmapping.api.XmapEbean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
/**
* Reads the Xml deployment information.
*/
class InternalConfigXmlRead {
private static final Logger log = LoggerFactory.getLogger(InternalConfigXmlRead.class);
private final ToXmapEbean to = new ToXmapEbean();
private final ClassLoader classLoader;
private final List<String> mappingLocations;
InternalConfigXmlRead(ClassLoader classLoader, List<String> mappingLocations) {
this.classLoader = classLoader;
this.mappingLocations = mappingLocations;
// if (config.getClassLoadConfig().isJavaxJAXBPresent()) {
// init();
// }
}
List<XmapEbean> read() {
List<XmapEbean> list = new ArrayList<>();
list.addAll(to.toBeans(XmlMappingReader.readByResourceName(classLoader, "ebean.xml")));
list.addAll(to.toBeans(XmlMappingReader.readByResourceList(xmlMappingResources())));
return list;
}
private List<Resource> xmlMappingResources() {
List<ClassPathScanner> scanners = scanners();
List<Resource> resourceList = new ArrayList<>();
long st = System.currentTimeMillis();
if (mappingLocations != null && !mappingLocations.isEmpty()) {
for (ClassPathScanner finder : scanners) {
for (String mappingLocation : mappingLocations) {
resourceList.addAll(finder.scanForResources(mappingLocation, resourceName -> resourceName.endsWith(".xml")));
}
}
}
long searchTime = System.currentTimeMillis() - st;
log.debug("Classpath search mappings[{}] searchTime[{}]", resourceList.size(), searchTime);
return resourceList;
}
/**
* Return the list of ClassPathScanner services using DatabaseConfig service loader.
*/
private List<ClassPathScanner> scanners() {
List<ClassPathScanner> scanners = new ArrayList<>();
for (ClassPathScannerFactory factory : ServiceLoader.load(ClassPathScannerFactory.class, classLoader)) {
scanners.add(factory.createScanner(classLoader));
}
return scanners;
}
}
@@ -1,14 +0,0 @@
package io.ebeaninternal.xmlmapping;
import io.ebeaninternal.xmapping.api.XmapEbean;
import io.ebeaninternal.xmapping.api.XmapService;
import java.util.List;
public class JaxbXmapService implements XmapService {
@Override
public List<XmapEbean> read(ClassLoader classLoader, List<String> mappingLocations) {
return new InternalConfigXmlRead(classLoader, mappingLocations).read();
}
}
@@ -1,85 +0,0 @@
package io.ebeaninternal.xmlmapping;
import io.ebeaninternal.xmapping.api.XmapDto;
import io.ebeaninternal.xmapping.api.XmapEbean;
import io.ebeaninternal.xmapping.api.XmapEntity;
import io.ebeaninternal.xmapping.api.XmapNamedQuery;
import io.ebeaninternal.xmapping.api.XmapRawSql;
import io.ebeaninternal.xmlmapping.model.XmAliasMapping;
import io.ebeaninternal.xmlmapping.model.XmColumnMapping;
import io.ebeaninternal.xmlmapping.model.XmDto;
import io.ebeaninternal.xmlmapping.model.XmEbean;
import io.ebeaninternal.xmlmapping.model.XmEntity;
import io.ebeaninternal.xmlmapping.model.XmNamedQuery;
import io.ebeaninternal.xmlmapping.model.XmRawSql;
import java.util.List;
import static java.util.stream.Collectors.toList;
public class ToXmapEbean {
public List<XmapEbean> toBeans(List<XmEbean> xmBeans) {
return xmBeans.stream()
.map(this::toBean)
.collect(toList());
}
private XmapEbean toBean(XmEbean bean) {
XmapEbean xmap = new XmapEbean();
xmap.getDto().addAll(toDto(bean.getDto()));
xmap.getEntity().addAll(toEntity(bean.getEntity()));
return xmap;
}
private List<XmapEntity> toEntity(List<XmEntity> xmEntity) {
return xmEntity.stream()
.map(this::toEntity)
.collect(toList());
}
private XmapEntity toEntity(XmEntity xmEntity) {
XmapEntity entity = new XmapEntity(xmEntity.getClazz());
for (XmNamedQuery named : xmEntity.getNamedQuery()) {
entity.getNamedQuery().add(toNamed(named));
}
for (XmRawSql xmRawSql : xmEntity.getRawSql()) {
entity.getRawSql().add(toRaw(xmRawSql));
}
return entity;
}
private XmapNamedQuery toNamed(XmNamedQuery named) {
return new XmapNamedQuery(named.getName(), named.getQuery().getValue());
}
private List<XmapDto> toDto(List<XmDto> dto) {
return dto.stream()
.map(this::toDto)
.collect(toList());
}
private XmapDto toDto(XmDto xmapDto) {
XmapDto dto = new XmapDto(xmapDto.getClazz());
dto.getRawSql().addAll(toRaw(xmapDto.getRawSql()));
return dto;
}
private List<XmapRawSql> toRaw(List<XmRawSql> rawSql) {
return rawSql.stream()
.map(this::toRaw)
.collect(toList());
}
private XmapRawSql toRaw(XmRawSql xmRawSql) {
XmapRawSql rawSql = new XmapRawSql(xmRawSql.getName(), xmRawSql.getQuery().getValue());
for (XmColumnMapping xmCol : xmRawSql.getColumnMapping()) {
rawSql.addColumnMapping(xmCol.getColumn(), xmCol.getProperty());
}
for (XmAliasMapping xmAlias : xmRawSql.getAliasMapping()) {
rawSql.addAliasMapping(xmAlias.getAlias(), xmAlias.getProperty());
}
return rawSql;
}
}
@@ -1,71 +0,0 @@
package io.ebeaninternal.xmlmapping;
import io.avaje.classpath.scanner.Resource;
import io.ebeaninternal.util.UrlHelper;
import io.ebeaninternal.xmlmapping.model.XmEbean;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
public class XmlMappingReader {
/**
* Read and return a Migration from an xml document.
*/
public static XmEbean read(InputStream is) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(XmEbean.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
return (XmEbean) unmarshaller.unmarshal(is);
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
/**
* Read the deployment XML for the given resource name.
*/
public static List<XmEbean> readByResourceName(ClassLoader classLoader, String resourceName) {
try {
Enumeration<URL> resources = classLoader.getResources(resourceName);
List<XmEbean> mappings = new ArrayList<>();
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
try (InputStream is = UrlHelper.openNoCache(url)) {
mappings.add(XmlMappingReader.read(is));
}
}
return mappings;
} catch (IOException e) {
throw new RuntimeException("Error reading ebean xml mapping", e);
}
}
/**
* Read the deployment XML for the given resources.
*/
public static List<XmEbean> readByResourceList(List<Resource> resourceList) {
try {
List<XmEbean> mappings = new ArrayList<>();
for (Resource xmlMappingRes : resourceList) {
try (InputStream is = new FileInputStream(xmlMappingRes.getLocationOnDisk())) {
mappings.add(XmlMappingReader.read(is));
}
}
return mappings;
} catch (IOException e) {
throw new RuntimeException("Error reading ebean xml mapping", e);
}
}
}
@@ -1,78 +0,0 @@
package io.ebeaninternal.xmlmapping.model;
import javax.xml.bind.annotation.XmlRegistry;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the io.ebeaninternal.xmlmapping.model package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*/
@XmlRegistry
public class ObjectFactory {
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: io.ebeaninternal.xmlmapping.model
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link XmRawSql }
*/
public XmRawSql createRawSql() {
return new XmRawSql();
}
/**
* Create an instance of {@link XmAliasMapping }
*/
public XmAliasMapping createAliasMapping() {
return new XmAliasMapping();
}
/**
* Create an instance of {@link XmColumnMapping }
*/
public XmColumnMapping createColumnMapping() {
return new XmColumnMapping();
}
/**
* Create an instance of {@link XmQuery }
*/
public XmQuery createQuery() {
return new XmQuery();
}
/**
* Create an instance of {@link XmEbean }
*/
public XmEbean createEbean() {
return new XmEbean();
}
/**
* Create an instance of {@link XmEntity }
*/
public XmEntity createEntity() {
return new XmEntity();
}
/**
* Create an instance of {@link XmNamedQuery }
*/
public XmNamedQuery createNamedQuery() {
return new XmNamedQuery();
}
}
@@ -1,76 +0,0 @@
package io.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.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for anonymous complex type.
* <p>
* <p>The following schema fragment specifies the expected content contained within this class.
* <p>
* <pre>
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;attribute name="alias" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;attribute name="property" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
@XmlRootElement(name = "alias-mapping")
public class XmAliasMapping {
@XmlAttribute(name = "alias", required = true)
protected String alias;
@XmlAttribute(name = "property", required = true)
protected String property;
/**
* Gets the value of the alias property.
*
* @return possible object is
* {@link String }
*/
public String getAlias() {
return alias;
}
/**
* Sets the value of the alias property.
*
* @param value allowed object is
* {@link String }
*/
public void setAlias(String value) {
this.alias = value;
}
/**
* Gets the value of the property property.
*
* @return possible object is
* {@link String }
*/
public String getProperty() {
return property;
}
/**
* Sets the value of the property property.
*
* @param value allowed object is
* {@link String }
*/
public void setProperty(String value) {
this.property = value;
}
}
@@ -1,76 +0,0 @@
package io.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.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for anonymous complex type.
* <p>
* <p>The following schema fragment specifies the expected content contained within this class.
* <p>
* <pre>
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;attribute name="column" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;attribute name="property" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
@XmlRootElement(name = "column-mapping")
public class XmColumnMapping {
@XmlAttribute(name = "column", required = true)
protected String column;
@XmlAttribute(name = "property", required = true)
protected String property;
/**
* Gets the value of the column property.
*
* @return possible object is
* {@link String }
*/
public String getColumn() {
return column;
}
/**
* Sets the value of the column property.
*
* @param value allowed object is
* {@link String }
*/
public void setColumn(String value) {
this.column = value;
}
/**
* Gets the value of the property property.
*
* @return possible object is
* {@link String }
*/
public String getProperty() {
return property;
}
/**
* Sets the value of the property property.
*
* @param value allowed object is
* {@link String }
*/
public void setProperty(String value) {
this.property = value;
}
}
@@ -1,121 +0,0 @@
package io.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;
import java.util.ArrayList;
import java.util.List;
/**
* <p>Java class for anonymous complex type.
* <p>
* <p>The following schema fragment specifies the expected content contained within this class.
* <p>
* <pre>
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element ref="{http://ebean-orm.github.io/xml/ns/ebean}named-query" maxOccurs="unbounded"/>
* &lt;element ref="{http://ebean-orm.github.io/xml/ns/ebean}raw-sql" maxOccurs="unbounded"/>
* &lt;/sequence>
* &lt;attribute name="class" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"namedQuery",
"rawSql"
})
@XmlRootElement(name = "dto")
public class XmDto {
@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>
* <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>
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getNamedQuery().add(newItem);
* </pre>
* <p>
* <p>
* <p>
* Objects of the following type(s) are allowed in the list
* {@link XmNamedQuery }
*/
public List<XmNamedQuery> getNamedQuery() {
if (namedQuery == null) {
namedQuery = new ArrayList<>();
}
return this.namedQuery;
}
/**
* Gets the value of the rawSql property.
* <p>
* <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 rawSql property.
* <p>
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getRawSql().add(newItem);
* </pre>
* <p>
* <p>
* <p>
* Objects of the following type(s) are allowed in the list
* {@link XmRawSql }
*/
public List<XmRawSql> getRawSql() {
if (rawSql == null) {
rawSql = new ArrayList<>();
}
return this.rawSql;
}
/**
* Gets the value of the clazz property.
*
* @return possible object is
* {@link String }
*/
public String getClazz() {
return clazz;
}
/**
* Sets the value of the clazz property.
*
* @param value allowed object is
* {@link String }
*/
public void setClazz(String value) {
this.clazz = value;
}
}
@@ -1,80 +0,0 @@
package io.ebeaninternal.xmlmapping.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import java.util.ArrayList;
import java.util.List;
/**
* <p>Java class for anonymous complex type.
* <p>
* <p>The following schema fragment specifies the expected content contained within this class.
* <p>
* <pre>
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element ref="{http://ebean-orm.github.io/xml/ns/ebean}entity" maxOccurs="unbounded"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"entity",
"dto"
})
@XmlRootElement(name = "ebean")
public class XmEbean {
@XmlElement(required = false)
protected List<XmEntity> entity;
@XmlElement(required = false)
protected List<XmDto> dto;
/**
* Gets the value of the entity property.
* <p>
* <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 entity property.
* <p>
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getEntity().add(newItem);
* </pre>
* <p>
* <p>
* <p>
* Objects of the following type(s) are allowed in the list
* {@link XmEntity }
*/
public List<XmEntity> getEntity() {
if (entity == null) {
entity = new ArrayList<>();
}
return this.entity;
}
/**
* Returns the List of XmDto beans.
*/
public List<XmDto> getDto() {
if (dto == null) {
dto = new ArrayList<>();
}
return this.dto;
}
}
@@ -1,121 +0,0 @@
package io.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;
import java.util.ArrayList;
import java.util.List;
/**
* <p>Java class for anonymous complex type.
* <p>
* <p>The following schema fragment specifies the expected content contained within this class.
* <p>
* <pre>
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element ref="{http://ebean-orm.github.io/xml/ns/ebean}named-query" maxOccurs="unbounded"/>
* &lt;element ref="{http://ebean-orm.github.io/xml/ns/ebean}raw-sql" maxOccurs="unbounded"/>
* &lt;/sequence>
* &lt;attribute name="class" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*/
@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>
* <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>
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getNamedQuery().add(newItem);
* </pre>
* <p>
* <p>
* <p>
* Objects of the following type(s) are allowed in the list
* {@link XmNamedQuery }
*/
public List<XmNamedQuery> getNamedQuery() {
if (namedQuery == null) {
namedQuery = new ArrayList<>();
}
return this.namedQuery;
}
/**
* Gets the value of the rawSql property.
* <p>
* <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 rawSql property.
* <p>
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getRawSql().add(newItem);
* </pre>
* <p>
* <p>
* <p>
* Objects of the following type(s) are allowed in the list
* {@link XmRawSql }
*/
public List<XmRawSql> getRawSql() {
if (rawSql == null) {
rawSql = new ArrayList<>();
}
return this.rawSql;
}
/**
* Gets the value of the clazz property.
*
* @return possible object is
* {@link String }
*/
public String getClazz() {
return clazz;
}
/**
* Sets the value of the clazz property.
*
* @param value allowed object is
* {@link String }
*/
public void setClazz(String value) {
this.clazz = value;
}
}
@@ -1,81 +0,0 @@
package io.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>
* <p>The following schema fragment specifies the expected content contained within this class.
* <p>
* <pre>
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element ref="{http://ebean-orm.github.io/xml/ns/ebean}query"/>
* &lt;/sequence>
* &lt;attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/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;
}
}
@@ -1,54 +0,0 @@
package io.ebeaninternal.xmlmapping.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
/**
* <p>Java class for anonymous complex type.
* <p>
* <p>The following schema fragment specifies the expected content contained within this class.
* <p>
* <pre>
* &lt;complexType>
* &lt;simpleContent>
* &lt;extension base="&lt;http://www.w3.org/2001/XMLSchema>string">
* &lt;/extension>
* &lt;/simpleContent>
* &lt;/complexType>
* </pre>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"value"
})
@XmlRootElement(name = "query")
public class XmQuery {
@XmlValue
protected String value;
/**
* Gets the value of the value property.
*
* @return possible object is
* {@link String }
*/
public String getValue() {
return value;
}
/**
* Sets the value of the value property.
*
* @param value allowed object is
* {@link String }
*/
public void setValue(String value) {
this.value = value;
}
}
@@ -1,145 +0,0 @@
package io.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;
import java.util.ArrayList;
import java.util.List;
/**
* <p>Java class for anonymous complex type.
* <p>
* <p>The following schema fragment specifies the expected content contained within this class.
* <p>
* <pre>
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element ref="{http://ebean-orm.github.io/xml/ns/ebean}alias-mapping" maxOccurs="unbounded" minOccurs="0"/>
* &lt;element ref="{http://ebean-orm.github.io/xml/ns/ebean}column-mapping" maxOccurs="unbounded" minOccurs="0"/>
* &lt;element ref="{http://ebean-orm.github.io/xml/ns/ebean}query"/>
* &lt;/sequence>
* &lt;attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"aliasMapping",
"columnMapping",
"query"
})
@XmlRootElement(name = "raw-sql")
public class XmRawSql {
@XmlElement(name = "alias-mapping")
protected List<XmAliasMapping> aliasMapping;
@XmlElement(name = "column-mapping")
protected List<XmColumnMapping> columnMapping;
@XmlElement(required = true)
protected XmQuery query;
@XmlAttribute(name = "name", required = true)
protected String name;
/**
* Gets the value of the aliasMapping property.
* <p>
* <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 aliasMapping property.
* <p>
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getAliasMapping().add(newItem);
* </pre>
* <p>
* <p>
* <p>
* Objects of the following type(s) are allowed in the list
* {@link XmAliasMapping }
*/
public List<XmAliasMapping> getAliasMapping() {
if (aliasMapping == null) {
aliasMapping = new ArrayList<>();
}
return this.aliasMapping;
}
/**
* Gets the value of the columnMapping property.
* <p>
* <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 columnMapping property.
* <p>
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getColumnMapping().add(newItem);
* </pre>
* <p>
* <p>
* <p>
* Objects of the following type(s) are allowed in the list
* {@link XmColumnMapping }
*/
public List<XmColumnMapping> getColumnMapping() {
if (columnMapping == null) {
columnMapping = new ArrayList<>();
}
return this.columnMapping;
}
/**
* 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;
}
}
@@ -1,2 +0,0 @@
@javax.xml.bind.annotation.XmlSchema(namespace = "http://ebean-orm.github.io/xml/ns/ebean", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package io.ebeaninternal.xmlmapping.model;
@@ -1 +0,0 @@
io.ebeaninternal.xmlmapping.JaxbXmapService
@@ -1,80 +0,0 @@
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://ebean-orm.github.io/xml/ns/ebean"
targetNamespace="http://ebean-orm.github.io/xml/ns/ebean" elementFormDefault="qualified">
<!-- Root level type : extra-ddl -->
<xsd:element name="ebean">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="entity" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="dto" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="entity">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="named-query" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="raw-sql" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="class" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="dto">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="named-query" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="raw-sql" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="class" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="named-query">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="query" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="raw-sql">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="alias-mapping" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="column-mapping" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="query" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="alias-mapping">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" use="required"/>
<xsd:attribute name="property" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="column-mapping">
<xsd:complexType>
<xsd:attribute name="column" type="xsd:string" use="required"/>
<xsd:attribute name="property" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="query">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<!--<xsd:attribute name="class" type="xsd:string" use="required"/>-->
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>
@@ -13,16 +13,16 @@ import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
public class NamedDtoQueryTest extends BaseTestCase {
public class DtoQuery2Test extends BaseTestCase {
private static final Logger log = LoggerFactory.getLogger(NamedDtoQueryTest.class);
private static final Logger log = LoggerFactory.getLogger(DtoQuery2Test.class);
@Test
public void dto_findList_constructorMatch() {
ResetBasicData.reset();
DtoQuery<DCust> dtoQuery = server().createNamedDtoQuery(DCust.class, "findList");
DtoQuery<DCust> dtoQuery = server().findDto(DCust.class, "select id, name from o_customer");
List<DCust> list = dtoQuery.findList();
@@ -36,7 +36,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
ResetBasicData.reset();
LoggedSqlCollector.start();
server().createNamedDtoQuery(DCust.class, "findGtId")
server().findDto(DCust.class, "select id, name from o_customer where id > :id")
.setParameter("id", 0)
.findEach(it -> log.info("got " + it.getId() + " " + it.getName()));
@@ -50,7 +50,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
ResetBasicData.reset();
LoggedSqlCollector.start();
server().createNamedDtoQuery(DCust.class, "findGtIdDesc")
server().findDto(DCust.class, "select id, name from o_customer where id > :id order by id desc")
.setParameter("id", 0)
.findEachWhile(customer -> {
log.info("got " + customer.getId() + " " + customer.getName());
@@ -66,13 +66,13 @@ public class NamedDtoQueryTest extends BaseTestCase {
ResetBasicData.reset();
Optional<DCust> rob = server().createNamedDtoQuery(DCust.class, "findByName")
Optional<DCust> rob = server().findDto(DCust.class, "select id, name from o_customer where name = :name")
.setParameter("name", "Fiona")
.findOneOrEmpty();
assertThat(rob.isPresent()).isTrue();
Optional<DCust> oneOrEmpty = server().createNamedDtoQuery(DCust.class, "findByName")
Optional<DCust> oneOrEmpty = server().findDto(DCust.class, "select id, name from o_customer where name = :name")
.setParameter("name", "DoesNotExistMyFriend")
.findOneOrEmpty();
@@ -84,13 +84,13 @@ public class NamedDtoQueryTest extends BaseTestCase {
ResetBasicData.reset();
DCust fiona = server().createNamedDtoQuery(DCust.class, "findByName")
DCust fiona = server().findDto(DCust.class, "select id, name from o_customer where name = :name")
.setParameter("name", "Fiona")
.findOne();
assertThat(fiona.getName()).isEqualTo("Fiona");
DCust empty = server().createNamedDtoQuery(DCust.class, "findByName")
DCust empty = server().findDto(DCust.class, "select id, name from o_customer where name = :name")
.setParameter("name", "DoesNotExistMyFriend")
.findOne();
@@ -109,7 +109,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
for (String name : names) {
List<DCust> custs = server().createNamedDtoQuery(DCust.class, "findByName_c3")
List<DCust> custs = server().findDto(DCust.class, "select c3.id, c3.name from o_customer c3 where c3.name = :name")
.setLabel("basic")
.setParameter("name", name)
.findList();
@@ -130,7 +130,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
assertThat(queryMetric.getName()).isEqualTo("dto.DCust_basic");
server().createNamedDtoQuery(DCust.class, "findByName_c4")
server().findDto(DCust.class, "select c4.id, c4.name from o_customer c4 where lower(c4.name) = :name")
.setLabel("basic2")
.setParameter("name", "rob")
.findList();
@@ -149,7 +149,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
ResetBasicData.reset();
List<DCust3> list = server().createNamedDtoQuery(DCust3.class, "findByName_relaxedMode")
List<DCust2> list = server().findDto(DCust2.class, "select id, '42' as something_we_cannot_map, name from o_customer")
.setRelaxedMode()
.findList();
@@ -162,7 +162,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
ResetBasicData.reset();
List<DCust2> list = server().createNamedDtoQuery(DCust2.class, "findByName_relaxedMode")
List<DCust2> list = server().findDto(DCust2.class, "select id, '42' as something_we_cannot_map, name from o_customer")
.setRelaxedMode()
.findList();
@@ -175,7 +175,13 @@ public class NamedDtoQueryTest extends BaseTestCase {
ResetBasicData.reset();
List<DCust> dtos = server().createNamedDtoQuery(DCust.class, "findListByName")
String sql = "select c.id, c.name, count(o.id) as totalOrders\n" +
" from o_customer c\n" +
" join o_order o on o.kcustomer_id = c.id\n" +
" where c.name like :name\n" +
" group by c.id, c.name";
List<DCust> dtos = server().findDto(DCust.class, sql)
.setParameter("name", "Rob")
.findList();
@@ -188,7 +194,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
ResetBasicData.reset();
DtoQuery<DCust2> dtoQuery = server().createNamedDtoQuery(DCust2.class, "findList");
DtoQuery<DCust2> dtoQuery = server().findDto(DCust2.class, "select id, name from o_customer");
List<DCust2> list = dtoQuery.findList();
@@ -200,7 +206,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
ResetBasicData.reset();
List<DCust3> robs = server().createNamedDtoQuery(DCust3.class, "findByNameLike")
List<DCust3> robs = server().findDto(DCust3.class, "select id, name, 42 as totalOrders from o_customer where name like ?")
.setParameter("Rob")
.setMaxRows(10)
.findList();
@@ -215,11 +221,10 @@ public class NamedDtoQueryTest extends BaseTestCase {
ResetBasicData.reset();
List<DCust3> robs = server().createNamedDtoQuery(DCust3.class, "findByName")
List<DCust3> robs = server().findDto(DCust3.class, "select id, name from o_customer where name = :name")
.setParameter("name", "Rob")
.findList();
log.info(robs.toString());
assertThat(robs).isNotEmpty();
}
@@ -6,11 +6,10 @@ import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;
import javax.persistence.PersistenceException;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
public class EbeanServer_eqlTest extends BaseTestCase {
@@ -90,7 +89,7 @@ public class EbeanServer_eqlTest extends BaseTestCase {
// check also select count(*)
LoggedSqlCollector.start();
query.findCount();
List<String>sql = LoggedSqlCollector.stop();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).startsWith("select count(*) from o_customer t0;");
}
@@ -116,7 +115,7 @@ public class EbeanServer_eqlTest extends BaseTestCase {
// check also select count(*)
LoggedSqlCollector.start();
query.findCount();
List<String>sql = LoggedSqlCollector.stop();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).startsWith("select count(*) from o_customer t0;");
}
@@ -233,33 +232,4 @@ public class EbeanServer_eqlTest extends BaseTestCase {
assertSql(query).contains("from o_customer t0 left join contact t1 on t1.customer_id = t0.id ");
}
@Test
public void namedQuery_fromXml() {
ResetBasicData.reset();
Query<Customer> query = server()
.createNamedQuery(Customer.class, "withContactsById")
.setParameter("id", 1);
query.setUseCache(false);
query.findOne();
assertSql(query).contains("from o_customer t0 left join contact t1 on t1.customer_id = t0.id ");
}
@Test
public void namedQuery_fromCustomXmlLocations() {
ResetBasicData.reset();
Query<Customer> query = server()
.createNamedQuery(Customer.class, "withContactsById2")
.setParameter("id", 1);
query.setUseCache(false);
query.findOne();
assertSql(query).contains("from o_customer t0 left join contact t1 on t1.customer_id = t0.id ");
}
}
@@ -1,21 +0,0 @@
package io.ebeaninternal.xmlmapping.model;
import io.ebeaninternal.xmlmapping.XmlMappingReader;
import org.junit.Test;
import java.io.InputStream;
import static org.junit.Assert.assertNotNull;
public class XmlMappingReaderTest {
@Test
public void read() throws Exception {
InputStream is = XmlMappingReaderTest.class.getResourceAsStream("/test-ebean.xml");
XmEbean testMapping = XmlMappingReader.read(is);
assertNotNull(testMapping);
}
}
@@ -93,61 +93,4 @@ public class TestOrderTotalAmountReportBean extends BaseTestCase {
assertSql(query).contains("count(*) as totalItems, sum(order_qty*unit_price) as totalAmount");
}
@Test
public void testDefaultNamedRawSql() {
Query<OrderAggregate> query = Ebean.find(OrderAggregate.class);
List<OrderAggregate> list = query.findList();
assertSql(query).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount");
assertNotNull(list);
}
@Test
public void testNamedRawSql() {
ResetBasicData.reset();
Query<OrderAggregate> query = Ebean.getDefaultServer().createNamedQuery(OrderAggregate.class, "withMax");
List<OrderAggregate> list = query.findList();
assertSql(query).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount, max(order_qty*unit_price) as maxAmount from o_order_detail");
assertNotNull(list);
}
@Test
public void testNamedRawSql_with_extraPredicates() {
ResetBasicData.reset();
Query<OrderAggregate> query = Ebean.getDefaultServer().createNamedQuery(OrderAggregate.class, "withMax");
List<OrderAggregate> list = query
.where().gt("order.id", 1)
.having().gt("totalItems", 1)
.order().desc("totalAmount")
.findList();
assertSql(query).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount, max(order_qty*unit_price) as maxAmount from o_order_detail");
assertSql(query).contains("from o_order_detail where order_id > ? group by order_id having count(*) > ? order by sum(order_qty*unit_price) desc");
assertNotNull(list);
}
@Test
public void testNamedRawSql_with_param() {
ResetBasicData.reset();
Query<OrderAggregate> query = Ebean.getDefaultServer().createNamedQuery(OrderAggregate.class, "withParam");
List<OrderAggregate> list = query
.setParameter("minId", 2)
.where().isNotNull("order.id")
.having().lt("totalAmount", 100)
.order().desc("totalAmount")
.setMaxRows(10)
.findList();
assertSql(query).contains("count(*) as totalItems, sum(order_qty*unit_price) as totalAmount, max(order_qty*unit_price) as maxAmount from o_order_detail");
assertSql(query).contains("from o_order_detail where id > ? and order_id is not null group by order_id having sum(order_qty*unit_price) < ? order by sum(order_qty*unit_price) desc");
assertNotNull(list);
}
}
@@ -24,71 +24,6 @@ import static org.assertj.core.api.Assertions.assertThat;
public class TestRawSqlOrmQuery extends BaseTestCase {
@IgnorePlatform(Platform.ORACLE)
@Test
public void testNamed() {
ResetBasicData.reset();
Query<Order> query = Ebean.createNamedQuery(Order.class, "myRawTest");
query.setParameter("orderStatus", Order.Status.NEW);
query.setMaxRows(10);
List<Order> list = query.findList();
for (Order order : list) {
order.getCretime();
}
String sql = query.getGeneratedSql();
if (isSqlServer()) {
assertThat(sql).contains("select top 10 o.id,");
} else {
assertThat(sql).contains("select o.id,");
assertThat(sql).contains("limit 10");
}
assertThat(sql).contains("o.id, o.status, o.ship_date, c.id, c.name, a.id, a.line_1, a.line_2, a.city from o_order o");
assertThat(sql).contains("join o_customer c on o.kcustomer_id = c.id ");
assertThat(sql).contains("where o.status = ? order by c.name, c.id");
}
@IgnorePlatform(Platform.ORACLE)
@Test
public void testNamed_fromCustomXmlLocations() {
ResetBasicData.reset();
Query<Order> query = Ebean.createNamedQuery(Order.class, "myRawTest2");
query.setParameter("orderStatus", Order.Status.NEW);
query.setMaxRows(10);
List<Order> list = query.findList();
for (Order order : list) {
order.getCretime();
}
String sql = query.getGeneratedSql();
if (isSqlServer()) {
assertThat(sql).contains("select top 10 o.id,");
} else {
assertThat(sql).contains("select o.id,");
assertThat(sql).contains("limit 10");
}
assertThat(sql).contains("o.id, o.status, o.ship_date, c.id, c.name, a.id, a.line_1, a.line_2, a.city from o_order o");
assertThat(sql).contains("join o_customer c on o.kcustomer_id = c.id ");
assertThat(sql).contains("where o.status = ? order by c.name, c.id");
}
@IgnorePlatform(Platform.ORACLE)
@Test
public void testNamed_fromCustomXmlLocations_withComments() {
ResetBasicData.reset();
Query<Order> query = Ebean.createNamedQuery(Order.class, "myRawTest3");
query.setMaxRows(10);
List<Order> list = query.findList();
assertThat(list).isNotEmpty();
}
@Test
public void test() {
@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ebean xmlns="http://ebean-orm.github.io/xml/ns/ebean">
<entity class="org.tests.model.basic.Customer">
<named-query name="withContactsById2">
<query>
select (name, version)
fetch contacts (firstName, lastName, email)
where id = :id
</query>
</named-query>
</entity>
</ebean>
@@ -1,77 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ebean xmlns="http://ebean-orm.github.io/xml/ns/ebean">
<dto class="io.ebean.NamedDtoQueryTest$DCust">
<raw-sql name="findList">
<query>
select id, name from o_customer
</query>
</raw-sql>
<raw-sql name="findGtId">
<query>
select id, name from o_customer where id > :id
</query>
</raw-sql>
<raw-sql name="findGtIdDesc">
<query>
select id, name from o_customer where id > :id order by id desc
</query>
</raw-sql>
<raw-sql name="findByName">
<query>
select id, name from o_customer where name = :name
</query>
</raw-sql>
<raw-sql name="findByName_c3">
<query>
select c3.id, c3.name from o_customer c3 where c3.name = :name
</query>
</raw-sql>
<raw-sql name="findByName_c4">
<query>
select c4.id, c4.name from o_customer c4 where lower(c4.name) = :name
</query>
</raw-sql>
<raw-sql name="findListByName">
<query>
select c.id, c.name, count(o.id) as totalOrders
from o_customer c
join o_order o on o.kcustomer_id = c.id
where c.name like :name
group by c.id, c.name
</query>
</raw-sql>
</dto>
<dto class="io.ebean.NamedDtoQueryTest$DCust2">
<raw-sql name="findByName_relaxedMode">
<query>
select id, '42' as something_we_cannot_map, name from o_customer
</query>
</raw-sql>
<raw-sql name="findList">
<query>
select id, name from o_customer
</query>
</raw-sql>
</dto>
<dto class="io.ebean.NamedDtoQueryTest$DCust3">
<raw-sql name="findByName_relaxedMode">
<query>
select id, name, 42 as total, '42' as something_we_cannot_map from o_customer
</query>
</raw-sql>
<raw-sql name="findByNameLike">
<query>
select id, name, 42 as totalOrders from o_customer where name like ?
</query>
</raw-sql>
<raw-sql name="findByName">
<query>
select id, name from o_customer where name = :name
</query>
</raw-sql>
</dto>
</ebean>
@@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ebean xmlns="http://ebean-orm.github.io/xml/ns/ebean">
<entity class="org.tests.model.basic.Order">
<raw-sql name="myRawTest2">
<alias-mapping alias="c" property="customer"/>
<alias-mapping alias="a" property="customer.billingAddress"/>
<query>
select o.id, o.status, o.ship_date, c.id, c.name, a.id, a.line_1, a.line_2, a.city
from o_order o
join o_customer c on o.kcustomer_id = c.id
join o_address a on c.billing_address_id = a.id
where o.status = :orderStatus
order by c.name, c.id
</query>
</raw-sql>
<raw-sql name="myRawTest3">
<column-mapping column="o.id" property="id"/>
<column-mapping column="o.status" property="status"/>
<query>
-- must be unparsed raw sql
select o.id, o.status
from o_order o
</query>
</raw-sql>
</entity>
</ebean>
-59
View File
@@ -1,59 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ebean xmlns="http://ebean-orm.github.io/xml/ns/ebean">
<entity class="org.tests.model.basic.OrderAggregate">
<raw-sql name="default">
<column-mapping column="order_id" property="order.id"/>
<query>
select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount
from o_order_detail
group by order_id
</query>
</raw-sql>
<raw-sql name="withMax">
<column-mapping column="order_id" property="order.id"/>
<query>
select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount, max(order_qty*unit_price) as maxAmount
from o_order_detail
group by order_id
</query>
</raw-sql>
<raw-sql name="withParam">
<column-mapping column="order_id" property="order.id"/>
<query>
select order_id, count(*) as totalItems, sum(order_qty*unit_price) as totalAmount, max(order_qty*unit_price) as maxAmount
from o_order_detail where id > :minId
group by order_id
</query>
</raw-sql>
</entity>
<entity class="org.tests.model.basic.Order">
<raw-sql name="myRawTest">
<alias-mapping alias="c" property="customer"/>
<alias-mapping alias="a" property="customer.billingAddress"/>
<query>
select o.id, o.status, o.ship_date, c.id, c.name, a.id, a.line_1, a.line_2, a.city
from o_order o
join o_customer c on o.kcustomer_id = c.id
join o_address a on c.billing_address_id = a.id
where o.status = :orderStatus
order by c.name, c.id
</query>
</raw-sql>
</entity>
<entity class="org.tests.model.basic.Customer">
<named-query name="withContactsById">
<query>
select (name, version)
fetch contacts (firstName, lastName, email)
where id = :id
</query>
</named-query>
</entity>
</ebean>
@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ebean xmlns="http://ebean-orm.github.io/xml/ns/ebean">
<entity class="org.tests.model.basic.OrderAggregate">
<raw-sql name="default">
<column-mapping column="order_id" property="order.id"/>
<query>
select order_id, count(*) as totalItems, sum(order_qty*unit_price) as totalAmount
from o_order_detail
group by order_id
</query>
</raw-sql>
<raw-sql name="default">
<column-mapping column="order_id" property="order.id"/>
<query>
select order_id, count(*) as totalItems, sum(order_qty*unit_price) as totalAmount
from o_order_detail
group by order_id
</query>
</raw-sql>
</entity>
</ebean>