Re: unit testing Cayenne objects

From: Cris Daniluk (
Date: Wed May 04 2005 - 17:02:14 EDT

  • Next message: Andrus Adamchik: "Re: unit testing Cayenne objects"

    > My next question is about configuration and how to do some of it
    > through the API. I want to use a file-based cayenne.xml and .map.xml
    > file, but I want to configure JDBC URL through the API rather than
    > through a .driver.xml file.

    You can use a ConfigLoaderDelegate to replace the DataSource in the
    DataNode. This is a little hackish, but pretty simple. Something like
    this ought to give you a start:

    DefaultConfiguration cayenneConfiguration = new
    RuntimeLoadDelegate(cayenneConfiguration, cayenneConfiguration
            .getLoadStatus(), Level.DEBUG) {

        public void shouldLoadDataNode(String domainName, String nodeName,
    String dataSource, String adapter,
                String factory) {
            // adjust behavior as necessary
            super.shouldLoadDataNode(domainName, nodeName, dataSource,
    adapter, factory);

    You can actually obtain and modify the DataNode without the Delegate
    (from the DataContext or Configuration), but I do not believe you can
    do this before the first connection attempt is made. Either way, you
    want to create a DriverDataSource containing your URL.

    Hopefully someone else knows a cleaner way :)


    This archive was generated by hypermail 2.0.0 : Wed May 04 2005 - 17:02:16 EDT