You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by D Tim Cummings <ti...@triptera.com.au> on 2018/07/26 08:03:34 UTC
4.1.M2 deprecates DataChannelFilter
I see that 4.1.M2 has deprecated DataChannelFilter. Apparently we should use either DataChannelQueryFilter or DataChannelSyncFilter.
I am following the example on https://cayenne.apache.org/docs/4.1/cayenne-guide/#lifecycle-events which still refers to DataChannelFilter. I would use DataChannelSyncFilter in this example but DataChannelSyncFilter does not have an init() method to override so would I initialise counter where it gets declared?
Here is the code from the example.
public class CommittedObjectCounter implements DataChannelFilter {
private ThreadLocal<int[]> counter;
@Override
public void init(DataChannel channel) {
counter = new ThreadLocal<int[]>();
}
@Override
public QueryResponse onQuery(ObjectContext originatingContext, Query query, DataChannelFilterChain filterChain) {
return filterChain.onQuery(originatingContext, query);
}
@Override
public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType,
DataChannelFilterChain filterChain) {
// init the counter for the current commit
counter.set(new int[1]);
try {
return filterChain.onSync(originatingContext, changes, syncType);
} finally {
// process aggregated result and release the counter
System.out.println("Committed " + counter.get()[0] + " object(s)");
counter.set(null);
}
}
@PostPersist(entityAnnotations = Tag.class)
@PostUpdate(entityAnnotations = Tag.class)
@PostRemove(entityAnnotations = Tag.class)
void afterCommit(Persistent object) {
counter.get()[0]++;
}
}
Regards
Tim
Re: 4.1.M2 deprecates DataChannelFilter
Posted by Andrus Adamchik <an...@objectstyle.org>.
In fact one of the reasons for this refactoring was to avoid an incorrect implication that filters do have a lifecycle instead of being simple singletons within the Cayenne stack.
Andrus
> On Jul 27, 2018, at 11:56 AM, Nikita Timofeev <nt...@objectstyle.com> wrote:
>
> Yeah, the simple version of fix is this:
>
> private ThreadLocal<int[]> counter = new ThreadLocal<int[]>();
>
> Filters don't have any complex lifecycle, so should be no problem to
> init everything upfront.
>
> On Thu, Jul 26, 2018 at 11:03 AM, D Tim Cummings <ti...@triptera.com.au> wrote:
>> I see that 4.1.M2 has deprecated DataChannelFilter. Apparently we should use
>> either DataChannelQueryFilter or DataChannelSyncFilter.
>>
>> I am following the example on
>> https://cayenne.apache.org/docs/4.1/cayenne-guide/#lifecycle-events which
>> still refers to DataChannelFilter. I would use DataChannelSyncFilter in this
>> example but DataChannelSyncFilter does not have an init() method to override
>> so would I initialise counter where it gets declared?
>>
>> Here is the code from the example.
>>
>> public class CommittedObjectCounter implements DataChannelFilter {
>>
>> private ThreadLocal<int[]> counter;
>>
>> @Override
>> public void init(DataChannel channel) {
>> counter = new ThreadLocal<int[]>();
>> }
>>
>> @Override
>> public QueryResponse onQuery(ObjectContext originatingContext, Query
>> query, DataChannelFilterChain filterChain) {
>> return filterChain.onQuery(originatingContext, query);
>> }
>>
>> @Override
>> public GraphDiff onSync(ObjectContext originatingContext, GraphDiff
>> changes, int syncType,
>> DataChannelFilterChain filterChain) {
>>
>> // init the counter for the current commit
>> counter.set(new int[1]);
>>
>> try {
>> return filterChain.onSync(originatingContext, changes,
>> syncType);
>> } finally {
>>
>> // process aggregated result and release the counter
>> System.out.println("Committed " + counter.get()[0] + "
>> object(s)");
>> counter.set(null);
>> }
>> }
>>
>> @PostPersist(entityAnnotations = Tag.class)
>> @PostUpdate(entityAnnotations = Tag.class)
>> @PostRemove(entityAnnotations = Tag.class)
>> void afterCommit(Persistent object) {
>> counter.get()[0]++;
>> }
>> }
>>
>>
>>
>>
>> Regards
>>
>> Tim
>
>
>
> --
> Best regards,
> Nikita Timofeev
Re: 4.1.M2 deprecates DataChannelFilter
Posted by Nikita Timofeev <nt...@objectstyle.com>.
Yeah, the simple version of fix is this:
private ThreadLocal<int[]> counter = new ThreadLocal<int[]>();
Filters don't have any complex lifecycle, so should be no problem to
init everything upfront.
On Thu, Jul 26, 2018 at 11:03 AM, D Tim Cummings <ti...@triptera.com.au> wrote:
> I see that 4.1.M2 has deprecated DataChannelFilter. Apparently we should use
> either DataChannelQueryFilter or DataChannelSyncFilter.
>
> I am following the example on
> https://cayenne.apache.org/docs/4.1/cayenne-guide/#lifecycle-events which
> still refers to DataChannelFilter. I would use DataChannelSyncFilter in this
> example but DataChannelSyncFilter does not have an init() method to override
> so would I initialise counter where it gets declared?
>
> Here is the code from the example.
>
> public class CommittedObjectCounter implements DataChannelFilter {
>
> private ThreadLocal<int[]> counter;
>
> @Override
> public void init(DataChannel channel) {
> counter = new ThreadLocal<int[]>();
> }
>
> @Override
> public QueryResponse onQuery(ObjectContext originatingContext, Query
> query, DataChannelFilterChain filterChain) {
> return filterChain.onQuery(originatingContext, query);
> }
>
> @Override
> public GraphDiff onSync(ObjectContext originatingContext, GraphDiff
> changes, int syncType,
> DataChannelFilterChain filterChain) {
>
> // init the counter for the current commit
> counter.set(new int[1]);
>
> try {
> return filterChain.onSync(originatingContext, changes,
> syncType);
> } finally {
>
> // process aggregated result and release the counter
> System.out.println("Committed " + counter.get()[0] + "
> object(s)");
> counter.set(null);
> }
> }
>
> @PostPersist(entityAnnotations = Tag.class)
> @PostUpdate(entityAnnotations = Tag.class)
> @PostRemove(entityAnnotations = Tag.class)
> void afterCommit(Persistent object) {
> counter.get()[0]++;
> }
> }
>
>
>
>
> Regards
>
> Tim
--
Best regards,
Nikita Timofeev