8006139: add missing methods to javax.sql.rowset.serial.SQLInputImpl, SQLOutputImpl
Reviewed-by: naoto, ulfzibis, alanb
This commit is contained in:
parent
4e11f499f4
commit
c98a554aaf
jdk/src/share/classes/javax/sql/rowset/serial
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -55,6 +55,7 @@ import java.util.Map;
|
||||
* stream to the method <code>SQLData.readSQL</code>, which in turn
|
||||
* calls the <code>SQLInputImpl</code> reader methods
|
||||
* to read the attributes from the input stream.
|
||||
* @since 1.5
|
||||
* @see java.sql.SQLData
|
||||
*/
|
||||
public class SQLInputImpl implements SQLInput {
|
||||
@ -142,6 +143,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
throw new SQLException("SQLInputImpl exception: Invalid read " +
|
||||
"position");
|
||||
} else {
|
||||
lastValueWasNull = attrib[idx] == null;
|
||||
return attrib[idx];
|
||||
}
|
||||
}
|
||||
@ -168,16 +170,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
* position or if there are no further values in the stream.
|
||||
*/
|
||||
public String readString() throws SQLException {
|
||||
|
||||
String attrib = (String)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return null;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib;
|
||||
}
|
||||
return (String)getNextAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -195,16 +188,8 @@ public class SQLInputImpl implements SQLInput {
|
||||
* position or if there are no further values in the stream.
|
||||
*/
|
||||
public boolean readBoolean() throws SQLException {
|
||||
|
||||
Boolean attrib = (Boolean)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return false;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib.booleanValue();
|
||||
}
|
||||
return (attrib == null) ? false : attrib.booleanValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -223,14 +208,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
*/
|
||||
public byte readByte() throws SQLException {
|
||||
Byte attrib = (Byte)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return (byte)0;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib.byteValue();
|
||||
}
|
||||
return (attrib == null) ? 0 : attrib.byteValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -248,14 +226,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
*/
|
||||
public short readShort() throws SQLException {
|
||||
Short attrib = (Short)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return (short)0;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib.shortValue();
|
||||
}
|
||||
return (attrib == null) ? 0 : attrib.shortValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -273,14 +244,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
*/
|
||||
public int readInt() throws SQLException {
|
||||
Integer attrib = (Integer)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return 0;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib.intValue();
|
||||
}
|
||||
return (attrib == null) ? 0 : attrib.intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -298,14 +262,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
*/
|
||||
public long readLong() throws SQLException {
|
||||
Long attrib = (Long)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return (long)0;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib.longValue();
|
||||
}
|
||||
return (attrib == null) ? 0 : attrib.longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -323,14 +280,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
*/
|
||||
public float readFloat() throws SQLException {
|
||||
Float attrib = (Float)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return (float)0;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib.floatValue();
|
||||
}
|
||||
return (attrib == null) ? 0 : attrib.floatValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -348,14 +298,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
*/
|
||||
public double readDouble() throws SQLException {
|
||||
Double attrib = (Double)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return (double)0;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib.doubleValue();
|
||||
}
|
||||
return (attrib == null) ? 0 : attrib.doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -372,15 +315,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
* position or if there are no more values in the stream
|
||||
*/
|
||||
public java.math.BigDecimal readBigDecimal() throws SQLException {
|
||||
java.math.BigDecimal attrib = (java.math.BigDecimal)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return null;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib;
|
||||
}
|
||||
return (java.math.BigDecimal)getNextAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -397,15 +332,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
* position or if there are no more values in the stream
|
||||
*/
|
||||
public byte[] readBytes() throws SQLException {
|
||||
byte[] attrib = (byte[])getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return null;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib;
|
||||
}
|
||||
return (byte[])getNextAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -422,15 +349,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
* position or if there are no more values in the stream
|
||||
*/
|
||||
public java.sql.Date readDate() throws SQLException {
|
||||
java.sql.Date attrib = (java.sql.Date)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return null;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib;
|
||||
}
|
||||
return (java.sql.Date)getNextAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -448,15 +367,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
* position; or if there are no further values in the stream.
|
||||
*/
|
||||
public java.sql.Time readTime() throws SQLException {
|
||||
java.sql.Time attrib = (java.sql.Time)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return null;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib;
|
||||
}
|
||||
return (java.sql.Time)getNextAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -469,15 +380,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
* position; or if there are no further values in the stream.
|
||||
*/
|
||||
public java.sql.Timestamp readTimestamp() throws SQLException {
|
||||
java.sql.Timestamp attrib = (java.sql.Timestamp)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return null;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib;
|
||||
}
|
||||
return (java.sql.Timestamp)getNextAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -494,15 +397,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
* position; or if there are no further values in the stream.
|
||||
*/
|
||||
public java.io.Reader readCharacterStream() throws SQLException {
|
||||
java.io.Reader attrib = (java.io.Reader)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return null;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib;
|
||||
}
|
||||
return (java.io.Reader)getNextAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -520,15 +415,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
* position; or if there are no further values in the stream.
|
||||
*/
|
||||
public java.io.InputStream readAsciiStream() throws SQLException {
|
||||
java.io.InputStream attrib = (java.io.InputStream)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return null;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib;
|
||||
}
|
||||
return (java.io.InputStream)getNextAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -546,15 +433,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
* position; or if there are no further values in the stream.
|
||||
*/
|
||||
public java.io.InputStream readBinaryStream() throws SQLException {
|
||||
java.io.InputStream attrib = (java.io.InputStream)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return null;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib;
|
||||
}
|
||||
return (java.io.InputStream)getNextAttribute();
|
||||
}
|
||||
|
||||
//================================================================
|
||||
@ -589,39 +468,32 @@ public class SQLInputImpl implements SQLInput {
|
||||
*/
|
||||
public Object readObject() throws SQLException {
|
||||
Object attrib = getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return null;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
if (attrib instanceof Struct) {
|
||||
Struct s = (Struct)attrib;
|
||||
// look up the class in the map
|
||||
Class<?> c = map.get(s.getSQLTypeName());
|
||||
if (c != null) {
|
||||
// create new instance of the class
|
||||
SQLData obj = null;
|
||||
try {
|
||||
obj = (SQLData)c.newInstance();
|
||||
} catch (java.lang.InstantiationException ex) {
|
||||
throw new SQLException("Unable to instantiate: " +
|
||||
ex.getMessage());
|
||||
} catch (java.lang.IllegalAccessException ex) {
|
||||
throw new SQLException("Unable to instantiate: " +
|
||||
ex.getMessage());
|
||||
}
|
||||
// get the attributes from the struct
|
||||
Object attribs[] = s.getAttributes(map);
|
||||
// create the SQLInput "stream"
|
||||
SQLInputImpl sqlInput = new SQLInputImpl(attribs, map);
|
||||
// read the values...
|
||||
obj.readSQL(sqlInput, s.getSQLTypeName());
|
||||
return obj;
|
||||
if (attrib instanceof Struct) {
|
||||
Struct s = (Struct)attrib;
|
||||
// look up the class in the map
|
||||
Class<?> c = map.get(s.getSQLTypeName());
|
||||
if (c != null) {
|
||||
// create new instance of the class
|
||||
SQLData obj = null;
|
||||
try {
|
||||
obj = (SQLData)c.newInstance();
|
||||
} catch (java.lang.InstantiationException ex) {
|
||||
throw new SQLException("Unable to instantiate: " +
|
||||
ex.getMessage());
|
||||
} catch (java.lang.IllegalAccessException ex) {
|
||||
throw new SQLException("Unable to instantiate: " +
|
||||
ex.getMessage());
|
||||
}
|
||||
// get the attributes from the struct
|
||||
Object attribs[] = s.getAttributes(map);
|
||||
// create the SQLInput "stream"
|
||||
SQLInputImpl sqlInput = new SQLInputImpl(attribs, map);
|
||||
// read the values...
|
||||
obj.readSQL(sqlInput, s.getSQLTypeName());
|
||||
return obj;
|
||||
}
|
||||
return attrib;
|
||||
}
|
||||
return attrib;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -635,15 +507,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
* position; or if there are no further values in the stream.
|
||||
*/
|
||||
public Ref readRef() throws SQLException {
|
||||
Ref attrib = (Ref)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return null;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib;
|
||||
}
|
||||
return (Ref)getNextAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -664,15 +528,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
* position; or if there are no further values in the stream.
|
||||
*/
|
||||
public Blob readBlob() throws SQLException {
|
||||
Blob attrib = (Blob)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return null;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib;
|
||||
}
|
||||
return (Blob)getNextAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -693,15 +549,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
* position; or if there are no further values in the stream.
|
||||
*/
|
||||
public Clob readClob() throws SQLException {
|
||||
|
||||
Clob attrib = (Clob)getNextAttribute();
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return null;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib;
|
||||
}
|
||||
return (Clob)getNextAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -723,15 +571,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
|
||||
*/
|
||||
public Array readArray() throws SQLException {
|
||||
Array attrib = (Array)getNextAttribute();
|
||||
|
||||
if (attrib == null) {
|
||||
lastValueWasNull = true;
|
||||
return null;
|
||||
} else {
|
||||
lastValueWasNull = false;
|
||||
return attrib;
|
||||
}
|
||||
return (Array)getNextAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -766,7 +606,7 @@ public class SQLInputImpl implements SQLInput {
|
||||
* position; or if there are no further values in the stream.
|
||||
*/
|
||||
public java.net.URL readURL() throws SQLException {
|
||||
throw new SQLException("Operation not supported");
|
||||
return (java.net.URL)getNextAttribute();
|
||||
}
|
||||
|
||||
//---------------------------- JDBC 4.0 -------------------------
|
||||
@ -779,10 +619,11 @@ public class SQLInputImpl implements SQLInput {
|
||||
* at the head of the stream; <code>null</code> if the value read is
|
||||
* SQL <code>NULL</code>
|
||||
* @exception SQLException if a database access error occurs
|
||||
* @since 1.6
|
||||
*/
|
||||
public NClob readNClob() throws SQLException {
|
||||
throw new UnsupportedOperationException("Operation not supported");
|
||||
}
|
||||
return (NClob)getNextAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next attribute in the stream and returns it as a <code>String</code>
|
||||
@ -792,9 +633,10 @@ public class SQLInputImpl implements SQLInput {
|
||||
*
|
||||
* @return the attribute; if the value is SQL <code>NULL</code>, returns <code>null</code>
|
||||
* @exception SQLException if a database access error occurs
|
||||
* @since 1.6
|
||||
*/
|
||||
public String readNString() throws SQLException {
|
||||
throw new UnsupportedOperationException("Operation not supported");
|
||||
return (String)getNextAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -805,12 +647,13 @@ public class SQLInputImpl implements SQLInput {
|
||||
* at the head of the stream; <code>null</code> if the value read is
|
||||
* SQL <code>NULL</code>
|
||||
* @exception SQLException if a database access error occurs
|
||||
* @since 1.6
|
||||
*/
|
||||
public SQLXML readSQLXML() throws SQLException {
|
||||
throw new UnsupportedOperationException("Operation not supported");
|
||||
return (SQLXML)getNextAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Reads an SQL <code>ROWID</code> value from the stream and returns it as a
|
||||
* <code>RowId</code> object in the Java programming language.
|
||||
*
|
||||
@ -818,9 +661,10 @@ public class SQLInputImpl implements SQLInput {
|
||||
* at the head of the stream; <code>null</code> if the value read is
|
||||
* SQL <code>NULL</code>
|
||||
* @exception SQLException if a database access error occurs
|
||||
* @since 1.6
|
||||
*/
|
||||
public RowId readRowId() throws SQLException {
|
||||
throw new UnsupportedOperationException("Operation not supported");
|
||||
return (RowId)getNextAttribute();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -579,7 +579,7 @@ public class SQLOutputImpl implements SQLOutput {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Writes the next attribute to the stream as a <code>String</code>
|
||||
* in the Java programming language. The driver converts this to a
|
||||
* SQL <code>NCHAR</code> or
|
||||
@ -594,8 +594,8 @@ public class SQLOutputImpl implements SQLOutput {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void writeNString(String x) throws SQLException {
|
||||
throw new UnsupportedOperationException("Operation not supported");
|
||||
}
|
||||
attribs.add(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an SQL <code>NCLOB</code> value to the stream.
|
||||
@ -608,8 +608,8 @@ public class SQLOutputImpl implements SQLOutput {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void writeNClob(NClob x) throws SQLException {
|
||||
throw new UnsupportedOperationException("Operation not supported");
|
||||
}
|
||||
attribs.add(x);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -623,8 +623,8 @@ public class SQLOutputImpl implements SQLOutput {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
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 {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void writeSQLXML(SQLXML x) throws SQLException {
|
||||
throw new UnsupportedOperationException("Operation not supported");
|
||||
attribs.add(x);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user