Andreas Dembach wrote:
> Hello list,
>
> we have the following situation:
>
> - we are migrating mod_perl application to Catalyst under mod_perl2 and
> use DBIC as persistence layer.
> - the apache server hosts two (in fact even more) virtual hosts with the
> same application but different configurations (e.g. one for test and one
> for production).
> - beneath other configuration items, like template-root we want the
> different virtual hosts to use different database connections.
>
> Problem:
>
> As far as I can tell from the source code, DBIx::Class::Storage::DBI
> caches the database handle in '_dbh' which results in always using the
> first database handle that inititated a connection. So we end up having
> the configured $dbh of whatever virtual host is called first within a
> newly created Apache process.
>
> Question:
>
> Is this a design decision to support only one DB connection per process
> or is this a little bug that could be fixed by caching the dbh with some
> additional meta info (e.g. the connection parameters à la
> DBI->connect_cached)?
This is neither a design decision nor a bug. You've just misunderstood how
stuff works.
DBIx::Class supports as many connections to different databases per process as
you like. Catalyst::Model::DBIC::Schema can handle being instantiated multiple
times with different connections.
The problem is that the model references in Catalyst are held as
one-per-process by default. Get rid of your nasty hack in Storage and add an
ACCEPT_CONTEXT method to your C::M::DBIC::Schema class that returns the
appropriate one based on whatever; this is documented in Catalyst::Component.
Catalyst will support multiple instances of the same app with different
configurations for 5.80, but 5.70 doesn't; if you're interested, there's a
branch in the Catalyst repository but discussion of that should probably be on
either the catalyst or catalyst-dev lsits rather than here :)
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/