cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Custom configuration class ignored in 3.0 snapshot
Date Sat, 03 May 2008 07:05:50 GMT
I was looking for any clues in the code, nothing concrete... And I  
found it. The recent fix to CAY-785 deprecated and stopped calling  
"Configuration.getDataSourceFactory()" replacing it with  
"Configuration.getDataSourceFactory(String)". So you need to override  
the new method. Also I checked in a fix that restores backwards  
compatibility. It should be available from the Hudson CI server soon  
(build #109 or newer).

Andrus


On May 3, 2008, at 3:21 AM, Brian Nelson wrote:

> Andrus,
>
> I'm not sure exactly how you want the code sample. If you need me to  
> provide a self contained app
> I can do that. For now I'll just copy the code from my app so you  
> can take a look at it. I have a
> static method that configures my custom DataSourceFactory. The call  
> to DbUtils.openDb succeeds,
> but the getDataSourceFactory method in CompanyConfiguration is never  
> called.
>
> public class DbUtils {
> 	private static DataContext globalContext;
> 	private static DataContext estimateContext;
> 	private static DataContext roomContext;
> 	private static DataContext assemblyContext;
> 	private static DataContext partsContext;
>
>        public static void openDb(String pathToDb) throws Exception {
> 		try {
> 			CompanyDataSourceFactory.setDbPath(pathToDb);
> 			 
> Configuration 
> .initializeSharedConfiguration(CompanyConfiguration.class);
> 			Configuration config = Configuration.getSharedConfiguration();
> 			DataDomain domain = config.getDomain();
> 			
> 			globalContext = DataContext.createDataContext(domain.getName());
> 			estimateContext = DataContext.createDataContext(domain.getName());
> 			roomContext = DataContext.createDataContext(domain.getName());
> 			assemblyContext = DataContext.createDataContext(domain.getName());
> 			partsContext = DataContext.createDataContext(domain.getName());
> 		} catch (Exception e) {
> 			throw new Exception("Unable to initialize database!", e);
> 		}
> 	}
> }
>
> public class CompanyConfiguration extends DefaultConfiguration {
> 	
> 	private static CompanyDataSourceFactory factory = new  
> CompanyDataSourceFactory();
> 	
> 	@Override
> 	public DataSourceFactory getDataSourceFactory() {
> 		return factory;
> 	}
>
> }
>
> public class CompanyDataSourceFactory implements DataSourceFactory {
>
> 	private static DataSource ds = null;
> 	private static String dbPath = "Companies/db";
> 	
> 	public static void setDbPath(String val) {
> 		dbPath = val;
> 	}
> 	
> 	@Override
> 	public DataSource getDataSource(String arg0) throws Exception {
> 		if(dbPath.startsWith("server")) {
> 			// server:host
> 			ClientDataSource40 tmpDS = new ClientDataSource40();
> 			String[] sArray = dbPath.split(":");
> 			tmpDS.setServerName(sArray[1]);
> 			tmpDS.setDatabaseName("db");
> 			tmpDS.setUser("user");
> 			tmpDS.setPassword("pass");
> 			ds = tmpDS;
> 		} else {
> 			EmbeddedDataSource40 tmpDS = new EmbeddedDataSource40();
> 			tmpDS.setDatabaseName(dbPath);
> 			tmpDS.setUser("user");
> 			tmpDS.setPassword("db");
> 			ds = tmpDS;
> 		}
> 		
> 		
> 	
> 		return ds;
> 	}
>
> 	@Override
> 	public void initializeWithParentConfiguration(Configuration arg0) {		
> 	}
>
> }
>
> Hopefully that's enough. If not let me know what I should provide.
>
> Thanks for your help!
>
> Brian
>
> --- Andrus Adamchik <andrus@objectstyle.org> wrote:
>
>> Strange. That should still work the same. The only change to
>> Configuration since M3 was related to the DataSourceFactory handling
>> (CAY-785)...  Do you have a code example that demonstrates the  
>> problem?
>>
>> Thanks,
>> Andrus
>>
>>
>> On May 1, 2008, at 10:29 PM, Brian Nelson wrote:
>>> I've been using a custom subclass of DefaultConfiguration to
>>> customize my database connection.
>>> This works great with 3.0M3. However, today I upgraded to the
>>> snapshot build and it seems to be
>>> ignoring the custom configuration class I pass into the
>>> Configuration.initializeSharedConfiguration method. Has the way
>>> custom configurations work
>>> changed?
>>>
>>> Thanks in advance!
>>>
>>> Brian
>>>
>>>
>>
>>
>
>


Mime
View raw message