Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  * implied.
  *
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.ops4j.pax.jdbc.pool.aries.impl.ds;
 
 import java.util.Map;
 
 
Creates pooled and optionally XA ready DataSources out of a non pooled DataSourceFactory. XA transaction handling Besides pooling this also supports to provide a DataSource that wraps a XADataSource and handles the XA Resources. This kind of DataSource can then for example be used in persistence.xml as jta-data-source
 
 public class PooledDataSourceFactory implements DataSourceFactory {
 
     private static final String POOL_PREFIX = "pool.";
     private Logger LOG = LoggerFactory.getLogger(PooledDataSourceFactory.class);
     private DataSourceFactory dsFactory;
     private AriesTransactionManager tm;

    
Initialize XA PoolingDataSourceFactory

Parameters:
dsFactory non pooled DataSourceFactory we delegate to
tm transaction manager (Only needed for XA mode)
 
         this. = dsFactory;
         this. = tm;
     }

    
Initialize non XA PoolingDataSourceFactory

Parameters:
dsFactory non pooled DataSourceFactory we delegate to
 
     public PooledDataSourceFactory(DataSourceFactory dsFactory) {
         this(dsFactorynull);
     }
 
     @Override
     public DataSource createDataSource(Properties propsthrows SQLException {
         try {
             CommonDataSource ds;
             if ( != null) {
                 ds = .createXADataSource(getNonPoolProps(props));
             }
             else {
                 ds = .createDataSource(getNonPoolProps(props));
             }
             RecoverableDataSource mds = new RecoverableDataSource();
             mds.setTransactionManager();
             mds.setDataSource(ds);
             BeanConfig.configure(mdsgetPoolProps(props));
             mds.start();
             return mds;
         }
         catch (Throwable e) {
             .error("Error creating pooled datasource" + e.getMessage(), e);
             if (e instanceof SQLException) {
                 throw (SQLExceptione;
             }
             else if (e instanceof RuntimeException) {
                 throw (RuntimeExceptione;
             }
             else {
                 throw new RuntimeException(e.getMessage(), e);
             }
        }
    }
    private Map<StringStringgetPoolProps(Properties props) {
        Map<StringStringpoolProps = new HashMap<StringString>();
        for (Object keyO : props.keySet()) {
            String key = (StringkeyO;
            if (key.startsWith()) {
                String strippedKey = key.substring(.length());
                poolProps.put(strippedKey, (Stringprops.get(key));
            }
        }
        return poolProps;
    }
    private Properties getNonPoolProps(Properties props) {
        Properties dsProps = new Properties();
        for (Object keyO : props.keySet()) {
            String key = (StringkeyO;
            if (!key.startsWith()) {
                dsProps.put(keyprops.get(key));
            }
        }
        return dsProps;
    }
    @Override
        throws SQLException {
        throw new SQLException("Not supported");
    }
    @Override
    public XADataSource createXADataSource(Properties propsthrows SQLException {
        throw new SQLException("Not supported");
    }
    @Override
    public Driver createDriver(Properties propsthrows SQLException {
        throw new SQLException("Not supported");
    }
New to GrepCode? Check out our FAQ X