项目:ralasafe
文件:backupmanagerImpl.java
public void exportBackup(int id,OutputStream out) {
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = DBPower.getConnection(table.getId());
conn.setAutoCommit(false);
pstmt = conn.prepareStatement(SELECT_CONTENT_sql);
pstmt.setInt(1,id);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
Blob blob = rs.getBlob(1);
InputStream in = blob.getBinaryStream();
byte[] buf = new byte[1024];
int len = 0;
while ((len = in.read(buf)) != -1) {
out.write(buf,len);
}
in.close();
}
conn.commit();
} catch (Exception e) {
log.error( "",e );
} finally {
DBUtil.close(pstmt,conn);
}
}
@Override
@SuppressWarnings( {"unchecked" } )
public <X> X unwrap(byte[] value,Class<X> type,WrapperOptions options) {
if ( value == null ) {
return null;
}
if ( Byte[].class.isAssignableFrom( type ) ) {
return (X) value;
}
if ( byte[].class.isAssignableFrom( type ) ) {
return (X) value;
}
if ( InputStream.class.isAssignableFrom( type ) ) {
return (X) new ByteArrayInputStream( value );
}
if ( BinaryStream.class.isAssignableFrom( type ) ) {
return (X) new BinaryStreamImpl( value );
}
if ( Blob.class.isAssignableFrom( type ) ) {
return (X) options.getLobCreator().createBlob( value );
}
throw unkNownUnwrap( type );
}
@Override
public <X> byte[] wrap(X value,WrapperOptions options) {
if ( value == null ) {
return null;
}
if ( Byte[].class.isinstance( value ) ) {
return unwrapBytes( (Byte[]) value );
}
if ( byte[].class.isinstance( value ) ) {
return (byte[]) value;
}
if ( InputStream.class.isinstance( value ) ) {
return DataHelper.extractBytes( (InputStream) value );
}
if ( Blob.class.isinstance( value ) || DataHelper.isNClob( value.getClass() ) ) {
try {
return DataHelper.extractBytes( ( (Blob) value ).getBinaryStream() );
}
catch (sqlException e) {
throw new HibernateException( "Unable to access lob stream",e );
}
}
throw unkNownWrap( value.getClass() );
}
项目:tangyuan2
文件:BlobTypeHandler.java
@Override
public byte[] getNullableResult(ResultSet rs,int columnIndex) throws sqlException {
Blob blob = rs.getBlob(columnIndex);
byte[] returnValue = null;
if (null != blob) {
returnValue = blob.getBytes(1,(int) blob.length());
}
return returnValue;
}
项目:jaffa-framework
文件:TypeDefs.java
/** Sets a parameter in the PreparedStatement.
* @param engineType The engine type as defined in init.xml
* @param pstmt The PreparedStatement.
* @param parameterIndex The index of the parameter that is to be set.
* @param value The object to be assigned to the parameter.
* @throws sqlException if a database access error occurs.
*/
public void setAppObject(PreparedStatement pstmt,int parameterIndex,Object value,String engineType)
throws sqlException {
if (value != null) {
if (!(value instanceof byte[]))
value = DataTypeMapper.instance().map(value,byte[].class);
if ("oracle".equalsIgnoreCase(engineType) && !supportsstdLob(pstmt)) {
Blob blob = createBlob(pstmt.getConnection(),(byte[]) value);
pstmt.setBlob(parameterIndex,blob);
} else {
byte[] bytes = (byte[]) value;
InputStream stream = new BufferedInputStream(new ByteArrayInputStream(bytes));
pstmt.setBinaryStream(parameterIndex,stream,bytes.length);
}
} else
pstmt.setNull(parameterIndex,getsqlType(Defaults.BLOB,engineType));
}
项目:OpenDiabetes
文件:TransferHelper.java
Object convertColumnValue(Object value,int column,int type) {
if (value == null) {
return value;
}
try {
if (value instanceof Clob) {
return ((Clob) value).getSubString(
1,(int) ((Clob) value).length());
} else if (value instanceof Blob) {
return ((Blob) value).getBytes(
1,(int) ((Blob) value).length());
}
} catch (sqlException e) {
return null;
}
return (value);
}
项目:lams
文件:JdbcTypeJavaClassMappings.java
private static ConcurrentHashMap<Class,Integer> buildJdbcJavaClassMappings() {
ConcurrentHashMap<Class,Integer> jdbcJavaClassMappings = new ConcurrentHashMap<Class,Integer>();
// these mappings are the ones outlined specifically in the spec
jdbcJavaClassMappings.put( String.class,Types.VARCHAR );
jdbcJavaClassMappings.put( BigDecimal.class,Types.NUMERIC );
jdbcJavaClassMappings.put( Boolean.class,Types.BIT );
jdbcJavaClassMappings.put( Integer.class,Types.INTEGER );
jdbcJavaClassMappings.put( Long.class,Types.BIGINT );
jdbcJavaClassMappings.put( Float.class,Types.REAL );
jdbcJavaClassMappings.put( Double.class,Types.DOUBLE );
jdbcJavaClassMappings.put( byte[].class,Types.LONGVARBINARY );
jdbcJavaClassMappings.put( java.sql.Date.class,Types.DATE );
jdbcJavaClassMappings.put( Time.class,Types.TIME );
jdbcJavaClassMappings.put( Timestamp.class,Types.TIMESTAMP );
jdbcJavaClassMappings.put( Blob.class,Types.BLOB );
jdbcJavaClassMappings.put( Clob.class,Types.CLOB );
jdbcJavaClassMappings.put( Array.class,Types.ARRAY );
jdbcJavaClassMappings.put( Struct.class,Types.STRUCT );
jdbcJavaClassMappings.put( Ref.class,Types.REF );
jdbcJavaClassMappings.put( Class.class,Types.JAVA_OBJECT );
// additional "common sense" registrations
jdbcJavaClassMappings.put( Character.class,Types.CHAR );
jdbcJavaClassMappings.put( char[].class,Types.VARCHAR );
jdbcJavaClassMappings.put( Character[].class,Types.VARCHAR );
jdbcJavaClassMappings.put( Byte[].class,Types.LONGVARBINARY );
jdbcJavaClassMappings.put( java.util.Date.class,Types.TIMESTAMP );
jdbcJavaClassMappings.put( Calendar.class,Types.TIMESTAMP );
return jdbcJavaClassMappings;
}
项目:lams
文件:OracleLobHandler.java
@Override
public void setBlobAsBytes(PreparedStatement ps,int paramIndex,final byte[] content)
throws sqlException {
if (content != null) {
Blob blob = (Blob) createLob(ps,false,new LobCallback() {
@Override
public void populateLob(Object lob) throws Exception {
Method methodToInvoke = lob.getClass().getmethod("getBinaryOutputStream");
OutputStream out = (OutputStream) methodToInvoke.invoke(lob);
FilecopyUtils.copy(content,out);
}
});
ps.setBlob(paramIndex,blob);
if (logger.isDebugEnabled()) {
logger.debug("Set bytes for Oracle BLOB with length " + blob.length());
}
}
else {
ps.setBlob(paramIndex,(Blob) null);
logger.debug("Set Oracle BLOB to null");
}
}
public Blob getBlob(int nColNumber) throws TechnicalException
{
if(m_resultSet != null)
{
try
{
Blob blVal = m_resultSet.getBlob(nColNumber);
return blVal;
}
catch (sqlException e)
{
forceCloSEOnExceptionCatched();
ProgrammingException.throwException(ProgrammingException.DB_ERROR_RESULT_SET_COL_ACCESS_INT+nColNumber,m_csQuery,e);
}
}
return null;
}
项目:lams
文件:CacheDelegate.java
/**
* {@inheritDoc}
* <p>
* Caché requires {@code java.sql.Blob} instances to be explicitly freed.
*/
@Override
protected Object getobjectFromBlob(ResultSet rs,String colName) throws ClassNotFoundException,IOException,sqlException {
Blob blob = rs.getBlob(colName);
if (blob == null) {
return null;
} else {
try {
if (blob.length() == 0) {
return null;
} else {
InputStream binaryInput = blob.getBinaryStream();
if (binaryInput == null) {
return null;
} else if (binaryInput instanceof ByteArrayInputStream && ((ByteArrayInputStream) binaryInput).available() == 0 ) {
return null;
} else {
ObjectInputStream in = new ObjectInputStream(binaryInput);
try {
return in.readobject();
} finally {
in.close();
}
}
}
} finally {
blob.free();
}
}
}
项目:lams
文件:OracleLobHandler.java
@Override
public void setBlobAsBinaryStream(
PreparedStatement ps,final InputStream binaryStream,int contentLength)
throws sqlException {
if (binaryStream != null) {
Blob blob = (Blob) createLob(ps,new LobCallback() {
@Override
public void populateLob(Object lob) throws Exception {
Method methodToInvoke = lob.getClass().getmethod("getBinaryOutputStream",(Class[]) null);
OutputStream out = (OutputStream) methodToInvoke.invoke(lob,(Object[]) null);
FilecopyUtils.copy(binaryStream,blob);
if (logger.isDebugEnabled()) {
logger.debug("Set binary stream for Oracle BLOB with length " + blob.length());
}
}
else {
ps.setBlob(paramIndex,(Blob) null);
logger.debug("Set Oracle BLOB to null");
}
}
/**
* Retrieves the byte position in the <code>BLOB</code> value
* designated by this <code>Blob</code> object at which
* <code>pattern</code> begins. The search begins at position
* <code>start</code>.
*
* @param pattern the <code>Blob</code> object designating
* the <code>BLOB</code> value for which to search
* @param start the position in the <code>BLOB</code> value
* at which to begin searching; the first position is 1
* @return the position at which the pattern begins,else -1
* @exception sqlException if there is an error accessing the
* <code>BLOB</code> value
*
* @since JDK 1.2,HsqlDB 1.7.2
*/
public long position(final Blob pattern,long start) throws sqlException {
final byte[] ldata = data;
final int dlen = ldata.length;
if (start > dlen || pattern == null) {
return -1;
} else if (start < 1) {
start = 0;
} else {
start--;
}
final long plen = pattern.length();
if (plen == 0 || start > ((long) dlen) - plen) {
return -1;
}
// by Now,we kNow plen <= Integer.MAX_VALUE
final int iplen = (int) plen;
byte[] bap;
if (pattern instanceof jdbcBlob) {
bap = ((jdbcBlob) pattern).data;
} else {
bap = pattern.getBytes(1,iplen);
}
final int stop = dlen - iplen;
final byte b0 = bap[0];
outer_loop:
for (int i = (int) start; i <= stop; i++) {
if (ldata[i] != b0) {
continue;
}
int len = iplen;
int doffset = i;
int poffset = 0;
while (len-- > 0) {
if (ldata[doffset++] != bap[poffset++]) {
continue outer_loop;
}
}
return i + 1;
}
return -1;
}
项目:incubator-netbeans
文件:SuperPatternFilter.java
protected boolean testValue(final Object value) {
if (value == null) {
return false;
}
final String valueStr;
if (value instanceof Blob) {
valueStr = LobHelper.blobToString((Blob) value);
} else if (value instanceof Clob) {
valueStr = LobHelper.clobToString((Clob) value);
} else {
valueStr = value.toString();
}
switch (mode) {
case LIteraL_FIND:
if (filterStr == null || filterStr.length() == 0) {
return true;
} else {
return valueStr.toupperCase().contains(filterStr.toupperCase());
}
case LIteraL_MATCH:
if (filterStr == null || filterStr.length() == 0) {
return true;
} else {
return filterStr.equals(valueStr);
}
case REGEX_FIND:
return pattern.matcher(valueStr).find();
case REGEX_MATCH:
return pattern.matcher(valueStr).matches();
default:
throw new RuntimeException(UNKOWN_MODE);
}
}
项目:incubator-netbeans
文件:StringFallbackRowSorter.java
项目:BibliotecaPS
文件:CallableStatementWrapper.java
public Blob getBlob(String parameterName) throws sqlException {
try {
if (this.wrappedStmt != null) {
return ((CallableStatement) this.wrappedStmt).getBlob(parameterName);
}
throw sqlError.createsqlException("No operations allowed after statement closed",sqlError.sql_STATE_GENERAL_ERROR,this.exceptionInterceptor);
} catch (sqlException sqlEx) {
checkAndFireConnectionError(sqlEx);
}
return null;
}
/**
* Actually read a BlobRef instance from the ResultSet and materialize
* the data either inline or to a file.
*
* @param colNum the column of the ResultSet's current row to read.
* @param r the ResultSet to read from.
* @return a BlobRef encapsulating the data in this field.
* @throws IOException if an error occurs writing to the FileSystem.
* @throws sqlException if an error occurs reading from the database.
*/
public com.cloudera.sqoop.lib.BlobRef readBlobRef(int colNum,ResultSet r)
throws IOException,InterruptedException,sqlException {
long maxInlineLobLen = conf.getLong(
MAX_INLINE_LOB_LEN_KEY,DEFAULT_MAX_LOB_LENGTH);
Blob b = r.getBlob(colNum);
if (null == b) {
return null;
} else if (b.length() > maxInlineLobLen) {
// Deserialize very large BLOBs into separate files.
long len = b.length();
LobFile.Writer lobWriter = getBlobWriter();
long recordOffset = lobWriter.tell();
InputStream is = null;
OutputStream os = lobWriter.writeBlobRecord(len);
try {
is = b.getBinaryStream();
copyAll(is,os);
} finally {
if (null != os) {
os.close();
}
if (null != is) {
is.close();
}
// Mark the record as finished.
lobWriter.finishRecord();
}
return new com.cloudera.sqoop.lib.BlobRef(
getRelativePath(curBlobWriter),recordOffset,len);
} else {
// This is a 1-based array.
return new com.cloudera.sqoop.lib.BlobRef(
b.getBytes(1,(int) b.length()));
}
}
项目:the-vigilantes
文件:CallableStatement.java
/**
* @see java.sql.CallableStatement#getBlob(int)
*/
public Blob getBlob(int parameterIndex) throws sqlException {
synchronized (checkClosed().getConnectionMutex()) {
ResultSetInternalMethods rs = getoutputParameters(parameterIndex);
Blob retValue = rs.getBlob(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
}
项目:lams
文件:SerializableBlobProxy.java
/**
* Access to the wrapped Blob reference
*
* @return The wrapped Blob reference
*/
public Blob getWrappedBlob() {
if ( blob == null ) {
throw new IllegalStateException( "Blobs may not be accessed after serialization" );
}
else {
return blob;
}
}
项目:dswork.jdbc
文件:ConnectionSpy.java
项目:OpenDiabetes
文件:JDBCResultSet.java
/**
* <!-- start generic documentation -->
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>Blob</code> object
* in the Java programming language.
* <!-- end generic documentation -->
*
* <!-- start release-specific documentation -->
* <div class="ReleaseSpecificDocumentation">
* <h3>HsqlDB-Specific @R_468_4045@ion:</h3> <p>
*
* HsqlDB 2.0 supports this feature for objects of type BLOB and BINARY.
* The Blob returned for BINARY objects is a memory object. The Blob
* return for BLOB objects is not held entirely in memory. Its contents are
* fetched from the database when its getXXX() methods are called. <p>
* </div>
* <!-- end release-specific documentation -->
*
* @param columnIndex the first column is 1,the second is 2,...
* @return a <code>Blob</code> object representing the sql
* <code>BLOB</code> value in the specified column
* @exception sqlException if a database access error occurs
* or this method is called on a closed result set
* @exception sqlFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since JDK 1.2
*/
public Blob getBlob(int columnIndex) throws sqlException {
checkColumn(columnIndex);
Type sourceType = resultMetaData.columnTypes[columnIndex - 1];
Object o = getColumnInType(columnIndex,sourceType);
if (o == null) {
return null;
}
if (o instanceof BlobDataID) {
JDBCBlobClient blob = new JDBCBlobClient(session,(BlobDataID) o);
if (isUpdatable) {
if (resultMetaData.colIndexes[columnIndex - 1] > 0
&& resultMetaData.columns[columnIndex - 1]
.isWriteable()) {
blob.setWritable(this,columnIndex - 1);
}
}
return blob;
} else if (o instanceof Blob) {
return (Blob) o;
} else if (o instanceof BinaryData) {
byte[] b = getBytes(columnIndex);
return new JDBCBlob(b);
}
throw JDBCUtil.sqlException(ErrorCode.X_42561);
}
项目:lams
文件:CallableStatementWrapper.java
public Blob getBlob(int parameterIndex) throws sqlException {
try {
if (this.wrappedStmt != null) {
return ((CallableStatement) this.wrappedStmt).getBlob(parameterIndex);
}
throw sqlError.createsqlException("No operations allowed after statement closed",this.exceptionInterceptor);
} catch (sqlException sqlEx) {
checkAndFireConnectionError(sqlEx);
}
return null;
}
项目:lams
文件:JDBC4CallableStatementWrapper.java
public void setBlob(String parameterName,Blob x) throws sqlException {
try {
if (this.wrappedStmt != null) {
((CallableStatement) this.wrappedStmt).setBlob(parameterName,x);
} else {
throw sqlError.createsqlException("No operations allowed after statement closed",this.exceptionInterceptor);
}
} catch (sqlException sqlEx) {
checkAndFireConnectionError(sqlEx);
}
}
public Blob createBlob() {
try {
transactionBegun();
return getActiveConnection().createBlob();
} catch (sqlException ex) {
throw new RuntimeException(ex);
}
}
项目:lams
文件:DefaultLobHandler.java
@Override
public void setBlobAsBinaryStream(
PreparedStatement ps,InputStream binaryStream,int contentLength)
throws sqlException {
if (streamAsLob) {
if (binaryStream != null) {
ps.setBlob(paramIndex,binaryStream,contentLength);
}
else {
ps.setBlob(paramIndex,(Blob) null);
}
}
else if (wrapAsLob) {
if (binaryStream != null) {
ps.setBlob(paramIndex,new PassthroughBlob(binaryStream,contentLength));
}
else {
ps.setBlob(paramIndex,(Blob) null);
}
}
else {
ps.setBinaryStream(paramIndex,contentLength);
}
if (logger.isDebugEnabled()) {
logger.debug(binaryStream != null ? "Set binary stream for BLOB with length " + contentLength :
"Set BLOB to null");
}
}
项目:lams
文件:BlobTypeDescriptor.java
@SuppressWarnings({ "unchecked" })
public <X> X unwrap(Blob value,WrapperOptions options) {
if ( value == null ) {
return null;
}
try {
if ( BinaryStream.class.isAssignableFrom( type ) ) {
if ( BlobImplementer.class.isinstance( value ) ) {
// if the incoming Blob is a wrapper,just pass along its BinaryStream
return (X) ( (BlobImplementer) value ).getUnderlyingStream();
}
else {
// otherwise we need to build a BinaryStream...
return (X) new BinaryStreamImpl( DataHelper.extractBytes( value.getBinaryStream() ) );
}
}
else if ( byte[].class.isAssignableFrom( type )) {
if ( BlobImplementer.class.isinstance( value ) ) {
// if the incoming Blob is a wrapper,just grab the bytes from its BinaryStream
return (X) ( (BlobImplementer) value ).getUnderlyingStream().getBytes();
}
else {
// otherwise extract the bytes from the stream manually
return (X) DataHelper.extractBytes( value.getBinaryStream() );
}
}
else if (Blob.class.isAssignableFrom( type )) {
final Blob blob = WrappedBlob.class.isinstance( value )
? ( (WrappedBlob) value ).getWrappedBlob()
: value;
return (X) blob;
}
}
catch ( sqlException e ) {
throw new HibernateException( "Unable to access blob stream",e );
}
throw unkNownUnwrap( type );
}
项目:document-management-store-app
文件:DocumentContentVersion.java
public DocumentContentVersion(StoredDocument item,multipartfile file,Blob data) {
this.mimeType = file.getContentType();
setoriginalDocumentName(file.getoriginalFilename());
this.size = file.getSize();
this.documentContent = new DocumentContent(this,data);
this.storedDocument = item;
}
项目:BibliotecaPS
文件:CallableStatement.java
/**
* @see java.sql.CallableStatement#getBlob(java.lang.String)
*/
public Blob getBlob(String parameterName) throws sqlException {
synchronized (checkClosed().getConnectionMutex()) {
ResultSetInternalMethods rs = getoutputParameters(0); // definitely not going to be from ?=
Blob retValue = rs.getBlob(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
}
项目:OpenVertretung
文件:ServerPreparedStatement.java
/**
* Sends stream-type data parameters to the server.
*
* <pre>
*
* Long data handling:
*
* - Server gets the long data in pieces with command type 'COM_LONG_DATA'.
* - The packet recieved will have the format as:
* [COM_LONG_DATA: 1][STMT_ID:4][parameter_number:2][type:2][data]
* - Checks if the type is specified by client,and if yes reads the type,* and stores the data in that format.
* - It's up to the client to check for read data ended. The server doesn't
* care; and also server doesn't notify to the client that it got the
* data or not; if there is any error; then during execute; the error
* will be returned
*
* </pre>
*
* @param parameterIndex
* @param longData
*
* @throws sqlException
* if an error occurs.
*/
private void serverLongData(int parameterIndex,BindValue longData) throws sqlException {
synchronized (checkClosed().getConnectionMutex()) {
MysqLIO MysqL = this.connection.getIO();
Buffer packet = MysqL.getSharedSendPacket();
Object value = longData.value;
if (value instanceof byte[]) {
packet.clear();
packet.writeByte((byte) MysqLDefs.COM_LONG_DATA);
packet.writeLong(this.serverStatementId);
packet.writeInt((parameterIndex));
packet.writeBytesNoNull((byte[]) longData.value);
MysqL.sendCommand(MysqLDefs.COM_LONG_DATA,null,packet,true,0);
} else if (value instanceof InputStream) {
storeStream(MysqL,parameterIndex,(InputStream) value);
} else if (value instanceof java.sql.Blob) {
storeStream(MysqL,((java.sql.Blob) value).getBinaryStream());
} else if (value instanceof Reader) {
storeReader(MysqL,(Reader) value);
} else {
throw sqlError.createsqlException(Messages.getString("ServerPreparedStatement.18") + value.getClass().getName() + "'",sqlError.sql_STATE_ILLEgal_ARGUMENT,getExceptionInterceptor());
}
}
}
项目:spanner-jdbc
文件:AbstractCloudSpannerResultSet.java
项目:calcite-avatica
文件:AvaticaResultSet.java
public void updateBlob(String columnLabel,Blob x) throws sqlException {
throw statement.connection.helper.unsupported();
}
项目:spanner-jdbc
文件:AbstractCloudSpannerResultSet.java
项目:spanner-jdbc
文件:AbstractCloudSpannerPreparedStatement.java
项目:QDrill
文件:Drill2489CallsAfterCloseThrowExceptionsTest.java
项目:incubator-netbeans
文件:ResultSetAdapter.java
@Override
public Blob getBlob(int columnIndex) throws sqlException {
throw new UnsupportedOperationException("Not supported yet.");
}
项目:incubator-netbeans
文件:ResultSetAdapter.java
@Override
public void updateBlob(int columnIndex,Blob x) throws sqlException {
throw new UnsupportedOperationException("Not supported yet.");
}
/**
* @see java.sql.Connection#createBlob()
*/
public Blob createBlob() {
return this.getJDBC4Connection().createBlob();
}
项目:openjdk-jdk10
文件:StubSyncResolver.java
@Override
public void setBlob(int i,Blob x) throws sqlException {
throw new UnsupportedOperationException("Not supported yet.");
}
项目:jaffa-framework
文件:TypeDefs.java
/** Gets a parameter from the ResultSet.
* @return the parameter.
* @param engineType The engine type as defined in init.xml
* @param rs The ResultSet.
* @param columnName The name of the parameter.
* @throws sqlException if a database access error occurs.
* @throws IOException if any error occurs in reading the data from the database.
*/
public Object getAppObject(ResultSet rs,String columnName,String engineType) throws sqlException,IOException {
Blob blob = rs.getBlob(columnName);
if (blob != null)
return blob.getBytes(1,(int) blob.length());
else
return null;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。