[hibernate-commits] Hibernate SVN: r12729 - in shards/trunk/src: java/org/hibernate/shards/cfg and 2 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Jul 5 17:50:54 EDT 2007


Author: max.ross
Date: 2007-07-05 17:50:54 -0400 (Thu, 05 Jul 2007)
New Revision: 12729

Modified:
   shards/trunk/src/java/org/hibernate/shards/ShardedConfiguration.java
   shards/trunk/src/java/org/hibernate/shards/cfg/ConfigurationToShardConfigurationAdapter.java
   shards/trunk/src/java/org/hibernate/shards/cfg/ShardConfiguration.java
   shards/trunk/src/test/org/hibernate/shards/ShardedConfigurationTest.java
   shards/trunk/src/test/org/hibernate/shards/defaultmock/ShardConfigurationDefaultMock.java
Log:
Fix HSHARDS-37
Users can now specify a datasource instead of a username/password/url.

Modified: shards/trunk/src/java/org/hibernate/shards/ShardedConfiguration.java
===================================================================
--- shards/trunk/src/java/org/hibernate/shards/ShardedConfiguration.java	2007-07-05 01:37:10 UTC (rev 12728)
+++ shards/trunk/src/java/org/hibernate/shards/ShardedConfiguration.java	2007-07-05 21:50:54 UTC (rev 12729)
@@ -225,14 +225,25 @@
    * in the prototype config.
    */
   void populatePrototypeWithVariableProperties(ShardConfiguration config) {
-    prototypeConfiguration.setProperty(Environment.USER, config.getShardUser());
-    prototypeConfiguration.setProperty(Environment.PASS, config.getShardPassword());
-    prototypeConfiguration.setProperty(Environment.URL, config.getShardUrl());
-    prototypeConfiguration.setProperty(Environment.SESSION_FACTORY_NAME, config.getShardSessionFactoryName());
-    prototypeConfiguration.setProperty(ShardedEnvironment.SHARD_ID_PROPERTY, config.getShardId().toString());
+    safeSet(prototypeConfiguration, Environment.USER, config.getShardUser());
+    safeSet(prototypeConfiguration, Environment.PASS, config.getShardPassword());
+    safeSet(prototypeConfiguration, Environment.URL, config.getShardUrl());
+    safeSet(prototypeConfiguration, Environment.DATASOURCE, config.getShardDatasource());
+    safeSet(prototypeConfiguration, Environment.SESSION_FACTORY_NAME, config.getShardSessionFactoryName());
+    safeSet(prototypeConfiguration, ShardedEnvironment.SHARD_ID_PROPERTY, config.getShardId().toString());
   }
 
   /**
+   * Set the key to the given value on the given config, but only if the
+   * value is not null.
+   */
+  static void safeSet(Configuration config, String key, String value) {
+    if(value != null) {
+      config.setProperty(key, value);
+    }
+  }
+
+  /**
    * Helper function that creates an actual SessionFactory.
    */
   private SessionFactoryImplementor buildSessionFactory() {

Modified: shards/trunk/src/java/org/hibernate/shards/cfg/ConfigurationToShardConfigurationAdapter.java
===================================================================
--- shards/trunk/src/java/org/hibernate/shards/cfg/ConfigurationToShardConfigurationAdapter.java	2007-07-05 01:37:10 UTC (rev 12728)
+++ shards/trunk/src/java/org/hibernate/shards/cfg/ConfigurationToShardConfigurationAdapter.java	2007-07-05 21:50:54 UTC (rev 12729)
@@ -51,5 +51,9 @@
 
   public Integer getShardId() {
     return Integer.parseInt(config.getProperty(ShardedEnvironment.SHARD_ID_PROPERTY));
-  }  
+  }
+
+  public String getShardDatasource() {
+    return config.getProperty(Environment.DATASOURCE);
+  }
 }

Modified: shards/trunk/src/java/org/hibernate/shards/cfg/ShardConfiguration.java
===================================================================
--- shards/trunk/src/java/org/hibernate/shards/cfg/ShardConfiguration.java	2007-07-05 01:37:10 UTC (rev 12728)
+++ shards/trunk/src/java/org/hibernate/shards/cfg/ShardConfiguration.java	2007-07-05 21:50:54 UTC (rev 12729)
@@ -26,16 +26,19 @@
 public interface ShardConfiguration {
 
   /**
-   * @return the url of the shard
+   * @see org.hibernate.cfg.Environment#URL
+   * @return the url of the shard.
    */
   String getShardUrl();
 
   /**
+   * @see org.hibernate.cfg.Environment#USER
    * @return the user that will be sent to the shard for authentication
    */
   String getShardUser();
 
   /**
+   * @see org.hibernate.cfg.Environment#PASS
    * @return the password that will be sent to the shard for authentication
    */
   String getShardPassword();
@@ -50,4 +53,10 @@
    * @return unique id of the shard
    */
   Integer getShardId();
+
+  /**
+   * @see org.hibernate.cfg.Environment#DATASOURCE
+   * @return the datasource for the shard
+   */
+  String getShardDatasource();
 }

Modified: shards/trunk/src/test/org/hibernate/shards/ShardedConfigurationTest.java
===================================================================
--- shards/trunk/src/test/org/hibernate/shards/ShardedConfigurationTest.java	2007-07-05 01:37:10 UTC (rev 12728)
+++ shards/trunk/src/test/org/hibernate/shards/ShardedConfigurationTest.java	2007-07-05 21:50:54 UTC (rev 12729)
@@ -162,5 +162,9 @@
     public Integer getShardId() {
       return shardId;
     }
+
+    public String getShardDatasource() {
+      return null;
+    }
   }
 }

Modified: shards/trunk/src/test/org/hibernate/shards/defaultmock/ShardConfigurationDefaultMock.java
===================================================================
--- shards/trunk/src/test/org/hibernate/shards/defaultmock/ShardConfigurationDefaultMock.java	2007-07-05 01:37:10 UTC (rev 12728)
+++ shards/trunk/src/test/org/hibernate/shards/defaultmock/ShardConfigurationDefaultMock.java	2007-07-05 21:50:54 UTC (rev 12729)
@@ -43,5 +43,9 @@
   public Integer getShardId() {
     throw new UnsupportedOperationException();
   }
+
+  public String getShardDatasource() {
+    throw new UnsupportedOperationException();
+  }
 }
 




More information about the hibernate-commits mailing list