Commit aa3f843a authored by unknown's avatar unknown

test

parent 2f8135fd
Pipeline #379 failed with stages
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="XqueryDemo" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="XqueryDemo" options="-parameters" />
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="http://maven.aliyun.com/nexus/content/groups/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8.0_371" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.linghu</groupId>
<artifactId>XqueryDemo</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.basex</groupId>
<artifactId>basex</artifactId>
<version>9.7.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sf.xmldb-org/xmldb-api -->
<dependency>
<groupId>net.sf.xmldb-org</groupId>
<artifactId>xmldb-api</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.linghu;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MainApp {
public static void main(String[] args) {
SpringApplication.run(MainApp.class,args);
}
}
\ No newline at end of file
package com.linghu.controller;
import com.linghu.response.Msg;
import com.linghu.service.DataBaseService;
import com.linghu.service.Impl.DataBaseServiceImpl;
import com.linghu.util.BaseXClientUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
@RestController
public class OperatorDB {
DataBaseService dataBaseService=new DataBaseServiceImpl();
@GetMapping("/create")
public Msg createApi() throws IOException {
dataBaseService.createDB(BaseXClientUtil.getClient(),"xquery/createDataBase.xqy");
return Msg.success();
}
}
package com.linghu.dao;
import com.linghu.util.BaseXClient;
import javax.xml.bind.JAXBException;
import java.io.IOException;
public interface DataBaseDAO {
//创建数据库
public void createDB(BaseXClient client,String path);
//遍历数据库中的元素
public String selectElements(BaseXClient client,String path) throws IOException, JAXBException;
}
package com.linghu.dao.Impl;
import com.linghu.dao.DataBaseDAO;
import com.linghu.util.BaseXClient;
import com.linghu.util.BaseXClientUtil;
import com.linghu.util.XmlUtil;
import org.springframework.stereotype.Repository;
import javax.xml.bind.JAXBException;
import java.io.IOException;
@Repository
public class DataBaseDAOImpl implements DataBaseDAO {
//新建 数据库
@Override
public void createDB(BaseXClient client, String path){
String paths = BaseXClientUtil.getQueryResource(path);
try {
client.query(paths).execute();
} catch (IOException e) {
e.printStackTrace();
}
}
//执行查询
@Override
public String selectElements(BaseXClient client, String path) throws IOException, JAXBException {
String paths = BaseXClientUtil.getQueryResource(path);
String xmlData = client.query(paths).execute();
return XmlUtil.convertToObject(xmlData, String.class);
}
}
package com.linghu.response;
import java.util.HashMap;
import java.util.Map;
/**
* @author 令狐
* @version 1.0
* Msg:后端程序返回给前端的json数据的Msg对象==>本质就是数据规范
*/
public class Msg {
// 状态码,200 成功,400 失败
private int code;
// 信息
private String msg;
// 返回给浏览器的数据
private Map<String, Object> extend = new HashMap<String, Object>();
public static Msg success() {
Msg res = new Msg();
res.setCode(200);
res.setMsg("success");
return res;
}
public static Msg fail() {
Msg res = new Msg();
res.setCode(400);
res.setMsg("fail");
return res;
}
public Msg add(String key, Object value) {
this.getExtend().put(key, value);
return this;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Map<String, Object> getExtend() {
return extend;
}
public void setExtend(Map<String, Object> extend) {
this.extend = extend;
}
}
package com.linghu.service;
import com.linghu.util.BaseXClient;
public interface DataBaseService {
public void createDB(BaseXClient client, String path);
}
package com.linghu.service.Impl;
import com.linghu.dao.DataBaseDAO;
import com.linghu.dao.Impl.DataBaseDAOImpl;
import com.linghu.service.DataBaseService;
import com.linghu.util.BaseXClient;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class DataBaseServiceImpl implements DataBaseService {
@Resource
DataBaseDAO dataBaseDAO=new DataBaseDAOImpl();
@Override
public void createDB(BaseXClient client, String path) {
dataBaseDAO.createDB(client,path);
}
}
This diff is collapsed.
package com.linghu.util;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
/**
* @author linghu 改造了一下工具类
* @description
* @date 2023-04-12 09:32
*/
public class BaseXClientUtil {
/**
* 创建client连接对象,并获取连接
*/
public static BaseXClient getClient() throws IOException {
BaseXClient client = new BaseXClient("localhost", 1984, "admin", "admin");
return client;
}
/**
* 这个方法的功能是执行XQuery查询
* @param client
* @param path
* @param
* @return
*/
// public static String executeQuery(BaseXClient client, String path) {
// //有调用了getQueryResource这个方法,把Xquery对应文件的路径传入
// return getQueryResource(path);
// }
/**
*这个方法就是专门处理"xquery/calculate_flow/flow/createCalculateFlow.xqy"
* @param path "xquery/calculate_flow/flow/createCalculateFlow.xqy",这是指定路径下的Xquery文件
* @return
*/
public static String getQueryResource(String path){
//创建一个 StringBuilder 对象,用于构建返回的字符串。
StringBuilder stringBuilder = new StringBuilder();
try {
/**
* ClassPathResource专门用来访问类路径上的资源类resource下的文件
*/
Resource resource = new ClassPathResource(path);
InputStream resourceAsStream = resource.getInputStream();
InputStreamReader reader = new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8);
BufferedReader bufReader = new BufferedReader(reader);
String strLine = null;
while ((strLine = bufReader.readLine()) != null) {
stringBuilder.append(strLine).append("\n");
}
bufReader.close();
} catch (IOException e) {
e.printStackTrace();
}
return stringBuilder.toString();
}
}
package com.linghu.util;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import java.io.StringReader;
import java.io.StringWriter;
/**
* 封装了XML转换成object,object转换成XML的代码
*
* @author xcq
* {@code @date} 2023/03/09
*/
public class XmlUtil {
/**
* xml字符串转换为对象
*
* @param tClazz t clazz
* @param string 字符串
* @return {@link T}
* @throws JAXBException jaxbexception
*/
public static <T>T convertToObject(String string, Class<T> tClazz) throws JAXBException {
JAXBContext context = JAXBContext.newInstance(tClazz);
Unmarshaller unmarshaller = context.createUnmarshaller();
try (StringReader sr = new StringReader(string)) {
return (T) unmarshaller.unmarshal(sr);
}
}
/**
* 将对象转为xml字符串 编码为utf-8
*
* @param obj 待转的对象
* @return String xml字符串
*/
public static String objectToXml(Object obj) throws JAXBException {
JAXBContext context = JAXBContext.newInstance(obj.getClass());
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
// marshaller.setProperty(CharacterEscapeHandler.class.getName(), (CharacterEscapeHandler) (ch, start, length, isAttVal, writer) -> writer.write(ch, start, length));
StringWriter writer = new StringWriter();
marshaller.marshal(obj, writer);
return writer.toString();
}
}
db:add('linghu', <a/>, 'doc06.xml')
\ No newline at end of file
for $book in //book
let $title := $book/title/text()
let $author := $book/author/text()
return
<book id="{xs:string($book/@id)}">
<title>{xs:string($title)}</title>
<author>{xs:string($author)}</author>
</book>
\ No newline at end of file
package com.linghu.dao.Impl;
import com.linghu.dao.DataBaseDAO;
import com.linghu.util.BaseXClient;
import com.linghu.util.BaseXClientUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import javax.xml.bind.JAXBException;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootApplication
class DataBaseDAOImplTest {
DataBaseDAO dataBaseDAO=new DataBaseDAOImpl();
@Test
void createDB() {
BaseXClient client = null;
try {
client = BaseXClientUtil.getClient();//获取Base X连接
} catch (IOException e) {
e.printStackTrace();
}
dataBaseDAO.createDB(client,"xquery/createDataBase.xqy");
}
@Test
void selectElements() throws JAXBException, IOException {
BaseXClient client = null;
try {
client = BaseXClientUtil.getClient();//获取Base X连接
} catch (IOException e) {
e.printStackTrace();
}
String s = dataBaseDAO.selectElements(client, "xquery/selectBookElement.xqy");
System.out.println(s);
}
}
\ No newline at end of file
package com.linghu.service.Impl;
import com.linghu.service.DataBaseService;
import com.linghu.util.BaseXClientUtil;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
class DataBaseServiceImplTest {
DataBaseService dataBaseService=new DataBaseServiceImpl();
@Test
void createDB() throws IOException {
dataBaseService.createDB(BaseXClientUtil.getClient(),"xquery/createDataBase.xqy");
}
}
\ No newline at end of file
db:add('linghu', <a/>, 'doc06.xml')
\ No newline at end of file
for $book in //book
let $title := $book/title/text()
let $author := $book/author/text()
return
<book id="{xs:string($book/@id)}">
<title>{xs:string($title)}</title>
<author>{xs:string($author)}</author>
</book>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment