Loading properties from properties file

Ask around here!

Loading properties from properties file

Postby igorShprukh » Sun Jan 23, 2011 1:08 pm

Hello Wallace,
I am using the ActiveObjects ORM with boneCP and I would like to load the properties for the pool from a file.
The EntityManager for the orm is obtained with a regular command
Code: Select all
manager = EntityManagerBuilder.url(sSource).username(sUserName).password(sPassword).boneCP().fieldNameConverter(new net.java.ao.schema.UnderscoreFieldNameConverter(false)).build();


and I have a datasource loader in the ActiveObjects jar.
I do not create a BoneCPConfig class at all, is it possible somehow to load the props ?

below is the DataSource file from ActiveObjects
Code: Select all
package net.java.ao.builder.bonecp;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.sql.Driver;
import java.util.Properties;

import com.jolbox.bonecp.BoneCP;
import com.jolbox.bonecp.BoneCPConfig;
import com.jolbox.bonecp.BoneCPDataSource;

import net.java.ao.DisposableDataSource;
import net.java.ao.builder.ClassUtils;
import net.java.ao.builder.DataSourceFactory;
import net.java.ao.builder.DelegatingDisposableDataSource;

public class BoneCPDataSourceFactory implements DataSourceFactory {

   public DisposableDataSource getDataSource(
         Class<? extends Driver> driverClass, String url, String username,
         String password) throws FileNotFoundException
      {
      final BoneCPDataSource bonecpds = new BoneCPDataSource();
      bonecpds.setJdbcUrl(url);
      bonecpds.setUsername(username);
      bonecpds.setPassword(password);
      bonecpds.setPartitionCount(1);
      bonecpds.setIdleConnectionTestPeriod(1);
      bonecpds.setIdleMaxAge(1);
      bonecpds.setAcquireRetryDelay(10000);
      bonecpds.setConnectionTimeout(60000);
      bonecpds.setAcquireRetryAttempts(0);
   
       return new DelegatingDisposableDataSource(bonecpds)
        {
            public void dispose()
            {
                bonecpds.close();
            }
        };
         
   }

    public static boolean isAvailable()
    {
        return ClassUtils.loadClass("com.jolbox.bonecp.BoneCPDataSource") != null;
    }
   
}
igorShprukh
 
Posts: 2
Joined: Wed Dec 08, 2010 3:32 pm

Re: Loading properties from properties file

Postby wwadge » Sun Jan 23, 2011 3:18 pm

Hi,

First of all, a BoneCPDatasource extends BoneCPConfig. You may load properties either by passing in a properties file directly or else by placing a bonecp-config.xml file somewhere in the xml containing the properties you care about.

Wallace
wwadge
Site Admin
 
Posts: 713
Joined: Mon Oct 19, 2009 7:50 pm


Return to BoneCP - Help, Q&A, Whatever!

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest

cron