You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Daniel Toffetti <dt...@yahoo.com.ar> on 2010/04/05 05:43:54 UTC
SchemaGenerator and connections
Hi all,
I'm attempting to write a Netbeans plugin that should work as a GUI
frontend for ReverseMappingTool, it should be able to let me choose an (IDE
configured) connection, choose tables and objects, select options that
affect generation, and call RMT to let it create Entities.
Now, currently I have to setup database connection parameters (driver
etc) and a new connection is created internally, even many times to get all
schema objects. But this forces me to add the driver jars into the plugin or
else I get CNFEs.
I would like to add SchemaGenerator the possibility to work with a
connection provided externally so I don't have to care about the specific
drivers used to create it (they are already configured in the IDE).
I've created a local copy of SchemaGenerator with these changes and it
seems to work well, is there any reason not to use it in this way ? Is
there any other way I can achieve this functionality by providing
SchemaGenerator with different config options, so I don't have to keep a
modified copy of it ?
Cheers,
Daniel
--
View this message in context: http://n2.nabble.com/SchemaGenerator-and-connections-tp4852136p4852136.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: SchemaGenerator and connections
Posted by Daniel Toffetti <dt...@yahoo.com.ar>.
Hi,
I've tried to use JDBCStoreManager.RefCountConnection but it's actually
quite unfriendly for reuse, I mean, it's a protected inner class and is
related to private static fields and initialization. Even attempting to
subclass JDBCStoreManager is hard, besides of missing the point.
For now I'll keep using my modified copy of SchemaGenerator, even
without proper connection cleanup. If I reach a point where I get a nice
working plugin, it will hopefully be a good case to justify upstream changes
in SchemaGenerator.
Thanks for your help,
Daniel
Michael Dick wrote:
>
> I'd have to look at the code paths involved, but in the 'mainline' code we
> wrap the real connection in a RefCountConnection. RefCountConnection
> maintains a count of the number of times it's been handed out decrementing
> it when ever it's closed. The real connection won't be closed until the
> counter reaches 0.
>
> If we create the same wrapper in the SchemaGenerator then you should be
> able
> to get the connection in the main method (incrementing the count) and then
> close it at the end.
>
> If everything's working right the individual methods will get the same
> connection - the count won't drop to 0 until the end of the main method
> and
> you should be okay.
>
> Something along those lines should be feasible, and with some luck you
> won't
> have to change any signatures along the way.
>
--
View this message in context: http://n2.nabble.com/SchemaGenerator-and-connections-tp4852136p4885851.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: SchemaGenerator and connections
Posted by Michael Dick <mi...@gmail.com>.
I'd have to look at the code paths involved, but in the 'mainline' code we
wrap the real connection in a RefCountConnection. RefCountConnection
maintains a count of the number of times it's been handed out decrementing
it when ever it's closed. The real connection won't be closed until the
counter reaches 0.
If we create the same wrapper in the SchemaGenerator then you should be able
to get the connection in the main method (incrementing the count) and then
close it at the end.
If everything's working right the individual methods will get the same
connection - the count won't drop to 0 until the end of the main method and
you should be okay.
Something along those lines should be feasible, and with some luck you won't
have to change any signatures along the way.
Best Regards,
-mike
On Mon, Apr 5, 2010 at 4:06 PM, Daniel Toffetti <dt...@yahoo.com.ar> wrote:
>
> Sure I can, the problem is that I tried the quickest approach that came
> to mind just to see if it worked, and that means receiving a Connection in
> the constructor and keeping a local reference to it.
> I'm mostly sure such a thing will probably be frowned upon since it can
> lead to leaks and/or unproperly managed resources. The current code
> properly
> obtains a Connection in every method body's beggining and releases it at
> the
> end. But since I get the connection from outside, I can't close it and
> create it again later.
> I'll try to come up with a better solution and provide a patch.
>
> Thanks for your help !
>
> Daniel
>
>
> Rick Curtis wrote:
> >
> >
> > I haven't really looked at the SchemaGenerator before, but what all did
> > you
> > change? Perhaps you can post a patch with your changes?
> >
> >
>
> --
> View this message in context:
> http://n2.nabble.com/SchemaGenerator-and-connections-tp4852136p4855448.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
Re: SchemaGenerator and connections
Posted by Daniel Toffetti <dt...@yahoo.com.ar>.
Sure I can, the problem is that I tried the quickest approach that came
to mind just to see if it worked, and that means receiving a Connection in
the constructor and keeping a local reference to it.
I'm mostly sure such a thing will probably be frowned upon since it can
lead to leaks and/or unproperly managed resources. The current code properly
obtains a Connection in every method body's beggining and releases it at the
end. But since I get the connection from outside, I can't close it and
create it again later.
I'll try to come up with a better solution and provide a patch.
Thanks for your help !
Daniel
Rick Curtis wrote:
>
>
> I haven't really looked at the SchemaGenerator before, but what all did
> you
> change? Perhaps you can post a patch with your changes?
>
>
--
View this message in context: http://n2.nabble.com/SchemaGenerator-and-connections-tp4852136p4855448.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: SchemaGenerator and connections
Posted by Rick Curtis <cu...@gmail.com>.
I haven't really looked at the SchemaGenerator before, but what all did you
change? Perhaps you can post a patch with your changes?
--
Thanks,
Rick
On Sun, Apr 4, 2010 at 10:43 PM, Daniel Toffetti <dt...@yahoo.com.ar>wrote:
>
> Hi all,
>
> I'm attempting to write a Netbeans plugin that should work as a GUI
> frontend for ReverseMappingTool, it should be able to let me choose an (IDE
> configured) connection, choose tables and objects, select options that
> affect generation, and call RMT to let it create Entities.
> Now, currently I have to setup database connection parameters (driver
> etc) and a new connection is created internally, even many times to get all
> schema objects. But this forces me to add the driver jars into the plugin
> or
> else I get CNFEs.
> I would like to add SchemaGenerator the possibility to work with a
> connection provided externally so I don't have to care about the specific
> drivers used to create it (they are already configured in the IDE).
> I've created a local copy of SchemaGenerator with these changes and it
> seems to work well, is there any reason not to use it in this way ? Is
> there any other way I can achieve this functionality by providing
> SchemaGenerator with different config options, so I don't have to keep a
> modified copy of it ?
>
> Cheers,
>
> Daniel
>
> --
> View this message in context:
> http://n2.nabble.com/SchemaGenerator-and-connections-tp4852136p4852136.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>