1 19 20 package org.apache.avalon.excalibur.datasource.cluster; 21 22 import java.sql.Connection ; 23 import java.sql.SQLException ; 24 25 import org.apache.avalon.excalibur.datasource.NoValidConnectionException; 26 27 127 public class DefaultHashedDataSourceCluster 128 extends AbstractDataSourceCluster 129 implements HashedDataSourceCluster 130 { 131 134 public DefaultHashedDataSourceCluster() 135 { 136 } 137 138 141 144 public Connection getConnection() throws SQLException 145 { 146 throw new NoValidConnectionException( 147 "getConnection() should not be called for a " + getClass().getName() + ". " + 148 "Please verify your configuration." ); 149 } 150 151 154 157 169 public Connection getConnectionForHashObject( Object hashObject ) throws SQLException 170 { 171 return getConnectionForIndex( getIndexForHashObject( hashObject ) ); 172 } 173 174 186 public Connection getConnectionForHashCode( int hashCode ) throws SQLException 187 { 188 return getConnectionForIndex( getIndexForHashCode( hashCode ) ); 189 } 190 191 194 205 public int getIndexForHashObject( Object hashObject ) 206 { 207 return getIndexForHashCode( hashObject.hashCode() ); 208 } 209 210 221 public int getIndexForHashCode( int hashCode ) 222 { 223 227 long lHashCode = ( (long)hashCode ) & 0xffffffffL; 229 230 return (int)( lHashCode % getClusterSize() ); 231 } 232 } 233 234 | Popular Tags |