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 2017/02/16 20:00:33 UTC

Changing the size of the snapshot cache in code

Hi all,
I’m attempting to change the size of the snapshot cache in code (not in the project xml-file). It seems this should be set through a property, right? Well, I’m just not managing to set properties in code. I’ve set properties in code previously using something like the below, but they just don’t seem to take?

builder.addModule( binder -> ServerModule.contributeProperties( binder ).put( DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY, "123456" ) )

Any ideas?

- hugi

Re: Changing the size of the snapshot cache in code

Posted by Hugi Thordarson <hu...@godurkodi.is>.
Thanks Andrus, constructing my own DataRowStore did the trick :).

For anyone stumbling across this thread, here’s a method that will do this for you.

	/**
	 * Workaround for Cayenne not having an easy way to set the size of the snapshot cache in code.
	 * It depends on the snapshotCache being lazily created, thus we can create a new cache before it has been accessed.
	 * 
	 * This will be fixed in a future version of Cayenne (4.0.M5 is current when this is written)
	 */
	private static void setSizeOfSnapshotCache( DataDomain dataDomain, Integer size ) {
		Map<String,String> properties = dataDomain.getProperties();
		properties.put( DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY, size.toString() );
		DataRowStore snapshotCache = new DataRowStore( dataDomain.getName(), properties, dataDomain.getEventManager() );
		dataDomain.setSharedSnapshotCache( snapshotCache );		
	}

Cheers,
- hugi


> On 21. feb. 2017, at 19:10, Andrus Adamchik <an...@objectstyle.org> wrote:
> 
> Hmm.. Custom modules used to override builder modules in the past. Looks like this is no longer the case since M4 (and I no longer remember what was the motivation for such reordering).
> 
> Anyways, since DataRowStore is initialized lazily, you can create DataRowStore on your own after Cayenne startup and use DataDomain.setSharedSnapshotCache(..). Not ideal, but should work.
> 
> Note to self:
> 
> * We need to port property-based init flow for DataDomain into DI.
> * SyntheticNodeDataDomainProvider should be folded in the main DataDomainProvider (though we need to distinguish a case of "disconnected" stack and a stack that has a known DataSource, and simply needs an implicit DataNode).
> 
> Andrus
> 
>> On Feb 21, 2017, at 2:12 PM, Hugi Thordarson <hu...@godurkodi.is> wrote:
>> 
>> I created a custom DataDomainProvider, but it never gets used. The reason is that I’m using serverRuntimeBuilder.dataSource( DataSource ) to set the DataSource. This causes ServerRuntimeBuilder to set it’s dataSourceFactory, which then causes it to bind it’s own SyntheticNodeDataDomainProvider when it invokes it’s builderModules() method at build time, overriding my own DataDomainProvider.
>> 
>> <PastedGraphic-1.png>
>> 
>> How best to get around this?
>> 
>> - hugi
>> 
>> 
>> 
>>> On 17. feb. 2017, at 06:59, Andrus Adamchik <an...@objectstyle.org> wrote:
>>> 
>>> Only properties defined in org.apache.cayenne.configuration.Constants are recognized by DI. DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY is not one of them. 
>>> 
>>> We were actually going to bring the whole DataDomain configuration process into DI form the Modeler (perhaps right after M5). For now your best bet is overriding DataDomainProvider.
>>> 
>>> Andrus
>>> 
>>> 
>>> 
>>>> On Feb 16, 2017, at 11:06 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>>>> 
>>>> Can’t do that, the signature for put is ( String, <? extends String> ).
>>>> I've also tried a different method:
>>>> 
>>>> builder.addModule( binder -> binder.bindMap( Constants.PROPERTIES_MAP ).put( DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY, 123456 ) );
>>>> 
>>>> …where I used an int, doesn’t work either.
>>>> 
>>>> - hugi
>>>> 
>>>> 
>>>>> On 16. feb. 2017, at 20:03, John Huss <jo...@gmail.com> wrote:
>>>>> 
>>>>> Maybe try using an int instead of the string "123456"?
>>>>> 
>>>>> On Thu, Feb 16, 2017 at 2:00 PM Hugi Thordarson <hu...@karlmenn.is> wrote:
>>>>> 
>>>>>> Hi all,
>>>>>> I’m attempting to change the size of the snapshot cache in code (not in
>>>>>> the project xml-file). It seems this should be set through a property,
>>>>>> right? Well, I’m just not managing to set properties in code. I’ve set
>>>>>> properties in code previously using something like the below, but they just
>>>>>> don’t seem to take?
>>>>>> 
>>>>>> builder.addModule( binder -> ServerModule.contributeProperties( binder
>>>>>> ).put( DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY, "123456" ) )
>>>>>> 
>>>>>> Any ideas?
>>>>>> 
>>>>>> - hugi
>>>> 
>>> 
>> 
> 


Re: Changing the size of the snapshot cache in code

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hmm.. Custom modules used to override builder modules in the past. Looks like this is no longer the case since M4 (and I no longer remember what was the motivation for such reordering).

Anyways, since DataRowStore is initialized lazily, you can create DataRowStore on your own after Cayenne startup and use DataDomain.setSharedSnapshotCache(..). Not ideal, but should work.

Note to self:

* We need to port property-based init flow for DataDomain into DI.
* SyntheticNodeDataDomainProvider should be folded in the main DataDomainProvider (though we need to distinguish a case of "disconnected" stack and a stack that has a known DataSource, and simply needs an implicit DataNode).

Andrus

> On Feb 21, 2017, at 2:12 PM, Hugi Thordarson <hu...@godurkodi.is> wrote:
> 
> I created a custom DataDomainProvider, but it never gets used. The reason is that I’m using serverRuntimeBuilder.dataSource( DataSource ) to set the DataSource. This causes ServerRuntimeBuilder to set it’s dataSourceFactory, which then causes it to bind it’s own SyntheticNodeDataDomainProvider when it invokes it’s builderModules() method at build time, overriding my own DataDomainProvider.
> 
> <PastedGraphic-1.png>
> 
> How best to get around this?
> 
> - hugi
> 
> 
> 
>> On 17. feb. 2017, at 06:59, Andrus Adamchik <an...@objectstyle.org> wrote:
>> 
>> Only properties defined in org.apache.cayenne.configuration.Constants are recognized by DI. DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY is not one of them. 
>> 
>> We were actually going to bring the whole DataDomain configuration process into DI form the Modeler (perhaps right after M5). For now your best bet is overriding DataDomainProvider.
>> 
>> Andrus
>> 
>> 
>> 
>>> On Feb 16, 2017, at 11:06 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>>> 
>>> Can’t do that, the signature for put is ( String, <? extends String> ).
>>> I've also tried a different method:
>>> 
>>> builder.addModule( binder -> binder.bindMap( Constants.PROPERTIES_MAP ).put( DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY, 123456 ) );
>>> 
>>> …where I used an int, doesn’t work either.
>>> 
>>> - hugi
>>> 
>>> 
>>>> On 16. feb. 2017, at 20:03, John Huss <jo...@gmail.com> wrote:
>>>> 
>>>> Maybe try using an int instead of the string "123456"?
>>>> 
>>>> On Thu, Feb 16, 2017 at 2:00 PM Hugi Thordarson <hu...@karlmenn.is> wrote:
>>>> 
>>>>> Hi all,
>>>>> I’m attempting to change the size of the snapshot cache in code (not in
>>>>> the project xml-file). It seems this should be set through a property,
>>>>> right? Well, I’m just not managing to set properties in code. I’ve set
>>>>> properties in code previously using something like the below, but they just
>>>>> don’t seem to take?
>>>>> 
>>>>> builder.addModule( binder -> ServerModule.contributeProperties( binder
>>>>> ).put( DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY, "123456" ) )
>>>>> 
>>>>> Any ideas?
>>>>> 
>>>>> - hugi
>>> 
>> 
> 


Re: Changing the size of the snapshot cache in code

Posted by Hugi Thordarson <hu...@godurkodi.is>.
I created a custom DataDomainProvider, but it never gets used. The reason is that I’m using serverRuntimeBuilder.dataSource( DataSource ) to set the DataSource. This causes ServerRuntimeBuilder to set it’s dataSourceFactory, which then causes it to bind it’s own SyntheticNodeDataDomainProvider when it invokes it’s builderModules() method at build time, overriding my own DataDomainProvider.



How best to get around this?

- hugi



> On 17. feb. 2017, at 06:59, Andrus Adamchik <an...@objectstyle.org> wrote:
> 
> Only properties defined in org.apache.cayenne.configuration.Constants are recognized by DI. DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY is not one of them. 
> 
> We were actually going to bring the whole DataDomain configuration process into DI form the Modeler (perhaps right after M5). For now your best bet is overriding DataDomainProvider.
> 
> Andrus
> 
> 
> 
>> On Feb 16, 2017, at 11:06 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>> 
>> Can’t do that, the signature for put is ( String, <? extends String> ).
>> I've also tried a different method:
>> 
>> builder.addModule( binder -> binder.bindMap( Constants.PROPERTIES_MAP ).put( DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY, 123456 ) );
>> 
>> …where I used an int, doesn’t work either.
>> 
>> - hugi
>> 
>> 
>>> On 16. feb. 2017, at 20:03, John Huss <jo...@gmail.com> wrote:
>>> 
>>> Maybe try using an int instead of the string "123456"?
>>> 
>>> On Thu, Feb 16, 2017 at 2:00 PM Hugi Thordarson <hu...@karlmenn.is> wrote:
>>> 
>>>> Hi all,
>>>> I’m attempting to change the size of the snapshot cache in code (not in
>>>> the project xml-file). It seems this should be set through a property,
>>>> right? Well, I’m just not managing to set properties in code. I’ve set
>>>> properties in code previously using something like the below, but they just
>>>> don’t seem to take?
>>>> 
>>>> builder.addModule( binder -> ServerModule.contributeProperties( binder
>>>> ).put( DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY, "123456" ) )
>>>> 
>>>> Any ideas?
>>>> 
>>>> - hugi
>> 
> 


Re: Changing the size of the snapshot cache in code

Posted by Hugi Thordarson <hu...@karlmenn.is>.
Ah, ok. Thanks Andrus :).

- hugi


> On 17. feb. 2017, at 06:59, Andrus Adamchik <an...@objectstyle.org> wrote:
> 
> Only properties defined in org.apache.cayenne.configuration.Constants are recognized by DI. DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY is not one of them. 
> 
> We were actually going to bring the whole DataDomain configuration process into DI form the Modeler (perhaps right after M5). For now your best bet is overriding DataDomainProvider.
> 
> Andrus
> 
> 
> 
>> On Feb 16, 2017, at 11:06 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>> 
>> Can’t do that, the signature for put is ( String, <? extends String> ).
>> I've also tried a different method:
>> 
>> builder.addModule( binder -> binder.bindMap( Constants.PROPERTIES_MAP ).put( DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY, 123456 ) );
>> 
>> …where I used an int, doesn’t work either.
>> 
>> - hugi
>> 
>> 
>>> On 16. feb. 2017, at 20:03, John Huss <jo...@gmail.com> wrote:
>>> 
>>> Maybe try using an int instead of the string "123456"?
>>> 
>>> On Thu, Feb 16, 2017 at 2:00 PM Hugi Thordarson <hu...@karlmenn.is> wrote:
>>> 
>>>> Hi all,
>>>> I’m attempting to change the size of the snapshot cache in code (not in
>>>> the project xml-file). It seems this should be set through a property,
>>>> right? Well, I’m just not managing to set properties in code. I’ve set
>>>> properties in code previously using something like the below, but they just
>>>> don’t seem to take?
>>>> 
>>>> builder.addModule( binder -> ServerModule.contributeProperties( binder
>>>> ).put( DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY, "123456" ) )
>>>> 
>>>> Any ideas?
>>>> 
>>>> - hugi
>> 
> 


Re: Changing the size of the snapshot cache in code

Posted by Andrus Adamchik <an...@objectstyle.org>.
Only properties defined in org.apache.cayenne.configuration.Constants are recognized by DI. DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY is not one of them. 

We were actually going to bring the whole DataDomain configuration process into DI form the Modeler (perhaps right after M5). For now your best bet is overriding DataDomainProvider.

Andrus

 

> On Feb 16, 2017, at 11:06 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
> 
> Can’t do that, the signature for put is ( String, <? extends String> ).
> I've also tried a different method:
> 
> builder.addModule( binder -> binder.bindMap( Constants.PROPERTIES_MAP ).put( DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY, 123456 ) );
> 
> …where I used an int, doesn’t work either.
> 
> - hugi
> 
> 
>> On 16. feb. 2017, at 20:03, John Huss <jo...@gmail.com> wrote:
>> 
>> Maybe try using an int instead of the string "123456"?
>> 
>> On Thu, Feb 16, 2017 at 2:00 PM Hugi Thordarson <hu...@karlmenn.is> wrote:
>> 
>>> Hi all,
>>> I’m attempting to change the size of the snapshot cache in code (not in
>>> the project xml-file). It seems this should be set through a property,
>>> right? Well, I’m just not managing to set properties in code. I’ve set
>>> properties in code previously using something like the below, but they just
>>> don’t seem to take?
>>> 
>>> builder.addModule( binder -> ServerModule.contributeProperties( binder
>>> ).put( DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY, "123456" ) )
>>> 
>>> Any ideas?
>>> 
>>> - hugi
> 


Re: Changing the size of the snapshot cache in code

Posted by Hugi Thordarson <hu...@karlmenn.is>.
Can’t do that, the signature for put is ( String, <? extends String> ).
I've also tried a different method:

builder.addModule( binder -> binder.bindMap( Constants.PROPERTIES_MAP ).put( DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY, 123456 ) );

…where I used an int, doesn’t work either.

- hugi


> On 16. feb. 2017, at 20:03, John Huss <jo...@gmail.com> wrote:
> 
> Maybe try using an int instead of the string "123456"?
> 
> On Thu, Feb 16, 2017 at 2:00 PM Hugi Thordarson <hu...@karlmenn.is> wrote:
> 
>> Hi all,
>> I’m attempting to change the size of the snapshot cache in code (not in
>> the project xml-file). It seems this should be set through a property,
>> right? Well, I’m just not managing to set properties in code. I’ve set
>> properties in code previously using something like the below, but they just
>> don’t seem to take?
>> 
>> builder.addModule( binder -> ServerModule.contributeProperties( binder
>> ).put( DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY, "123456" ) )
>> 
>> Any ideas?
>> 
>> - hugi


Re: Changing the size of the snapshot cache in code

Posted by John Huss <jo...@gmail.com>.
Maybe try using an int instead of the string "123456"?

On Thu, Feb 16, 2017 at 2:00 PM Hugi Thordarson <hu...@karlmenn.is> wrote:

> Hi all,
> I’m attempting to change the size of the snapshot cache in code (not in
> the project xml-file). It seems this should be set through a property,
> right? Well, I’m just not managing to set properties in code. I’ve set
> properties in code previously using something like the below, but they just
> don’t seem to take?
>
> builder.addModule( binder -> ServerModule.contributeProperties( binder
> ).put( DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY, "123456" ) )
>
> Any ideas?
>
> - hugi