blob: cdbfd0c3203fa72da16bfe70f2c95a3536881285 [file] [log] [blame]
---
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
title: DataContextDelegate
url: /docs/1.2/datacontextdelegate.html
layout: docs_legacy
---
<P>DataContext supports runtime customization via a DataContextDelegate interface. A user can assign a custom delegate instance to a DataContext by calling DataContext.setDelegate(..). Delegate is optional, and if it is not set, DataContext would go on with its default behavior. If a delegate is set, DataContext consults with it at some critical points in the normal flow execution. A delegate can modify the flow, abort an operation, modify objects participating in an operation, or perform any other tasks it deems necessary.</P>
<P>DataContextDelegate currently has two groups of methods - method to filter select queries, and methods to react to external updates of the ObjectStore:</P>
<UL>
<LI><TT>public Query willPerformQuery(DataContext context, Query query)</TT></LI>
</UL>
<P>Called from DataContext.performQuery(...) before running any select query, including prefetch queries. Implementation has a choice to modify an original query, replace it with alternative one, or return NULL, blocking query execution alltogether.</P>
<UL>
<LI><TT>public boolean shouldMergeChanges(DataObject object, DataRow snapshotInStore)</TT><BR>
<TT>public boolean shouldProcessDelete(DataObject object)</TT><BR>
<TT>public void finishedMergeChanges(DataObject object)</TT><BR>
<TT>public void finishedProcessDelete(DataObject object)</TT></LI>
</UL>
<P>These methods are called by the ObjectStore whenever it performs an update of its state triggered by external events. Default ObjectStore behavior is to merge all changes to the existing objects, and change deleted objects state to TRANSIENT, removing them from the store. Delegate has an option to abort standard processing by returning &quot;false&quot; from &quot;should*&quot; methods.</P>