You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by "Aleksey V. Katorgin" <pr...@gmail.com> on 2012/11/08 09:47:35 UTC

No way to remove Context user property

Hi!

There is no way to remove user property from data context because property
container implementation uses ConcurrentHashMap that does not support null
values. Can I create task in cayenne jira bugtracker?



-- 
Aleksey V. Katorgin,
Sr. developer, architect

Russia, Chelyabinsk
cell: +79085792691
skype: aleksey_katorgin

Re: No way to remove Context user property

Posted by Andrus Adamchik <an...@objectstyle.org>.
> Very strange what my question still has no answers.

Nah, it is normal that everyone's availability to help on the community list varies, and sometimes you don't get an immediate answer.

> There is no way to remove user property from data context because property
> container implementation uses ConcurrentHashMap that does not support null
> values. Can I create task in cayenne jira bugtracker?


Good catch. Definitely create a Jira. We'll need to fix it.

Thanks,
Andrus


On Nov 9, 2012, at 7:29 AM, Alexey Katorgin <pr...@gmail.com> wrote:
> Very strange what my question still has no answers. I'll try to be more clear:
> 
>        ServerRuntime runtime = ...;
> 
>        ObjectContext ctx = runtime.getContext();
> 
>        ctx.setUserProperty("my-property", "value");
> 
>        ctx.setUserProperty("my-property", null); // throws NPE and no another 
> way to delete property.
> 
>        /// Workaround:
>        // Define global constant: public static final Object EMPTY_VALUE = new 
> Object();
> 
>        // Clear property:
>        ctx.setUserProperty("my-property", EMPTY_VALUE);
> 
>        // Check if empty:        
>        if (EMPTY_VALUE.equals(ctx.getUserProperty("my-property"))) {
>            // ...
>        }
> 
>        // Should have in API anything like:
>        ctx.removeUserProperty("my-property");
> 
> 
> May be should I ask this question to devel group?
> 
> 
> Thanks,
> Alexey Katorgin.
> 
> 
> 


Re: No way to remove Context user property

Posted by Alexey Katorgin <pr...@gmail.com>.
Very strange what my question still has no answers. I'll try to be more clear:

        ServerRuntime runtime = ...;

        ObjectContext ctx = runtime.getContext();
        
        ctx.setUserProperty("my-property", "value");
        
        ctx.setUserProperty("my-property", null); // throws NPE and no another 
way to delete property.

        /// Workaround:
        // Define global constant: public static final Object EMPTY_VALUE = new 
Object();

        // Clear property:
        ctx.setUserProperty("my-property", EMPTY_VALUE);
        
        // Check if empty:        
        if (EMPTY_VALUE.equals(ctx.getUserProperty("my-property"))) {
            // ...
        }
        
        // Should have in API anything like:
        ctx.removeUserProperty("my-property");


May be should I ask this question to devel group?


Thanks,
Alexey Katorgin.