You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by bhorvat <ho...@gmail.com> on 2012/11/21 00:14:59 UTC

Adding new properties from AppModule

I have a few execution environments like prod, qa, dev and such and I want to
set a certain property based on that. Basically I want to set config
property progrematically inside QAMode,ProdMode and DevMode

    @Contribute(HibernateSessionSource.class)
    public void
addHibernateSessionSource(OrderedConfiguration<HibernateConfigurer> conf,
            @Value("${config}") final String executionMode) {

        conf.add("HibernateConfig", new HibernateConfigurer() {
            @Override
            public void configure(org.hibernate.cfg.Configuration
configuration) {
                configuration.configure("scripts/db/" + config +
"/hibernate.cfg.xml");
            }
        });
    }

Thanks for help.

Cheers



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Adding-new-properties-from-AppModule-tp5718137.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Adding new properties from AppModule

Posted by bhorvat <ho...@gmail.com>.
I will try to add a bit more content. 

What I am trying to do is create environments for my development, and one of
the key aspect here would be the database connection. 

So in my hibernate.cfg.xml file I need to set hibernate.connection.url, so I
would like to set it using the properties or for example
hibernate.connection.username and hibernate.connection.password. 

So in this way I will have one hibernate.cfg.xml and use the diff modules to
set it up. So can I set this one up somehow with MappedConfiguration<K,V> or
use System.setProperty()?



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Adding-new-properties-from-AppModule-tp5718137p5718164.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Adding new properties from AppModule

Posted by Lance Java <la...@googlemail.com>.
> How can I add new properties
This question is pretty vague, most likely you will use a
MappedConfiguration<K,V> which allows you to contribute to a service which
takes a Map<K,V> in it's constructor.

> Should I simply use System.setProperties
Most likely not

> Also one other question what is the order of the model load?
Quick answer: In the order that they are needed. Tapestry IOC is lazy, none
of your services are instantiated initially. Instead, tapestry creates a
proxy which will only instantiate your service implementation the first time
a method is invoked on the proxy.

You can force a service to load using eager loading
(http://tapestry.apache.org/defining-tapestry-ioc-services.html#DefiningTapestryIOCServices-EagerLoadingServices)

Tapestry includes a page in your application where you can check the status
of your services (http://tapestry.apache.org/service-status.html)



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Adding-new-properties-from-AppModule-tp5718137p5718151.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Adding new properties from AppModule

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 20 Nov 2012 21:33:31 -0200, bhorvat <ho...@gmail.com>  
wrote:

> Also one other question what is the order of the model load?

You shouldn't rely on that. That's why OrderedConfiguration exists.

-- 
Thiago H. de Paula Figueiredo

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


Re: Adding new properties from AppModule

Posted by bhorvat <ho...@gmail.com>.
Ok then my question remains. How can I add new properties, is there any way
to add some custom properties or should I simply use System.setPropertie...

Also one other question what is the order of the model load?

AppModule, ExecutionModelus, SubModules defined in AppModule? Also does it
load everything from one module or does it go method by method?

For example it first calls bind() in all modules and then it moves on to
contributeApplicationDefaults?

tnx for fast response

cheers



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Adding-new-properties-from-AppModule-tp5718137p5718141.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Adding new properties from AppModule

Posted by Howard Lewis Ship <hl...@gmail.com>.
No, I'm saying you should analyze what values and/or services are needed in
each of your scenarios and Tapestry gives you the flexibility to
do exactly what you want or need.


On Tue, Nov 20, 2012 at 3:19 PM, bhorvat <ho...@gmail.com> wrote:

> hm...so what you are saying is that I should not set a property that will
> be
> used by other module, but instead copy the method into my 3 modules and
> make
> it custom for them, right?
>
> i guess the only problem that I have is code duplication
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Adding-new-properties-from-AppModule-tp5718137p5718139.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

Re: Adding new properties from AppModule

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 20 Nov 2012 21:19:36 -0200, bhorvat <ho...@gmail.com>  
wrote:

> hm...so what you are saying is that I should not set a property that  
> will be used by other module, but instead copy the method into my 3  
> modules and make it custom for them, right?

No.

> i guess the only problem that I have is code duplication

Just use ordinary Java code reuse: put the shared code inside a method in  
some class and call this method in any class you need. Code duplication  
avoided.

-- 
Thiago H. de Paula Figueiredo

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


Re: Adding new properties from AppModule

Posted by bhorvat <ho...@gmail.com>.
hm...so what you are saying is that I should not set a property that will be
used by other module, but instead copy the method into my 3 modules and make
it custom for them, right? 

i guess the only problem that I have is code duplication



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Adding-new-properties-from-AppModule-tp5718137p5718139.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Adding new properties from AppModule

Posted by Howard Lewis Ship <hl...@gmail.com>.
This is what execution modes are about.

Execution modes map to modules; those modules are only loaded if the
execution mode is active. It is entirely for these particular kinds of
environmental customizations.


On Tue, Nov 20, 2012 at 3:14 PM, bhorvat <ho...@gmail.com> wrote:

> I have a few execution environments like prod, qa, dev and such and I want
> to
> set a certain property based on that. Basically I want to set config
> property progrematically inside QAMode,ProdMode and DevMode
>
>     @Contribute(HibernateSessionSource.class)
>     public void
> addHibernateSessionSource(OrderedConfiguration<HibernateConfigurer> conf,
>             @Value("${config}") final String executionMode) {
>
>         conf.add("HibernateConfig", new HibernateConfigurer() {
>             @Override
>             public void configure(org.hibernate.cfg.Configuration
> configuration) {
>                 configuration.configure("scripts/db/" + config +
> "/hibernate.cfg.xml");
>             }
>         });
>     }
>
> Thanks for help.
>
> Cheers
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Adding-new-properties-from-AppModule-tp5718137.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com