You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by John Armstrong <si...@gmail.com> on 2008/06/16 06:55:54 UTC
Dynamic database attribute
Hello Cayenne people,
First off, thank god for Cayenne. Its made my life a lot better and
Hibernate is but a nightmare now. Thanks.
Ok so my issue. I have a stand-alone app. In this app it uses the ant
api to create a derby database in the users home directory. Some
snippets:
I config ant as :
p.setProperty("dbFile", System.getProperty("user.home")
+ "/portfolioDB");
And then my build.xml says:
<database url="jdbc:derby:${dbFile}"
driverClassName="org.apache.derby.jdbc.EmbeddedDriver" username=""
password="" />
This allows me to inject my ddl into the database on first run and
have the database be localized to the user account across platforms.
I need a way to inject this same ${dbFile} context into the
*Node.driver file so that Cayenne accesses the database I just created
and populated at first run.
Currently mine says:
<url value="jdbc:derby:/portfolioDB;create=true"/>
Which obviously is not dynamic. It would be great if I could set it to
<url value="jdbc:derby:${dbFile};create=true"/>
Is this possible? I am imagining a way to set an environment variable
or some sort of custom config class that sets this. This app is
launched from a webstart so rewriting the config file is not a good
answer for me unless I absolutely have to. That would obviously
require a custom config class of some sort but is a level of
complexity that feels unnecessary.
Thanks, this is a bit into the internals for me and I lose my way quickly.
John-
Re: Dynamic database attribute
Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi John,
Actually a good idea for us to introduce a concept of ant-like dynamic
variable substitution in the future.
Now back down to Earth... The way to customize that now is via a
custom DataSourceFactory class:
http://cayenne.apache.org/doc/api/org/apache/cayenne/conf/DataSourceFactory.html
This interface can be implemented in your code to do whatever your app
needs to do. You should enter the full class name the custom
implementation under DataNode -> DataSource Factory in the Modeler and
then Cayenne will pick it up.
Andrus
On Jun 16, 2008, at 7:55 AM, John Armstrong wrote:
> Hello Cayenne people,
> First off, thank god for Cayenne. Its made my life a lot better and
> Hibernate is but a nightmare now. Thanks.
>
> Ok so my issue. I have a stand-alone app. In this app it uses the ant
> api to create a derby database in the users home directory. Some
> snippets:
>
> I config ant as :
> p.setProperty("dbFile", System.getProperty("user.home")
> + "/portfolioDB");
>
> And then my build.xml says:
> <database url="jdbc:derby:${dbFile}"
> driverClassName="org.apache.derby.jdbc.EmbeddedDriver" username=""
> password="" />
>
> This allows me to inject my ddl into the database on first run and
> have the database be localized to the user account across platforms.
>
> I need a way to inject this same ${dbFile} context into the
> *Node.driver file so that Cayenne accesses the database I just created
> and populated at first run.
>
> Currently mine says:
>
> <url value="jdbc:derby:/portfolioDB;create=true"/>
>
> Which obviously is not dynamic. It would be great if I could set it to
> <url value="jdbc:derby:${dbFile};create=true"/>
>
> Is this possible? I am imagining a way to set an environment variable
> or some sort of custom config class that sets this. This app is
> launched from a webstart so rewriting the config file is not a good
> answer for me unless I absolutely have to. That would obviously
> require a custom config class of some sort but is a level of
> complexity that feels unnecessary.
>
> Thanks, this is a bit into the internals for me and I lose my way
> quickly.
>
> John-
>