You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Kalle Korhonen <ka...@gmail.com> on 2009/11/13 19:18:47 UTC

Re: Switching between Stage & Production DB with Tapestry5 & Hibernate3

Best practice - use a combination of Tapestry and Hibernate "tricks".
Use separate configuration files, and pick to use based on the mode
you are running in your AppModule:

	public void contributeHibernateSessionSource(OrderedConfiguration<HibernateConfigurer>
configurer,
			@InjectService("DefaultHibernateConfigurer") HibernateConfigurer
defaultHibernateConfigurer) {

		class RunModeDependentHibernateConfigurer implements HibernateConfigurer {

			public void configure(org.hibernate.cfg.Configuration configuration) {
				if (productionMode ||
"true".equals(System.getProperty(Symbols.FORCE_PERSISTENT_DB)))
configuration
						.configure("/hibernate-production.cfg.xml");
				else configuration.configure("/hibernate-test.cfg.xml");
			}
		}
		;
		configurer.add(productionMode == true ? "production" : "test", new
RunModeDependentHibernateConfigurer(), "before:*");
	}

I had earlier (in bind()) set the static productionMode flag based on
the value of System.getProperty(SymbolConstants.PRODUCTION_MODE). We
also use another flag to force the persistent db even if we are
running in development mode (handy when you want to with the
production database).

Even if you don't understand the code, copy and paste it to your
AppModule and resolve errors and see how it behaves, then read the
documentation for tapestry-ioc and tapestry-hibernate modules.

Kalle


On Fri, Nov 13, 2009 at 9:46 AM, Alessandro Bottoni
<al...@gmail.com> wrote:
> Hi All,
> I'm almost completely new to Tapestry and Hibernate so, please, be patient..
>
> In your opinion, what's the best (simplest/most-maintainable) way to
> deal with two different databases with T5 and H3?
>
> I have the classical stage/production environment with the same software
> (and the same RDBMS) on the two machines but two different data sets and
> I have to switch from the one to the other when deploying the T5 stuff.
>
> Is it better to rely on the mechanisms provided by Hibernate (loading
> different configuration files, for example) or is it better to use some
> Tapestry-specific trick?
>
> How do you do that, usually?
>
> Thanks in advance for your attention.
>
> --
>
> Alessandro Bottoni
> Website: http://www.alessandrobottoni.it/
>
> "In mathematics you don't understand things. You just get used to them."
>     -- John von Neumann
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Switching between Stage & Production DB with Tapestry5 & Hibernate3

Posted by "Juan E. Maya" <ma...@gmail.com>.
U could also use maven for this using maven profiles and resource filtering.

<build>
		<resources>
			<resource>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
			</resource>
		</resources>
	</build>

This would allow to create variables inside your resources that could
be changed during the maven build process.

U could have a jdbc.properties or an hibernate.cfg that uses variables like:

jdbc.url=${nebula.jdbc.url}
jdbc.username=${nebula.jdbc.username}
jdbc.password=${nebula.jdbc.password}

Those variables could be defined in ur pom.xml, u r maven settings.xml

U can read more about
http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

This would example be good if u don't want to commit the user and
password of ur production environments to the repository.

On Fri, Nov 13, 2009 at 7:18 PM, Kalle Korhonen
<ka...@gmail.com> wrote:
> Best practice - use a combination of Tapestry and Hibernate "tricks".
> Use separate configuration files, and pick to use based on the mode
> you are running in your AppModule:
>
>        public void contributeHibernateSessionSource(OrderedConfiguration<HibernateConfigurer>
> configurer,
>                        @InjectService("DefaultHibernateConfigurer") HibernateConfigurer
> defaultHibernateConfigurer) {
>
>                class RunModeDependentHibernateConfigurer implements HibernateConfigurer {
>
>                        public void configure(org.hibernate.cfg.Configuration configuration) {
>                                if (productionMode ||
> "true".equals(System.getProperty(Symbols.FORCE_PERSISTENT_DB)))
> configuration
>                                                .configure("/hibernate-production.cfg.xml");
>                                else configuration.configure("/hibernate-test.cfg.xml");
>                        }
>                }
>                ;
>                configurer.add(productionMode == true ? "production" : "test", new
> RunModeDependentHibernateConfigurer(), "before:*");
>        }
>
> I had earlier (in bind()) set the static productionMode flag based on
> the value of System.getProperty(SymbolConstants.PRODUCTION_MODE). We
> also use another flag to force the persistent db even if we are
> running in development mode (handy when you want to with the
> production database).
>
> Even if you don't understand the code, copy and paste it to your
> AppModule and resolve errors and see how it behaves, then read the
> documentation for tapestry-ioc and tapestry-hibernate modules.
>
> Kalle
>
>
> On Fri, Nov 13, 2009 at 9:46 AM, Alessandro Bottoni
> <al...@gmail.com> wrote:
>> Hi All,
>> I'm almost completely new to Tapestry and Hibernate so, please, be patient..
>>
>> In your opinion, what's the best (simplest/most-maintainable) way to
>> deal with two different databases with T5 and H3?
>>
>> I have the classical stage/production environment with the same software
>> (and the same RDBMS) on the two machines but two different data sets and
>> I have to switch from the one to the other when deploying the T5 stuff.
>>
>> Is it better to rely on the mechanisms provided by Hibernate (loading
>> different configuration files, for example) or is it better to use some
>> Tapestry-specific trick?
>>
>> How do you do that, usually?
>>
>> Thanks in advance for your attention.
>>
>> --
>>
>> Alessandro Bottoni
>> Website: http://www.alessandrobottoni.it/
>>
>> "In mathematics you don't understand things. You just get used to them."
>>     -- John von Neumann
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org