2012-07-03 25 views
0

要看到问题:为什么在插入BLOB时在ValueOfCopyOfInterpreter中获得NPE?

  1. 在Oracle中创建表:

    create table ut_table_ut_service_pj (
        PATH VARCHAR(80), 
        BINARY BLOB 
    ); 
    
  2. 粘贴在XPL沙箱下面的管道,你可以访问http://localhost:8080/orbeon/sandbox-transformations/xpl/,更换数据库URI,用户名和密码酌情您的系统上:

    <p:config xmlns:p="http://www.orbeon.com/oxf/pipeline" 
          xmlns:oxf="http://www.orbeon.com/oxf/processors" 
          xmlns:xforms="http://www.w3.org/2002/xforms" 
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
          xmlns:sql="http://orbeon.org/oxf/xml/sql" 
          xmlns:odt="http://orbeon.org/oxf/xml/datatypes" 
          xmlns:xs="http://www.w3.org/2001/XMLSchema" 
          xmlns:exist="http://exist.sourceforge.net/NS/exist"> 
    
        <p:processor name="oxf:url-generator"> 
         <p:input name="config"> 
          <config> 
           <url>test.pdf</url> 
           <mode>binary</mode> 
          </config> 
         </p:input> 
         <p:output name="data" id="document"/> 
        </p:processor> 
    
        <p:processor name="oxf:sql"> 
         <p:input name="datasource"> 
          <datasource> 
           <driver-class-name>oracle.jdbc.OracleDriver</driver-class-name> 
           <uri>jdbc:oracle:thin:@//localhost:1522/globaldb</uri> 
           <username>orbeon</username> 
           <password>password</password> 
          </datasource> 
         </p:input> 
         <p:input name="data" href="#document"/> 
         <p:input name="config"> 
          <sql:config> 
           <sql:connection> 
            <sql:execute> 
             <sql:update debug="write"> 
              insert into ut_table_ut_service_pj 
              values('test.pdf', 
              <sql:param select="/*" 
                 type="xs:base64Binary" sql-type="blob"/> 
              ) 
             </sql:update> 
            </sql:execute> 
           </sql:connection> 
          </sql:config> 
         </p:input> 
        </p:processor> 
    
    </p:config> 
    

这导致以下异常:

|----------------------------------------------------------------------------------------------------------------------| 
|Exception: java.lang.NullPointerException                    | 
|----------------------------------------------------------------------------------------------------------------------| 
|org.orbeon.oxf.processor.sql.interpreters.ValueOfCo|<init>      |ValueOfCopyOfInterpreter.java | 48| 
|org.orbeon.oxf.processor.sql.SQLProcessor$Interpret|addAllDefaultElementHandlers |SQLProcessor.java    | 476| 
|org.orbeon.oxf.processor.sql.interpreters.ConfigInt|start       |ConfigInterpreter.java  | 32| 
|org.orbeon.oxf.processor.sql.SQLProcessor$Interpret|startElement     |SQLProcessor.java    | 503| 
|org.orbeon.oxf.processor.sql.SQLProcessor$RootInter|startElement     |SQLProcessor.java    | 280| 

这究竟是为什么?

回答

0

NPE是bug。截至2012年7月3日,这是fixed

  • ValueOfCopyOfInterpreter中,interpreterContext.getCurrentNode()为空。
    • SQLProcessorInterpreterContextRootInterpreter的构造函数中创建。
    • 在解释器的上下文currentNodesSQLProcessorInterpreterContext.setInput()加入,这是由RootInterpreter调用null第一节点。
    • null来自SQLProcessor.execute()决定配置中的所有XPath表达式(这里只是/*)可以流式传输,因此文档不需要被读取,这是可以的。
  • ValueOfCopyOfInterpreter使用该包装来:
    • 列表(雾化),包列表中的每个元素上评估string(.)
    • Node
  • 在这两种情况下评估string(.),它确实是有意义的要创建的包装基础data输入文档,而不是从Dom4jUtils.createDocument(),虽然我不知道确切知道什么影响将会。
  • 修复
    • 但由于在这一点上,我们必须有一个当前节点,因为我们呼吁XPathUtils.selectObjectValue()传递当前节点,似乎是有道理的延迟包装的创作,直到这一点。
    • 仍然保留wrapper作为对象属性,所以我们不会不必要地重新创建包装。

下一个错误是:Invalid sql-type attribute: blob,由于其他bug。这是截至2012年7月3日的fixed

  • 这是由<sql:param select="/*" type="xs:base64Binary" sql-type="blob"/>触发的。
  • QueryInterpreter中,如果类型为xs:anyURI,那么我们对BLOB和CLOB都使用相同的技术。
  • 但是,如果类型是xs:base64Binary,那么如果类型是BLOB,我们会发生异常。
    • 顺便说一下,这是MySQL和Oracle持久层存储文件时使用的内容。
  • 因此,当类型为xs:base64Binary时,做同样的事情似乎也是合理的。