clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject git commit: CLEREZZA-931: Properly read integer properties
Date Wed, 30 Jul 2014 09:19:37 GMT
Repository: clerezza
Updated Branches:
  refs/heads/master 95fb6ea6a -> 5d0239fdc


CLEREZZA-931: Properly read integer properties


Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/5d0239fd
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/5d0239fd
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/5d0239fd

Branch: refs/heads/master
Commit: 5d0239fdc98407257b6ec805ca99aa923953a22f
Parents: 95fb6ea
Author: Minto van der Sluis <misl@apache.org>
Authored: Wed Jul 30 11:18:52 2014 +0200
Committer: Minto van der Sluis <misl@apache.org>
Committed: Wed Jul 30 11:18:52 2014 +0200

----------------------------------------------------------------------
 .../access/VirtuosoWeightedProvider.java        | 33 ++++++++++++++------
 1 file changed, 23 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/5d0239fd/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/access/VirtuosoWeightedProvider.java
----------------------------------------------------------------------
diff --git a/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/access/VirtuosoWeightedProvider.java
b/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/access/VirtuosoWeightedProvider.java
index 82ba243..5fc1bf7 100644
--- a/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/access/VirtuosoWeightedProvider.java
+++ b/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/access/VirtuosoWeightedProvider.java
@@ -21,6 +21,7 @@ package org.apache.clerezza.rdf.virtuoso.storage.access;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.Writer;
+import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -31,6 +32,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Collections;
+import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -183,7 +185,7 @@ public class VirtuosoWeightedProvider implements WeightedTcProvider, QueryableTc
 	 *             No component context given and connection was not set.
 	 */
 	@Activate
-	public void activate(ComponentContext cCtx) {
+	public void activate(ComponentContext cCtx) throws ConfigurationException {
 		logger.trace("activate(ComponentContext {})", cCtx);
 		logger.info("Activating VirtuosoWeightedProvider...");
 
@@ -226,21 +228,14 @@ public class VirtuosoWeightedProvider implements WeightedTcProvider,
QueryableTc
 					}));
 				}
 
-				// FIXME The following should not be needed...
-				try {
-					this.weight = (Integer) cCtx.getProperties().get(WEIGHT);
-				} catch (NumberFormatException nfe) {
-					logger.warn(nfe.toString());
-					logger.warn("Setting weight to defaults");
-					this.weight = DEFAULT_WEIGHT;
-				}
+				weight = readIntegerProperty( cCtx.getProperties(), WEIGHT, DEFAULT_WEIGHT );
 
 				/**
 				 * Initialize connection properties
 				 */
 				// We take the configuration of the SCR component
 				Object phost = cCtx.getProperties().get(HOST);
-				Object pport = Integer.valueOf((String)cCtx.getProperties().get(PORT));
+				Object pport = readIntegerProperty( cCtx.getProperties(), PORT, null );
 				Object puser = cCtx.getProperties().get(USER);
 				Object ppwd = cCtx.getProperties().get(PASSWORD);
 
@@ -272,6 +267,7 @@ public class VirtuosoWeightedProvider implements WeightedTcProvider, QueryableTc
 				user = (String) puser;
 				pwd = (String) ppwd;
 
+				logger.info("Connecting to Virtuoso on '{}' with username '{}'", host + ":" + port, user);
 				initConnectionPoolDataSource();
 				// Prepare SPARQL data access
 				this.sparqlDataAccess = createDataAccess();
@@ -322,6 +318,23 @@ public class VirtuosoWeightedProvider implements WeightedTcProvider,
QueryableTc
 				.append(":").append(portNumber).append("/charset=UTF-8/log_enable=2")
 				.toString();
 	}
+	
+	private Integer readIntegerProperty( Dictionary<?, ?> properties, String key, Integer
defaultValue ) throws ConfigurationException {
+		// Start if with default.
+		Integer value = defaultValue;
+
+		Object propertyValue = properties.get( key );
+		if(propertyValue instanceof Number){
+			value = ((Number)propertyValue).intValue();
+		} else if(propertyValue != null){
+			try {
+				value = new BigDecimal(propertyValue.toString()).intValueExact();
+			} catch (RuntimeException e) {
+				throw new ConfigurationException( key, "Unable to parse integer!", e);
+			}
+		}
+		return value;
+	}
 
 	private Set<UriRef> readRememberedGraphs() {
 		logger.trace(" readRememberedGraphs()");


Mime
View raw message