cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [1/3] cayenne git commit: CAY-2077 Bug in CayenneRuntimeException using wrong specified string in Formatter plus cleanup
Date Fri, 24 Mar 2017 11:56:52 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 873314765 -> 2be06d62b


http://git-wip-us.apache.org/repos/asf/cayenne/blob/2be06d62/cayenne-server/src/main/java/org/apache/cayenne/util/PersistentObjectSet.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/util/PersistentObjectSet.java
b/cayenne-server/src/main/java/org/apache/cayenne/util/PersistentObjectSet.java
index 0f15550..0275e5a 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/util/PersistentObjectSet.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/util/PersistentObjectSet.java
@@ -82,16 +82,12 @@ public class PersistentObjectSet extends RelationshipFault
 
         if (value == null || value instanceof Set) {
             setObjectSet((Set) value);
-        }
-        // we can wrap non-set collections on the fly - this is needed for prefetch
-        // handling...
-        // although it seems to be breaking the contract for 'setValueDirectly' ???
-        else if (value instanceof Collection) {
+        } else if (value instanceof Collection) {
+            // we can wrap non-set collections on the fly - this is needed for prefetch handling...
+            // although it seems to be breaking the contract for 'setValueDirectly' ???
             setObjectSet(new HashSet((Collection) value));
-        }
-        else {
-            throw new CayenneRuntimeException("Value must be a list, got: "
-                    + value.getClass().getName());
+        } else {
+            throw new CayenneRuntimeException("Value must be a list, got: %s", value.getClass().getName());
         }
 
         return old;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/2be06d62/cayenne-server/src/main/java/org/apache/cayenne/velocity/VelocitySQLTemplateProcessor.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/velocity/VelocitySQLTemplateProcessor.java
b/cayenne-server/src/main/java/org/apache/cayenne/velocity/VelocitySQLTemplateProcessor.java
index 49fac9d..1fc4f14 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/velocity/VelocitySQLTemplateProcessor.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/velocity/VelocitySQLTemplateProcessor.java
@@ -192,16 +192,15 @@ public class VelocitySQLTemplateProcessor implements SQLTemplateProcessor
{
 
 	private SimpleNode parse(String template) {
 
-		SimpleNode nodeTree = null;
-
+		SimpleNode nodeTree;
 		try {
 			nodeTree = velocityRuntime.parse(new StringReader(template), template);
 		} catch (ParseException pex) {
-			throw new CayenneRuntimeException("Error parsing template '" + template + "' : " + pex.getMessage());
+			throw new CayenneRuntimeException("Error parsing template '%s' : %s", template, pex.getMessage());
 		}
 
 		if (nodeTree == null) {
-			throw new CayenneRuntimeException("Error parsing template " + template);
+			throw new CayenneRuntimeException("Error parsing template %s", template);
 		}
 
 		return nodeTree;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/2be06d62/docs/doc/src/main/resources/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt
index 4be4483..2e54c9f 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -28,6 +28,7 @@ CAY-2272 ColumnSelect: methods to manually control DISTINCT clause
 
 Bug Fixes:
 
+CAY-2077 Bug in CayenneRuntimeException using wrong specified string in Formatter
 CAY-2094 SelectById query doesn't work from ROP client
 CAY-2240 Modeler: issue with cursor rendering for EJBQL query
 CAY-2243 ObjectContext.getGraphManager().unregisterObject() inconsistencies

http://git-wip-us.apache.org/repos/asf/cayenne/blob/2be06d62/eventbridges/cayenne-xmpp/src/main/java/org/apache/cayenne/event/XMPPBridge.java
----------------------------------------------------------------------
diff --git a/eventbridges/cayenne-xmpp/src/main/java/org/apache/cayenne/event/XMPPBridge.java
b/eventbridges/cayenne-xmpp/src/main/java/org/apache/cayenne/event/XMPPBridge.java
index 5a2b339..d506d6c 100644
--- a/eventbridges/cayenne-xmpp/src/main/java/org/apache/cayenne/event/XMPPBridge.java
+++ b/eventbridges/cayenne-xmpp/src/main/java/org/apache/cayenne/event/XMPPBridge.java
@@ -117,12 +117,10 @@ public class XMPPBridge extends EventBridge {
 
         String portString = properties.get(XMPP_PORT_PROPERTY);
         if (portString != null) {
-
             try {
                 this.xmppPort = Integer.parseInt(portString);
-            }
-            catch (NumberFormatException e) {
-                throw new CayenneRuntimeException("Invalid port: " + portString);
+            } catch (NumberFormatException e) {
+                throw new CayenneRuntimeException("Invalid port: %s", portString);
             }
         }
     }
@@ -201,8 +199,7 @@ public class XMPPBridge extends EventBridge {
             if (secureConnection) {
                 int port = xmppPort > 0 ? xmppPort : DEFAULT_XMPP_SECURE_PORT;
                 this.connection = new SSLXMPPConnection(xmppHost, port);
-            }
-            else {
+            } else {
                 int port = xmppPort > 0 ? xmppPort : DEFAULT_XMPP_PORT;
                 this.connection = new XMPPConnection(xmppHost, port);
             }
@@ -212,33 +209,20 @@ public class XMPPBridge extends EventBridge {
                 // third argument ("sessionHandle" is such string); without it same
                 // loginId can not be reused from the same machine.
                 connection.login(loginId, password, sessionHandle);
-            }
-            else {
+            } else {
                 connection.loginAnonymously();
             }
+        } catch (XMPPException e) {
+            throw new CayenneRuntimeException("Error connecting to XMPP Server: %s", e.getLocalizedMessage());
         }
-        catch (XMPPException e) {
-            throw new CayenneRuntimeException("Error connecting to XMPP Server"
-                    + e.getLocalizedMessage());
-        }
-
-        String service = this.chatService != null
-                ? this.chatService
-                : DEFAULT_CHAT_SERVICE;
 
+        String service = chatService != null ? chatService : DEFAULT_CHAT_SERVICE;
         try {
-            this.groupChat = connection.createGroupChat(externalSubject
-                    + '@'
-                    + service
-                    + "."
-                    + connection.getHost());
-
+            groupChat = connection.createGroupChat(externalSubject + '@' + service + "."
+ connection.getHost());
             groupChat.join(sessionHandle);
             groupChat.addMessageListener(new XMPPListener());
-        }
-        catch (XMPPException e) {
-            throw new CayenneRuntimeException("Error setting up a group chat: "
-                    + e.getLocalizedMessage());
+        } catch (XMPPException e) {
+            throw new CayenneRuntimeException("Error setting up a group chat: %s", e.getLocalizedMessage());
         }
 
         this.connected = true;
@@ -280,19 +264,13 @@ public class XMPPBridge extends EventBridge {
 
                 // filter our own messages
                 if (sessionHandle.equals(message.getThread())) {
-                    // discarding
-                }
-                else {
-
                     String payload = message.getBody();
-
                     try {
                         Object event = deserializeFromString(payload);
                         if (event instanceof CayenneEvent) {
                             onExternalEvent((CayenneEvent) event);
                         }
-                    }
-                    catch (Exception ex) {
+                    } catch (Exception ex) {
                         // ignore for now... need to add logging.
                     }
                 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/2be06d62/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/ResolveDbRelationshipDialog.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/ResolveDbRelationshipDialog.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/ResolveDbRelationshipDialog.java
index 6c09638..4e252dd 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/ResolveDbRelationshipDialog.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/ResolveDbRelationshipDialog.java
@@ -151,16 +151,15 @@ public class ResolveDbRelationshipDialog extends CayenneDialog {
     private void initWithModel(DbRelationship aRelationship) {
         // sanity check
         if (aRelationship.getSourceEntity() == null) {
-            throw new CayenneRuntimeException("Null source entity: " + aRelationship);
+            throw new CayenneRuntimeException("Null source entity: %s", aRelationship);
         }
 
         if (aRelationship.getTargetEntity() == null) {
-            throw new CayenneRuntimeException("Null target entity: " + aRelationship);
+            throw new CayenneRuntimeException("Null target entity: %s", aRelationship);
         }
 
         if (aRelationship.getSourceEntity().getDataMap() == null) {
-            throw new CayenneRuntimeException("Null DataMap: "
-                    + aRelationship.getSourceEntity());
+            throw new CayenneRuntimeException("Null DataMap: %s", aRelationship.getSourceEntity());
         }
 
         // Once assigned, can reference relationship directly. Would it be

http://git-wip-us.apache.org/repos/asf/cayenne/blob/2be06d62/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayenneProjectPreferences.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayenneProjectPreferences.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayenneProjectPreferences.java
index f3b70f8..bc5a50a 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayenneProjectPreferences.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayenneProjectPreferences.java
@@ -37,10 +37,7 @@ public class CayenneProjectPreferences {
 
     public CayenneProjectPreferences() {
         cayennePreferences = new HashMap<>();
-
-        cayennePreferences.put(DBConnectionInfo.class, new ChildrenMapPreference(
-                new DBConnectionInfo()));
-
+        cayennePreferences.put(DBConnectionInfo.class, new ChildrenMapPreference(new DBConnectionInfo()));
         projectCayennePreferences = new HashMap<>();
 
         for (ChildrenMapPreference value : cayennePreferences.values()) {
@@ -60,13 +57,11 @@ public class CayenneProjectPreferences {
 
         if (preference == null) {
             try {
-                Constructor<? extends CayennePreference> ct = objectClass
-                        .getConstructor(Preferences.class);
+                Constructor<? extends CayennePreference> ct = objectClass.getConstructor(Preferences.class);
                 preference = ct.newInstance(preferences);
                 projectCayennePreferences.put(preferences, preference);
-            }
-            catch (Throwable e) {
-                new CayenneRuntimeException("Error initialzing preference", e);
+            } catch (Throwable e) {
+                throw new CayenneRuntimeException("Error initializing preferences", e);
             }
         }
 
@@ -78,9 +73,8 @@ public class CayenneProjectPreferences {
         try {
             preference.removeNode();
             projectCayennePreferences.remove(preference);
-        }
-        catch (BackingStoreException e) {
-            new CayenneRuntimeException("error delete preferences " + e);
+        } catch (BackingStoreException e) {
+            throw new CayenneRuntimeException("Error delete preferences", e);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/2be06d62/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/pref/ChildrenMapPreference.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/pref/ChildrenMapPreference.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/pref/ChildrenMapPreference.java
index 5e433cf..01f8757 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/pref/ChildrenMapPreference.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/pref/ChildrenMapPreference.java
@@ -18,10 +18,8 @@
  ****************************************************************/
 package org.apache.cayenne.pref;
 
-import java.lang.reflect.Constructor;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.prefs.BackingStoreException;
@@ -50,21 +48,14 @@ public class ChildrenMapPreference extends PreferenceDecorator {
 		Map<String, Object> children = new HashMap<>();
 		try {
 			String[] names = getCurrentPreference().childrenNames();
-			for (int i = 0; i < names.length; i++) {
-
+			for (String name : names) {
 				try {
-					Class cls = delegate.getClass();
-					Class partypes[] = new Class[2];
-					partypes[0] = String.class;
-					partypes[1] = boolean.class;
-					Constructor ct = cls.getConstructor(partypes);
-					Object arglist[] = new Object[2];
-					arglist[0] = names[i];
-					arglist[1] = true;
-					Object retobj = ct.newInstance(arglist);
-					children.put(names[i], retobj);
+					Object newInstance = delegate.getClass()
+							.getConstructor(String.class, boolean.class)
+							.newInstance(name, true);
+					children.put(name, newInstance);
 				} catch (Throwable e) {
-					new CayenneRuntimeException("Error initializing preference", e);
+					throw new CayenneRuntimeException("Error initializing preference", e);
 				}
 			}
 
@@ -89,18 +80,12 @@ public class ChildrenMapPreference extends PreferenceDecorator {
 
 	public CayennePreference create(String nodeName) {
 		try {
-			Class cls = delegate.getClass();
-			Class partypes[] = new Class[2];
-			partypes[0] = String.class;
-			partypes[1] = boolean.class;
-			Constructor ct = cls.getConstructor(partypes);
-			Object arglist[] = new Object[2];
-			arglist[0] = nodeName;
-			arglist[1] = false;
-			Object retobj = ct.newInstance(arglist);
-			children.put(nodeName, retobj);
+			Object newInstance = delegate.getClass()
+					.getConstructor(String.class, boolean.class)
+					.newInstance(nodeName, false);
+			children.put(nodeName, newInstance);
 		} catch (Throwable e) {
-			new CayenneRuntimeException("Error creating preference");
+			throw new CayenneRuntimeException("Error creating preference");
 		}
 		return (CayennePreference) children.get(nodeName);
 	}
@@ -111,22 +96,18 @@ public class ChildrenMapPreference extends PreferenceDecorator {
 
 	public void save() {
 		if (removeObject.size() > 0) {
-			for (int i = 0; i < removeObject.size(); i++) {
+			for (String aRemoveObject : removeObject) {
 				try {
-					delegate.getCurrentPreference().node(removeObject.get(i)).removeNode();
+					delegate.getCurrentPreference().node(aRemoveObject).removeNode();
 				} catch (BackingStoreException e) {
-					new CayenneRuntimeException("Error saving preference");
+					throw new CayenneRuntimeException("Error saving preference");
 				}
 			}
 		}
 
-		Iterator it = children.entrySet().iterator();
-		while (it.hasNext()) {
-			Map.Entry pairs = (Map.Entry) it.next();
-
-			delegate.getCurrentPreference().node((String) pairs.getKey());
+		for (Map.Entry<String, Object> pairs : children.entrySet()) {
+			delegate.getCurrentPreference().node(pairs.getKey());
 			((CayennePreference) pairs.getValue()).saveObjectPreference();
-
 		}
 	}
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/2be06d62/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/swing/BeanActionBinding.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/swing/BeanActionBinding.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/swing/BeanActionBinding.java
index 5184788..dfccc74 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/swing/BeanActionBinding.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/swing/BeanActionBinding.java
@@ -70,8 +70,7 @@ public class BeanActionBinding extends BindingBase {
         }
 
         if (!foundActionEvents) {
-            throw new CayenneRuntimeException("Component does not define action events: "
-                    + component);
+            throw new CayenneRuntimeException("Component does not define action events: %s",
component);
         }
     }
 


Mime
View raw message