简体   繁体   English

将Java文件更改为存储过程

[英]Changing Java file to Stored procedure

I have a java file name E2BXmlParser where I am reading and manipulating the XML data fetched from the database. 我有一个Java文件名E2BXmlParser ,用于读取和处理从数据库中获取的XML数据。

Now I am trying to execute the java file using Oracle SQL Developer after changing the file like this 现在,在像这样更改文件后,我尝试使用Oracle SQL Developer执行Java文件

CREATE AND COMPILE JAVA SOURCE NAMED "E2BXmlParser" AS

--(Rest of Code).

And rest of code looks like this-- 其余的代码看起来像这样-

import oracle.jdbc.*
import oracle.xdb.XMLType;
import oracle.xml.parser.v2.XMLDocument;
import oracle.jdbc.*;
import org.w3c.dom.*;
import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.*;
import java.sql.Connection;
import java.util.*
import javax.xml.xpath.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.io.StringReader;

class Reaction {

}

public class E2BXmlParser {

   //variables

    public E2BXmlParser(int regReportId, int reportId) {
       //connection
    }
    public static void parseXML(int regReportId, int reportId, int isBlinded, int reportFormid,int pi_is_r3_profile,int pi_max_length,String pi_risk_category) throws SQLException, XPathExpressionException, TransformerException {
        //fetching data
    }
    private static Document getDocumentFromString(String xmlContent) throws Exception {

    }

    private String getStringByElementName(String tagName, Element element) {

    }
    private OracleConnection getConnecton() {
       //oracle connection

    }
private Document getXmlDocumentFromDb(int regReportId, int reportId) {
    //fetching and manipulating data
}
private List<Reaction> getReactionIds() {
    //logic 
}
private void findById(Reaction reaction, String id) {

    //xpath for finding nodes

}
private boolean checkNodeExists(Element el, String nodeName) {
    NodeList list = el.getElementsByTagName(nodeName);
    return list.getLength() > 0;
}
private void updateNode(Reaction reaction, Element el) {

  //update xml

}
private void updateXmlInDB(int regReportId, int reportId) throws SQLException {
    //update xml in db
}

private void updateDrugNode() {
    Element rootElement = document.getDocumentElement();
    //logic
}

private void updateDrugEventandDrugRelatedness(int reportFormid) {
    //update xml 

}

private void updateMedicinalActiveSubstance(int regReportId, int isBlinded, int reportFormid,int pi_is_r3_profile,int pi_max_length,String pi_risk_category) {

   //update xml after fetching data and changing in DB
}

private Boolean compareStrings(String strOne, String strTwo) {

    //logic
}

private void updateDosageInformation() {
   //logic
}

private void updateActiveSubstanceName() {

   updating activesubstance using xpath 

}

private void RemoveDuplicateActiveSubstance(NodeList activesubstancenameList, List<String> names) {

// logic
     }
}

Now it is asking for multiple values(reactions,nodelist,node) that are used in code. 现在,它要求在代码中使用多个值(反应,节点列表,节点)。

But this is not the case when I am executing the java file from command line like this 但是,当我从这样的命令行执行java文件时,情况并非如此

loadjava -user  username/password@DBalias -r E2BXmlParser.java

PS I have to change my E2BXmlParser.java file to E2BXmlParser.sql file so that I can execute it from oracle sql developer. PS 我必须将我的E2BXmlParser.java文件更改为E2BXmlParser.sql文件,以便可以从oracle sql developer执行它。

Please help. 请帮忙。

The easiest solution is wrapping all logic of your class into one static method in class. 最简单的解决方案是将类的所有逻辑包装到类中的一个静态方法中。 Next you have to publish this method to pl sql. 接下来,您必须将此方法发布到pl sql。

And publication of static function will be look (more or less) like this. 静态功能的发布将(或多或少)像这样。

CREATE PROCEDURE parseXML (regReportId NUMBER, reportId NUMBER, isBlinded NUMBER, reportFormid NUMBER, pi_is_r3_profile NUMBER, pi_max_length NUMBER, pi_risk_category varchar2)
AS LANGUAGE JAVA
NAME 'E2BXmlParser.parseXML(int regReportId, int reportId, int isBlinded, int reportFormid,int pi_is_r3_profile,int pi_max_length,java.lang.String pi_risk_category)';

Note. 注意。 In plsql you have to use full path to object example String -> java.lang.String 在PLSQL你必须使用完整路径,例如对象的String - > java.lang.String

Of course oracle allows to use java class in more object oriented way but this is more complicated. 当然,oracle允许以更多面向对象的方式使用java类,但这更加复杂。

For more information check this manual. 有关更多信息,请参阅本手册。 https://docs.oracle.com/cd/E18283_01/java.112/e10588/toc.htm https://docs.oracle.com/cd/E18283_01/java.112/e10588/toc.htm

Chapter 3 (Calling Java Methods in Oracle Database) - for basic solutions. 第3章(在Oracle数据库中调用Java方法)-有关基本解决方案。
Chapter 6 (Publishing Java Classes With Call Specifications) - ( paragraph Writing Object Type Call Specifications) - for publishing full java class. 第6章(发布具有调用规范的Java类)-(编写对象类型调用规范的段落)-用于发布完整的Java类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM