You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Brian Nelson <br...@yahoo.com> on 2008/05/01 21:29:20 UTC

Custom configuration class ignored in 3.0 snapshot

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


Re: Custom configuration class ignored in 3.0 snapshot

Posted by Brian Nelson <br...@yahoo.com>.
Thanks for the link. I'll use the snapshots provided there from now on. 

I just downloaded and tried the latest snapshot from there and I still have the same behavior. 

Brian


--- Andrus Adamchik <an...@objectstyle.org> wrote:

> BTW, there is some ambiguity as to the snapshot versions (we  
> occasionally post to the snapshot Maven repo; and there is also an  
> independent CI server doing builds on code changes), I recommend using  
> the jars built by the CI server (choose "Cayenne Aggregated Server  
> Jar") :
> 
> http://hudson.zones.apache.org/hudson/job/Cayenne-trunk/lastBuild/
> 
> Andrus
> 
> 
> 
> On May 2, 2008, at 10:30 PM, Andrus Adamchik 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
> >>
> >>
> >
> >
> 
> 


Re: Custom configuration class ignored in 3.0 snapshot

Posted by Andrus Adamchik <an...@objectstyle.org>.
BTW, there is some ambiguity as to the snapshot versions (we  
occasionally post to the snapshot Maven repo; and there is also an  
independent CI server doing builds on code changes), I recommend using  
the jars built by the CI server (choose "Cayenne Aggregated Server  
Jar") :

http://hudson.zones.apache.org/hudson/job/Cayenne-trunk/lastBuild/

Andrus



On May 2, 2008, at 10:30 PM, Andrus Adamchik 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
>>
>>
>
>


Re: Custom configuration class ignored in 3.0 snapshot

Posted by Brian Nelson <br...@yahoo.com>.
Andrus,

That fixed it. Thanks for the quick response!

Brian

--- Andrus Adamchik <an...@objectstyle.org> wrote:

> 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 <an...@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
> >>>
> >>>
> >>
> >>
> >
> >
> 
> 


Re: Custom configuration class ignored in 3.0 snapshot

Posted by Andrus Adamchik <an...@objectstyle.org>.
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 <an...@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
>>>
>>>
>>
>>
>
>


Re: Custom configuration class ignored in 3.0 snapshot

Posted by Brian Nelson <br...@yahoo.com>.
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 <an...@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
> >
> >
> 
> 


Re: Custom configuration class ignored in 3.0 snapshot

Posted by Andrus Adamchik <an...@objectstyle.org>.
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
>
>


Datamodel advice

Posted by Fredrik Liden <fl...@translate.com>.
Hi, I'm wondering what is the best way to implement this structure in
Cayenne:

Let's say there is a list of users assigned to a client:
m:n between USER (userid) and CLIENT (clientid) and between CLIENT_USER
(userid,clientid) is the flattened table.

Now from that list of users in CLIENT_USER I want to one and assign to
say a certain languages. I believe the correct datamodel would be:

m:n between CLIENT_USER (userid,clientid) and LANGUAGE (languageid)
where ASSIGNMENT (userid,clientid,languageid) would be the between
(flattened) table.
 
Is it possible to have a flattened table (ASSIGNMENT) based on another
flattened table (CLIENT_USER)? Or should I unflatten CLIENT_USER and add
a cayenne generated id so it would be
CLIENT_USER(client_userid,userid,clientid) and ASSIGNEMENT
(client_userid,languaged) would be flattened.
I find that I'm often coming back to this situation so just wondering if
anyone has any suggestions.

Thanks,
Fredrik