You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2013/05/22 20:29:57 UTC

svn commit: r1485321 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/services/context/ iapi/services/jmx/ impl/services/jmx/ impl/services/jmxnone/ impl/services/locks/ vti/

Author: kahatlen
Date: Wed May 22 18:29:56 2013
New Revision: 1485321

URL: http://svn.apache.org/r1485321
Log:
DERBY-5840: Clean up compiler warnings introduced by using Java 5 language features

Remove various @SuppressWarnings annotations and adjust the code so
that the compiler doesn't complain.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/context/ContextService.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/jmx/ManagementService.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmxnone/NoManagementService.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSpace.java
    db/derby/code/trunk/java/engine/org/apache/derby/vti/ForeignTableVTI.java
    db/derby/code/trunk/java/engine/org/apache/derby/vti/VTITemplate.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/context/ContextService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/context/ContextService.java?rev=1485321&r1=1485320&r2=1485321&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/context/ContextService.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/context/ContextService.java Wed May 22 18:29:56 2013
@@ -24,7 +24,7 @@ package org.apache.derby.iapi.services.c
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.HashSet;
-import java.util.Iterator;
+import java.util.Stack;
 
 import org.apache.derby.iapi.error.ShutdownException;
 import org.apache.derby.iapi.services.monitor.Monitor;
@@ -62,11 +62,11 @@ public final class ContextService //OLD 
             and this is enforced by synchronization outside the ContextManager.
             E.g for JDBC connections, synchronization at the JDBC level.
 
-		<LI> java.util.Stack containing ContextManagers - the current
+        <LI> ContextManagerStack containing ContextManagers - the current
         thread is actively using multiple different ContextManagers,
         with nesting. All ContextManagers in the stack will have
         activeThread set to the current thread, and their activeCount
-        set to -1. This is beacause nesting is soley represented by
+        set to -1. This is because nesting is solely represented by
         the stack, with the current context manager on top of the stack.
         This supports multiple levels of nesting across two stacks, e.g.
         C1->C2->C2->C1->C2.
@@ -94,7 +94,7 @@ public final class ContextService //OLD 
 		for the lifetime of the request. In this case this variable will contain a  WeakReference.
 		</UL>
         <BR>
-        Single thread for Connection exection.
+        Single thread for Connection execution.
         <pre>
         threadContextList.get() == cm
         // while in JDBC engine code
@@ -283,9 +283,7 @@ public final class ContextService //OLD 
 		if (list == null)
 			return null;
 
-		java.util.Stack stack = (java.util.Stack) list;
-		return (ContextManager) (stack.peek());
-
+        return ((ContextManagerStack) list).peek();
 	}
 
     /**
@@ -345,17 +343,17 @@ public final class ContextService //OLD 
 			return;
 		}
 
-		java.util.Stack stack = (java.util.Stack) tcl.get();
+        ContextManagerStack stack = (ContextManagerStack) tcl.get();
 
-		Object oldCM = stack.pop();
+        // Remove the context manager at the top of the stack.
+        stack.pop();
 
-		ContextManager nextCM = (ContextManager) stack.peek();
+        ContextManager nextCM = stack.peek();
 
 		boolean seenMultipleCM = false;
 		boolean seenCM = false;
-		for (int i = 0; i < stack.size(); i++) {
+        for (ContextManager stackCM : stack) {
 
-			Object stackCM = stack.elementAt(i);
 			if (stackCM != nextCM)
 				seenMultipleCM = true;
 
@@ -389,7 +387,6 @@ public final class ContextService //OLD 
      * @see ContextManager#activeCount
      * @see ContextManager#activeThread
     */
-    @SuppressWarnings("unchecked")
 	private boolean addToThreadList(Thread me, ContextManager associateCM) {
 
 		ThreadLocal<Object> tcl = threadContextList;
@@ -412,7 +409,7 @@ public final class ContextService //OLD 
 			return true;
 		}
 
- 		java.util.Stack<ContextManager> stack;
+        ContextManagerStack stack;
 		if (list instanceof ContextManager) {
             
             // Could be two situations:
@@ -432,7 +429,7 @@ public final class ContextService //OLD 
             
             // Nested, need to create a Stack of ContextManagers,
             // the top of the stack will be the active one.
-			stack = new java.util.Stack<ContextManager>();
+            stack = new ContextManagerStack();
 			tcl.set(stack);
             
             // The stack represents the true nesting
@@ -449,7 +446,7 @@ public final class ContextService //OLD 
 		{
             // existing stack, nesting represented
             // by stack entries, not activeCount.
-			stack = (java.util.Stack<ContextManager>) list;
+            stack = (ContextManagerStack) list;
 		}
 
 		stack.push(associateCM);
@@ -545,9 +542,7 @@ public final class ContextService //OLD 
 		Thread me = Thread.currentThread();
 
 		synchronized (this) {
-			for (Iterator<ContextManager> i = allContexts.iterator(); i.hasNext(); ) {
-
-				ContextManager cm = i.next();
+            for (ContextManager cm : allContexts) {
 
 				Thread active = cm.activeThread;
 
@@ -561,8 +556,8 @@ public final class ContextService //OLD 
 				if (cm.setInterrupted(c))
                 {
                     AccessController.doPrivileged(
-                            new PrivilegedAction<Object>() {
-                                public Object run()  {
+                            new PrivilegedAction<Void>() {
+                                public Void run()  {
                                     fActive.interrupt();
                                     return null;
                                 }
@@ -581,4 +576,14 @@ public final class ContextService //OLD 
         if (allContexts != null)
             allContexts.remove( cm);
     }
+
+    /** Specialized stack class that contains context managers. */
+    private static class ContextManagerStack extends Stack<ContextManager> {
+        // The class is empty. Its primary purpose is to allow type-safe casts
+        // from Object, which are needed because the stacks live in a
+        // ThreadLocal<Object> rather than ThreadLocal<Stack<ContextManager>>.
+        // Casts from Object to Stack<ContextManager> will cause an unchecked
+        // conversion warning, whereas casts from Object to ContextManagerStack
+        // won't.
+    }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/jmx/ManagementService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/jmx/ManagementService.java?rev=1485321&r1=1485320&r2=1485321&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/jmx/ManagementService.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/jmx/ManagementService.java Wed May 22 18:29:56 2013
@@ -62,8 +62,8 @@ public interface ManagementService exten
      * 
      * @return An idenitifier that can later be used to unregister the mbean.
      */
-    public Object registerMBean(Object bean,
-            Class beanInterface,
+    public <T> Object registerMBean(T bean,
+            Class<T> beanInterface,
             String keyProperties)
             throws StandardException;
     

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java?rev=1485321&r1=1485320&r2=1485321&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java Wed May 22 18:29:56 2013
@@ -201,8 +201,8 @@ public final class JMXManagementService 
      * class name without the package.
      * 
      */
-    public synchronized Object registerMBean(final Object bean,
-            final Class beanInterface,
+    public synchronized <T> Object registerMBean(final T bean,
+            final Class<T> beanInterface,
             final String keyProperties)
             throws StandardException {
 
@@ -211,7 +211,6 @@ public final class JMXManagementService 
                     DERBY_JMX_DOMAIN + ":" + keyProperties
                     + ",system=" + systemIdentifier);
 
-            @SuppressWarnings("unchecked")
             final StandardMBean standardMBean =
                 new StandardMBean(bean, beanInterface) {
                 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmxnone/NoManagementService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmxnone/NoManagementService.java?rev=1485321&r1=1485320&r2=1485321&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmxnone/NoManagementService.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmxnone/NoManagementService.java Wed May 22 18:29:56 2013
@@ -30,9 +30,9 @@ import org.apache.derby.iapi.services.jm
 public final class NoManagementService implements ManagementService {
     public NoManagementService() {
     }
-    public Object registerMBean(final Object bean,
-            final Class beanInterface,
-            final String keyProperties)
+    public <T> Object registerMBean(T bean,
+            Class<T> beanInterface,
+            String keyProperties)
     {
         return null;
     }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSpace.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSpace.java?rev=1485321&r1=1485320&r2=1485321&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSpace.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSpace.java Wed May 22 18:29:56 2013
@@ -29,6 +29,7 @@ import org.apache.derby.iapi.util.Matcha
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.error.StandardException;
 
+import java.util.ArrayDeque;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -56,7 +57,12 @@ final class LockSpace implements Compati
 	/** Reference to the owner of this compatibility space. */
 	private final LockOwner owner;
 
-	private HashMap spareGroups[] = new HashMap[3];
+    /** The maximum number of elements to cache in {@link #spareGroups}. */
+    private static final int MAX_CACHED_GROUPS = 3;
+
+    /** Cached HashMaps for storing lock groups. */
+    private final ArrayDeque<HashMap<Lock, Object>> spareGroups =
+            new ArrayDeque<HashMap<Lock, Object>>(MAX_CACHED_GROUPS);
 
 	// the Limit info.
 	private Object callbackGroup;
@@ -143,8 +149,8 @@ final class LockSpace implements Compati
 		if (dl == null)
 			return;
 
-		for (Iterator list = dl.keySet().iterator(); list.hasNext(); ) {
-			lset.unlock((Lock) list.next(), 0);
+        for (Lock lock : dl.keySet()) {
+            lset.unlock(lock, 0);
 		}
 
 		if ((callbackGroup != null) && group.equals(callbackGroup)) {
@@ -154,17 +160,8 @@ final class LockSpace implements Compati
 		saveGroup(dl);
 	}
 
-    @SuppressWarnings("unchecked")
 	private HashMap<Lock,Object> getGroupMap(Object group) {
-		HashMap[] sg = spareGroups;
-		HashMap<Lock,Object> dl = null;
-		for (int i = 0; i < 3; i++) {
-			dl = (HashMap<Lock,Object>) sg[i];
-			if (dl != null) {
-				sg[i] = null;
-				break;
-			}
-		}
+        HashMap<Lock,Object> dl = spareGroups.poll();
 
 		if (dl == null)
 			dl = new HashMap<Lock,Object>(5, 0.8f);
@@ -172,15 +169,12 @@ final class LockSpace implements Compati
 		groups.put(group, dl);
 		return dl;
 	}
-	private void saveGroup(HashMap dl) {
-		HashMap[] sg = spareGroups;
-		for (int i = 0; i < 3; i++) {
-			if (sg[i] == null) {
-				sg[i] = dl;
-				dl.clear();
-				break;
-			}
-		}
+
+    private void saveGroup(HashMap<Lock, Object> dl) {
+        if (spareGroups.size() < MAX_CACHED_GROUPS) {
+            spareGroups.offer(dl);
+            dl.clear();
+        }
 	}
 
 	/**
@@ -192,9 +186,8 @@ final class LockSpace implements Compati
 			return; //  no group at all
 
 		boolean allUnlocked = true;
-		for (Iterator e = dl.keySet().iterator(); e.hasNext(); ) {
-
-			Lock lock = (Lock) e.next();
+        for (Iterator<Lock> e = dl.keySet().iterator(); e.hasNext(); ) {
+            Lock lock = e.next();
 			if (!key.match(lock.getLockable())) {
 				allUnlocked = false;
 				continue;
@@ -246,9 +239,7 @@ final class LockSpace implements Compati
 
 	private void mergeGroups(HashMap<Lock,Object> from, HashMap<Lock,Object> into) {
 
-		for (Iterator<Lock> e = from.keySet().iterator(); e.hasNext(); ) {
-
-			Lock lock = e.next();
+        for (Lock lock : from.keySet()) {
 
 			Object lockI = into.get(lock);
 
@@ -356,10 +347,8 @@ final class LockSpace implements Compati
 
 		int count = 0;
 
-		for (Iterator<HashMap<Lock,Object>> it = groups.values().iterator(); it.hasNext(); ) {
-			HashMap<Lock,Object> group = it.next();
-			for (Iterator<Lock> locks = group.keySet().iterator(); locks.hasNext(); ) {
-					Lock lock = locks.next();
+        for (HashMap<Lock,Object> group: groups.values()) {
+            for (Lock lock: group.keySet()) {
 					count += lock.getCount();
 					if (count > bail)
 						return count;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/vti/ForeignTableVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/vti/ForeignTableVTI.java?rev=1485321&r1=1485320&r2=1485321&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/vti/ForeignTableVTI.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/vti/ForeignTableVTI.java Wed May 22 18:29:56 2013
@@ -120,7 +120,6 @@ import org.apache.derby.iapi.util.IdUtil
  * select lastName from foreignEmployee where employeeID = 2;
  * </pre>
  */
-@SuppressWarnings("deprecation")
 public	class   ForeignTableVTI extends VTITemplate implements  RestrictedVTI
 {
     ////////////////////////////////////////////////////////////////////////
@@ -243,7 +242,8 @@ public	class   ForeignTableVTI extends V
     
     public  BigDecimal 	getBigDecimal(int i) throws SQLException
     { return _foreignResultSet.getBigDecimal( mapColumnNumber( i ) ); }
-    
+
+    @Deprecated
     public  BigDecimal 	getBigDecimal(int i, int scale) throws SQLException
     { return _foreignResultSet.getBigDecimal( mapColumnNumber( i ), scale ); }
     

Modified: db/derby/code/trunk/java/engine/org/apache/derby/vti/VTITemplate.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/vti/VTITemplate.java?rev=1485321&r1=1485320&r2=1485321&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/vti/VTITemplate.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/vti/VTITemplate.java Wed May 22 18:29:56 2013
@@ -68,7 +68,6 @@ import java.util.Map;
 	For table functions and virtual tables, the database engine only calls methods defined
 	in the JDBC 2.0 definition of java.sql.ResultSet.
  */
-@SuppressWarnings("deprecation")
 public abstract class VTITemplate   implements ResultSet
 {
     public  boolean 	isWrapperFor(Class<?> iface) throws SQLException { throw notImplemented( "isWrapperFor" ); }
@@ -87,6 +86,7 @@ public abstract class VTITemplate   impl
     public long getLong(String columnName) throws SQLException { return getLong(findColumn(columnName)); }
     public float getFloat(String columnName) throws SQLException { return getFloat(findColumn(columnName)); }
     public double getDouble(String columnName) throws SQLException { return getDouble(findColumn(columnName)); }
+    @Deprecated
     public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException { return getBigDecimal(findColumn(columnName), scale); }
     public byte[] getBytes(String columnName) throws SQLException { return getBytes(findColumn(columnName)); }
     public java.sql.Date getDate(String columnName) throws SQLException { return getDate(findColumn(columnName)); }
@@ -109,15 +109,18 @@ public abstract class VTITemplate   impl
     public long getLong(int columnIndex) throws SQLException { throw notImplemented( "getLong" ); }
     public float getFloat(int columnIndex) throws SQLException { throw notImplemented( "getFloat" ); }
     public double getDouble(int columnIndex) throws SQLException { throw notImplemented( "getDouble" ); }
+    @Deprecated
     public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { throw notImplemented( "getBigDecimal" ); }
     public byte[] getBytes(int columnIndex) throws SQLException { throw notImplemented( "] getBytes" ); }
     public java.sql.Date getDate(int columnIndex) throws SQLException { throw notImplemented( "sql.Date getDate" ); }
     public java.sql.Time getTime(int columnIndex) throws SQLException { throw notImplemented( "sql.Time getTime" ); }
     public java.sql.Timestamp getTimestamp(int columnIndex) throws SQLException { throw notImplemented( "sql.Timestamp getTimestamp" ); }
     public java.io.InputStream getAsciiStream(int columnIndex) throws SQLException { throw notImplemented( "io.InputStream getAsciiStream" ); }
+    @Deprecated
     public java.io.InputStream getUnicodeStream(int columnIndex) throws SQLException { throw notImplemented( "io.InputStream getUnicodeStream" ); }
     public java.io.InputStream getBinaryStream(int columnIndex) throws SQLException { throw notImplemented( "io.InputStream getBinaryStream" ); }
     public java.io.InputStream getAsciiStream(String columnName) throws SQLException { throw notImplemented( "io.InputStream getAsciiStream" ); }
+    @Deprecated
     public java.io.InputStream getUnicodeStream(String columnName) throws SQLException { throw notImplemented( "io.InputStream getUnicodeStream" ); }
     public java.io.InputStream getBinaryStream(String columnName) throws SQLException { throw notImplemented( "io.InputStream getBinaryStream" ); }
     public SQLWarning getWarnings() throws SQLException { return null; }