ENH: Add named DtoQuery, such that we can define native SQL queries in ebean mapping xml for DtoQuery.

This commit is contained in:
yuanxuegui
2018-03-19 18:04:49 +08:00
parent 9d336cb20b
commit 5575273c96
13 changed files with 814 additions and 104 deletions
@@ -1,11 +1,17 @@
package io.ebeaninternal.xmlmapping;
import io.ebeaninternal.xmlmapping.model.XmEbean;
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;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.InputStream;
import org.avaje.classpath.scanner.Resource;
public class XmlMappingReader {
@@ -24,4 +30,34 @@ public class XmlMappingReader {
throw new RuntimeException(e);
}
}
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 = url.openStream()) {
mappings.add(XmlMappingReader.read(is));
}
}
return mappings;
} catch (IOException e) {
throw new RuntimeException("Error reading ebean xml mapping", e);
}
}
public static List<XmEbean> readByResourceList(ClassLoader classLoader, 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);
}
}
}