Re: 4.1 config file path migration question

John Huss <[email protected]>
Newsgroups gmane.comp.java.cayenne.user
Message-ID <CAOUwSGt22qW6EdB99qp7tHKFGE7TwE6At-=C0ThcZ0n_ZSKPFw@mail.gmail.com>
You'll have to subclass ResourceLocator and implement it:

    /**

     * Finds a collection of matching resources for a given name. The name
components must

     * be separated by forward slashes.

     */

    Collection<Resource> findResources(String name);



For example, The name portion could just be the file name
"cayenne-blah.xml", and your subclass could hardcode the directory path.
The logic could be copied from FilesystemResourceLocator:


            File resourceFile = *new* File(root, name);

            *if* (resourceFile.exists()) {

                *try* {

                    resources.add(*new* URLResource(resourceFile
.toURI().toURL()));

                }

                *catch* (MalformedURLException e) {

                    *throw* *new* CayenneRuntimeException("Can't convert
file to URL: %s", e,  resourceFile.getAbsolutePath());

                }

            }



Binding it using DI looks like this:


        // a locator of resources, such as XML descriptors

        binder.bind(ResourceLocator.*class*).to(MyResourceLocator.*class*);

        binder.bind(Key.*get*(ResourceLocator.*class*, Constants.
*SERVER_RESOURCE_LOCATOR*)).to(MyResourceLocator.*class*);


On Fri, Oct 11, 2019 at 8:57 AM Andrew Willerding <[email protected]>
wrote:

> I have hopefully a quick question on how Cayenne can be configured to
> use a configuration file outside of a JAR/WAR.
>
> I currently use this to reference an absolute file path for my Cayenne
> files but I see that FilesystemResourceLocator is now deprecated ...
>
>              Module myModule = (org.apache.cayenne.di.Binder binder) -> {
>                  binder.bind(ResourceLocator.class).toInstance(new
> FilesystemResourceLocator(filePathForCayenne));
>                  ...
>
> What is the "new" way to replicate the same functionality.  The
> deprecated notes just provide the same example I'm already using.
>
> Thanks,
>
> Andrew
>
>
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.