提交 06879c2d 编写于 作者: L lancea

8006139: add missing methods to javax.sql.rowset.serial.SQLInputImpl, SQLOutputImpl

Reviewed-by: naoto, ulfzibis, alanb
上级 94082ec6
/* /*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -55,6 +55,7 @@ import java.util.Map; ...@@ -55,6 +55,7 @@ import java.util.Map;
* stream to the method <code>SQLData.readSQL</code>, which in turn * stream to the method <code>SQLData.readSQL</code>, which in turn
* calls the <code>SQLInputImpl</code> reader methods * calls the <code>SQLInputImpl</code> reader methods
* to read the attributes from the input stream. * to read the attributes from the input stream.
* @since 1.5
* @see java.sql.SQLData * @see java.sql.SQLData
*/ */
public class SQLInputImpl implements SQLInput { public class SQLInputImpl implements SQLInput {
...@@ -142,6 +143,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -142,6 +143,7 @@ public class SQLInputImpl implements SQLInput {
throw new SQLException("SQLInputImpl exception: Invalid read " + throw new SQLException("SQLInputImpl exception: Invalid read " +
"position"); "position");
} else { } else {
lastValueWasNull = attrib[idx] == null;
return attrib[idx]; return attrib[idx];
} }
} }
...@@ -168,16 +170,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -168,16 +170,7 @@ public class SQLInputImpl implements SQLInput {
* position or if there are no further values in the stream. * position or if there are no further values in the stream.
*/ */
public String readString() throws SQLException { public String readString() throws SQLException {
return (String)getNextAttribute();
String attrib = (String)getNextAttribute();
if (attrib == null) {
lastValueWasNull = true;
return null;
} else {
lastValueWasNull = false;
return attrib;
}
} }
/** /**
...@@ -195,16 +188,8 @@ public class SQLInputImpl implements SQLInput { ...@@ -195,16 +188,8 @@ public class SQLInputImpl implements SQLInput {
* position or if there are no further values in the stream. * position or if there are no further values in the stream.
*/ */
public boolean readBoolean() throws SQLException { public boolean readBoolean() throws SQLException {
Boolean attrib = (Boolean)getNextAttribute(); Boolean attrib = (Boolean)getNextAttribute();
return (attrib == null) ? false : attrib.booleanValue();
if (attrib == null) {
lastValueWasNull = true;
return false;
} else {
lastValueWasNull = false;
return attrib.booleanValue();
}
} }
/** /**
...@@ -223,14 +208,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -223,14 +208,7 @@ public class SQLInputImpl implements SQLInput {
*/ */
public byte readByte() throws SQLException { public byte readByte() throws SQLException {
Byte attrib = (Byte)getNextAttribute(); Byte attrib = (Byte)getNextAttribute();
return (attrib == null) ? 0 : attrib.byteValue();
if (attrib == null) {
lastValueWasNull = true;
return (byte)0;
} else {
lastValueWasNull = false;
return attrib.byteValue();
}
} }
/** /**
...@@ -248,14 +226,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -248,14 +226,7 @@ public class SQLInputImpl implements SQLInput {
*/ */
public short readShort() throws SQLException { public short readShort() throws SQLException {
Short attrib = (Short)getNextAttribute(); Short attrib = (Short)getNextAttribute();
return (attrib == null) ? 0 : attrib.shortValue();
if (attrib == null) {
lastValueWasNull = true;
return (short)0;
} else {
lastValueWasNull = false;
return attrib.shortValue();
}
} }
/** /**
...@@ -273,14 +244,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -273,14 +244,7 @@ public class SQLInputImpl implements SQLInput {
*/ */
public int readInt() throws SQLException { public int readInt() throws SQLException {
Integer attrib = (Integer)getNextAttribute(); Integer attrib = (Integer)getNextAttribute();
return (attrib == null) ? 0 : attrib.intValue();
if (attrib == null) {
lastValueWasNull = true;
return 0;
} else {
lastValueWasNull = false;
return attrib.intValue();
}
} }
/** /**
...@@ -298,14 +262,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -298,14 +262,7 @@ public class SQLInputImpl implements SQLInput {
*/ */
public long readLong() throws SQLException { public long readLong() throws SQLException {
Long attrib = (Long)getNextAttribute(); Long attrib = (Long)getNextAttribute();
return (attrib == null) ? 0 : attrib.longValue();
if (attrib == null) {
lastValueWasNull = true;
return (long)0;
} else {
lastValueWasNull = false;
return attrib.longValue();
}
} }
/** /**
...@@ -323,14 +280,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -323,14 +280,7 @@ public class SQLInputImpl implements SQLInput {
*/ */
public float readFloat() throws SQLException { public float readFloat() throws SQLException {
Float attrib = (Float)getNextAttribute(); Float attrib = (Float)getNextAttribute();
return (attrib == null) ? 0 : attrib.floatValue();
if (attrib == null) {
lastValueWasNull = true;
return (float)0;
} else {
lastValueWasNull = false;
return attrib.floatValue();
}
} }
/** /**
...@@ -348,14 +298,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -348,14 +298,7 @@ public class SQLInputImpl implements SQLInput {
*/ */
public double readDouble() throws SQLException { public double readDouble() throws SQLException {
Double attrib = (Double)getNextAttribute(); Double attrib = (Double)getNextAttribute();
return (attrib == null) ? 0 : attrib.doubleValue();
if (attrib == null) {
lastValueWasNull = true;
return (double)0;
} else {
lastValueWasNull = false;
return attrib.doubleValue();
}
} }
/** /**
...@@ -372,15 +315,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -372,15 +315,7 @@ public class SQLInputImpl implements SQLInput {
* position or if there are no more values in the stream * position or if there are no more values in the stream
*/ */
public java.math.BigDecimal readBigDecimal() throws SQLException { public java.math.BigDecimal readBigDecimal() throws SQLException {
java.math.BigDecimal attrib = (java.math.BigDecimal)getNextAttribute(); return (java.math.BigDecimal)getNextAttribute();
if (attrib == null) {
lastValueWasNull = true;
return null;
} else {
lastValueWasNull = false;
return attrib;
}
} }
/** /**
...@@ -397,15 +332,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -397,15 +332,7 @@ public class SQLInputImpl implements SQLInput {
* position or if there are no more values in the stream * position or if there are no more values in the stream
*/ */
public byte[] readBytes() throws SQLException { public byte[] readBytes() throws SQLException {
byte[] attrib = (byte[])getNextAttribute(); return (byte[])getNextAttribute();
if (attrib == null) {
lastValueWasNull = true;
return null;
} else {
lastValueWasNull = false;
return attrib;
}
} }
/** /**
...@@ -422,15 +349,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -422,15 +349,7 @@ public class SQLInputImpl implements SQLInput {
* position or if there are no more values in the stream * position or if there are no more values in the stream
*/ */
public java.sql.Date readDate() throws SQLException { public java.sql.Date readDate() throws SQLException {
java.sql.Date attrib = (java.sql.Date)getNextAttribute(); return (java.sql.Date)getNextAttribute();
if (attrib == null) {
lastValueWasNull = true;
return null;
} else {
lastValueWasNull = false;
return attrib;
}
} }
/** /**
...@@ -448,15 +367,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -448,15 +367,7 @@ public class SQLInputImpl implements SQLInput {
* position; or if there are no further values in the stream. * position; or if there are no further values in the stream.
*/ */
public java.sql.Time readTime() throws SQLException { public java.sql.Time readTime() throws SQLException {
java.sql.Time attrib = (java.sql.Time)getNextAttribute(); return (java.sql.Time)getNextAttribute();
if (attrib == null) {
lastValueWasNull = true;
return null;
} else {
lastValueWasNull = false;
return attrib;
}
} }
/** /**
...@@ -469,15 +380,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -469,15 +380,7 @@ public class SQLInputImpl implements SQLInput {
* position; or if there are no further values in the stream. * position; or if there are no further values in the stream.
*/ */
public java.sql.Timestamp readTimestamp() throws SQLException { public java.sql.Timestamp readTimestamp() throws SQLException {
java.sql.Timestamp attrib = (java.sql.Timestamp)getNextAttribute(); return (java.sql.Timestamp)getNextAttribute();
if (attrib == null) {
lastValueWasNull = true;
return null;
} else {
lastValueWasNull = false;
return attrib;
}
} }
/** /**
...@@ -494,15 +397,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -494,15 +397,7 @@ public class SQLInputImpl implements SQLInput {
* position; or if there are no further values in the stream. * position; or if there are no further values in the stream.
*/ */
public java.io.Reader readCharacterStream() throws SQLException { public java.io.Reader readCharacterStream() throws SQLException {
java.io.Reader attrib = (java.io.Reader)getNextAttribute(); return (java.io.Reader)getNextAttribute();
if (attrib == null) {
lastValueWasNull = true;
return null;
} else {
lastValueWasNull = false;
return attrib;
}
} }
/** /**
...@@ -520,15 +415,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -520,15 +415,7 @@ public class SQLInputImpl implements SQLInput {
* position; or if there are no further values in the stream. * position; or if there are no further values in the stream.
*/ */
public java.io.InputStream readAsciiStream() throws SQLException { public java.io.InputStream readAsciiStream() throws SQLException {
java.io.InputStream attrib = (java.io.InputStream)getNextAttribute(); return (java.io.InputStream)getNextAttribute();
if (attrib == null) {
lastValueWasNull = true;
return null;
} else {
lastValueWasNull = false;
return attrib;
}
} }
/** /**
...@@ -546,15 +433,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -546,15 +433,7 @@ public class SQLInputImpl implements SQLInput {
* position; or if there are no further values in the stream. * position; or if there are no further values in the stream.
*/ */
public java.io.InputStream readBinaryStream() throws SQLException { public java.io.InputStream readBinaryStream() throws SQLException {
java.io.InputStream attrib = (java.io.InputStream)getNextAttribute(); return (java.io.InputStream)getNextAttribute();
if (attrib == null) {
lastValueWasNull = true;
return null;
} else {
lastValueWasNull = false;
return attrib;
}
} }
//================================================================ //================================================================
...@@ -589,12 +468,6 @@ public class SQLInputImpl implements SQLInput { ...@@ -589,12 +468,6 @@ public class SQLInputImpl implements SQLInput {
*/ */
public Object readObject() throws SQLException { public Object readObject() throws SQLException {
Object attrib = getNextAttribute(); Object attrib = getNextAttribute();
if (attrib == null) {
lastValueWasNull = true;
return null;
} else {
lastValueWasNull = false;
if (attrib instanceof Struct) { if (attrib instanceof Struct) {
Struct s = (Struct)attrib; Struct s = (Struct)attrib;
// look up the class in the map // look up the class in the map
...@@ -622,7 +495,6 @@ public class SQLInputImpl implements SQLInput { ...@@ -622,7 +495,6 @@ public class SQLInputImpl implements SQLInput {
} }
return attrib; return attrib;
} }
}
/** /**
* Retrieves the value at the head of this <code>SQLInputImpl</code> object * Retrieves the value at the head of this <code>SQLInputImpl</code> object
...@@ -635,15 +507,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -635,15 +507,7 @@ public class SQLInputImpl implements SQLInput {
* position; or if there are no further values in the stream. * position; or if there are no further values in the stream.
*/ */
public Ref readRef() throws SQLException { public Ref readRef() throws SQLException {
Ref attrib = (Ref)getNextAttribute(); return (Ref)getNextAttribute();
if (attrib == null) {
lastValueWasNull = true;
return null;
} else {
lastValueWasNull = false;
return attrib;
}
} }
/** /**
...@@ -664,15 +528,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -664,15 +528,7 @@ public class SQLInputImpl implements SQLInput {
* position; or if there are no further values in the stream. * position; or if there are no further values in the stream.
*/ */
public Blob readBlob() throws SQLException { public Blob readBlob() throws SQLException {
Blob attrib = (Blob)getNextAttribute(); return (Blob)getNextAttribute();
if (attrib == null) {
lastValueWasNull = true;
return null;
} else {
lastValueWasNull = false;
return attrib;
}
} }
/** /**
...@@ -693,15 +549,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -693,15 +549,7 @@ public class SQLInputImpl implements SQLInput {
* position; or if there are no further values in the stream. * position; or if there are no further values in the stream.
*/ */
public Clob readClob() throws SQLException { public Clob readClob() throws SQLException {
return (Clob)getNextAttribute();
Clob attrib = (Clob)getNextAttribute();
if (attrib == null) {
lastValueWasNull = true;
return null;
} else {
lastValueWasNull = false;
return attrib;
}
} }
/** /**
...@@ -723,15 +571,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -723,15 +571,7 @@ public class SQLInputImpl implements SQLInput {
*/ */
public Array readArray() throws SQLException { public Array readArray() throws SQLException {
Array attrib = (Array)getNextAttribute(); return (Array)getNextAttribute();
if (attrib == null) {
lastValueWasNull = true;
return null;
} else {
lastValueWasNull = false;
return attrib;
}
} }
/** /**
...@@ -766,7 +606,7 @@ public class SQLInputImpl implements SQLInput { ...@@ -766,7 +606,7 @@ public class SQLInputImpl implements SQLInput {
* position; or if there are no further values in the stream. * position; or if there are no further values in the stream.
*/ */
public java.net.URL readURL() throws SQLException { public java.net.URL readURL() throws SQLException {
throw new SQLException("Operation not supported"); return (java.net.URL)getNextAttribute();
} }
//---------------------------- JDBC 4.0 ------------------------- //---------------------------- JDBC 4.0 -------------------------
...@@ -779,9 +619,10 @@ public class SQLInputImpl implements SQLInput { ...@@ -779,9 +619,10 @@ public class SQLInputImpl implements SQLInput {
* at the head of the stream; <code>null</code> if the value read is * at the head of the stream; <code>null</code> if the value read is
* SQL <code>NULL</code> * SQL <code>NULL</code>
* @exception SQLException if a database access error occurs * @exception SQLException if a database access error occurs
* @since 1.6
*/ */
public NClob readNClob() throws SQLException { public NClob readNClob() throws SQLException {
throw new UnsupportedOperationException("Operation not supported"); return (NClob)getNextAttribute();
} }
/** /**
...@@ -792,9 +633,10 @@ public class SQLInputImpl implements SQLInput { ...@@ -792,9 +633,10 @@ public class SQLInputImpl implements SQLInput {
* *
* @return the attribute; if the value is SQL <code>NULL</code>, returns <code>null</code> * @return the attribute; if the value is SQL <code>NULL</code>, returns <code>null</code>
* @exception SQLException if a database access error occurs * @exception SQLException if a database access error occurs
* @since 1.6
*/ */
public String readNString() throws SQLException { public String readNString() throws SQLException {
throw new UnsupportedOperationException("Operation not supported"); return (String)getNextAttribute();
} }
/** /**
...@@ -805,9 +647,10 @@ public class SQLInputImpl implements SQLInput { ...@@ -805,9 +647,10 @@ public class SQLInputImpl implements SQLInput {
* at the head of the stream; <code>null</code> if the value read is * at the head of the stream; <code>null</code> if the value read is
* SQL <code>NULL</code> * SQL <code>NULL</code>
* @exception SQLException if a database access error occurs * @exception SQLException if a database access error occurs
* @since 1.6
*/ */
public SQLXML readSQLXML() throws SQLException { public SQLXML readSQLXML() throws SQLException {
throw new UnsupportedOperationException("Operation not supported"); return (SQLXML)getNextAttribute();
} }
/** /**
...@@ -818,9 +661,10 @@ public class SQLInputImpl implements SQLInput { ...@@ -818,9 +661,10 @@ public class SQLInputImpl implements SQLInput {
* at the head of the stream; <code>null</code> if the value read is * at the head of the stream; <code>null</code> if the value read is
* SQL <code>NULL</code> * SQL <code>NULL</code>
* @exception SQLException if a database access error occurs * @exception SQLException if a database access error occurs
* @since 1.6
*/ */
public RowId readRowId() throws SQLException { public RowId readRowId() throws SQLException {
throw new UnsupportedOperationException("Operation not supported"); return (RowId)getNextAttribute();
} }
......
/* /*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -594,7 +594,7 @@ public class SQLOutputImpl implements SQLOutput { ...@@ -594,7 +594,7 @@ public class SQLOutputImpl implements SQLOutput {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void writeNString(String x) throws SQLException { public void writeNString(String x) throws SQLException {
throw new UnsupportedOperationException("Operation not supported"); attribs.add(x);
} }
/** /**
...@@ -608,7 +608,7 @@ public class SQLOutputImpl implements SQLOutput { ...@@ -608,7 +608,7 @@ public class SQLOutputImpl implements SQLOutput {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void writeNClob(NClob x) throws SQLException { public void writeNClob(NClob x) throws SQLException {
throw new UnsupportedOperationException("Operation not supported"); attribs.add(x);
} }
...@@ -623,7 +623,7 @@ public class SQLOutputImpl implements SQLOutput { ...@@ -623,7 +623,7 @@ public class SQLOutputImpl implements SQLOutput {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void writeRowId(RowId x) throws SQLException { public void writeRowId(RowId x) throws SQLException {
throw new UnsupportedOperationException("Operation not supported"); attribs.add(x);
} }
...@@ -638,7 +638,7 @@ public class SQLOutputImpl implements SQLOutput { ...@@ -638,7 +638,7 @@ public class SQLOutputImpl implements SQLOutput {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void writeSQLXML(SQLXML x) throws SQLException { public void writeSQLXML(SQLXML x) throws SQLException {
throw new UnsupportedOperationException("Operation not supported"); attribs.add(x);
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册