提交 5d76a0d3 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 5014ea9b
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jdbc;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.sql.BatchUpdateException;
import java.sql.SQLException;
public class JdbcBatchUpdateException extends BatchUpdateException {
private static final long serialVersionUID = 9006432914018679675L;
/**
* INTERNAL
*/
public JdbcBatchUpdateException(SQLException next, int[] updateCounts) {
super(next.getMessage(), next.getSQLState(), next.getErrorCode(), updateCounts);
}
/**
* INTERNAL
*/
public void printStackTrace() {
super.printStackTrace();
if(getNextException() != null) {
getNextException().printStackTrace();
}
}
/**
* INTERNAL
*/
public void printStackTrace(PrintWriter s) {
if(s!=null) {
super.printStackTrace(s);
if(getNextException() != null) {
getNextException().printStackTrace(s);
}
}
}
/**
* INTERNAL
*/
public void printStackTrace(PrintStream s) {
if(s!=null) {
super.printStackTrace(s);
if(getNextException() != null) {
getNextException().printStackTrace(s);
}
}
}
}
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jdbc;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Blob;
import java.sql.SQLException;
import org.h2.engine.Constants;
import org.h2.engine.SessionInterface;
import org.h2.message.Message;
import org.h2.message.TraceObject;
import org.h2.util.IOUtils;
import org.h2.value.Value;
/**
* Represents a BLOB value.
*/
public class JdbcBlob extends TraceObject implements Blob {
private Value value;
private JdbcConnection conn;
/**
* INTERNAL
*/
public JdbcBlob(SessionInterface session, JdbcConnection conn, Value value, int id) {
setTrace(session.getTrace(), TraceObject.BLOB, id);
this.conn = conn;
this.value = value;
}
/**
* Returns the length.
*
* @return the length
*/
public long length() throws SQLException {
try {
debugCodeCall("length");
checkClosed();
if(value.getType() == Value.BLOB) {
long precision = value.getPrecision();
if(precision > 0) {
return precision;
}
}
long size = 0;
InputStream in = value.getInputStream();
try {
byte[] buff = new byte[Constants.FILE_BLOCK_SIZE];
while(true) {
int len = in.read(buff, 0, Constants.FILE_BLOCK_SIZE);
if(len <= 0) {
break;
}
size += len;
}
} finally {
in.close();
}
return size;
} catch(Throwable e) {
throw Message.convert(e);
}
}
/**
* Truncates the object.
*
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
public void truncate(long len) throws SQLException {
debugCodeCall("truncate", len);
throw Message.getUnsupportedException();
}
/**
* Returns some bytes of the object.
*
* @param pos the index, the first byte is at position 1
* @param length the number of bytes
* @return the bytes, at most length bytes
*/
public byte[] getBytes(long pos, int length) throws SQLException {
try {
debugCode("getBytes("+pos+", "+length+");");
checkClosed();
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream in = value.getInputStream();
try {
IOUtils.skipFully(in, pos - 1);
while(length > 0) {
int x = in.read();
if(x<0) {
break;
}
out.write(x);
length--;
}
} finally {
in.close();
}
return out.toByteArray();
} catch(Throwable e) {
throw Message.convert(e);
}
}
/**
* Sets some bytes of the object.
*
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
public int setBytes(long pos, byte[] bytes) throws SQLException {
debugCode("setBytes("+pos+", bytes);");
throw Message.getUnsupportedException();
}
/**
* Sets some bytes of the object.
*
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException {
debugCode("setBytes("+pos+", bytes, "+offset+", "+len+");");
throw Message.getUnsupportedException();
}
/**
* Returns the input stream.
*
* @return the input stream
*/
public InputStream getBinaryStream() throws SQLException {
debugCodeCall("getBinaryStream");
return value.getInputStream();
}
/**
* Returns an output stream.
*
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
public OutputStream setBinaryStream(long pos) throws SQLException {
debugCodeCall("setBinaryStream", pos);
throw Message.getUnsupportedException();
}
/**
* Searches a pattern and return the position.
*
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
public long position(byte[] pattern, long start) throws SQLException {
debugCode("position(pattern, "+start+");");
throw Message.getUnsupportedException();
// TODO test
// *
// * @param pattern the pattern to search
// * @param start the index, the first byte is at position 1
// * @return the position (first byte is at position 1), or -1 for not found
// try {
// debugCode("position(pattern, "+start+");");
// if(pattern == null) {
// return -1;
// }
// if(pattern.length == 0) {
// return 1;
// }
// // TODO performance: blob pattern search is slow
// BufferedInputStream in = new BufferedInputStream(value.getInputStream());
// IOUtils.skipFully(in, start - 1);
// int pos = 0;
// int patternPos = 0;
// while(true) {
// int x = in.read();
// if(x<0) {
// break;
// }
// if(x == (pattern[patternPos] & 0xff)) {
// if(patternPos == 0) {
// in.mark(pattern.length);
// }
// if(patternPos == pattern.length) {
// return pos - patternPos;
// }
// patternPos++;
// } else {
// if(patternPos > 0) {
// in.reset();
// pos -= patternPos;
// }
// }
// pos++;
// }
// return -1;
// } catch(Throwable e) {
// throw Message.convert(e);
// }
}
/**
* Searches a pattern and return the position.
*
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
public long position(Blob blobPattern, long start) throws SQLException {
debugCode("position(blobPattern, "+start+");");
throw Message.getUnsupportedException();
// *
// * @param pattern the pattern to search
// * @param start the index, the first byte is at position 1
// * @return the position (first byte is at position 1), or -1 for not found
// try {
// debugCode("position(blobPattern, "+start+");");
// if(blobPattern == null) {
// return -1;
// }
// ByteArrayOutputStream out = new ByteArrayOutputStream();
// InputStream in = blobPattern.getBinaryStream();
// while(true) {
// int x = in.read();
// if(x < 0) {
// break;
// }
// out.write(x);
// }
// return position(out.toByteArray(), start);
// } catch(Throwable e) {
// throw Message.convert(e);
// }
}
/**
* Release all resources of this object.
*/
public void free() throws SQLException {
debugCodeCall("free");
value = null;
}
/**
* Returns the input stream, starting from an offset.
*
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
public InputStream getBinaryStream(long pos, long length) throws SQLException {
debugCode("getBinaryStream("+pos+", "+length+");");
throw Message.getUnsupportedException();
}
private void checkClosed() throws SQLException {
conn.checkClosed();
if (value == null) {
throw Message.getSQLException(Message.OBJECT_CLOSED);
}
}
}
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jdbc;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.sql.*;
import org.h2.engine.Constants;
import org.h2.engine.SessionInterface;
import org.h2.message.Message;
import org.h2.message.TraceObject;
import org.h2.util.IOUtils;
import org.h2.util.TypeConverter;
import org.h2.value.Value;
/**
* Represents a CLOB value.
*/
public class JdbcClob extends TraceObject implements Clob
//#ifdef JDK16
/*
, NClob
*/
//#endif
{
private Value value;
private JdbcConnection conn;
public JdbcClob(SessionInterface session, JdbcConnection conn, Value value, int id) {
setTrace(session.getTrace(), TraceObject.CLOB, id);
this.conn = conn;
this.value = value;
}
/**
* Returns the length.
*
* @return the length
*/
public long length() throws SQLException {
try {
debugCodeCall("length");
checkClosed();
if(value.getType() == Value.CLOB) {
long precision = value.getPrecision();
if(precision > 0) {
return precision;
}
}
Reader in = value.getReader();
try {
long size = 0;
char[] buff = new char[Constants.FILE_BLOCK_SIZE];
while(true) {
int len = in.read(buff, 0, Constants.FILE_BLOCK_SIZE);
if(len <= 0) {
break;
}
size += len;
}
return size;
} finally {
in.close();
}
} catch(Throwable e) {
throw Message.convert(e);
}
}
/**
* Truncates the object.
*
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
public void truncate(long len) throws SQLException {
debugCodeCall("truncate", len);
throw Message.getUnsupportedException();
}
/**
* Returns the input stream.
*
* @return the input stream
*/
public InputStream getAsciiStream() throws SQLException {
try {
debugCodeCall("getAsciiStream");
checkClosed();
String s = value.getString();
return s == null ? null : TypeConverter.getInputStream(s);
} catch(Throwable e) {
throw logAndConvert(e);
}
}
/**
* Returns an output stream.
*
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
public OutputStream setAsciiStream(long pos) throws SQLException {
debugCodeCall("setAsciiStream", pos);
throw Message.getUnsupportedException();
}
/**
* Returns the reader.
*
* @return the reader
*/
public Reader getCharacterStream() throws SQLException {
try {
debugCodeCall("getCharacterStream");
checkClosed();
return value.getReader();
} catch(Throwable e) {
throw logAndConvert(e);
}
}
/**
* Returns a writer.
*
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
public Writer setCharacterStream(long pos) throws SQLException {
debugCodeCall("setCharacterStream", pos);
throw Message.getUnsupportedException();
}
/**
* Returns a substring.
*
* @param pos the position (the first character is at position 1)
* @param length the number of characters
* @return the string
*/
public String getSubString(long pos, int length) throws SQLException {
try {
debugCode("getSubString("+pos+", "+length+");");
checkClosed();
if(pos < 1) {
throw Message.getInvalidValueException("pos", ""+pos);
}
if(length < 0) {
throw Message.getInvalidValueException("length", ""+length);
}
StringBuffer buff = new StringBuffer(length);
Reader reader = value.getReader();
try {
IOUtils.skipFully(reader, pos - 1);
for(int i=0; i<length; i++) {
int ch = reader.read();
if(ch < 0) {
break;
}
buff.append((char) ch);
}
} finally {
reader.close();
}
return buff.toString();
} catch(Throwable e) {
throw logAndConvert(e);
}
}
/**
* Sets a substring.
*
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
public int setString(long pos, String str) throws SQLException {
debugCode("setString("+pos+", "+quote(str)+");");
throw Message.getUnsupportedException();
}
/**
* Sets a substring.
*
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
public int setString(long pos, String str, int offset, int len) throws SQLException {
debugCode("setString("+pos+", "+quote(str)+", "+offset+", "+len+");");
throw Message.getUnsupportedException();
}
/**
* Searches a pattern and return the position.
*
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
public long position(String pattern, long start) throws SQLException {
debugCode("position("+quote(pattern)+", "+start+");");
throw Message.getUnsupportedException();
}
/**
* Searches a pattern and return the position.
*
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
public long position(Clob clobPattern, long start) throws SQLException {
debugCode("position(clobPattern, "+start+");");
throw Message.getUnsupportedException();
}
/**
* Release all resources of this object.
*/
public void free() throws SQLException {
debugCodeCall("free");
value = null;
}
/**
* Returns the reader, starting from an offset.
*
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
public Reader getCharacterStream(long pos, long length) throws SQLException {
debugCode("getCharacterStream("+pos+", "+length+");");
throw Message.getUnsupportedException();
}
private void checkClosed() throws SQLException {
conn.checkClosed();
if (value == null) {
throw Message.getSQLException(Message.OBJECT_CLOSED);
}
}
}
差异被折叠。
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jdbc;
import java.sql.*;
import org.h2.command.CommandInterface;
import org.h2.engine.SessionInterface;
import org.h2.message.Message;
import org.h2.message.TraceObject;
/**
* Information about the parameters of a prepared statement.
*/
public class JdbcParameterMetaData extends TraceObject
// #ifdef JDK14
implements ParameterMetaData
// #endif
{
private JdbcPreparedStatement prep;
private int paramCount;
/**
* Returns the number of parameters.
*
* @return the number
*/
public int getParameterCount() throws SQLException {
try {
debugCodeCall("getParameterCount");
checkClosed();
return paramCount;
} catch(Throwable e) {
throw logAndConvert(e);
}
}
/**
* Returns the parameter mode.
* Always returns parameterModeIn
*
* @return parameterModeIn
*/
public int getParameterMode(int param) throws SQLException {
try {
debugCodeCall("getParameterMode", param);
checkParameterIndex(param);
return parameterModeIn;
} catch(Throwable e) {
throw logAndConvert(e);
}
}
/**
* Returns the parameter type.
* Always returns Types.VARCHAR everything can be passed as a VARCHAR.
*
* @return Types.VARCHAR
*/
public int getParameterType(int param) throws SQLException {
try {
debugCodeCall("getParameterType", param);
checkParameterIndex(param);
return Types.VARCHAR;
} catch(Throwable e) {
throw logAndConvert(e);
}
}
/**
* Returns the parameter precision.
* Always returns 0.
*
* @return 0
*/
public int getPrecision(int param) throws SQLException {
try {
debugCodeCall("getPrecision", param);
checkParameterIndex(param);
return 0;
} catch(Throwable e) {
throw logAndConvert(e);
}
}
/**
* Returns the parameter precision.
* Always returns 0.
*
* @return 0
*/
public int getScale(int param) throws SQLException {
try {
debugCodeCall("getScale", param);
checkParameterIndex(param);
return 0;
} catch(Throwable e) {
throw logAndConvert(e);
}
}
/**
* Checks if this is nullable parameter.
* Returns ResultSetMetaData.columnNullableUnknown..
*
* @return ResultSetMetaData.columnNullableUnknown
*/
public int isNullable(int param) throws SQLException {
try {
debugCodeCall("isNullable", param);
checkParameterIndex(param);
return ResultSetMetaData.columnNullableUnknown;
} catch(Throwable e) {
throw logAndConvert(e);
}
}
/**
* Checks if this parameter is signed.
* It always returns true.
*
* @return true
*/
public boolean isSigned(int param) throws SQLException {
try {
debugCodeCall("isSigned", param);
checkParameterIndex(param);
return true;
} catch(Throwable e) {
throw logAndConvert(e);
}
}
/**
* Returns the parameter class name.
* Always returns java.lang.String.
*
* @return "java.lang.String"
*/
public String getParameterClassName(int param) throws SQLException {
try {
debugCodeCall("getParameterClassName", param);
checkParameterIndex(param);
return String.class.getName();
} catch(Throwable e) {
throw logAndConvert(e);
}
}
/**
* Returns the parameter type name.
* Always returns VARCHAR.
*
* @return "VARCHAR"
*/
public String getParameterTypeName(int param) throws SQLException {
try {
debugCodeCall("getParameterTypeName", param);
checkParameterIndex(param);
return "VARCHAR";
} catch(Throwable e) {
throw logAndConvert(e);
}
}
JdbcParameterMetaData(SessionInterface session, JdbcPreparedStatement prep, CommandInterface command, int id) {
setTrace(session.getTrace(), TraceObject.PARAMETER_META_DATA, id);
this.prep = prep;
this.paramCount = command.getParameters().size();
}
void checkParameterIndex(int param) throws SQLException {
checkClosed();
if (param < 1 || param > paramCount) {
throw Message.getInvalidValueException("" + param, "param");
}
}
void checkClosed() throws SQLException {
prep.checkClosed();
}
/**
* Return an object of this class if possible.
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
//#ifdef JDK16
/*
public Object unwrap(Class<?> iface) throws SQLException {
throw Message.getUnsupportedException();
}
*/
//#endif
/**
* Checks if unwrap can return an object of this class.
* @throws SQLException Unsupported Feature (SQL State 0A000)
*/
//#ifdef JDK16
/*
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw Message.getUnsupportedException();
}
*/
//#endif
}
差异被折叠。
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jdbc;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.sql.SQLException;
import org.h2.engine.Constants;
/**
* Represents an exception.
*/
public class JdbcSQLException extends SQLException {
private static final long serialVersionUID = -8200821788226954151L;
private Throwable cause;
private String originalMessage;
/**
* Creates a SQLException a message, sqlstate and cause.
*
* @param message the reason
* @param state the SQL state
* @param cause the exception that was the reason for this exception
*/
public JdbcSQLException(String message, String state, int errorCode, Throwable cause) {
super(message + " [" + state + "-" + Constants.BUILD_ID + "]", state, errorCode);
this.originalMessage = message;
this.cause = cause;
}
/**
* INTERNAL
*/
public String getOriginalMessage() {
return originalMessage;
}
/**
* Prints the stack trace to the standard error stream.
*/
public void printStackTrace() {
super.printStackTrace();
if (cause != null) {
cause.printStackTrace();
}
if(getNextException() != null) {
getNextException().printStackTrace();
}
}
/**
* Prints the stack trace to the specified print writer.
*
* @param s the print writer
*/
public void printStackTrace(PrintWriter s) {
if(s!=null) {
super.printStackTrace(s);
if (cause != null) {
cause.printStackTrace(s);
}
if(getNextException() != null) {
getNextException().printStackTrace(s);
}
}
}
/**
* Prints the stack trace to the specified print stream.
*
* @param s the print stream
*/
public void printStackTrace(PrintStream s) {
if(s!=null) {
super.printStackTrace(s);
if (cause != null) {
cause.printStackTrace(s);
}
if(getNextException() != null) {
getNextException().printStackTrace(s);
}
}
}
/**
* INTERNAL
*/
public Throwable getOriginalCause() {
return cause;
}
}
差异被折叠。
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论