You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Hugi Thordarson <hu...@karlmenn.is> on 2015/08/27 10:37:55 UTC

Getting the currently active ServerRuntime

Hi all.

I’m writing a Cayenne-based CRUD framework of sorts, in the form of a jar that plugs into Cayenne applications. Currently, I’m telling the framework about the Cayenne environment at application startup by setting a ServerRuntime variable manually in a configuration class. Is there any way for me to smooth out this operation by making the framework automatically obtain the active ServerRuntime in the current environment?

Cheers,
- hugi

// Hugi Thordarson
// http://www.loftfar.is/ <http://www.loftfar.is/>
// s. 895-6688




Re: Getting the currently active ServerRuntime

Posted by Hugi Thordarson <hu...@karlmenn.is>.
That’s great, thanks!

- hugi

// Hugi Thordarson
// http://www.loftfar.is/ <http://www.loftfar.is/>
// s. 895-6688



> On 27. ágú. 2015, at 18:04, Andrus Adamchik <an...@objectstyle.org> wrote:
> 
> You can add it to a List of project locations inside your Module 'configure':
> 
> public void configure(Binder binder) {
>   binder.bindList(Constants.SERVER_PROJECT_LOCATIONS_LIST).add("cayenne-xyz.xml");
> }
> 
> Or explicitly pass it to ServerRuntime, when you are creating it. 
> 
> Though the first approach provides better encapsulation of your framework.
> 
> Andrus
> 
> 
>> On Aug 27, 2015, at 6:45 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>> 
>> That’s pretty awesome. One question though, how do I tell the Module about the location of it's Cayenne Model? (like I do with the configurationLocation parameter in ServerRuntime)
>> 
>> Thanks!
>> - hugi
>> 
>> 
>> 
>>> On 27. ágú. 2015, at 10:44, Andrus Adamchik <an...@objectstyle.org> wrote:
>>> 
>>> Hi Hugi,
>>> 
>>> Are you using DI by any chance in your app? Cause if you do, it becomes as simple as making ServerRuntime one of the "services" and injecting it into your framework.
>>> 
>>> Or maybe you can invert that? Instead of telling the framework about ServerRuntime, you tell ServerRuntime about your framework (essentially relying on Cayenne to be your DI provider). To do that you expose your framework as a DI Module. That's our preferred way of loading Cayenne extensions. Maybe you can use the same approach with your own code:
>>> 
>>> // this comes from your framework. The module can define a class that decla
>>> public class MyModule implements Module {
>>>    public void configure(Binder binder) {
>>> 
>>>       // MyFrameworkImpl may inject ObjectContextFactory to obtain contexts
>>>       binder.bind(MyFramework.class).to(MyFrameworkImpl.class);
>>>    }
>>> }
>>> 
>>> // this is how you bootstrap both Cayenne and your framework in your app
>>> MyModule m = new MyModule();
>>> ServerRuntime runtime = new ServerRuntime("myproject.xml", m);
>>> 
>>> MyFramework f = runtime.getInjector().getInstance(MyFramework.class);
>>> // now you can call methods on f.
>>> 
>>> 
>>> Andrus
>>> 
>>> 
>>>> On Aug 27, 2015, at 11:54 AM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>>>> 
>>>>> On 27/08/2015 6:37pm, Hugi Thordarson wrote:
>>>>>> I’m writing a Cayenne-based CRUD framework of sorts, in the form of a jar that plugs into Cayenne applications. 
>>>>> 
>>>>> Is there overlap with this: http://nhl.github.io/link-rest/ which was already built over the top of Cayenne?
>>>> 
>>>> Not really, what we're doing works at a little lower level and serves more specific requirements. Framework looks nice though—and it’s fun to see Cayenne in the wild.
>>>> 
>>>> - hugi
>>> 
>> 
> 


Re: Getting the currently active ServerRuntime

Posted by Andrus Adamchik <an...@objectstyle.org>.
You can add it to a List of project locations inside your Module 'configure':

public void configure(Binder binder) {
   binder.bindList(Constants.SERVER_PROJECT_LOCATIONS_LIST).add("cayenne-xyz.xml");
}

Or explicitly pass it to ServerRuntime, when you are creating it. 

Though the first approach provides better encapsulation of your framework.

Andrus


> On Aug 27, 2015, at 6:45 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
> 
> That’s pretty awesome. One question though, how do I tell the Module about the location of it's Cayenne Model? (like I do with the configurationLocation parameter in ServerRuntime)
> 
> Thanks!
> - hugi
> 
> 
> 
>> On 27. ágú. 2015, at 10:44, Andrus Adamchik <an...@objectstyle.org> wrote:
>> 
>> Hi Hugi,
>> 
>> Are you using DI by any chance in your app? Cause if you do, it becomes as simple as making ServerRuntime one of the "services" and injecting it into your framework.
>> 
>> Or maybe you can invert that? Instead of telling the framework about ServerRuntime, you tell ServerRuntime about your framework (essentially relying on Cayenne to be your DI provider). To do that you expose your framework as a DI Module. That's our preferred way of loading Cayenne extensions. Maybe you can use the same approach with your own code:
>> 
>> // this comes from your framework. The module can define a class that decla
>> public class MyModule implements Module {
>>     public void configure(Binder binder) {
>> 
>>        // MyFrameworkImpl may inject ObjectContextFactory to obtain contexts
>>        binder.bind(MyFramework.class).to(MyFrameworkImpl.class);
>>     }
>> }
>> 
>> // this is how you bootstrap both Cayenne and your framework in your app
>> MyModule m = new MyModule();
>> ServerRuntime runtime = new ServerRuntime("myproject.xml", m);
>> 
>> MyFramework f = runtime.getInjector().getInstance(MyFramework.class);
>> // now you can call methods on f.
>> 
>> 
>> Andrus
>> 
>> 
>>> On Aug 27, 2015, at 11:54 AM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>>> 
>>>> On 27/08/2015 6:37pm, Hugi Thordarson wrote:
>>>>> I’m writing a Cayenne-based CRUD framework of sorts, in the form of a jar that plugs into Cayenne applications. 
>>>> 
>>>> Is there overlap with this: http://nhl.github.io/link-rest/ which was already built over the top of Cayenne?
>>> 
>>> Not really, what we're doing works at a little lower level and serves more specific requirements. Framework looks nice though—and it’s fun to see Cayenne in the wild.
>>> 
>>> - hugi
>> 
> 


Re: Getting the currently active ServerRuntime

Posted by Hugi Thordarson <hu...@karlmenn.is>.
That’s pretty awesome. One question though, how do I tell the Module about the location of it's Cayenne Model? (like I do with the configurationLocation parameter in ServerRuntime)

Thanks!
- hugi



> On 27. ágú. 2015, at 10:44, Andrus Adamchik <an...@objectstyle.org> wrote:
> 
> Hi Hugi,
> 
> Are you using DI by any chance in your app? Cause if you do, it becomes as simple as making ServerRuntime one of the "services" and injecting it into your framework.
> 
> Or maybe you can invert that? Instead of telling the framework about ServerRuntime, you tell ServerRuntime about your framework (essentially relying on Cayenne to be your DI provider). To do that you expose your framework as a DI Module. That's our preferred way of loading Cayenne extensions. Maybe you can use the same approach with your own code:
> 
>  // this comes from your framework. The module can define a class that decla
>  public class MyModule implements Module {
>      public void configure(Binder binder) {
> 
>         // MyFrameworkImpl may inject ObjectContextFactory to obtain contexts
>         binder.bind(MyFramework.class).to(MyFrameworkImpl.class);
>      }
>  }
> 
>  // this is how you bootstrap both Cayenne and your framework in your app
>  MyModule m = new MyModule();
>  ServerRuntime runtime = new ServerRuntime("myproject.xml", m);
> 
>  MyFramework f = runtime.getInjector().getInstance(MyFramework.class);
>  // now you can call methods on f.
> 
> 
> Andrus
> 
> 
>> On Aug 27, 2015, at 11:54 AM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>> 
>>> On 27/08/2015 6:37pm, Hugi Thordarson wrote:
>>>> I’m writing a Cayenne-based CRUD framework of sorts, in the form of a jar that plugs into Cayenne applications. 
>>> 
>>> Is there overlap with this: http://nhl.github.io/link-rest/ which was already built over the top of Cayenne?
>> 
>> Not really, what we're doing works at a little lower level and serves more specific requirements. Framework looks nice though—and it’s fun to see Cayenne in the wild.
>> 
>> - hugi
> 


Re: Getting the currently active ServerRuntime

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Hugi,

Are you using DI by any chance in your app? Cause if you do, it becomes as simple as making ServerRuntime one of the "services" and injecting it into your framework.

Or maybe you can invert that? Instead of telling the framework about ServerRuntime, you tell ServerRuntime about your framework (essentially relying on Cayenne to be your DI provider). To do that you expose your framework as a DI Module. That's our preferred way of loading Cayenne extensions. Maybe you can use the same approach with your own code:

  // this comes from your framework. The module can define a class that decla
  public class MyModule implements Module {
      public void configure(Binder binder) {

         // MyFrameworkImpl may inject ObjectContextFactory to obtain contexts
         binder.bind(MyFramework.class).to(MyFrameworkImpl.class);
      }
  }

  // this is how you bootstrap both Cayenne and your framework in your app
  MyModule m = new MyModule();
  ServerRuntime runtime = new ServerRuntime("myproject.xml", m);

  MyFramework f = runtime.getInjector().getInstance(MyFramework.class);
  // now you can call methods on f.


Andrus


> On Aug 27, 2015, at 11:54 AM, Hugi Thordarson <hu...@karlmenn.is> wrote:
> 
>> On 27/08/2015 6:37pm, Hugi Thordarson wrote:
>>> I’m writing a Cayenne-based CRUD framework of sorts, in the form of a jar that plugs into Cayenne applications. 
>> 
>> Is there overlap with this: http://nhl.github.io/link-rest/ which was already built over the top of Cayenne?
> 
> Not really, what we're doing works at a little lower level and serves more specific requirements. Framework looks nice though—and it’s fun to see Cayenne in the wild.
> 
> - hugi


Re: Getting the currently active ServerRuntime

Posted by Hugi Thordarson <hu...@karlmenn.is>.
> On 27/08/2015 6:37pm, Hugi Thordarson wrote:
>> I’m writing a Cayenne-based CRUD framework of sorts, in the form of a jar that plugs into Cayenne applications. 
> 
> Is there overlap with this: http://nhl.github.io/link-rest/ which was already built over the top of Cayenne?

Not really, what we're doing works at a little lower level and serves more specific requirements. Framework looks nice though—and it’s fun to see Cayenne in the wild.

- hugi

Re: Getting the currently active ServerRuntime

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 27/08/2015 6:37pm, Hugi Thordarson wrote:
> I’m writing a Cayenne-based CRUD framework of sorts, in the form of a jar that plugs into Cayenne applications. 

Is there overlap with this: http://nhl.github.io/link-rest/ which was already built over the top of Cayenne?

Ari


-- 
-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A