Class DataDomain

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

public class DataDomain extends Object implements DataChannel
DataDomain performs query routing functions in Cayenne. It creates single "ORM data source" abstraction over multiple physical DataNodes.
  • Field Details

    • name

      protected final String name
    • transactionManager

      protected final TransactionManager transactionManager
    • transactionFactory

      protected final TransactionFactory transactionFactory
    • flushActionFactory

      protected final DataDomainFlushActionFactory flushActionFactory
    • objectFactory

      protected final org.apache.cayenne.di.AdhocObjectFactory objectFactory
    • eventManager

      protected final EventManager eventManager
    • entitySorter

      protected final EntitySorter entitySorter
    • queryCache

      protected final QueryCache queryCache
    • sharedSnapshotCache

      protected final DataRowStore sharedSnapshotCache
    • entityResolver

      protected final EntityResolver entityResolver
    • maxIdQualifierSize

      protected final int maxIdQualifierSize
    • validatingObjectsOnCommit

      protected final boolean validatingObjectsOnCommit
    • queryFilters

      protected final List<DataChannelQueryFilter> queryFilters
    • syncFilters

      protected final List<DataChannelSyncFilter> syncFilters
    • nodes

      protected final Map<String,DataNode> nodes
    • nodesByDataMapName

      protected final Map<String,DataNode> nodesByDataMapName
    • defaultNode

      protected DataNode defaultNode
    • stopped

      protected boolean stopped
  • Constructor Details

  • Method Details

    • checkStopped

      protected void checkStopped() throws DomainStoppedException
      Throws DomainStoppedException if the domain was previously shut down.
      Throws:
      DomainStoppedException
      Since:
      3.0
    • getEntitySorter

      public EntitySorter getEntitySorter()
      Since:
      3.1
    • getEventManager

      public EventManager getEventManager()
      Returns EventManager used by this DataDomain.
      Specified by:
      getEventManager in interface DataChannel
      Since:
      1.2
    • getName

      public String getName()
      Returns "name" property value.
    • isSharedCacheEnabled

      public boolean isSharedCacheEnabled()
      Returns true if DataContexts produced by this DataDomain are using shared DataRowStore. Returns false if each DataContext would work with its own DataRowStore. Note that this setting can be overwritten per DataContext.
    • isValidatingObjectsOnCommit

      public boolean isValidatingObjectsOnCommit()
      Returns whether child DataContexts default behavior is to perform object validation before commit is executed.
      Since:
      1.1
    • getSharedSnapshotCache

      public DataRowStore getSharedSnapshotCache()
      Returns the snapshots cache shared by the DataContexts of this DataDomain, or null if the domain runs with per-DataContext caches.
    • addDataMap

      public void addDataMap(DataMap dataMap)
    • getDataMap

      public DataMap getDataMap(String mapName)
      Since:
      3.1
    • removeDataMap

      public void removeDataMap(String mapName)
      Removes named DataMap from this DataDomain and any underlying DataNodes that include it.
      Since:
      3.1
    • removeDataNode

      public void removeDataNode(String nodeName)
      Removes a DataNode from DataDomain. Any maps previously associated with this node within domain will still be kept around, however they wan't be mapped to any node.
    • getDataMaps

      public Collection<DataMap> getDataMaps()
      Returns a collection of registered DataMaps.
    • getDataNodes

      public Collection<DataNode> getDataNodes()
      Returns an unmodifiable collection of DataNodes associated with this domain.
    • addNode

      public void addNode(DataNode node)
      Adds new DataNode.
    • getDataNode

      public DataNode getDataNode(String nodeName)
      Returns registered DataNode whose name matches name parameter.
      Since:
      3.1
    • lookupDataNode

      public DataNode lookupDataNode(DataMap map)
      Returns a DataNode that should handle queries for all entities in a DataMap.
      Since:
      1.1
    • shutdown

      @BeforeScopeEnd public void shutdown()
      Shutdowns all owned data nodes and marks this domain as stopped.
    • getParent

      public DataChannel getParent()
      Returns null, as DataDomain is the root of the DataChannel stack.
      Specified by:
      getParent in interface DataChannel
      Since:
      5.0
    • onQuery

      public List<QueryResult> onQuery(ObjectContext context, Query query, boolean iteratedResult)
      Runs a query, returning all of its results as a list of QueryResults.
      Specified by:
      onQuery in interface DataChannel
      Parameters:
      context - 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.
      Since:
      1.2
    • onInvalidate

      public void onInvalidate(ObjectContext originatingContext, Collection<ObjectId> objectIds)
      Evicts snapshots of the given objects from the snapshot cache, notifying all contexts that share it.
      Specified by:
      onInvalidate in interface DataChannel
      Parameters:
      originatingContext - an ObjectContext that originated the invalidation.
      objectIds - ids of the objects to invalidate.
      Since:
      5.0
    • onIdQuery

      public Persistent onIdQuery(ObjectContext context, ObjectId id)
      Resolves an object from the snapshot cache, or from the database if the cache lookup fails.
      Specified by:
      onIdQuery in interface DataChannel
      Parameters:
      context - 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.
      Since:
      5.0
    • onRelationshipQuery

      public List<Persistent> onRelationshipQuery(ObjectContext context, ObjectId sourceId, String relationshipName)
      Resolves a relationship from the snapshot cache, or from the database if the cache lookup fails.
      Specified by:
      onRelationshipQuery in interface DataChannel
      Parameters:
      context - 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.
      Since:
      5.0
    • getEntityResolver

      public EntityResolver getEntityResolver()
      Returns an EntityResolver that stores mapping information for this domain.
      Specified by:
      getEntityResolver in interface DataChannel
    • onSync

      public GraphDiff onSync(ObjectContext context, GraphDiff changes, int syncType)
      Only handles commit-type synchronization, ignoring any other type.
      Specified by:
      onSync in interface DataChannel
      Parameters:
      context - 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.
      Since:
      1.2
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getQueryCache

      public QueryCache getQueryCache()
      Returns shared QueryCache used by this DataDomain.
      Since:
      3.0
    • getQueryFilters

      public List<DataChannelQueryFilter> getQueryFilters()
      Returns an unmodifiable list of query filters registered with this DataDomain.

      Filter ordering note: filters are applied in reverse order of their occurrence in the filter list. I.e. the last filter in the list called first in the chain.

      Since:
      4.1
    • getSyncFilters

      public List<DataChannelSyncFilter> getSyncFilters()
      Returns an unmodifiable list of sync filters registered with this DataDomain.

      Filter ordering note: filters are applied in reverse order of their occurrence in the filter list. I.e. the last filter in the list called first in the chain.

      Since:
      4.1
    • addQueryFilter

      public void addQueryFilter(DataChannelQueryFilter filter)
      Adds a new query filter. Also registers passed filter as an event listener, if any of its methods have event annotations.
      Since:
      4.1
    • addSyncFilter

      public void addSyncFilter(DataChannelSyncFilter filter)
      Adds a new sync filter. Also registers passed filter as an event listener, if any of its methods have event annotations.
      Since:
      4.1
    • removeQueryFilter

      public void removeQueryFilter(DataChannelQueryFilter filter)
      Removes a query filter from the filter chain.
      Since:
      4.1
    • removeSyncFilter

      public void removeSyncFilter(DataChannelSyncFilter filter)
      Removes a sync filter from the filter chain.
      Since:
      4.1
    • addListener

      public void addListener(Object listener)
      Adds a listener, mapping its methods to events based on annotations. This is a shortcut for 'getEntityResolver().getCallbackRegistry().addListener(listener)'.
      Since:
      4.0
    • getDefaultNode

      public DataNode getDefaultNode()
      An optional DataNode that is used for DataMaps that are not linked to a DataNode explicitly.
      Since:
      3.1
    • setDefaultNode

      public void setDefaultNode(DataNode defaultNode)
      Since:
      3.1
    • getMaxIdQualifierSize

      public int getMaxIdQualifierSize()
      Returns a maximum number of object IDs to match in a single query for queries that select objects based on collection of ObjectIds. This affects queries generated by Cayenne when processing paginated queries and DISJOINT_BY_ID prefetches and is intended to address database limitations on the size of SQL statements as well as to cap memory use in Cayenne when generating such queries. The default is 10000. It can be changed by setting the RuntimeProperties.MAX_ID_QUALIFIER_SIZE_PROPERTY property.
      Since:
      3.1