Grokbase Groups Cayenne user May 2008
FAQ
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

Search Discussions

  • Fredrik Liden at May 2, 2008 at 7:14 pm
    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
  • Andrus Adamchik at May 2, 2008 at 7:30 pm
    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
  • Andrus Adamchik at May 2, 2008 at 7:38 pm
    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
  • Brian Nelson at May 3, 2008 at 12:24 am
    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 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
  • Brian Nelson at May 3, 2008 at 12:22 am
    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 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
  • Andrus Adamchik at May 3, 2008 at 7:06 am
    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 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
  • Brian Nelson at May 5, 2008 at 8:47 pm
    Andrus,

    That fixed it. Thanks for the quick response!

    Brian

    --- Andrus Adamchik 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 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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedMay 1, '08 at 7:29p
activeMay 5, '08 at 8:47p
posts8
users3
websitecayenne.apache.org

People

Translate

site design / logo © 2021 Grokbase