You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Scott Anderson <sa...@airvana.com> on 2008/04/03 02:38:53 UTC

How can I customize the driver/url/login

Is there a way I can customize the driver/url/login information through
my application code? I want the user to be able to select the location
and login credentials, but the schema is known. I don't want the user to
have to write his or her own configuration files and repackage the
distributed jar, though.


RE: How can I customize the driver/url/login

Posted by Scott Anderson <sa...@airvana.com>.
public class ConnectionSource implements DataSource {
	private Connection conn;
	
	public ConnectionSource(Connection conn) {
		this.conn = conn;
	}
	
	public Connection getConnection() throws SQLException {
		return conn;
	}
	
...
}


Are there any other methods I'm required to implement?

-----Original Message-----
From: Andrus Adamchik [mailto:andrus@objectstyle.org] 
Sent: Thursday, April 03, 2008 12:43 PM
To: user@cayenne.apache.org
Subject: Re: How can I customize the driver/url/login

> I'm using a custom DataSourceFactory now;


So how does this code look like? There's something in the DataSource  
it returns that results in the errors you've mentioned.

Andrus

On Apr 3, 2008, at 7:18 PM, Scott Anderson wrote:

> I'm using a custom DataSourceFactory now; if I switch it back to
> DriverDataSourceFactory and set the minimum connections to 2, Derby
> complains about how there can't be two connections, as I'm using the
> EmbeddedDriver.
>
> -----Original Message-----
> From: Michael Gentry [mailto:blacknext@gmail.com]
> Sent: Thursday, April 03, 2008 12:01 PM
> To: user@cayenne.apache.org
> Subject: Re: How can I customize the driver/url/login
>
> Just for kicks, bump up your minimum DB connections in the modeler and
> see what happens ...
>
>
> On Thu, Apr 3, 2008 at 11:37 AM, Scott Anderson  
> <sa...@airvana.com>
> wrote:
>> While I know enough to briefly describe what a connection pool is, I
>> have no idea how Cayenne uses it, or how it's configured. Could you
> go
>> in to a little more detail? AFAIK, I'm using what ever the default
>> settings are.
>>
>> It seems unlikely to me that it's derby related because when I use
> the
>> modeler to specify the database location, I don't see anything like
>> this. Could it be that the adapter isn't being specified? I noticed
> that
>> Cayenne is warning that it's using the "automatic" one.
>>
>> Apr 3, 2008 11:33:56 AM org.apache.cayenne.conf.RuntimeLoadDelegate
>> initAdapter
>> INFO: no adapter set, using automatic adapter.
>


RE: How can I customize the driver/url/login

Posted by Scott Anderson <sa...@airvana.com>.
      @Override

      public DataSource getDataSource(String arg0) throws Exception {

            DatabaseSettings settings = new DatabaseSettings();

            settings.load();

            

            // Set up the driver, in case it's not on the classpath

            try {

                  DriverManager.getDriver(settings.url);

            } catch(SQLException e) {

                  Out.debug(getClass(), "Registering " +
settings.driver);

                  Driver d =
(Driver)JARLoader.forName(settings.driver).newInstance();

                  DriverManager.registerDriver(new DriverShim(d));

            }

            

            // Connect

            Out.debug(getClass(), "Connecting to " + settings.url);

            conn = DriverManager.getConnection(settings.url,
settings.username, settings.password);

            

            // Wrap the connection

            return new ConnectionSource(conn);

      }

 

      @Override

      public void initializeWithParentConfiguration(Configuration
parentConfiguration) {

 
super.initializeWithParentConfiguration(parentConfiguration);

      }

 

-----Original Message-----
From: Andrus Adamchik [mailto:andrus@objectstyle.org] 
Sent: Thursday, April 03, 2008 12:43 PM
To: user@cayenne.apache.org
Subject: Re: How can I customize the driver/url/login

 

> I'm using a custom DataSourceFactory now;

 

 

So how does this code look like? There's something in the DataSource  

it returns that results in the errors you've mentioned.

 

Andrus

 

On Apr 3, 2008, at 7:18 PM, Scott Anderson wrote:

 

> I'm using a custom DataSourceFactory now; if I switch it back to

> DriverDataSourceFactory and set the minimum connections to 2, Derby

> complains about how there can't be two connections, as I'm using the

> EmbeddedDriver.

> 

> -----Original Message-----

> From: Michael Gentry [mailto:blacknext@gmail.com]

> Sent: Thursday, April 03, 2008 12:01 PM

> To: user@cayenne.apache.org

> Subject: Re: How can I customize the driver/url/login

> 

> Just for kicks, bump up your minimum DB connections in the modeler and

> see what happens ...

> 

> 

> On Thu, Apr 3, 2008 at 11:37 AM, Scott Anderson  

> <sa...@airvana.com>

> wrote:

>> While I know enough to briefly describe what a connection pool is, I

>> have no idea how Cayenne uses it, or how it's configured. Could you

> go

>> in to a little more detail? AFAIK, I'm using what ever the default

>> settings are.

>> 

>> It seems unlikely to me that it's derby related because when I use

> the

>> modeler to specify the database location, I don't see anything like

>> this. Could it be that the adapter isn't being specified? I noticed

> that

>> Cayenne is warning that it's using the "automatic" one.

>> 

>> Apr 3, 2008 11:33:56 AM org.apache.cayenne.conf.RuntimeLoadDelegate

>> initAdapter

>> INFO: no adapter set, using automatic adapter.

> 

 


Re: How can I customize the driver/url/login

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Apr 4, 2008, at 7:41 PM, Scott Anderson wrote:

> FWIW, I did manage to figure this out. Basically, I was trying to use
> the connection for my own purposes (to initialize the schema) before
> Cayenne got ahold of it, which was causing it to be in an invalid  
> state
> when Cayenne tried to use it.
>
> The solution was to replace my wrapper with a PoolManager, which I
> figured out by copying DriverDataSourceFactory.java, and making sure  
> to
> close() the connection after I was done with my initialization block.

Yep. I was about to mention that.

Andrus


RE: How can I customize the driver/url/login

Posted by Scott Anderson <sa...@airvana.com>.
FWIW, I did manage to figure this out. Basically, I was trying to use
the connection for my own purposes (to initialize the schema) before
Cayenne got ahold of it, which was causing it to be in an invalid state
when Cayenne tried to use it.

The solution was to replace my wrapper with a PoolManager, which I
figured out by copying DriverDataSourceFactory.java, and making sure to
close() the connection after I was done with my initialization block.

-----Original Message-----
From: Andrus Adamchik [mailto:andrus@objectstyle.org] 
Sent: Thursday, April 03, 2008 12:43 PM
To: user@cayenne.apache.org
Subject: Re: How can I customize the driver/url/login

> I'm using a custom DataSourceFactory now;


So how does this code look like? There's something in the DataSource  
it returns that results in the errors you've mentioned.

Andrus

On Apr 3, 2008, at 7:18 PM, Scott Anderson wrote:

> I'm using a custom DataSourceFactory now; if I switch it back to
> DriverDataSourceFactory and set the minimum connections to 2, Derby
> complains about how there can't be two connections, as I'm using the
> EmbeddedDriver.
>
> -----Original Message-----
> From: Michael Gentry [mailto:blacknext@gmail.com]
> Sent: Thursday, April 03, 2008 12:01 PM
> To: user@cayenne.apache.org
> Subject: Re: How can I customize the driver/url/login
>
> Just for kicks, bump up your minimum DB connections in the modeler and
> see what happens ...
>
>
> On Thu, Apr 3, 2008 at 11:37 AM, Scott Anderson  
> <sa...@airvana.com>
> wrote:
>> While I know enough to briefly describe what a connection pool is, I
>> have no idea how Cayenne uses it, or how it's configured. Could you
> go
>> in to a little more detail? AFAIK, I'm using what ever the default
>> settings are.
>>
>> It seems unlikely to me that it's derby related because when I use
> the
>> modeler to specify the database location, I don't see anything like
>> this. Could it be that the adapter isn't being specified? I noticed
> that
>> Cayenne is warning that it's using the "automatic" one.
>>
>> Apr 3, 2008 11:33:56 AM org.apache.cayenne.conf.RuntimeLoadDelegate
>> initAdapter
>> INFO: no adapter set, using automatic adapter.
>


Re: How can I customize the driver/url/login

Posted by Andrus Adamchik <an...@objectstyle.org>.
> I'm using a custom DataSourceFactory now;


So how does this code look like? There's something in the DataSource  
it returns that results in the errors you've mentioned.

Andrus

On Apr 3, 2008, at 7:18 PM, Scott Anderson wrote:

> I'm using a custom DataSourceFactory now; if I switch it back to
> DriverDataSourceFactory and set the minimum connections to 2, Derby
> complains about how there can't be two connections, as I'm using the
> EmbeddedDriver.
>
> -----Original Message-----
> From: Michael Gentry [mailto:blacknext@gmail.com]
> Sent: Thursday, April 03, 2008 12:01 PM
> To: user@cayenne.apache.org
> Subject: Re: How can I customize the driver/url/login
>
> Just for kicks, bump up your minimum DB connections in the modeler and
> see what happens ...
>
>
> On Thu, Apr 3, 2008 at 11:37 AM, Scott Anderson  
> <sa...@airvana.com>
> wrote:
>> While I know enough to briefly describe what a connection pool is, I
>> have no idea how Cayenne uses it, or how it's configured. Could you
> go
>> in to a little more detail? AFAIK, I'm using what ever the default
>> settings are.
>>
>> It seems unlikely to me that it's derby related because when I use
> the
>> modeler to specify the database location, I don't see anything like
>> this. Could it be that the adapter isn't being specified? I noticed
> that
>> Cayenne is warning that it's using the "automatic" one.
>>
>> Apr 3, 2008 11:33:56 AM org.apache.cayenne.conf.RuntimeLoadDelegate
>> initAdapter
>> INFO: no adapter set, using automatic adapter.
>


RE: How can I customize the driver/url/login

Posted by Scott Anderson <sa...@airvana.com>.
I'm using a custom DataSourceFactory now; if I switch it back to
DriverDataSourceFactory and set the minimum connections to 2, Derby
complains about how there can't be two connections, as I'm using the
EmbeddedDriver.

-----Original Message-----
From: Michael Gentry [mailto:blacknext@gmail.com] 
Sent: Thursday, April 03, 2008 12:01 PM
To: user@cayenne.apache.org
Subject: Re: How can I customize the driver/url/login

Just for kicks, bump up your minimum DB connections in the modeler and
see what happens ...


On Thu, Apr 3, 2008 at 11:37 AM, Scott Anderson <sa...@airvana.com>
wrote:
> While I know enough to briefly describe what a connection pool is, I
>  have no idea how Cayenne uses it, or how it's configured. Could you
go
>  in to a little more detail? AFAIK, I'm using what ever the default
>  settings are.
>
>  It seems unlikely to me that it's derby related because when I use
the
>  modeler to specify the database location, I don't see anything like
>  this. Could it be that the adapter isn't being specified? I noticed
that
>  Cayenne is warning that it's using the "automatic" one.
>
>  Apr 3, 2008 11:33:56 AM org.apache.cayenne.conf.RuntimeLoadDelegate
>  initAdapter
>  INFO: no adapter set, using automatic adapter.

Re: How can I customize the driver/url/login

Posted by Michael Gentry <bl...@gmail.com>.
Just for kicks, bump up your minimum DB connections in the modeler and
see what happens ...


On Thu, Apr 3, 2008 at 11:37 AM, Scott Anderson <sa...@airvana.com> wrote:
> While I know enough to briefly describe what a connection pool is, I
>  have no idea how Cayenne uses it, or how it's configured. Could you go
>  in to a little more detail? AFAIK, I'm using what ever the default
>  settings are.
>
>  It seems unlikely to me that it's derby related because when I use the
>  modeler to specify the database location, I don't see anything like
>  this. Could it be that the adapter isn't being specified? I noticed that
>  Cayenne is warning that it's using the "automatic" one.
>
>  Apr 3, 2008 11:33:56 AM org.apache.cayenne.conf.RuntimeLoadDelegate
>  initAdapter
>  INFO: no adapter set, using automatic adapter.

RE: How can I customize the driver/url/login

Posted by Scott Anderson <sa...@airvana.com>.
While I know enough to briefly describe what a connection pool is, I
have no idea how Cayenne uses it, or how it's configured. Could you go
in to a little more detail? AFAIK, I'm using what ever the default
settings are.

It seems unlikely to me that it's derby related because when I use the
modeler to specify the database location, I don't see anything like
this. Could it be that the adapter isn't being specified? I noticed that
Cayenne is warning that it's using the "automatic" one.

Apr 3, 2008 11:33:56 AM org.apache.cayenne.conf.RuntimeLoadDelegate
initAdapter
INFO: no adapter set, using automatic adapter.

-----Original Message-----
From: Andrus Adamchik [mailto:andrus@objectstyle.org] 
Sent: Thursday, April 03, 2008 11:30 AM
To: user@cayenne.apache.org
Subject: Re: How can I customize the driver/url/login

I can't say what it is, but definitely something Derby-related.  
Googling the exception shows quite a few hits. Which connection pool  
you end up using anyways? The built in Cayenne version?

Andrus


On Apr 3, 2008, at 6:13 PM, Scott Anderson wrote:
> Awesome; that's exactly what I was looking for.
>
> I'm getting an exception I don't quite understand, now. Cayenne is
> complaining about having "no current connection," but it has already
> performed a single query and received results!
>
> Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger logQuery
> INFO: SELECT t0.name, t0.description, t0.access, t0.cmdgroup, t0.id  
> FROM
> command t0 WHERE t0.name = ? [bind: 1->name:'access'] - prepared in 16
> ms.
> Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger
> logSelectCount
> INFO: === returned 1 row. - took 125 ms.
> Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger
> logCommitTransaction
> INFO: +++ transaction committed.
> Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger
> logQueryStart
> INFO: --- will run 1 query.
> Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger
> logBeginTransaction
> INFO: --- transaction started.
> Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger
> logQueryError
> INFO: *** error.
> java.sql.SQLTransientConnectionException: No current connection.
> 	at
> org 
> .apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown
> Source)
> 	at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown
> Source)
> 	at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown
> Source)
> 	at org.apache.derby.impl.jdbc.Util.noCurrentConnection(Unknown
> Source)
> 	at
> org.apache.derby.impl.jdbc.EmbedConnection.checkIfClosed(Unknown  
> Source)
> 	at
> org.apache.derby.impl.jdbc.EmbedConnection.getAutoCommit(Unknown  
> Source)
> 	at
> org 
> .apache.cayenne.access.InternalTransaction.fixConnectionState(Interna
> lTransaction.java:48)
> 	at
> org 
> .apache.cayenne.access.ExternalTransaction.addConnection(ExternalTran
> saction.java:71)
> 	at
> org.apache.cayenne.access.DataNode 
> $TransactionDataSource.getConnection(D
> ataNode.java:322)
> 	at
> org.apache.cayenne.access.DataNode.performQueries(DataNode.java:209)
> 	at
> org 
> .apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQuery
> Action.java:416)
> 	at
> org.apache.cayenne.access.DataDomainQueryAction.access 
> $000(DataDomainQue
> ryAction.java:67)
> 	at
> org.apache.cayenne.access.DataDomainQueryAction 
> $2.transform(DataDomainQu
> eryAction.java:389)
> 	at
> org 
> .apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:84
> 7)
> 	at
> org 
> .apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(Da
> taDomainQueryAction.java:386)
> 	at
> org 
> .apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryA
> ction.java:119)
> 	at
> org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:740)
> 	at
> org 
> .apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQ
> ueryAction.java:304)
> 	at
> org 
> .apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQu
> eryAction.java:88)
> 	at
> org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1343)
> 	at
> org.apache.cayenne.access.DataContext.performQuery(DataContext.java: 
> 1332
> )
> 	at
> org 
> .apache.cayenne.DataObjectUtils.objectForQuery(DataObjectUtils.java:2
> 75)
> 	at net.bnubot.db.Command.get(Command.java:39)
> 	at net.bnubot.core.Profile.registerCommand(Profile.java:32)
> 	at
> net 
> .bnubot.bot.CommandEventHandler.initializeCommands(CommandEventHandle
> r.java:123)
> 	at
> net.bnubot.bot.CommandEventHandler.<clinit>(CommandEventHandler.java: 
> 46)
> 	at net.bnubot.core.Profile.insertConnection(Profile.java:109)
> 	at net.bnubot.core.Profile.add(Profile.java:52)
> 	at net.bnubot.core.Profile.newConnection(Profile.java:157)
> 	at net.bnubot.Main.main(Main.java:106)
> Caused by: java.sql.SQLException: No current connection.
> 	at
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
> Source)
> 	at
> org 
> .apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcr
> ossDRDA(Unknown Source)
> 	... 30 more
>
> Any ideas?
>
> Thanks so much.
>
> -----Original Message-----
> From: Andrus Adamchik [mailto:andrus@objectstyle.org]
> Sent: Thursday, April 03, 2008 10:11 AM
> To: user@cayenne.apache.org
> Subject: Re: How can I customize the driver/url/login
>
> In the Modeler there is a dropdown for the DataNode called "DataSource
> Factory". Here you can specify your own class that implements
> "org.apache.cayenne.conf.DataSourceFactory" interface. Your own
> factory can implement 'getDataSource' method to pop up a dialog asking
> user to enter DB info on first call, or do whatever is appropriate in
> your case.
>
> Cheers,
> Andrus
>
>
> On Apr 3, 2008, at 3:38 AM, Scott Anderson wrote:
>
>> Is there a way I can customize the driver/url/login information
>> through
>> my application code? I want the user to be able to select the  
>> location
>> and login credentials, but the schema is known. I don't want the
>> user to
>> have to write his or her own configuration files and repackage the
>> distributed jar, though.
>>
>
>


Re: How can I customize the driver/url/login

Posted by Andrus Adamchik <an...@objectstyle.org>.
I can't say what it is, but definitely something Derby-related.  
Googling the exception shows quite a few hits. Which connection pool  
you end up using anyways? The built in Cayenne version?

Andrus


On Apr 3, 2008, at 6:13 PM, Scott Anderson wrote:
> Awesome; that's exactly what I was looking for.
>
> I'm getting an exception I don't quite understand, now. Cayenne is
> complaining about having "no current connection," but it has already
> performed a single query and received results!
>
> Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger logQuery
> INFO: SELECT t0.name, t0.description, t0.access, t0.cmdgroup, t0.id  
> FROM
> command t0 WHERE t0.name = ? [bind: 1->name:'access'] - prepared in 16
> ms.
> Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger
> logSelectCount
> INFO: === returned 1 row. - took 125 ms.
> Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger
> logCommitTransaction
> INFO: +++ transaction committed.
> Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger
> logQueryStart
> INFO: --- will run 1 query.
> Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger
> logBeginTransaction
> INFO: --- transaction started.
> Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger
> logQueryError
> INFO: *** error.
> java.sql.SQLTransientConnectionException: No current connection.
> 	at
> org 
> .apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown
> Source)
> 	at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown
> Source)
> 	at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown
> Source)
> 	at org.apache.derby.impl.jdbc.Util.noCurrentConnection(Unknown
> Source)
> 	at
> org.apache.derby.impl.jdbc.EmbedConnection.checkIfClosed(Unknown  
> Source)
> 	at
> org.apache.derby.impl.jdbc.EmbedConnection.getAutoCommit(Unknown  
> Source)
> 	at
> org 
> .apache.cayenne.access.InternalTransaction.fixConnectionState(Interna
> lTransaction.java:48)
> 	at
> org 
> .apache.cayenne.access.ExternalTransaction.addConnection(ExternalTran
> saction.java:71)
> 	at
> org.apache.cayenne.access.DataNode 
> $TransactionDataSource.getConnection(D
> ataNode.java:322)
> 	at
> org.apache.cayenne.access.DataNode.performQueries(DataNode.java:209)
> 	at
> org 
> .apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQuery
> Action.java:416)
> 	at
> org.apache.cayenne.access.DataDomainQueryAction.access 
> $000(DataDomainQue
> ryAction.java:67)
> 	at
> org.apache.cayenne.access.DataDomainQueryAction 
> $2.transform(DataDomainQu
> eryAction.java:389)
> 	at
> org 
> .apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:84
> 7)
> 	at
> org 
> .apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(Da
> taDomainQueryAction.java:386)
> 	at
> org 
> .apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryA
> ction.java:119)
> 	at
> org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:740)
> 	at
> org 
> .apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQ
> ueryAction.java:304)
> 	at
> org 
> .apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQu
> eryAction.java:88)
> 	at
> org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1343)
> 	at
> org.apache.cayenne.access.DataContext.performQuery(DataContext.java: 
> 1332
> )
> 	at
> org 
> .apache.cayenne.DataObjectUtils.objectForQuery(DataObjectUtils.java:2
> 75)
> 	at net.bnubot.db.Command.get(Command.java:39)
> 	at net.bnubot.core.Profile.registerCommand(Profile.java:32)
> 	at
> net 
> .bnubot.bot.CommandEventHandler.initializeCommands(CommandEventHandle
> r.java:123)
> 	at
> net.bnubot.bot.CommandEventHandler.<clinit>(CommandEventHandler.java: 
> 46)
> 	at net.bnubot.core.Profile.insertConnection(Profile.java:109)
> 	at net.bnubot.core.Profile.add(Profile.java:52)
> 	at net.bnubot.core.Profile.newConnection(Profile.java:157)
> 	at net.bnubot.Main.main(Main.java:106)
> Caused by: java.sql.SQLException: No current connection.
> 	at
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
> Source)
> 	at
> org 
> .apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcr
> ossDRDA(Unknown Source)
> 	... 30 more
>
> Any ideas?
>
> Thanks so much.
>
> -----Original Message-----
> From: Andrus Adamchik [mailto:andrus@objectstyle.org]
> Sent: Thursday, April 03, 2008 10:11 AM
> To: user@cayenne.apache.org
> Subject: Re: How can I customize the driver/url/login
>
> In the Modeler there is a dropdown for the DataNode called "DataSource
> Factory". Here you can specify your own class that implements
> "org.apache.cayenne.conf.DataSourceFactory" interface. Your own
> factory can implement 'getDataSource' method to pop up a dialog asking
> user to enter DB info on first call, or do whatever is appropriate in
> your case.
>
> Cheers,
> Andrus
>
>
> On Apr 3, 2008, at 3:38 AM, Scott Anderson wrote:
>
>> Is there a way I can customize the driver/url/login information
>> through
>> my application code? I want the user to be able to select the  
>> location
>> and login credentials, but the schema is known. I don't want the
>> user to
>> have to write his or her own configuration files and repackage the
>> distributed jar, though.
>>
>
>


RE: How can I customize the driver/url/login

Posted by Scott Anderson <sa...@airvana.com>.
Awesome; that's exactly what I was looking for.

I'm getting an exception I don't quite understand, now. Cayenne is
complaining about having "no current connection," but it has already
performed a single query and received results!

Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger logQuery
INFO: SELECT t0.name, t0.description, t0.access, t0.cmdgroup, t0.id FROM
command t0 WHERE t0.name = ? [bind: 1->name:'access'] - prepared in 16
ms.
Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger
logSelectCount
INFO: === returned 1 row. - took 125 ms.
Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger
logCommitTransaction
INFO: +++ transaction committed.
Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger
logQueryStart
INFO: --- will run 1 query.
Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger
logBeginTransaction
INFO: --- transaction started.
Apr 3, 2008 11:10:54 AM org.apache.cayenne.access.QueryLogger
logQueryError
INFO: *** error.
java.sql.SQLTransientConnectionException: No current connection.
	at
org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown
Source)
	at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown
Source)
	at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown
Source)
	at org.apache.derby.impl.jdbc.Util.noCurrentConnection(Unknown
Source)
	at
org.apache.derby.impl.jdbc.EmbedConnection.checkIfClosed(Unknown Source)
	at
org.apache.derby.impl.jdbc.EmbedConnection.getAutoCommit(Unknown Source)
	at
org.apache.cayenne.access.InternalTransaction.fixConnectionState(Interna
lTransaction.java:48)
	at
org.apache.cayenne.access.ExternalTransaction.addConnection(ExternalTran
saction.java:71)
	at
org.apache.cayenne.access.DataNode$TransactionDataSource.getConnection(D
ataNode.java:322)
	at
org.apache.cayenne.access.DataNode.performQueries(DataNode.java:209)
	at
org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQuery
Action.java:416)
	at
org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQue
ryAction.java:67)
	at
org.apache.cayenne.access.DataDomainQueryAction$2.transform(DataDomainQu
eryAction.java:389)
	at
org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:84
7)
	at
org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(Da
taDomainQueryAction.java:386)
	at
org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryA
ction.java:119)
	at
org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:740)
	at
org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQ
ueryAction.java:304)
	at
org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQu
eryAction.java:88)
	at
org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1343)
	at
org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1332
)
	at
org.apache.cayenne.DataObjectUtils.objectForQuery(DataObjectUtils.java:2
75)
	at net.bnubot.db.Command.get(Command.java:39)
	at net.bnubot.core.Profile.registerCommand(Profile.java:32)
	at
net.bnubot.bot.CommandEventHandler.initializeCommands(CommandEventHandle
r.java:123)
	at
net.bnubot.bot.CommandEventHandler.<clinit>(CommandEventHandler.java:46)
	at net.bnubot.core.Profile.insertConnection(Profile.java:109)
	at net.bnubot.core.Profile.add(Profile.java:52)
	at net.bnubot.core.Profile.newConnection(Profile.java:157)
	at net.bnubot.Main.main(Main.java:106)
Caused by: java.sql.SQLException: No current connection.
	at
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
Source)
	at
org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcr
ossDRDA(Unknown Source)
	... 30 more

Any ideas?

Thanks so much.

-----Original Message-----
From: Andrus Adamchik [mailto:andrus@objectstyle.org] 
Sent: Thursday, April 03, 2008 10:11 AM
To: user@cayenne.apache.org
Subject: Re: How can I customize the driver/url/login

In the Modeler there is a dropdown for the DataNode called "DataSource  
Factory". Here you can specify your own class that implements  
"org.apache.cayenne.conf.DataSourceFactory" interface. Your own  
factory can implement 'getDataSource' method to pop up a dialog asking  
user to enter DB info on first call, or do whatever is appropriate in  
your case.

Cheers,
Andrus


On Apr 3, 2008, at 3:38 AM, Scott Anderson wrote:

> Is there a way I can customize the driver/url/login information  
> through
> my application code? I want the user to be able to select the location
> and login credentials, but the schema is known. I don't want the  
> user to
> have to write his or her own configuration files and repackage the
> distributed jar, though.
>


Re: How can I customize the driver/url/login

Posted by Andrus Adamchik <an...@objectstyle.org>.
In the Modeler there is a dropdown for the DataNode called "DataSource  
Factory". Here you can specify your own class that implements  
"org.apache.cayenne.conf.DataSourceFactory" interface. Your own  
factory can implement 'getDataSource' method to pop up a dialog asking  
user to enter DB info on first call, or do whatever is appropriate in  
your case.

Cheers,
Andrus


On Apr 3, 2008, at 3:38 AM, Scott Anderson wrote:

> Is there a way I can customize the driver/url/login information  
> through
> my application code? I want the user to be able to select the location
> and login credentials, but the schema is known. I don't want the  
> user to
> have to write his or her own configuration files and repackage the
> distributed jar, though.
>