From b055efc73bc8b6252afe96abb75ea2e648802041 Mon Sep 17 00:00:00 2001 From: Lance Andersen Date: Tue, 12 Apr 2011 12:25:15 -0400 Subject: [PATCH] 7035615: Address lint warnings for javax.sql.rowset & com.sun.rowset Reviewed-by: alanb, darcy --- .../com/sun/rowset/CachedRowSetImpl.java | 50 ++++++---------- .../com/sun/rowset/JdbcRowSetImpl.java | 24 ++++---- .../com/sun/rowset/JoinRowSetImpl.java | 18 +++--- .../classes/javax/sql/rowset/BaseRowSet.java | 58 +++++++++---------- .../javax/sql/rowset/RowSetMetaDataImpl.java | 12 +++- .../javax/sql/rowset/RowSetProvider.java | 8 +-- 6 files changed, 81 insertions(+), 89 deletions(-) diff --git a/jdk/src/share/classes/com/sun/rowset/CachedRowSetImpl.java b/jdk/src/share/classes/com/sun/rowset/CachedRowSetImpl.java index cce2997202b..74ac1b2bf23 100644 --- a/jdk/src/share/classes/com/sun/rowset/CachedRowSetImpl.java +++ b/jdk/src/share/classes/com/sun/rowset/CachedRowSetImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 @@ -111,13 +111,13 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern */ private String tableName; - /** * A Vector object containing the Row * objects that comprise this CachedRowSetImpl object. * @serial */ - private Vector rvh; + private Vector rvh; + /** * The current postion of the cursor in this CachedRowSetImpl * object. @@ -293,12 +293,12 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern /** * The Vector holding the Match Columns */ - private Vector iMatchColumns; + private Vector iMatchColumns; /** * The Vector that will hold the Match Column names. */ - private Vector strMatchColumns; + private Vector strMatchColumns; /** * Trigger that indicates whether the active SyncProvider is exposes the @@ -484,7 +484,7 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern */ private void initContainer() { - rvh = new Vector(100); + rvh = new Vector(100); cursorPos = 0; absolutePos = 0; numRows = 0; @@ -523,12 +523,12 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern //Instantiating the vector for MatchColumns - iMatchColumns = new Vector(10); + iMatchColumns = new Vector(10); for(int i = 0; i < 10 ; i++) { iMatchColumns.add(i,Integer.valueOf(-1)); } - strMatchColumns = new Vector(10); + strMatchColumns = new Vector(10); for(int j = 0; j < 10; j++) { strMatchColumns.add(j,null); } @@ -622,7 +622,7 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern Row currentRow; int numCols; int i; - Map map = getTypeMap(); + Map> map = getTypeMap(); Object obj; int mRows; @@ -939,14 +939,9 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern */ public void acceptChanges(Connection con) throws SyncProviderException{ - try{ - setConnection(con); - acceptChanges(); - } catch (SyncProviderException spe) { - throw spe; - } catch(SQLException sqle){ - throw new SyncProviderException(sqle.getMessage()); - } + setConnection(con); + acceptChanges(); + } /** @@ -1289,14 +1284,7 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern */ public Collection toCollection() throws SQLException { - TreeMap tMap; - int count = 0; - Row origRow; - Vector newRow; - - int colCount = ((RowSetMetaDataImpl)this.getMetaData()).getColumnCount(); - - tMap = new TreeMap(); + TreeMap tMap = new TreeMap<>(); for (int i = 0; i toCollection(int column) throws SQLException { - Vector vec; - Row origRow; int nRows = numRows; - vec = new Vector(nRows); + Vector vec = new Vector<>(nRows); // create a copy CachedRowSetImpl crsTemp; @@ -2953,7 +2939,7 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern */ public Object getObject(int columnIndex) throws SQLException { Object value; - java.util.Map map; + Map> map; // sanity check. checkIndex(columnIndex); @@ -7257,7 +7243,7 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern Row currentRow; int numCols; int i; - Map map = getTypeMap(); + Map> map = getTypeMap(); Object obj; int mRows; @@ -7304,11 +7290,11 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern resultSet.absolute(start -1); } if( pageSize == 0) { - rvh = new Vector(getMaxRows()); + rvh = new Vector(getMaxRows()); } else{ - rvh = new Vector(getPageSize()); + rvh = new Vector(getPageSize()); } if (data == null) { diff --git a/jdk/src/share/classes/com/sun/rowset/JdbcRowSetImpl.java b/jdk/src/share/classes/com/sun/rowset/JdbcRowSetImpl.java index fa46e55d858..f29d7d9ef2a 100644 --- a/jdk/src/share/classes/com/sun/rowset/JdbcRowSetImpl.java +++ b/jdk/src/share/classes/com/sun/rowset/JdbcRowSetImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 @@ -93,12 +93,12 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { /** * The Vector holding the Match Columns */ - private Vector iMatchColumns; + private Vector iMatchColumns; /** * The Vector that will hold the Match Column names. */ - private Vector strMatchColumns; + private Vector strMatchColumns; protected transient JdbcRowSetResourceBundle resBundle; @@ -213,12 +213,12 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { //Instantiating the vector for MatchColumns - iMatchColumns = new Vector(10); + iMatchColumns = new Vector(10); for(int i = 0; i < 10 ; i++) { iMatchColumns.add(i,Integer.valueOf(-1)); } - strMatchColumns = new Vector(10); + strMatchColumns = new Vector(10); for(int j = 0; j < 10; j++) { strMatchColumns.add(j,null); } @@ -286,12 +286,12 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { //Instantiating the vector for MatchColumns - iMatchColumns = new Vector(10); + iMatchColumns = new Vector(10); for(int i = 0; i < 10 ; i++) { iMatchColumns.add(i,Integer.valueOf(-1)); } - strMatchColumns = new Vector(10); + strMatchColumns = new Vector(10); for(int j = 0; j < 10; j++) { strMatchColumns.add(j,null); } @@ -373,12 +373,12 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { //Instantiating the vector for MatchColumns - iMatchColumns = new Vector(10); + iMatchColumns = new Vector(10); for(int i = 0; i < 10 ; i++) { iMatchColumns.add(i,Integer.valueOf(-1)); } - strMatchColumns = new Vector(10); + strMatchColumns = new Vector(10); for(int j = 0; j < 10; j++) { strMatchColumns.add(j,null); } @@ -463,12 +463,12 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { //Instantiating the vector for MatchColumns - iMatchColumns = new Vector(10); + iMatchColumns = new Vector(10); for(int i = 0; i < 10 ; i++) { iMatchColumns.add(i,Integer.valueOf(-1)); } - strMatchColumns = new Vector(10); + strMatchColumns = new Vector(10); for(int j = 0; j < 10; j++) { strMatchColumns.add(j,null); } @@ -675,7 +675,7 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { try { - Map aMap = getTypeMap(); + Map> aMap = getTypeMap(); if( aMap != null) { conn.setTypeMap(aMap); } diff --git a/jdk/src/share/classes/com/sun/rowset/JoinRowSetImpl.java b/jdk/src/share/classes/com/sun/rowset/JoinRowSetImpl.java index 060c82375b6..05feebc2824 100644 --- a/jdk/src/share/classes/com/sun/rowset/JoinRowSetImpl.java +++ b/jdk/src/share/classes/com/sun/rowset/JoinRowSetImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 @@ -59,8 +59,8 @@ public class JoinRowSetImpl extends WebRowSetImpl implements JoinRowSet { /** * A Vector object that contains the RowSet objects * that have been added to this JoinRowSet object. - */ - private Vector vecRowSetsInJOIN; + */ + private Vector vecRowSetsInJOIN; /** * The CachedRowSet object that encapsulates this @@ -78,13 +78,13 @@ public class JoinRowSetImpl extends WebRowSetImpl implements JoinRowSet { * for this JoinRowSet object. * The last join type set forms the basis of succeeding joins. */ - private Vector vecJoinType; + private Vector vecJoinType; /** * A Vector object containing the names of all the tables entering * the join. */ - private Vector vecTableNames; + private Vector vecTableNames; /** * An int that indicates the column index of the match column. @@ -121,10 +121,10 @@ public class JoinRowSetImpl extends WebRowSetImpl implements JoinRowSet { */ public JoinRowSetImpl() throws SQLException { - vecRowSetsInJOIN = new Vector(); + vecRowSetsInJOIN = new Vector(); crsInternal = new CachedRowSetImpl(); - vecJoinType = new Vector(); - vecTableNames = new Vector(); + vecJoinType = new Vector(); + vecTableNames = new Vector(); iMatchKey = -1; strMatchKey = null; supportedJOINs = @@ -222,7 +222,7 @@ public class JoinRowSetImpl extends WebRowSetImpl implements JoinRowSet { // either of the setter methods have been set. if(boolColId){ // - ArrayList indices = new ArrayList(); + ArrayList indices = new ArrayList<>(); for(int i=0;iRowSetReaderImpl object - * that a given parameter is a Unicode stream. This - * RowSetReaderImpl object is provided as an extension of the - * SyncProvider abstract class defined in the - * SyncFactory static factory SPI mechanism. - */ -public static final int UNICODE_STREAM_PARAM = 0; + /** + * A constant indicating to a RowSetReaderImpl object + * that a given parameter is a Unicode stream. This + * RowSetReaderImpl object is provided as an extension of the + * SyncProvider abstract class defined in the + * SyncFactory static factory SPI mechanism. + */ + public static final int UNICODE_STREAM_PARAM = 0; -/** - * A constant indicating to a RowSetReaderImpl object - * that a given parameter is a binary stream. A - * RowSetReaderImpl object is provided as an extension of the - * SyncProvider abstract class defined in the - * SyncFactory static factory SPI mechanism. - */ -public static final int BINARY_STREAM_PARAM = 1; + /** + * A constant indicating to a RowSetReaderImpl object + * that a given parameter is a binary stream. A + * RowSetReaderImpl object is provided as an extension of the + * SyncProvider abstract class defined in the + * SyncFactory static factory SPI mechanism. + */ + public static final int BINARY_STREAM_PARAM = 1; -/** - * A constant indicating to a RowSetReaderImpl object - * that a given parameter is an ASCII stream. A - * RowSetReaderImpl object is provided as an extension of the - * SyncProvider abstract class defined in the - * SyncFactory static factory SPI mechanism. - */ -public static final int ASCII_STREAM_PARAM = 2; + /** + * A constant indicating to a RowSetReaderImpl object + * that a given parameter is an ASCII stream. A + * RowSetReaderImpl object is provided as an extension of the + * SyncProvider abstract class defined in the + * SyncFactory static factory SPI mechanism. + */ + public static final int ASCII_STREAM_PARAM = 2; /** * The InputStream object that will be @@ -505,21 +505,21 @@ public static final int ASCII_STREAM_PARAM = 2; * custom mapping of user-defined types. * @serial */ - private Map map; + private Map> map; /** * A Vector object that holds the list of listeners * that have registered with this RowSet object. * @serial */ - private Vector listeners; + private Vector listeners; /** * A Vector object that holds the parameters set * for this RowSet object's current command. * @serial */ - private Hashtable params; // could be transient? + private Hashtable params; // could be transient? /** * Constructs a new BaseRowSet object initialized with @@ -529,7 +529,7 @@ public static final int ASCII_STREAM_PARAM = 2; */ public BaseRowSet() { // allocate the listeners collection - listeners = new Vector(); + listeners = new Vector(); } /** @@ -542,7 +542,7 @@ public static final int ASCII_STREAM_PARAM = 2; * a RowSet implementation extending this class. */ protected void initParams() { - params = new Hashtable(); + params = new Hashtable(); } //-------------------------------------------------------------------- diff --git a/jdk/src/share/classes/javax/sql/rowset/RowSetMetaDataImpl.java b/jdk/src/share/classes/javax/sql/rowset/RowSetMetaDataImpl.java index cd18b2afd91..f4591c09cb5 100644 --- a/jdk/src/share/classes/javax/sql/rowset/RowSetMetaDataImpl.java +++ b/jdk/src/share/classes/javax/sql/rowset/RowSetMetaDataImpl.java @@ -912,7 +912,12 @@ public class RowSetMetaDataImpl implements RowSetMetaData, Serializable { * @since 1.6 */ public T unwrap(java.lang.Class iface) throws java.sql.SQLException { - return (T)this; + + if(isWrapperFor(iface)) { + return iface.cast(this); + } else { + throw new SQLException("unwrap failed for:"+ iface); + } } /** @@ -929,8 +934,9 @@ public class RowSetMetaDataImpl implements RowSetMetaData, Serializable { * @throws java.sql.SQLException if an error occurs while determining whether this is a wrapper * for an object with the given interface. * @since 1.6 - */ public boolean isWrapperFor(Class interfaces) throws SQLException { - return false; + */ + public boolean isWrapperFor(Class interfaces) throws SQLException { + return interfaces.isInstance(this); } static final long serialVersionUID = 6893806403181801867L; diff --git a/jdk/src/share/classes/javax/sql/rowset/RowSetProvider.java b/jdk/src/share/classes/javax/sql/rowset/RowSetProvider.java index 4b81baa5756..c161eded789 100644 --- a/jdk/src/share/classes/javax/sql/rowset/RowSetProvider.java +++ b/jdk/src/share/classes/javax/sql/rowset/RowSetProvider.java @@ -204,9 +204,9 @@ public class RowSetProvider { * */ static private ClassLoader getContextClassLoader() throws SecurityException { - return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() { + return AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + public ClassLoader run() { ClassLoader cl = null; cl = Thread.currentThread().getContextClassLoader(); @@ -284,9 +284,9 @@ public class RowSetProvider { static private String getSystemProperty(final String propName) { String property = null; try { - property = (String) AccessController.doPrivileged(new PrivilegedAction() { + property = AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + public String run() { return System.getProperty(propName); } });