FileDocCategorySizeDatePackage
HALocalManagedConnectionFactory.javaAPI DocJBoss 4.2.16768Fri Jul 13 21:01:12 BST 2007org.jboss.resource.adapter.jdbc.local

HALocalManagedConnectionFactory

public class HALocalManagedConnectionFactory extends LocalManagedConnectionFactory
author
Alexey Loubyansky
version
$Revision: 59773 $

Fields Summary
private static final long
serialVersionUID
private URLSelector
urlSelector
private String
urlDelimiter
Constructors Summary
Methods Summary
public javax.resource.spi.ManagedConnectioncreateManagedConnection(javax.security.auth.Subject subject, javax.resource.spi.ConnectionRequestInfo cri)

      boolean trace = log.isTraceEnabled();
      Properties props = getConnectionProperties(subject, cri);
      // Some friendly drivers (Oracle, you guessed right) modify the props you supply.
      // Since we use our copy to identify compatibility in matchManagedConnection, we need
      // a pristine copy for our own use.  So give the friendly driver a copy.
      Properties copy = (Properties)props.clone();
      if(trace)
      {
         // Make yet another copy to mask the password
         Properties logCopy = copy;
         if(copy.getProperty("password") != null)
         {
            logCopy = (Properties)props.clone();
            logCopy.setProperty("password", "--hidden--");
         }
         log.trace("Using properties: " + logCopy);
      }

      return doCreateManagedConnection(copy, props);
   
private javax.resource.spi.ManagedConnectiondoCreateManagedConnection(java.util.Properties copy, java.util.Properties props)

      boolean trace = log.isTraceEnabled();
      
      if (urlSelector == null)
      {
         JBossStringBuilder buffer = new JBossStringBuilder();
         buffer.append("Missing configuration for HA local datasource. ");
         if (getConnectionURL() == null)
            buffer.append("No connection-url. ");
         if (urlDelimiter == null)
            buffer.append("No url-delimiter. ");
         throw new JBossResourceException(buffer.toString());
      }

      // try to get a connection as many times as many urls we have in the list
      for(int i = 0; i < urlSelector.getUrlList().size(); ++i)
      {
         String url = urlSelector.getUrl();

         if(trace)
         {
            log.trace("Trying to create a connection to " + url);
         }

         try
         {
            Driver d = getDriver(url);
            Connection con = d.connect(url, copy);
            if(con == null)
            {
               log.warn("Wrong driver class for this connection URL: " + url);
               urlSelector.failedUrl(url);
            }
            else
            {
               return new LocalManagedConnection(this, con, props, transactionIsolation, preparedStatementCacheSize);
            }
         }
         catch(Exception e)
         {
            log.warn("Failed to create connection for " + url + ": " + e.getMessage());
            urlSelector.failedUrl(url);
         }
      }

      // we have supposedly tried all the urls
      throw new JBossResourceException(
         "Could not create connection using any of the URLs: " + urlSelector.getUrlList()
      );
   
public java.lang.StringgetURLDelimiter()


     
   
      return urlDelimiter;
   
private voidinitUrlSelector()

      boolean trace = log.isTraceEnabled();
      
      List urlsList = new ArrayList();
      String urlsStr = getConnectionURL();
      String url;
      int urlStart = 0;
      int urlEnd = urlsStr.indexOf(urlDelimiter);
      while(urlEnd > 0)
      {
         url = urlsStr.substring(urlStart, urlEnd);
         urlsList.add(url);
         urlStart = ++urlEnd;
         urlEnd = urlsStr.indexOf(urlDelimiter, urlEnd);
         if (trace)
          log.trace("added HA connection url: " + url);
      }

      if(urlStart != urlsStr.length())
      {
         url = urlsStr.substring(urlStart, urlsStr.length());
         urlsList.add(url);
         if (trace)
            log.trace("added HA connection url: " + url);
      }

      this.urlSelector = new URLSelector(urlsList);
   
public voidsetConnectionURL(java.lang.String connectionURL)

      super.setConnectionURL(connectionURL);
      if(urlDelimiter != null)
      {
         initUrlSelector();
      }
   
public voidsetURLDelimiter(java.lang.String urlDelimiter)

      this.urlDelimiter = urlDelimiter;
      if(getConnectionURL() != null)
      {
         initUrlSelector();
      }