db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1485609 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl: services/locks/LockSpace.java store/access/PropertyConglomerate.java store/access/RAMAccessManager.java
Date Thu, 23 May 2013 08:26:21 GMT
Author: kahatlen
Date: Thu May 23 08:26:21 2013
New Revision: 1485609

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

Make the declared type of the lock groups HashMap<Lock, Lock> instead
of HashMap<Lock, Object>.

Stop suppressing unchecked conversion warnings in
PropertyConglomerate, and make all conversions checked.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSpace.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/PropertyConglomerate.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java

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=1485609&r1=1485608&r2=1485609&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 Thu
May 23 08:26:21 2013
@@ -53,7 +53,7 @@ import org.apache.derby.iapi.services.lo
 final class LockSpace implements CompatibilitySpace {
 
 	/** Map from group references to groups of locks. */
-	private final HashMap<Object,HashMap<Lock,Object>> groups;
+    private final HashMap<Object, HashMap<Lock, Lock>> groups;
 	/** Reference to the owner of this compatibility space. */
 	private final LockOwner owner;
 
@@ -61,8 +61,8 @@ final class LockSpace implements Compati
     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);
+    private final ArrayDeque<HashMap<Lock, Lock>> spareGroups =
+            new ArrayDeque<HashMap<Lock, Lock>>(MAX_CACHED_GROUPS);
 
 	// the Limit info.
 	private Object callbackGroup;
@@ -76,7 +76,7 @@ final class LockSpace implements Compati
 	 * @param owner an object representing the owner of the compatibility space
 	 */
 	LockSpace(LockOwner owner) {
-		groups = new HashMap<Object,HashMap<Lock,Object>>();
+        groups = new HashMap<Object, HashMap<Lock, Lock>>();
 		this.owner = owner;
 	}
 
@@ -97,11 +97,11 @@ final class LockSpace implements Compati
 
 		Lock lockInGroup = null;
 
-		HashMap<Lock,Object> dl = groups.get(group);
+        HashMap<Lock, Lock> dl = groups.get(group);
 		if (dl == null)	{
 			dl = getGroupMap(group);
 		} else if (lock.getCount() != 1) {
-			lockInGroup = (Lock) dl.get(lock);
+            lockInGroup = dl.get(lock);
 		}
 
 		if (lockInGroup == null) {
@@ -145,7 +145,7 @@ final class LockSpace implements Compati
 	*/
 
 	synchronized void unlockGroup(LockTable lset, Object group) {
-		HashMap<Lock,Object> dl = groups.remove(group);
+        HashMap<Lock, Lock> dl = groups.remove(group);
 		if (dl == null)
 			return;
 
@@ -160,17 +160,17 @@ final class LockSpace implements Compati
 		saveGroup(dl);
 	}
 
-	private HashMap<Lock,Object> getGroupMap(Object group) {
-        HashMap<Lock,Object> dl = spareGroups.poll();
+    private HashMap<Lock, Lock> getGroupMap(Object group) {
+        HashMap<Lock, Lock> dl = spareGroups.poll();
 
 		if (dl == null)
-			dl = new HashMap<Lock,Object>(5, 0.8f);
+            dl = new HashMap<Lock, Lock>(5, 0.8f);
 
 		groups.put(group, dl);
 		return dl;
 	}
 
-    private void saveGroup(HashMap<Lock, Object> dl) {
+    private void saveGroup(HashMap<Lock, Lock> dl) {
         if (spareGroups.size() < MAX_CACHED_GROUPS) {
             spareGroups.offer(dl);
             dl.clear();
@@ -181,7 +181,7 @@ final class LockSpace implements Compati
 		Unlock all locks in the group that match the key
 	*/
 	synchronized void unlockGroup(LockTable lset, Object group, Matchable key) {
-		HashMap<Lock,Object> dl = groups.get(group);
+        HashMap<Lock, Lock> dl = groups.get(group);
 		if (dl == null)
 			return; //  no group at all
 
@@ -206,11 +206,11 @@ final class LockSpace implements Compati
 	}
 
 	synchronized void transfer(Object oldGroup, Object newGroup) {
-		HashMap<Lock,Object> from = groups.get(oldGroup);
+        HashMap<Lock, Lock> from = groups.get(oldGroup);
 		if (from == null)
 			return;
 
-		HashMap<Lock,Object> to = groups.get(newGroup);
+        HashMap<Lock, Lock> to = groups.get(newGroup);
 		if (to == null) {
 			// simple case 
 			groups.put(newGroup, from);
@@ -237,11 +237,11 @@ final class LockSpace implements Compati
 		groups.remove(oldGroup);
 	}
 
-	private void mergeGroups(HashMap<Lock,Object> from, HashMap<Lock,Object> into)
{
+    private void mergeGroups(HashMap<Lock, Lock> from, HashMap<Lock, Lock> into)
{
 
         for (Lock lock : from.keySet()) {
 
-			Object lockI = into.get(lock);
+            Lock lockI = into.get(lock);
 
 			if (lockI == null) {
 				// lock is only in from list
@@ -249,7 +249,7 @@ final class LockSpace implements Compati
 			} else {
 				// merge the locks
 				Lock fromL = lock;
-				Lock intoL = (Lock) lockI;
+                Lock intoL = lockI;
 
 				intoL.count += fromL.getCount();
 			}
@@ -261,7 +261,7 @@ final class LockSpace implements Compati
 									 Object qualifier, Object group) {
 
 		// look for locks matching our reference and qualifier.
-		HashMap<Lock,Object> dl = groups.get(group);
+        HashMap<Lock, Lock> dl = groups.get(group);
 		if (dl == null)
 			return 0;
 
@@ -307,12 +307,11 @@ final class LockSpace implements Compati
 	synchronized boolean isLockHeld(Object group, Lockable ref, Object qualifier) {
 
 		// look for locks matching our reference and qualifier.
-		HashMap<Lock,Object> dl = groups.get(group);
+        HashMap<Lock, Lock> dl = groups.get(group);
 		if (dl == null)
 			return false;
 
-		Object heldLock = dl.get(new Lock(this, ref, qualifier));
-		return (heldLock != null);
+        return dl.containsKey(new Lock(this, ref, qualifier));
 	}
 
 	synchronized void setLimit(Object group, int limit, Limit callback) {
@@ -347,7 +346,7 @@ final class LockSpace implements Compati
 
 		int count = 0;
 
-        for (HashMap<Lock,Object> group: groups.values()) {
+        for (HashMap<Lock, Lock> group: groups.values()) {
             for (Lock lock: group.keySet()) {
 					count += lock.getCount();
 					if (count > bail)

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/PropertyConglomerate.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/PropertyConglomerate.java?rev=1485609&r1=1485608&r2=1485609&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/PropertyConglomerate.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/PropertyConglomerate.java
Thu May 23 08:26:21 2013
@@ -96,7 +96,7 @@ class PropertyConglomerate
 	protected long propertiesConglomId;
 	protected Properties serviceProperties;
 	private LockFactory lf;
-	private Dictionary	cachedSet;
+    private Dictionary<String, Object> cachedSet;
 	private CacheLock cachedLock;
 
 	private PropertyFactory  pf;
@@ -271,7 +271,7 @@ class PropertyConglomerate
 		else
 		{
 			synchronized (this) {
-				Hashtable defaults = new Hashtable();
+                Hashtable<Object, Object> defaults = new Hashtable<Object, Object>();
 				getProperties(tc,defaults,false/*!stringsOnly*/,true/*defaultsOnly*/);
 				validate(key,value,defaults);
 				valueToSave = map(key,value,defaults);
@@ -360,13 +360,12 @@ class PropertyConglomerate
 		}
 	}
 
-    @SuppressWarnings("unchecked")
 	void savePropertyDefault(TransactionController tc, String key, Serializable value)
 		 throws StandardException
 	{
 		if (saveServiceProperty(key,value)) return;
 
-		Hashtable<Object,Object> defaults = (Hashtable<Object,Object>)
+        FormatableHashtable defaults = (FormatableHashtable)
             readProperty(tc,AccessFactoryGlobals.DEFAULT_PROPERTY_NAME);
 		if (defaults == null) defaults = new FormatableHashtable();
 		if (value==null)
@@ -381,7 +380,7 @@ class PropertyConglomerate
 											 String key, Serializable value, boolean dbOnlyProperty)
 		 throws StandardException
 	{
-		Dictionary d = new Hashtable();
+        Dictionary<Object, Object> d = new Hashtable<Object, Object>();
 		getProperties(tc,d,false/*!stringsOnly*/,false/*!defaultsOnly*/);
 		Serializable mappedValue = pf.doValidateApplyAndMap(tc, key,
 																   value, d, dbOnlyProperty);
@@ -656,13 +655,15 @@ class PropertyConglomerate
 			return getCachedPropertyDefault(tc,key,null);
 		}
 	}
-									
-	private Dictionary<String,Object> copyValues(Dictionary<String,Object> to, Dictionary<String,Object>
from, boolean stringsOnly)
+
+    private <K, V> Dictionary<? super K, ? super V> copyValues(
+            Dictionary<? super K, ? super V> to,
+            Dictionary<K, V> from, boolean stringsOnly)
 	{
 		if (from == null) return to; 
-		for (Enumeration keys = from.keys(); keys.hasMoreElements(); ) {
-			String key = (String) keys.nextElement();
-			Object value = from.get(key);
+        for (Enumeration<K> keys = from.keys(); keys.hasMoreElements(); ) {
+            K key = keys.nextElement();
+            V value = from.get(key);
 			if ((value instanceof String) || !stringsOnly)
 				to.put(key, value);
 		}
@@ -679,28 +680,29 @@ class PropertyConglomerate
 		return p;
 	}
 
-    @SuppressWarnings("unchecked")
 	public void getProperties(TransactionController tc,
-							   Dictionary d,
+                               Dictionary<Object, Object> d,
 							   boolean stringsOnly,
 							   boolean defaultsOnly) throws StandardException
 	{
 		// See if I'm the exclusive owner. If so I cannot populate
 		// the cache as it would contain my uncommitted changes.
+        Dictionary<String, Object> dbProps;
 		if (iHoldTheUpdateLock(tc))
 		{
-			Dictionary dbProps = readDbProperties(tc);
-			Dictionary defaults = (Dictionary)dbProps.get(AccessFactoryGlobals.DEFAULT_PROPERTY_NAME);
-			copyValues(d,defaults,stringsOnly);
-			if (!defaultsOnly)copyValues(d,dbProps,stringsOnly);
+            dbProps = readDbProperties(tc);
 		}
 		else
 		{	
-			Dictionary dbProps = getCachedDbProperties(tc);
-			Dictionary defaults = (Dictionary)dbProps.get(AccessFactoryGlobals.DEFAULT_PROPERTY_NAME);
-			copyValues(d,defaults,stringsOnly);
-			if (!defaultsOnly)copyValues(d,dbProps,stringsOnly);
+            dbProps = getCachedDbProperties(tc);
 		}
+
+        FormatableHashtable defaults = (FormatableHashtable)
+                dbProps.get(AccessFactoryGlobals.DEFAULT_PROPERTY_NAME);
+        copyValues(d, defaults, stringsOnly);
+        if (!defaultsOnly) {
+            copyValues(d, dbProps, stringsOnly);
+        }
 	}
 
 	void resetCache() {cachedSet = null;}
@@ -739,10 +741,11 @@ class PropertyConglomerate
 		return set;
 	}
 
-	private Dictionary getCachedDbProperties(TransactionController tc)
+    private Dictionary<String, Object>
+            getCachedDbProperties(TransactionController tc)
 		 throws StandardException
 	{
-		Dictionary dbProps = cachedSet;
+        Dictionary<String, Object> dbProps = cachedSet;
 		//Get the cached set of properties.
 		if (dbProps == null)
 		{

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java?rev=1485609&r1=1485608&r2=1485609&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java
Thu May 23 08:26:21 2013
@@ -876,7 +876,7 @@ public abstract class RAMAccessManager
 		// set up the initial values by calling the validate and apply methods.
 		// the map methods are not called as they will have been called
 		// at runtime when the user set the property.
-		Dictionary d = new Hashtable();
+        Dictionary<Object, Object> d = new Hashtable<Object, Object>();
 		try {
 			xactProperties.getProperties(tc,d,false/*!stringsOnly*/,false/*!defaultsOnly*/);
 		} catch (StandardException se) {



Mime
View raw message