Table of Contents

TXDataTenantConnectionPool Class

Connection pool component that routes each request to the database shard of the current tenant, using the routing information provided by a TAureliusTenantCatalog.

Remarks

Assign the component to the Pool property of a XData.Comp.Server.TXDataServer. On every request, the current tenant is resolved from the ambient TTenantScope, from the ITenant context item set by Sparkle's tenant middleware, or from the catalog identifiers through the TenantLookups (the OnResolveTenant event can override that), the tenant and shard status are checked, and the connection is taken from the pool of the tenant's shard. The application only provides the connection for each shard (OnCreateShardConnection); the component pools connections per shard, maps tenancy errors to proper HTTP responses (unknown tenant, suspended tenant, unavailable shard or catalog) and can automatically enable the multitenant global filter on every request manager (EnableFilter, FilterName, FilterParamName).

Syntax

Unit: XData.Comp.TenantConnectionPool

TXDataTenantConnectionPool = class(TXDataCustomConnectionPool, ITenantResolver);

Constructors

Name Description
Create Creates a new TXDataTenantConnectionPool instance.

Methods

Name Description
GetPoolInterface Returns the tenant-routing IDBConnectionPool implemented by this component.
GetPoolProvider Returns the tenant-routing pool provider, for code that already knows the tenant id.
InvalidateAll Drops all cached routing information and all shard connection pools.
InvalidateShard Drops the cached information and the connection pool of a shard, so a fresh pool is built on next use.
InvalidateTenant Drops the cached routing information of a tenant, so the next request re-reads the catalog.
ReleasePoolInterface Releases the internally cached pool objects. They are recreated on next use.
SetupModule Subscribes the tenancy behavior to the events of an XData server module.
UpdateShardSchemas Overloaded
UpdateShardSchemas
UpdateShardSchemas()

Properties

Name Description
AntiEnumeration Indicates whether requests for existing but inactive tenants are answered with the same 404 response as unknown tenants.
Catalog The tenant catalog component providing tenant-to-shard routing information.
CleanupTimeout Gets or sets the time, in milliseconds, after which idle pooled connections are destroyed.
EnableFilter Indicates whether the multitenant global filter is enabled automatically on every request manager.
FilterName Gets or sets the name of the global filter enabled on request managers when EnableFilter is True.
FilterParamName Gets or sets the name of the filter parameter that receives the current tenant id.
HandleTenant​Exceptions Indicates whether tenancy exceptions are automatically mapped to HTTP error responses.
PoolSize Gets or sets the maximum number of pooled connections per shard.
TenantLookups Lookups that resolve the tenant of a request from the identifiers registered in the catalog.

Events

Name Description
OnCreateShard​Connection Fired when a database connection must be created for a shard.
OnCreateShardPool Fired when a connection pool must be created for a shard, allowing full control over pool creation.
OnDBConnection​Release Fired whenever a connection is released back to a shard pool.
OnResolveTenant Fired after the tenant id is resolved for the current request, allowing the handler to override or augment the resolution.