You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2014/04/12 13:17:17 UTC

svn commit: r1586849 - in /cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration: DefaultRuntimeProperties.java RuntimeProperties.java

Author: aadamchik
Date: Sat Apr 12 11:17:17 2014
New Revision: 1586849

URL: http://svn.apache.org/r1586849
Log:
adding new utility method to RuntimeProperties

this was an addition in CAY-1873 patches, but I'd like this commit to be separate from the rest
of CAY-1873 stuff, which is unrelated

Modified:
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/DefaultRuntimeProperties.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/RuntimeProperties.java

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/DefaultRuntimeProperties.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/DefaultRuntimeProperties.java?rev=1586849&r1=1586848&r2=1586849&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/DefaultRuntimeProperties.java (original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/DefaultRuntimeProperties.java Sat Apr 12 11:17:17 2014
@@ -23,10 +23,10 @@ import java.util.Map;
 import org.apache.cayenne.di.Inject;
 
 /**
- * An implementation of {@link RuntimeProperties} that returns properties that were
- * injected via a map in constructor. Each property can be overridden via -D command line
- * option (i.e. in this implementation JVM system properties take precedence over any
- * other property configuration mechanism).
+ * An implementation of {@link RuntimeProperties} that returns properties that
+ * were injected via a map in constructor. Each property can be overridden via
+ * -D command line option (i.e. in this implementation JVM system properties
+ * take precedence over any other property configuration mechanism).
  * 
  * @since 3.1
  */
@@ -38,10 +38,13 @@ public class DefaultRuntimeProperties im
         this.properties = properties;
     }
 
+    @Override
     public String get(String key) {
 
-        // TODO: note that System.getProperty uses a synchronized hashtable internally as
-        // of Java 1.6. So this method suddenly becomes a synchronization bottleneck.
+        // TODO: note that System.getProperty uses a synchronized hashtable
+        // internally as
+        // of Java 1.6. So this method suddenly becomes a synchronization
+        // bottleneck.
         String property = System.getProperty(key);
 
         if (property != null) {
@@ -50,7 +53,17 @@ public class DefaultRuntimeProperties im
 
         return properties.get(key);
     }
-    
+
+    /**
+     * @since 3.2
+     */
+    @Override
+    public String get(String key, String defaultValue) {
+        String string = get(key);
+        return string != null ? string : defaultValue;
+    }
+
+    @Override
     public long getLong(String key, long defaultValue) {
         String string = get(key);
         if (string == null) {
@@ -59,13 +72,13 @@ public class DefaultRuntimeProperties im
 
         try {
             return Long.parseLong(string);
-        }
-        catch (NumberFormatException e) {
+        } catch (NumberFormatException e) {
             // incorrect property format, should we rethrow?
             return defaultValue;
         }
     }
 
+    @Override
     public int getInt(String key, int defaultValue) {
         String string = get(key);
         if (string == null) {
@@ -74,13 +87,13 @@ public class DefaultRuntimeProperties im
 
         try {
             return Integer.parseInt(string);
-        }
-        catch (NumberFormatException e) {
+        } catch (NumberFormatException e) {
             // incorrect property format, should we rethrow?
             return defaultValue;
         }
     }
 
+    @Override
     public boolean getBoolean(String key, boolean defaultValue) {
         String string = get(key);
         return string != null ? "true".equalsIgnoreCase(string) : defaultValue;

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/RuntimeProperties.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/RuntimeProperties.java?rev=1586849&r1=1586848&r2=1586849&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/RuntimeProperties.java (original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/RuntimeProperties.java Sat Apr 12 11:17:17 2014
@@ -29,10 +29,18 @@ public interface RuntimeProperties {
      * Returns a String property value for a given key.
      */
     String get(String key);
-    
+
+    /**
+     * Returns a String property value for a given key or a default value if a
+     * value is not present in properties or is null.
+     * 
+     * @since 3.2
+     */
+    String get(String key, String defaultValue);
+
     int getInt(String key, int defaultValue);
-    
+
     long getLong(String key, long defaultValue);
-    
+
     boolean getBoolean(String key, boolean defaultValue);
 }