Record Class DataContextChannel

java.lang.Object
java.lang.Record
org.apache.cayenne.access.DataContextChannel
All Implemented Interfaces:
DataChannel

public record DataContextChannel(DataContext context) extends Record implements DataChannel
A DataChannel that connects a nested ObjectContext to its parent DataContext. All channel operations are delegated to the parent context. Note that the parent context posts channel events on its own behalf, so listeners interested in those events should listen to the context, not to this channel.
Since:
5.0
  • Constructor Details

    • DataContextChannel

      public DataContextChannel(DataContext context)
      Creates an instance of a DataContextChannel record class.
      Parameters:
      context - the value for the context record component
  • Method Details

    • getEventManager

      public EventManager getEventManager()
      Description copied from interface: DataChannel
      Returns an EventManager associated with this channel. Channel may return null if EventManager is not available for any reason.
      Specified by:
      getEventManager in interface DataChannel
    • getEntityResolver

      public EntityResolver getEntityResolver()
      Description copied from interface: DataChannel
      Returns an EntityResolver instance that contains runtime mapping information.
      Specified by:
      getEntityResolver in interface DataChannel
    • getParent

      public DataChannel getParent()
      Description copied from interface: DataChannel
      Returns the parent channel of this channel in the DataChannel stack, or null if this is a root channel (such as a DataDomain).
      Specified by:
      getParent in interface DataChannel
    • onQuery

      public List<QueryResult> onQuery(ObjectContext childContext, Query query, boolean iteratedResult)
      Description copied from interface: DataChannel
      Executes a query, using provided context to register persistent objects if query returns any objects.
      Specified by:
      onQuery in interface DataChannel
      Parameters:
      childContext - an ObjectContext that originated the query, used to register result objects.
      query - a query to execute.
      iteratedResult - if true, the result is returned as a ResultIterator item, and the caller is responsible for closing it. If false, the result is fully read into a list.
      Returns:
      all result sets, update counts, iterators and OUT parameters of the execution, in the order they were produced.
    • onInvalidate

      public void onInvalidate(ObjectContext childContext, Collection<ObjectId> objectIds)
      Description copied from interface: DataChannel
      Invalidates objects with the given ids in this channel and all its parents, so that they are refetched on the next access. In a context, matching registered objects are turned HOLLOW and their uncommitted changes are discarded. At the root of the channel stack, their snapshots are evicted from the snapshot cache, and peer contexts are notified via a snapshot event. Objects unknown to a given channel are ignored.

      This is a callback invoked by a child context after it has invalidated its own objects. Application code should call ObjectContext.invalidateObjects(Collection) instead.

      Specified by:
      onInvalidate in interface DataChannel
      Parameters:
      childContext - an ObjectContext that originated the invalidation.
      objectIds - ids of the objects to invalidate.
    • onIdQuery

      public Persistent onIdQuery(ObjectContext childContext, ObjectId id)
      Description copied from interface: DataChannel
      Resolves an object by id, returning it registered with the originating context. The object is looked up in the caches down the channel stack before being fetched from the database, so the returned object may reflect a cached state.

      This is a callback invoked by a child context to resolve a HOLLOW object, or to look up an object it has no registered copy of. Application code should call ObjectContext.objectForPK(ObjectId) instead.

      Specified by:
      onIdQuery in interface DataChannel
      Parameters:
      childContext - an ObjectContext that originated the request and that the returned object belongs to.
      id - id of the object to resolve.
      Returns:
      the object registered with the originating context, or null if no matching row exists.
    • onRelationshipQuery

      public List<Persistent> onRelationshipQuery(ObjectContext childContext, ObjectId sourceId, String relationshipName)
      Description copied from interface: DataChannel
      Resolves objects related to a given object via a mapped relationship, returning them registered with the originating context.
      Specified by:
      onRelationshipQuery in interface DataChannel
      Parameters:
      childContext - an ObjectContext that originated the request and that the returned objects belong to.
      sourceId - id of the object on the source side of the relationship.
      relationshipName - name of the relationship to resolve.
      Returns:
      related objects registered with the originating context. An empty list means that a to-one target is null, or a to-many relationship has no matching objects.
    • onSync

      public GraphDiff onSync(ObjectContext childContext, GraphDiff changes, int syncType)
      Description copied from interface: DataChannel
      Processes synchronization request from a child ObjectContext, returning a GraphDiff that describes changes to objects made on the receiving end as a result of synchronization.
      Specified by:
      onSync in interface DataChannel
      Parameters:
      childContext - an ObjectContext that initiated the sync. Can be null.
      changes - diff from the context that initiated the sync.
      syncType - One of DataChannel.FLUSH_NOCASCADE_SYNC, DataChannel.FLUSH_CASCADE_SYNC, DataChannel.ROLLBACK_CASCADE_SYNC.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • context

      public DataContext context()
      Returns the value of the context record component.
      Returns:
      the value of the context record component