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

x33g5p2x  于2022-01-24 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(290)

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

NClob介绍

暂无

代码示例

代码示例来源:origin: hibernate/hibernate-orm

@SuppressWarnings({ "unchecked" })
public <X> X unwrap(final NClob value, Class<X> type, WrapperOptions options) {
  if ( value == null ) {
    return null;
  }
  try {
    if ( CharacterStream.class.isAssignableFrom( type ) ) {
      if ( NClobImplementer.class.isInstance( value ) ) {
        // if the incoming NClob is a wrapper, just pass along its BinaryStream
        return (X) ( (NClobImplementer) value ).getUnderlyingStream();
      }
      else {
        // otherwise we need to build a BinaryStream...
        return (X) new CharacterStreamImpl( DataHelper.extractString( value.getCharacterStream() ) );
      }
    }
    else if (NClob.class.isAssignableFrom( type )) {
      final NClob nclob =  WrappedNClob.class.isInstance( value )
          ? ( (WrappedNClob) value ).getWrappedNClob()
          : value;
      return (X) nclob;
    }
  }
  catch ( SQLException e ) {
    throw new HibernateException( "Unable to access nclob stream", e );
  }
  
  throw unknownUnwrap( type );
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
  public NClob mergeNClob(NClob original, NClob target, SharedSessionContractImplementor session) {
    if ( original != target ) {
      try {
        // the NCLOB just read during the load phase of merge
        final OutputStream connectedStream = target.setAsciiStream( 1L );
        // the NCLOB from the detached state
        final InputStream detachedStream = original.getAsciiStream();
        StreamCopier.copy( detachedStream, connectedStream );
        return target;
      }
      catch (SQLException e ) {
        throw session.getFactory().getSQLExceptionHelper().convert( e, "unable to merge NCLOB data" );
      }
    }
    else {
      return NEW_LOCATOR_LOB_MERGE_STRATEGY.mergeNClob( original, target, session );
    }
  }
};

代码示例来源:origin: hibernate/hibernate-orm

@Override
  public NClob mergeNClob(NClob original, NClob target, SharedSessionContractImplementor session) {
    if ( original == null && target == null ) {
      return null;
    }
    try {
      final LobCreator lobCreator = session.getFactory().getServiceRegistry().getService( JdbcServices.class ).getLobCreator( session );
      return original == null
          ? lobCreator.createNClob( "" )
          : lobCreator.createNClob( original.getCharacterStream(), original.length() );
    }
    catch (SQLException e) {
      throw session.getFactory().getSQLExceptionHelper().convert( e, "unable to merge NCLOB data" );
    }
  }
};

代码示例来源:origin: apache/nifi

NClob nClob = rs.getNClob(i);
if (nClob != null) {
  final Reader characterStream = nClob.getCharacterStream();
  long numChars = (int) nClob.length();
  final CharBuffer buffer = CharBuffer.allocate((int) numChars);
  characterStream.read(buffer);
  buffer.flip();
  rec.put(i - 1, buffer.toString());
  nClob.free();
} else {
  rec.put(i - 1, null);

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

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

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

if (String.class.isInstance(value)) {
  clob = connection.createNClob();
  clob.setString(1, (String) value);
} else if (char[].class.isInstance(value)) {
  clob = connection.createNClob();
  clob.setString(1, new String((char[]) value));
} else if (Reader.class.isInstance(value)) {
  clob = connection.createNClob();
  try {
    IOUtils.copy((Reader) value, clob.setCharacterStream(1));
  } catch (IOException exception) {
    throw new JdbcTypeException(exception);
  clob = connection.createNClob();
  try {
    IOUtils.copy((InputStream) value, clob.setAsciiStream(1));
  } catch (IOException exception) {
    throw new JdbcTypeException(exception);

代码示例来源:origin: co.paralleluniverse/comsat-jdbc

@Override
  public InputStream call() throws SQLException {
    return nclob.getAsciiStream();
  }
});

代码示例来源:origin: future-architect/uroborosql

private Object getValue(final ResultSet rs, final ResultSetMetaData rsmd, final int columnIndex)
    throws SQLException {
  JDBCType type = JDBCType.valueOf(rsmd.getColumnType(columnIndex));
  switch (type) {
  case CLOB:
    Clob clob = rs.getClob(columnIndex);
    return clob.getSubString(1, (int) clob.length());
  case NCLOB:
    NClob nclob = rs.getNClob(columnIndex);
    return nclob.getSubString(1, (int) nclob.length());
  case BLOB:
    Blob blob = rs.getBlob(columnIndex);
    return blob.getBytes(1, (int) blob.length());
  case ARRAY:
    Array arr = rs.getArray(columnIndex);
    return arr.getArray();
  default:
    return rs.getObject(columnIndex);
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
  NClob rsNClob = rs.getNClob( name );
  if ( rsNClob == null || rsNClob.length() < HANANClobTypeDescriptor.this.maxLobPrefetchSize ) {
    return javaTypeDescriptor.wrap( rsNClob, options );
  }
  NClob nClob = new MaterializedNClob( DataHelper.extractString( rsNClob ) );
  return javaTypeDescriptor.wrap( nClob, options );
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
public NClob createNClob(String string) {
  try {
    final NClob nclob = createNClob();
    nclob.setString( 1, string );
    return nclob;
  }
  catch ( SQLException e ) {
    throw new JDBCException( "Unable to set NCLOB string after creation", e );
  }
}

代码示例来源:origin: co.paralleluniverse/comsat-jdbc

@Override
  public OutputStream call() throws SQLException {
    return nclob.setAsciiStream(pos);
  }
});

代码示例来源:origin: hibernate/hibernate-orm

for ( NClob nclob : nclobs ) {
  try {
    nclob.free();

代码示例来源:origin: org.apache.nifi/nifi-standard-processors

NClob nClob = rs.getNClob(i);
if (nClob != null) {
  final Reader characterStream = nClob.getCharacterStream();
  long numChars = (int) nClob.length();
  final CharBuffer buffer = CharBuffer.allocate((int) numChars);
  characterStream.read(buffer);
  buffer.flip();
  rec.put(i - 1, buffer.toString());
  nClob.free();
} else {
  rec.put(i - 1, null);

代码示例来源:origin: br.com.anteros/Anteros-Core

result = IOUtils.toByteArray(asciiStream);
} else if (source instanceof NClob) {
  InputStream asciiStream = ((NClob) source).getAsciiStream();
  if (asciiStream == null)
    return null;

代码示例来源:origin: br.com.anteros/Anteros-Core

String s = lob.getSubString(new Long(1).longValue(), (int) lob.length());
if (type == char[].class) {
  return s.toCharArray();

代码示例来源:origin: co.paralleluniverse/comsat-jdbc

@Override
  public Long call() throws SQLException {
    return nclob.length();
  }
});

代码示例来源:origin: co.paralleluniverse/comsat-jdbc

@Override
  public Integer call() throws SQLException {
    return nclob.setString(pos, str);
  }
});

代码示例来源:origin: co.paralleluniverse/comsat-jdbc

@Override
  public Void call() throws SQLException {
    nclob.free();
    return null;
  }
});

代码示例来源:origin: com.h2database/h2

/**
 * Sets the value of a parameter as a Clob.
 *
 * @param parameterIndex the parameter index (1, 2, ...)
 * @param x the value
 * @throws SQLException if this object is closed
 */
@Override
public void setNClob(int parameterIndex, NClob x) throws SQLException {
  try {
    if (isDebugEnabled()) {
      debugCode("setNClob("+parameterIndex+", x);");
    }
    checkClosedForWrite();
    Value v;
    if (x == null) {
      v = ValueNull.INSTANCE;
    } else {
      v = conn.createClob(x.getCharacterStream(), -1);
    }
    setParameter(parameterIndex, v);
  } catch (Exception e) {
    throw logAndConvert(e);
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
@RequiresDialectFeature(DialectChecks.SupportsNClob.class)
public void testNClob() {
  final int id = doInHibernate( this::sessionFactory, s -> {
    FileNClob file = new FileNClob();
    file.setClob( s.getLobHelper().createNClob( "TEST CASE" ) );
    // merge transient entity
    file = (FileNClob) s.merge( file );
    return file.getId();
  });
  doInHibernate( this::sessionFactory, s -> {
    FileNClob file = s.get( FileNClob.class, id );
    assertFalse( Hibernate.isPropertyInitialized( file, "clob" ) );
    NClob nClob = file.getClob();
    try {
      final char[] chars = new char[(int) file.getClob().length()];
      nClob.getCharacterStream().read( chars );
      assertTrue( Arrays.equals( "TEST CASE".toCharArray(), chars ) );
    }
    catch (SQLException ex ) {
      fail( "could not determine Lob length" );
    }
    catch (IOException ex) {
      fail( "could not read Lob" );
    }
  });
}

相关文章