User: patriot1burke
  Date: 01/07/03 15:56:19

  Modified:    src/main/org/jboss/pool/jdbc/xa XAPoolDataSource.java
                        XAConnectionFactory.java
  Log:
  added support for setting transaction isolation and setting the PS cache size.
  
  Revision  Changes    Path
  1.3       +215 -208  jbosspool/src/main/org/jboss/pool/jdbc/xa/XAPoolDataSource.java
  
  Index: XAPoolDataSource.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosspool/src/main/org/jboss/pool/jdbc/xa/XAPoolDataSource.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XAPoolDataSource.java     2001/07/02 03:20:08     1.2
  +++ XAPoolDataSource.java     2001/07/03 22:56:19     1.3
  @@ -23,217 +23,224 @@
    *
    * @author Aaron Mulder ([EMAIL PROTECTED])
    * @author <a href="mailto:[EMAIL PROTECTED]";>danch (Dan Christopherson)</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Bill Burke</a>
    * 
    * Revision:
    * 20010701 danch added code for timeout in blocking.
  + * 20010703 bill added code for transaction isolation and setting the ps cache size
    */
   public class XAPoolDataSource implements DataSource, Referenceable, ObjectFactory {
  -    private static HashMap sources = new HashMap();
  -    /**
  -     * Gets all the current JDBC pool data sources.
  -     */
  -    public static Collection getDataSources() {
  -        return new HashSet(sources.values());
  -    }
  -    /**
  -     * Gets a specific JDBC pool data source by pool name.
  -     */
  -    public static XAPoolDataSource getDataSource(String poolName) {
  -        return (XAPoolDataSource)sources.get(poolName);
  -    }
  -
  -
  -    private ObjectPool pool;
  -    private XAConnectionFactory factory;
  -    private PrintWriter logWriter;
  -    private int timeout;
  -    private boolean initialized = false;
  -    private String jndiName;
  -
  -    /**
  -     * Creates a new XA pool data source.  Be sure to configure it and then
  -     * call initialize before you try to use it.
  -     */
  -    public XAPoolDataSource() {
  -        pool = new ObjectPool();
  -        try {
  -            factory = new XAConnectionFactory();
  -        } catch(NamingException e) {
  -            e.printStackTrace();
  -        }
  -        XAPoolDriver.instance();
  -    }
  -
  -// Unique properties
  -    /**
  -     * If you use this to set a JNDI name, this pool will be bound to that name
  -     * using the default InitialContext.  You can also do this manually if you
  -     * have additional requirements.
  -     */
  -    public void setJNDIName(String name) throws NamingException {
  -        InitialContext ctx = new InitialContext();
  -        if(jndiName != null && !jndiName.equals(name))
  -            ctx.unbind(jndiName);
  -        if(name != null)
  -            ctx.bind(name, this);
  -        jndiName = name;
  -    }
  -
  -    /**
  -     * Gets the JNDI name this pool is bound to.  Only valid if you used
  -     * setJNDIName to bind it.
  -     * @see #setJNDIName
  -     */
  -    public String getJNDIName() {return jndiName;}
  -
  -// XA properties
  -    public void setDataSource(XADataSource ds) {factory.setDataSource(ds);}
  -    public XADataSource getDataSource() {return factory.getDataSource();}
  -    public void setTransactionManagerJNDIName(String name) 
{factory.setTransactionManagerJNDIName(name);}
  -    public String getTransactionManagerJNDIName() {return 
factory.getTransactionManagerJNDIName();}
  -    public void setJDBCUser(String user) {factory.setUser(user);}
  -    public String getJDBCUser() {return factory.getUser();}
  -    public void setJDBCPassword(String password) {factory.setPassword(password);}
  -    public String getJDBCPassword() {return factory.getPassword();}
  -// Pool properties
  -    public void setPoolName(String name) {
  -        pool.setName(name);
  -        sources.put(pool.getName(), this);
  -    }
  -    public String getPoolName() {return pool.getName();}
  -    public void setMinSize(int size) {pool.setMinSize(size);}
  -    public int getMinSize() {return pool.getMinSize();}
  -    public void setMaxSize(int size) {pool.setMaxSize(size);}
  -    public int getMaxSize() {return pool.getMaxSize();}
  -    public void setBlocking(boolean blocking) {pool.setBlocking(blocking);}
  -    public boolean isBlocking() {return pool.isBlocking();}
  -    public void setBlockingTimeout(int blockingTimeout) 
{pool.setBlockingTimeout(blockingTimeout);}
  -    public int getBlockingTimeout() {return pool.getBlockingTimeout();}
  -    public void setIdleTimeoutEnabled(boolean allowShrinking) 
{pool.setIdleTimeoutEnabled(allowShrinking);}
  -    public boolean isIdleTimeoutEnabled() {return pool.isIdleTimeoutEnabled();}
  -    public void setGCEnabled(boolean allowGC) {pool.setGCEnabled(allowGC);}
  -    public boolean isGCEnabled() {return pool.isGCEnabled();}
  -    public void setMaxIdleTimeoutPercent(float percent) 
{pool.setMaxIdleTimeoutPercent(percent);}
  -    public float getMaxIdleTimeoutPercent() {return 
pool.getMaxIdleTimeoutPercent();}
  -    public void setIdleTimeout(long millis) {pool.setIdleTimeout(millis);}
  -    public long getIdleTimeout() {return pool.getIdleTimeout();}
  -    public void setGCMinIdleTime(long millis) {pool.setGCMinIdleTime(millis);}
  -    public long getGCMinIdleTime() {return pool.getGCMinIdleTime();}
  -    public void setGCInterval(long millis) {pool.setGCInterval(millis);}
  -    public long getGCInterval() {return pool.getGCInterval();}
  -    public void setInvalidateOnError(boolean invalidate) 
{pool.setInvalidateOnError(invalidate);}
  -    public boolean isInvalidateOnError() {return pool.isInvalidateOnError();}
  -    public void setTimestampUsed(boolean timestamp) 
{pool.setTimestampUsed(timestamp);}
  -    public boolean isTimestampUsed() {return pool.isTimestampUsed();}
  -
  -// Other methods
  -
  -    /**
  -     * Initializes the pool.  You need to have configured all the pool and
  -     * XA properties first.
  -     */
  -    public void initialize() {
  -        initialized = true;
  -        pool.setObjectFactory(factory);
  -        pool.initialize();
  -    }
  -
  -    /**
  -     * Returns a string describing the pool status (number of connections
  -     * created, used, and maximum).
  -     */
  -    public String getPoolStatus() {
  -        return pool.toString();
  -    }
  -
  -    /**
  -     * Shuts down this data source and the underlying pool.  If you used
  -     * setJNDI name to bind it in JNDI, it is unbound.
  -     */
  -    public void close() {
  -        try {
  -            setJNDIName(null);
  -        } catch(NamingException e) {
  -            if(logWriter != null)
  -                e.printStackTrace(logWriter);
  -        }
  -        sources.remove(pool.getName());
  -        pool.shutDown();
  -        pool = null;
  -        factory = null;
  -    }
  -
  -    /**
  -     * Gets a connection from the pool.
  -     */
  -    public Connection getConnection() throws java.sql.SQLException {
  -        if(!initialized) initialize();
  -        return ((XAConnection)pool.getObject()).getConnection();
  -    }
  -
  -    /**
  -     * Gets a new connection from the pool.  If a new connection must be
  -     * created, it will use the specified user name and password.  If there is
  -     * a connection available in the pool, it will be used, regardless of the
  -     * user name and password use to created it initially.
  -     */
  -    public Connection getConnection(String user, String password) throws 
java.sql.SQLException {
  -        if(!initialized) initialize();
  -        factory.setUser(user);
  -        factory.setPassword(password);
  -        return ((XAConnection)pool.getObject()).getConnection();
  -    }
  -
  -    /**
  -     * Gets a log writer used to record pool events.
  -     */
  -    public PrintWriter getLogWriter() throws java.sql.SQLException {
  -        return logWriter;
  -    }
  -
  -    /**
  -     * Sets a log writer used to record pool events.
  -     */
  -    public void setLogWriter(PrintWriter writer) throws java.sql.SQLException {
  -        logWriter = writer;
  -        pool.setLogWriter(writer);
  -    }
  -
  -    /**
  -     * This property is not used by this implementation.
  -     */
  -    public int getLoginTimeout() throws java.sql.SQLException {
  -        return timeout;
  -    }
  -
  -    /**
  -     * This property is not used by this implementation.
  -     */
  -    public void setLoginTimeout(int timeout) throws java.sql.SQLException {
  -        this.timeout = timeout;
  -    }
  -
  -    // Referenceable implementation ----------------------------------
  -    /**
  -     * Gets a reference to this data source.
  -     */
  -    public Reference getReference() {
  -        return new Reference(getClass().getName(), new StringRefAddr("XAPool", 
pool.getName()), getClass().getName(), null);
  -    }
  -
  -    // ObjectFactory implementation ----------------------------------
  -    /**
  -     * Decodes a reference to a specific pool data source.
  -     */
  -    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
  -                                    Hashtable environment) {
  -        if(obj instanceof Reference) {
  -            Reference ref = (Reference)obj;
  -            if(ref.getClassName().equals(getClass().getName())) {
  -                RefAddr addr = ref.get("XAPool");
  -                return sources.get((String)addr.getContent());
  -            }
  -        }
  -        return null;
  -    }
  +   private static HashMap sources = new HashMap();
  +   /**
  +    * Gets all the current JDBC pool data sources.
  +    */
  +   public static Collection getDataSources() {
  +      return new HashSet(sources.values());
  +   }
  +   /**
  +    * Gets a specific JDBC pool data source by pool name.
  +    */
  +   public static XAPoolDataSource getDataSource(String poolName) {
  +      return (XAPoolDataSource)sources.get(poolName);
  +   }
  +
  +
  +   private ObjectPool pool;
  +   private XAConnectionFactory factory;
  +   private PrintWriter logWriter;
  +   private int timeout;
  +   private boolean initialized = false;
  +   private String jndiName;
  +
  +   /**
  +    * Creates a new XA pool data source.  Be sure to configure it and then
  +    * call initialize before you try to use it.
  +    */
  +   public XAPoolDataSource() {
  +      pool = new ObjectPool();
  +      try {
  +         factory = new XAConnectionFactory();
  +      } catch(NamingException e) {
  +         e.printStackTrace();
  +      }
  +      XAPoolDriver.instance();
  +   }
  +
  +   // Unique properties
  +   /**
  +    * If you use this to set a JNDI name, this pool will be bound to that name
  +    * using the default InitialContext.  You can also do this manually if you
  +    * have additional requirements.
  +    */
  +   public void setJNDIName(String name) throws NamingException {
  +      InitialContext ctx = new InitialContext();
  +      if(jndiName != null && !jndiName.equals(name))
  +         ctx.unbind(jndiName);
  +      if(name != null)
  +         ctx.bind(name, this);
  +      jndiName = name;
  +   }
  +
  +   /**
  +    * Gets the JNDI name this pool is bound to.  Only valid if you used
  +    * setJNDIName to bind it.
  +    * @see #setJNDIName
  +    */
  +   public String getJNDIName() {return jndiName;}
  +
  +   // XA properties
  +   public void setDataSource(XADataSource ds) {factory.setDataSource(ds);}
  +   public XADataSource getDataSource() {return factory.getDataSource();}
  +   public void setTransactionManagerJNDIName(String name) 
{factory.setTransactionManagerJNDIName(name);}
  +   public String getTransactionManagerJNDIName() {return 
factory.getTransactionManagerJNDIName();}
  +   public void setJDBCUser(String user) {factory.setUser(user);}
  +   public String getJDBCUser() {return factory.getUser();}
  +   public void setJDBCPassword(String password) {factory.setPassword(password);}
  +   public String getJDBCPassword() {return factory.getPassword();}
  +   public int getTransactionIsolation() {return factory.getTransactionIsolation();}
  +   public void setTransactionIsolation(int iso) { 
factory.setTransactionIsolation(iso); }
  +
  +   public int getPSCacheSize() {return factory.getPSCacheSize();}
  +   public void setPSCacheSize(int size) { factory.setPSCacheSize(size);}
  +   // Pool properties
  +   public void setPoolName(String name) {
  +      pool.setName(name);
  +      sources.put(pool.getName(), this);
  +   }
  +   public String getPoolName() {return pool.getName();}
  +   public void setMinSize(int size) {pool.setMinSize(size);}
  +   public int getMinSize() {return pool.getMinSize();}
  +   public void setMaxSize(int size) {pool.setMaxSize(size);}
  +   public int getMaxSize() {return pool.getMaxSize();}
  +   public void setBlocking(boolean blocking) {pool.setBlocking(blocking);}
  +   public boolean isBlocking() {return pool.isBlocking();}
  +   public void setBlockingTimeout(int blockingTimeout) 
{pool.setBlockingTimeout(blockingTimeout);}
  +   public int getBlockingTimeout() {return pool.getBlockingTimeout();}
  +   public void setIdleTimeoutEnabled(boolean allowShrinking) 
{pool.setIdleTimeoutEnabled(allowShrinking);}
  +   public boolean isIdleTimeoutEnabled() {return pool.isIdleTimeoutEnabled();}
  +   public void setGCEnabled(boolean allowGC) {pool.setGCEnabled(allowGC);}
  +   public boolean isGCEnabled() {return pool.isGCEnabled();}
  +   public void setMaxIdleTimeoutPercent(float percent) 
{pool.setMaxIdleTimeoutPercent(percent);}
  +   public float getMaxIdleTimeoutPercent() {return pool.getMaxIdleTimeoutPercent();}
  +   public void setIdleTimeout(long millis) {pool.setIdleTimeout(millis);}
  +   public long getIdleTimeout() {return pool.getIdleTimeout();}
  +   public void setGCMinIdleTime(long millis) {pool.setGCMinIdleTime(millis);}
  +   public long getGCMinIdleTime() {return pool.getGCMinIdleTime();}
  +   public void setGCInterval(long millis) {pool.setGCInterval(millis);}
  +   public long getGCInterval() {return pool.getGCInterval();}
  +   public void setInvalidateOnError(boolean invalidate) 
{pool.setInvalidateOnError(invalidate);}
  +   public boolean isInvalidateOnError() {return pool.isInvalidateOnError();}
  +   public void setTimestampUsed(boolean timestamp) 
{pool.setTimestampUsed(timestamp);}
  +   public boolean isTimestampUsed() {return pool.isTimestampUsed();}
  +
  +      // Other methods
  +
  +      /**
  +       * Initializes the pool.  You need to have configured all the pool and
  +       * XA properties first.
  +       */
  +      public void initialize() {
  +      initialized = true;
  +      pool.setObjectFactory(factory);
  +      pool.initialize();
  +   }
  +
  +   /**
  +    * Returns a string describing the pool status (number of connections
  +    * created, used, and maximum).
  +    */
  +   public String getPoolStatus() {
  +      return pool.toString();
  +   }
  +
  +   /**
  +    * Shuts down this data source and the underlying pool.  If you used
  +    * setJNDI name to bind it in JNDI, it is unbound.
  +    */
  +   public void close() {
  +      try {
  +         setJNDIName(null);
  +      } catch(NamingException e) {
  +         if(logWriter != null)
  +            e.printStackTrace(logWriter);
  +      }
  +      sources.remove(pool.getName());
  +      pool.shutDown();
  +      pool = null;
  +      factory = null;
  +   }
  +
  +   /**
  +    * Gets a connection from the pool.
  +    */
  +   public Connection getConnection() throws java.sql.SQLException {
  +      if(!initialized) initialize();
  +      return ((XAConnection)pool.getObject()).getConnection();
  +   }
  +
  +   /**
  +    * Gets a new connection from the pool.  If a new connection must be
  +    * created, it will use the specified user name and password.  If there is
  +    * a connection available in the pool, it will be used, regardless of the
  +    * user name and password use to created it initially.
  +    */
  +   public Connection getConnection(String user, String password) throws 
java.sql.SQLException {
  +      if(!initialized) initialize();
  +      factory.setUser(user);
  +      factory.setPassword(password);
  +      return ((XAConnection)pool.getObject()).getConnection();
  +   }
  +
  +   /**
  +    * Gets a log writer used to record pool events.
  +    */
  +   public PrintWriter getLogWriter() throws java.sql.SQLException {
  +      return logWriter;
  +   }
  +
  +   /**
  +    * Sets a log writer used to record pool events.
  +    */
  +   public void setLogWriter(PrintWriter writer) throws java.sql.SQLException {
  +      logWriter = writer;
  +      pool.setLogWriter(writer);
  +   }
  +
  +   /**
  +    * This property is not used by this implementation.
  +    */
  +   public int getLoginTimeout() throws java.sql.SQLException {
  +      return timeout;
  +   }
  +
  +   /**
  +    * This property is not used by this implementation.
  +    */
  +   public void setLoginTimeout(int timeout) throws java.sql.SQLException {
  +      this.timeout = timeout;
  +   }
  +
  +   // Referenceable implementation ----------------------------------
  +   /**
  +    * Gets a reference to this data source.
  +    */
  +   public Reference getReference() {
  +      return new Reference(getClass().getName(), new StringRefAddr("XAPool", 
pool.getName()), getClass().getName(), null);
  +   }
  +
  +   // ObjectFactory implementation ----------------------------------
  +   /**
  +    * Decodes a reference to a specific pool data source.
  +    */
  +   public Object getObjectInstance(Object obj, Name name, Context nameCtx,
  +                                   Hashtable environment) {
  +      if(obj instanceof Reference) {
  +         Reference ref = (Reference)obj;
  +         if(ref.getClassName().equals(getClass().getName())) {
  +            RefAddr addr = ref.get("XAPool");
  +            return sources.get((String)addr.getContent());
  +         }
  +      }
  +      return null;
  +   }
   }
  
  
  
  1.2       +32 -0     
jbosspool/src/main/org/jboss/pool/jdbc/xa/XAConnectionFactory.java
  
  Index: XAConnectionFactory.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosspool/src/main/org/jboss/pool/jdbc/xa/XAConnectionFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XAConnectionFactory.java  2001/05/15 07:58:24     1.1
  +++ XAConnectionFactory.java  2001/07/03 22:56:19     1.2
  @@ -37,14 +37,21 @@
    * the native JDBC 2 Standard Extension implementations.</P>
    *
    * @author Aaron Mulder ([EMAIL PROTECTED])
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Bill Burke</a>
  + *
  + * REVISIONS:
  + * 20010703 bill added code for transaction isolation
    */
   public class XAConnectionFactory extends PoolObjectFactory {
  +    public static final int DEFAULT_ISOLATION = -1;
  +
       private InitialContext ctx;
       private XADataSource source;
       private String userName;
       private String password;
       private String tmJndiName;
       private int psCacheSize = 10;
  +    private int transactionIsolation = DEFAULT_ISOLATION;
       private ConnectionEventListener listener, errorListener;
       private TransactionListener transListener;
       private ObjectPool pool;
  @@ -194,6 +201,20 @@
           return psCacheSize;
       }
   
  +
  +   /**
  +    * Gets the transaction isolation level of connections.  This defaults to
  +    * whatever the connection's default iso level is.
  +    */
  +    public int getTransactionIsolation()
  +    {
  +        return transactionIsolation;
  +    }
  +
  +    public void setTransactionIsolation(int iso)
  +    {
  +       this.transactionIsolation = iso;
  +    }
       /**
        * Sets the XADataSource used to generate XAConnections.  This may be
        * supplied by the vendor, or it may use the wrappers for non-compliant
  @@ -281,6 +302,17 @@
           if(con instanceof XAConnectionImpl) {
               ((XAConnectionImpl)con).setTransactionListener(transListener);
               ((XAConnectionImpl)con).setPSCacheSize(psCacheSize);
  +            if (transactionIsolation != DEFAULT_ISOLATION)
  +            {
  +                try
  +                {
  +                   
((XAConnectionImpl)con).setTransactionIsolation(transactionIsolation);
  +                }
  +                catch (SQLException sex)
  +                {
  +                   throw new RuntimeException("Unable to setTransactionIsolation: " 
+ sex.getMessage());
  +                }
  +            }
               if(trans != null) {
                   wrapperTx.put(con, trans); // For JDBC 1/2 wrappers, remember which
                   wrapperTx.put(trans, con); // connection goes with a given 
transaction
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to