java.sql.SQLXML类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(110)

本文整理了Java中java.sql.SQLXML类的一些代码示例,展示了SQLXML类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SQLXML类的具体详情如下:
包路径:java.sql.SQLXML
类名称:SQLXML

SQLXML介绍

[英]Maps SQL's XML type into Java.
[中]

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
@Nullable
public String getXmlAsString(ResultSet rs, String columnName) throws SQLException {
  SQLXML xmlObject = rs.getSQLXML(columnName);
  return (xmlObject != null ? xmlObject.getString() : null);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
@Nullable
public InputStream getXmlAsBinaryStream(ResultSet rs, String columnName) throws SQLException {
  SQLXML xmlObject = rs.getSQLXML(columnName);
  return (xmlObject != null ? xmlObject.getBinaryStream() : null);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void cleanup() {
  if (this.xmlObject != null) {
    try {
      this.xmlObject.free();
    }
    catch (SQLException ex) {
      throw new DataAccessResourceFailureException("Could not free SQLXML object", ex);
    }
  }
}

代码示例来源:origin: org.mybatis/mybatis

protected String sqlxmlToString(SQLXML sqlxml) throws SQLException {
 if (sqlxml == null) {
  return null;
 }
 try {
  return sqlxml.getString();
 } finally {
  sqlxml.free();
 }
}

代码示例来源:origin: org.teiid/teiid-adminshell

public static String prettyPrint(SQLXML xml) throws SQLException {
    try {
      TransformerFactory transFactory = TransformerFactory.newInstance();
      transFactory.setAttribute("indent-number", new Integer(2)); //$NON-NLS-1$
      
      Transformer tf = transFactory.newTransformer();
      tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$
      tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");//$NON-NLS-1$
      tf.setOutputProperty(OutputKeys.INDENT, "yes");//$NON-NLS-1$
      tf.setOutputProperty(OutputKeys.METHOD, "xml");//$NON-NLS-1$
      tf.setOutputProperty(OutputKeys.STANDALONE, "yes");//$NON-NLS-1$
      tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); //$NON-NLS-1$ //$NON-NLS-2$
      
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      StreamResult xmlOut = new StreamResult(new BufferedOutputStream(out));
      tf.transform(xml.getSource(StreamSource.class), xmlOut);
      
      return out.toString();
    } catch (Exception e) {
      return xml.getString();
    }
  }   
}

代码示例来源:origin: spring-projects/spring-framework

@Override
@Nullable
public Reader getXmlAsCharacterStream(ResultSet rs, String columnName) throws SQLException {
  SQLXML xmlObject = rs.getSQLXML(columnName);
  return (xmlObject != null ? xmlObject.getCharacterStream() : null);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  protected void provideXml(SQLXML xmlObject) throws SQLException, IOException {
    xmlObject.setString(value);
  }
};

代码示例来源:origin: org.mybatis/mybatis

@Override
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType)
  throws SQLException {
 SQLXML sqlxml = ps.getConnection().createSQLXML();
 try {
  sqlxml.setString(parameter);
  ps.setSQLXML(i, sqlxml);
 } finally {
  sqlxml.free();
 }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
@Nullable
public Source getXmlAsSource(ResultSet rs, String columnName, @Nullable Class<? extends Source> sourceClass)
    throws SQLException {
  SQLXML xmlObject = rs.getSQLXML(columnName);
  if (xmlObject == null) {
    return null;
  }
  return (sourceClass != null ? xmlObject.getSource(sourceClass) : xmlObject.getSource(DOMSource.class));
}

代码示例来源:origin: nuodb/migration-tools

@Override
  public <X> X unwrap(SQLXML value, Class<X> valueClass, Connection connection) throws SQLException {
    if (value == null) {
      return null;
    } else if (valueClass.isAssignableFrom(SQLXML.class)) {
      return (X) value;
    } else if (valueClass.isAssignableFrom(String.class)) {
      try {
        return (X) IOUtils.toString(value.getCharacterStream());
      } catch (IOException exception) {
        throw new JdbcTypeException(exception);
      }
    } else if (valueClass.isAssignableFrom(InputStream.class)) {
      try {
        return (X) IOUtils.toString(value.getBinaryStream());
      } catch (IOException exception) {
        throw new JdbcTypeException(exception);
      }
    } else if (valueClass.isAssignableFrom(Reader.class)) {
      return (X) value.getCharacterStream();
    } else {
      throw newUnwrapFailure(valueClass);
    }
  }
}

代码示例来源:origin: nuodb/migration-tools

@Override
public <X> SQLXML wrap(X value, Connection connection) throws SQLException {
  if (value == null) {
    return null;
  }
  SQLXML sqlXml;
  if (String.class.isInstance(value)) {
    sqlXml = connection.createSQLXML();
    sqlXml.setString((String) value);
  } else if (InputStream.class.isInstance(value)) {
    sqlXml = connection.createSQLXML();
    try {
      IOUtils.copy((InputStream) value, sqlXml.setBinaryStream());
    } catch (IOException exception) {
      throw new JdbcTypeException(exception);
    }
  } else if (Reader.class.isInstance(value)) {
    sqlXml = connection.createSQLXML();
    try {
      IOUtils.copy((Reader) value, sqlXml.setCharacterStream());
    } catch (IOException exception) {
      throw new JdbcTypeException(exception);
    }
  } else {
    throw newWrapFailure(value);
  }
  return sqlXml;
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.oracle

@Override
  public void set(DatabasePlatform platform, PreparedStatement statement, int index, AbstractSession session) throws SQLException {
    if (this.obj instanceof String) {
      //Bug#5200836, unwrap the connection prior to using.
      Connection con = session.getServerPlatform().unwrapConnection(statement.getConnection());
      SQLXML sqlxml = con.createSQLXML();
      sqlxml.setString((String) obj);
      this.obj = sqlxml;
    } else if (this.obj instanceof Document) {
      //Bug#5200836, unwrap the connection prior to using.
      Connection con = session.getServerPlatform().unwrapConnection(statement.getConnection());
      SQLXML sqlxml = con.createSQLXML();
      DOMResult result = sqlxml.setResult(DOMResult.class);
      result.setNode((Document) obj);
      this.obj = sqlxml;
    }
    super.set(platform, statement, index, session);
  }
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

/**
 * INTERNAL:
 * Casts the passed object to SQLXML and calls getString and free methods
 */
public static String getStringAndFreeSQLXML(Object sqlXml) throws SQLException {
  String str = ((SQLXML)sqlXml).getString();
  ((SQLXML)sqlXml).free();
  return str;
}

代码示例来源:origin: ModeShape/modeshape

public static String prettyPrint( SQLXML xml ) throws SQLException {
    try {
      TransformerFactory transFactory = TransformerFactory.newInstance();
      transFactory.setAttribute("indent-number", new Integer(2)); //$NON-NLS-1$

      Transformer tf = transFactory.newTransformer();
      tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$
      tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");//$NON-NLS-1$
      tf.setOutputProperty(OutputKeys.INDENT, "yes");//$NON-NLS-1$
      tf.setOutputProperty(OutputKeys.METHOD, "xml");//$NON-NLS-1$
      tf.setOutputProperty(OutputKeys.STANDALONE, "yes");//$NON-NLS-1$
      tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); //$NON-NLS-1$ //$NON-NLS-2$

      ByteArrayOutputStream out = new ByteArrayOutputStream();
      StreamResult xmlOut = new StreamResult(new BufferedOutputStream(out));
      tf.transform(xml.getSource(StreamSource.class), xmlOut);

      return out.toString();
    } catch (Exception e) {
      return xml.getString();
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
@Nullable
public Reader getXmlAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException {
  SQLXML xmlObject = rs.getSQLXML(columnIndex);
  return (xmlObject != null ? xmlObject.getCharacterStream() : null);
}

代码示例来源:origin: org.springframework/org.springframework.jdbc

@Override
  protected void provideXml(SQLXML xmlObject) throws SQLException, IOException {
    xmlObject.setString(value);
  }
};

代码示例来源:origin: spring-projects/spring-framework

@Override
@Nullable
public Source getXmlAsSource(ResultSet rs, int columnIndex, @Nullable Class<? extends Source> sourceClass)
    throws SQLException {
  SQLXML xmlObject = rs.getSQLXML(columnIndex);
  if (xmlObject == null) {
    return null;
  }
  return (sourceClass != null ? xmlObject.getSource(sourceClass) : xmlObject.getSource(DOMSource.class));
}

代码示例来源:origin: spring-projects/spring-framework

@Override
@Nullable
public String getXmlAsString(ResultSet rs, int columnIndex) throws SQLException {
  SQLXML xmlObject = rs.getSQLXML(columnIndex);
  return (xmlObject != null ? xmlObject.getString() : null);
}

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

/**
   * Casts the passed object to SQLXML and calls getString and free methods
   */
  public String getStringAndFreeSQLXML(Object sqlXml) throws SQLException { 
    String str = ((SQLXML)sqlXml).getString();
    ((SQLXML)sqlXml).free();
    return str;
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
@Nullable
public InputStream getXmlAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException {
  SQLXML xmlObject = rs.getSQLXML(columnIndex);
  return (xmlObject != null ? xmlObject.getBinaryStream() : null);
}

相关文章