# 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 Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected DataNode`
  `defaultNode`
  `protected final EntityResolver`
  `entityResolver`
  `protected final EntitySorter`
  `entitySorter`
  `protected final EventManager`
  `eventManager`
  `protected final DataDomainFlushActionFactory`
  `flushActionFactory`
  `protected final int`
  `maxIdQualifierSize`
  `protected final String`
  `name`
  `protected final Map<String,DataNode>`
  `nodes`
  `protected final Map<String,DataNode>`
  `nodesByDataMapName`
  `protected final AdhocObjectFactory`
  `objectFactory`
  `protected final QueryCache`
  `queryCache`
  `protected final List<DataChannelQueryFilter>`
  `queryFilters`
  `protected final DataRowStore`
  `sharedSnapshotCache`
  `protected boolean`
  `stopped`
  `protected final List<DataChannelSyncFilter>`
  `syncFilters`
  `protected final TransactionFactory`
  `transactionFactory`
  `protected final TransactionManager`
  `transactionManager`
  `protected final boolean`
  `validatingObjectsOnCommit`

  ### Fields inherited from interface DataChannel

  `FLUSH_CASCADE_SYNC, FLUSH_NOCASCADE_SYNC, GRAPH_CHANGED_SUBJECT, GRAPH_FLUSHED_SUBJECT, GRAPH_ROLLEDBACK_SUBJECT, ROLLBACK_CASCADE_SYNC`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DataDomain(String name, TransactionManager transactionManager, TransactionFactory transactionFactory, DataDomainFlushActionFactory flushActionFactory, AdhocObjectFactory objectFactory, EventManager eventManager, QueryCache queryCache, DataRowStore sharedSnapshotCache, int maxIdQualifierSize, boolean validatingObjectsOnCommit, EntityResolver entityResolver, EntitySorter entitySorter)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addDataMap(DataMap dataMap)`
  `void`
  `addListener(Object listener)`
  Adds a listener, mapping its methods to events based on annotations.
  `void`
  `addNode(DataNode node)`
  Adds new DataNode.
  `void`
  `addQueryFilter(DataChannelQueryFilter filter)`
  Adds a new query filter.
  `void`
  `addSyncFilter(DataChannelSyncFilter filter)`
  Adds a new sync filter.
  `protected void`
  `checkStopped()`
  Throws DomainStoppedException if the domain was previously shut down.
  `DataMap`
  `getDataMap(String mapName)`
  `Collection<DataMap>`
  `getDataMaps()`
  Returns a collection of registered DataMaps.
  `DataNode`
  `getDataNode(String nodeName)`
  Returns registered DataNode whose name matches `name` parameter.
  `Collection<DataNode>`
  `getDataNodes()`
  Returns an unmodifiable collection of DataNodes associated with this domain.
  `DataNode`
  `getDefaultNode()`
  An optional DataNode that is used for DataMaps that are not linked to a DataNode explicitly.
  `EntityResolver`
  `getEntityResolver()`
  Returns an EntityResolver that stores mapping information for this domain.
  `EntitySorter`
  `getEntitySorter()`
  `EventManager`
  `getEventManager()`
  Returns EventManager used by this DataDomain.
  `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.
  `String`
  `getName()`
  Returns "name" property value.
  `DataChannel`
  `getParent()`
  Returns null, as DataDomain is the root of the DataChannel stack.
  `QueryCache`
  `getQueryCache()`
  Returns shared `QueryCache` used by this DataDomain.
  `List<DataChannelQueryFilter>`
  `getQueryFilters()`
  Returns an unmodifiable list of query filters registered with this DataDomain.
  `DataRowStore`
  `getSharedSnapshotCache()`
  Returns the snapshots cache shared by the DataContexts of this DataDomain, or null if the domain runs with per-DataContext caches.
  `List<DataChannelSyncFilter>`
  `getSyncFilters()`
  Returns an unmodifiable list of sync filters registered with this DataDomain.
  `boolean`
  `isSharedCacheEnabled()`
  Returns `true` if DataContexts produced by this DataDomain are using shared DataRowStore.
  `boolean`
  `isValidatingObjectsOnCommit()`
  Returns whether child DataContexts default behavior is to perform object validation before commit is executed.
  `DataNode`
  `lookupDataNode(DataMap map)`
  Returns a DataNode that should handle queries for all entities in a DataMap.
  `QueryResponse`
  `onQuery(ObjectContext originatingContext, Query query)`
  Runs query returning generic QueryResponse.
  `GraphDiff`
  `onSync(ObjectContext originatingContext, GraphDiff changes, int syncType)`
  Only handles commit-type synchronization, ignoring any other type.
  `void`
  `removeDataMap(String mapName)`
  Removes named DataMap from this DataDomain and any underlying DataNodes that include it.
  `void`
  `removeDataNode(String nodeName)`
  Removes a DataNode from DataDomain.
  `void`
  `removeQueryFilter(DataChannelQueryFilter filter)`
  Removes a query filter from the filter chain.
  `void`
  `removeSyncFilter(DataChannelSyncFilter filter)`
  Removes a sync filter from the filter chain.
  `void`
  `setDefaultNode(DataNode defaultNode)`
  `void`
  `shutdown()`
  Shutdowns all owned data nodes and marks this domain as stopped.
  `String`
  `toString()`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## 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 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

  - ### DataDomain

    public DataDomain(String name, TransactionManager transactionManager, TransactionFactory transactionFactory, DataDomainFlushActionFactory flushActionFactory, AdhocObjectFactory objectFactory, EventManager eventManager, QueryCache queryCache, DataRowStore sharedSnapshotCache, int maxIdQualifierSize, boolean validatingObjectsOnCommit, EntityResolver entityResolver, EntitySorter entitySorter)

- ## 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 QueryResponse onQuery(ObjectContext originatingContext, Query query)
    Runs query returning generic QueryResponse.
    Specified by:
      `onQuery` in interface `DataChannel`
    Parameters:
      `originatingContext` - an ObjectContext that originated the query, used to register result objects.
    Returns:
      a generic response object that encapsulates result of the execution.
    Since:
      1.2

  - ### 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 originatingContext, GraphDiff changes, int syncType)
    Only handles commit-type synchronization, ignoring any other type.
    Specified by:
      `onSync` in interface `DataChannel`
    Parameters:
      `originatingContext` - 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 `Constants.MAX_ID_QUALIFIER_SIZE_PROPERTY` property.
    Since:
      3.1