Package org.jboss.resource

Examples of org.jboss.resource.JBossResourceException


         }
         con.close();
      }
      catch (Throwable e)
      {
         throw new JBossResourceException
            ("Could not properly close the session and connection", e);
      }
   }
View Full Code Here


               if (trace)
                  log.trace("Using a non-XA TopicConnection.  " +
                            "It will not be able to participate in a Global UOW");
            }
            else
               throw new JBossResourceException("Connection was not recognizable: " + con);

            if (trace)
               log.trace("xaTopicSession=" + xaTopicSession + ", topicSession=" + topicSession);
         }
         else if (info.getType() == JmsConnectionFactory.QUEUE)
         {
            String jndi = adapter.getQueueFactoryRef();
            if (jndi == null)
               throw new IllegalStateException("No configured 'QueueFactoryRef' on the jms provider " + mcf.getJmsProviderAdapterJNDI());
            factory = context.lookup(jndi);
            con = ConnectionFactoryHelper.createQueueConnection(factory, user, pwd);
            if (info.getClientID() != null)
               con.setClientID(info.getClientID());
            con.setExceptionListener(this);
            if (trace)
               log.debug("created connection: " + con);

            if (con instanceof XAQueueConnection)
            {
               xaQueueSession =
                  ((XAQueueConnection)con).createXAQueueSession();
               queueSession = xaQueueSession.getQueueSession();
               xaTransacted = true;
            }
            else if (con instanceof QueueConnection)
            {
               queueSession =
                  ((QueueConnection)con).createQueueSession(transacted, ack);
               if (trace)
                  log.trace("Using a non-XA QueueConnection.  " +
                            "It will not be able to participate in a Global UOW");
            }
            else
               throw new JBossResourceException("Connection was not reconizable: " + con);

            if (trace)
               log.trace("xaQueueSession=" + xaQueueSession + ", queueSession=" + queueSession);
         }
         else
         {
            String jndi = adapter.getFactoryRef();
            if (jndi == null)
               throw new IllegalStateException("No configured 'FactoryRef' on the jms provider " + mcf.getJmsProviderAdapterJNDI());
            factory = context.lookup(jndi);
            con = ConnectionFactoryHelper.createConnection(factory, user, pwd);
            if (info.getClientID() != null)
               con.setClientID(info.getClientID());
            con.setExceptionListener(this);
            if (trace)
               log.trace("created connection: " + con);

            if (con instanceof XAConnection)
            {
               xaSession =
                  ((XAConnection)con).createXASession();
               session = xaSession.getSession();
               xaTransacted = true;
            }
            else
            {
               session = con.createSession(transacted, ack);
               if (trace)
                  log.trace("Using a non-XA Connection.  " +
                            "It will not be able to participate in a Global UOW");
            }

            if (trace)
               log.debug("xaSession=" + xaQueueSession + ", Session=" + session);
         }

         if (trace)
            log.debug("transacted=" + transacted + ", ack=" + ack);
      }
      catch (NamingException e)
      {
         throw new JBossResourceException("Unable to setup connection", e);
      }
      catch (JMSException e)
      {
         throw new JBossResourceException("Unable to setup connection", e);
      }
   }
View Full Code Here

      }
      catch (Throwable t)
      {
         if (trace)
            log.trace("Could not enlist in transaction on entering meta-aware object! " + cl, t);
         throw new JBossResourceException("Could not enlist in transaction on entering meta-aware object!", t);
      }
   }
View Full Code Here

               if (xaResource.setTransactionTimeout(xaResourceTimeout) == false)
                  log.debug("XAResource does not support transaction timeout configuration: " + getJndiName());
            }
            catch (XAException e)
            {
               throw new JBossResourceException("Unable to set XAResource transaction timeout: " + getJndiName(), e);
            }
         }
      }

      ConnectionListener cli = new TxConnectionEventListener(mc, poolingStrategy, context, log, xaResource);
View Full Code Here

   @Override
   public Object createConnectionFactory(ConnectionManager cm) throws ResourceException
   {
      // check some invariants before they come back to haunt us
      if(driverClass == null)
         throw new JBossResourceException("driverClass is null");
      if(connectionURL == null && !getUseDataSource())
         throw new JBossResourceException("connectionURL is null");
     
      return super.createConnectionFactory(cm);
   }
View Full Code Here

       {
         String url = getConnectionURL();
         Driver d = getDriver(url);
         con = d.connect(url, copy);
         if (con == null)
           throw new JBossResourceException("Wrong driver class for this connection URL");        
       }
       else
       {
         final String user = props.getProperty("user");
         final String password = props.getProperty("password");
     
         con = (user != null)
           ? getDataSource().getConnection(user, password)
           : getDataSource().getConnection();

         if (con == null)
             throw new JBossResourceException("Could not create connection from data source " + getDriverClass());        
  
       }
      
       return new LocalManagedConnection(this, con, props, transactionIsolation, preparedStatementCacheSize);
     }
     catch (Throwable e)
     {
         if (con != null)
         {
            try
            {
               con.close();
            }
            catch (Throwable ignored)
            {
            }
         }
       throw new JBossResourceException("Could not create connection", e);
     }
   }
View Full Code Here

        urlSelector.failedUrlObject(url);
        }
      }

      // we have supposedly tried all the urls
    throw new JBossResourceException(
           "Could not create connection using any of the URLs: " + urlSelector.getAllUrlObjects());
   }
View Full Code Here

      if (trace)
         log.trace("Checking driver for URL: " + url);

      if (driverClass == null)
      {
         throw new JBossResourceException("No Driver class specified (url = " + url + ")!");
      }

      // Check if the driver is already loaded, if not then try to load it

      if (isDriverLoadedForURL(url))
      {
         return driver;
      } // end of if ()

      try
      {
         //try to load the class... this should register with DriverManager.
         Class clazz = Class.forName(driverClass, true, Thread.currentThread().getContextClassLoader());
         if (isDriverLoadedForURL(url))
            //return immediately, some drivers (Cloudscape) do not let you create an instance.
            return driver;

         //We loaded the class, but either it didn't register
         //and is not spec compliant, or is the wrong class.
         driver = (Driver) clazz.newInstance();
         DriverManager.registerDriver(driver);
         if (isDriverLoadedForURL(url))
            return driver;
         //We can even instantiate one, it must be the wrong class for the URL.
      }
      catch (Exception e)
      {
         throw new JBossResourceException("Failed to register driver for: " + driverClass, e);
      }

      throw new JBossResourceException("Apparently wrong driver class specified for URL: class: " + driverClass
            + ", url: " + url);
   }
View Full Code Here

   private synchronized DataSource getDataSource() throws ResourceException {
   
     if (dataSource == null)
        {
           if (driverClass == null)
              throw new JBossResourceException("No DataSourceClass supplied!");
          
           try
           {
              Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(driverClass);
              dataSource = (DataSource) clazz.newInstance();
              Class<?>[] NOCLASSES = new Class[] {};
             
              for (Iterator i = this.connectionProps.keySet().iterator(); i.hasNext();)
              {
                 String name = (String) i.next();
                 String value = this.connectionProps.getProperty(name);     
                 char firstCharName = Character.toUpperCase(name.charAt(0));
                  if (name.length() > 1)
                       name = firstCharName+name.substring(1);
                  else
                     name = ""+firstCharName;                                                                                                  
                 //This is a bad solution.  On the other hand the only known example
                 // of a setter with no getter is for Oracle with password.
                 //Anyway, each xadatasource implementation should get its
                 //own subclass of this that explicitly sets the
                 //properties individually.
                 Class type = null;
                 try
                 {
                    Method getter = clazz.getMethod("get" + name, NOCLASSES);
                    type = getter.getReturnType();
                 }
                 catch (NoSuchMethodException e)
                 {
                    try
                    {
                       Method isMethod = clazz.getMethod("is" + name, NOCLASSES);
                       type = isMethod.getReturnType();
                    }
                    catch(NoSuchMethodException nsme)
                    {
                      log.warn("Property with name " + name + " could not be found for datasource class" + getDriverClass() + ". This property will be ignored.");
                      continue;
                    }
                 }

                 Method setter = clazz.getMethod("set" + name, new Class[] { type });
                 PropertyEditor editor = PropertyEditorManager.findEditor(type);
                 if (editor == null)
                    throw new JBossResourceException("No property editor found for type: " + type);
                 editor.setAsText(value);
                 setter.invoke(dataSource, new Object[] { editor.getValue() });
              }
           }
           catch (ClassNotFoundException cnfe)
           {
              throw new JBossResourceException("Class not found for DataSource " + getDriverClass(), cnfe);
           }
           catch (InstantiationException ie)
           {
              throw new JBossResourceException("Could not create an DataSource: ", ie);
           }
           catch (IllegalAccessException iae)
           {
              throw new JBossResourceException("Could not set a property: ", iae);
           }
           catch (IllegalArgumentException iae)
           {
              throw new JBossResourceException("Could not set a property: ", iae);
           }
           catch (InvocationTargetException ite)
           {
              throw new JBossResourceException("Could not invoke setter on DataSource: ", ite);
           }
           catch (NoSuchMethodException nsme)
           {
              throw new JBossResourceException("Could not find accessor on DataSource: ", nsme);
           }
        }
        return dataSource;

  }
View Full Code Here

      return new WrapperDataSource(this, cm);
   }

   public Object createConnectionFactory() throws ResourceException
   {
      throw new JBossResourceException("Resource Adapter does not currently support running in a non-managed environment.");
   }
View Full Code Here

TOP

Related Classes of org.jboss.resource.JBossResourceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.