DBAdapter<C extends Object> class abstract

Base class for DB adapters.

A DBAdapter implementation is responsible to connect to the database and perform operations.

All DBAdapters comes with a built-in connection pool.

Inheritance
Implemented types
Mixed-in types
Implementers
Available extensions

Constructors

DBAdapter(String name, int minConnections, int maxConnections, DBAdapterCapability capability, {EntityRepositoryProvider? parentRepositoryProvider, DBAdapterConnectivity connectivity = DBAdapterConnectivity.any, Object? populateSource, Object? populateSourceVariables, String? workingPath})

Properties

callCloseTransactionRequired → bool
no setter
cancelTransactionResultWithError → bool
no setter
capability → DBAdapterCapability
The DBAdapter capability.
final
connectionInactivityLimit ↔ Duration
The maximum allowed duration of inactivity for a connection in the pool. Default: 15min
getter/setter pair
connectivity → DBAdapterConnectivity
The type of connectivity.
final
cyclicDependencies → List<Initializable>
The dependencies of the current (or last) initialization attempt that were not waited for: they were (transitively) waiting for this instance (a cycle), so they may still be initializing when initialize runs or when this instance is initialized.
no setterinherited
dialect → DBDialect
The DB dialect of this adapter.
no setter
dialectName → String
The DB dialect name of this adapter.
no setter
entityRepositories → List<EntityRepository<Object>>
no setter
entityRepositoriesBuildOrder → List<EntityRepository<Object>>
no setter
hashCode → int
The hash code for this object.
no setterinherited
initializationStatus → InitializationStatus
Returns the current InitializationStatus.
no setterinherited
instanceID → int
final
isAsyncInitialization → bool
Returns true if this instance initialization was asynchronous.
no setterinherited
isClosed → bool
no setterinherited
isInitialized → bool
Returns true if this instance is already initialized.
no setterinherited
isInitializing → bool
Returns true if this instance is in the middle of the initialization process.
no setterinherited
isPoolEmpty → bool
no setterinherited
isPoolNotEmpty → bool
no setterinherited
lastCheckPoolElapsedTimeMs → int
no setterinherited
maxConnections → int
The maximum number of connections in the pool of this adapter.
final
minConnections → int
The minimum number of connections in the pool of this adapter.
final
name → String
The name of the adapter.
final
onClose → Stream<DBAdapter<C>>
On close events.
latefinal
parentRepositoryProvider → EntityRepositoryProvider?
final
poolAliveElementsSize → int
no setterinherited
poolCreatedElementsCount → int
no setterinherited
poolDisposedElementsCount → int
no setterinherited
poolElements → Iterable<C>
no setterinherited
poolFullWaitTimeout → Duration
no setterinherited
poolFullYieldTimeout → Duration
no setterinherited
poolSize → int
no setterinherited
poolSizeDesiredLimit → int
no setter
poolYieldTimeout → Duration
no setterinherited
registeredEntityRepositories → List<EntityRepository<Object>>
no setteroverride
registeredEntityRepositoriesInformation → Map<EntityRepository<Object>, Object>
no setteroverride
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
throwTransactionResultWithError → bool
no setter

Methods

allRepositories({Map<Type, EntityRepository<Object>>? allRepositories, Set<EntityRepositoryProvider>? traversedProviders}) → Map<Type, EntityRepository<Object>>
override
callCheckPool() → FutureOr<bool>
inherited
cancelTransaction(Transaction transaction, C? connection, Object? error, StackTrace? stackTrace) → FutureOr<bool>
catchFromPool({Duration? timeout}) → FutureOr<C>
inherited
catchFromPopulatedPool() → FutureOr<C?>
inherited
checkConnections() → FutureOr<bool>
Checks the connections of the pool. Defaults: calls removeInvalidElementsFromPool.
checkDB() → FutureOr<bool>
checkEntityFields<O>(O o, String entityName, String table, {EntityHandler<O>? entityHandler}) → void
checkInitialized({bool allowInProgress = true}) → void
Checks if this instance is initialized, initializing it if possible.
inherited
checkNotClosed() → void
inherited
checkPool() → FutureOr<bool>
Checks the pool connections and limits.
checkPoolSize(int minSize, int maxSize, int checkInvalidsIntervalMs) → FutureOr<bool>
inherited
clearPool() → FutureOr<bool>
inherited
close() → bool
override
closeConnection(C connection) → FutureOr<bool>
closePoolElement(C o) → FutureOr<bool>
Defaults: calls closeConnection.
closeTransaction(Transaction transaction, C? connection) → FutureOr<void>
createConnection() → FutureOr<C>
Creates a connection C for this adapte
createPoolElement({bool force = false}) → FutureOr<C?>
Defaults: calls createConnection.
createPoolElementForced() → FutureOr<C>
inherited
createRepositoryAdapter<O>(String name, {String? tableName, Type? type}) → DBRepositoryAdapter<O>?
disposePoolElement(C o) → FutureOr<bool>
inherited
disposeTableSchemeCache(String table, {bool fieldsTypes = false}) → TableScheme?
Disposes a TableScheme for table. Forces refresh of previous scheme. With fieldsTypes, also its fields types (getTableFieldsTypes), e.g. after a migration changed its columns.
inherited
disposeTablesSchemesCaches({bool fieldsTypes = false}) → void
Disposes all the loaded TableSchemes (see disposeTableSchemeCache), e.g. the referenced and relationship tables too, after a migration.
inherited
doCount(TransactionOperation op, String entityName, String table, {EntityMatcher? matcher, Object? parameters, List? positionalParameters, Map<String, Object?>? namedParameters, PreFinishDBOperation<int, int>? preFinish}) → FutureOr<int>
doDelete<R>(TransactionOperation op, String entityName, String table, EntityMatcher matcher, {Object? parameters, List? positionalParameters, Map<String, Object?>? namedParameters, PreFinishDBOperation<Iterable<Map<String, dynamic>>, R>? preFinish}) → FutureOr<R>
doExistIDs<I extends Object>(TransactionOperation op, String entityName, String table, List<I> ids) → FutureOr<List<I>>
doInitialization({Initializable? parent}) → FutureOr<InitializationResult>
Initialize this instance if is not initialized yet. Same as ensureInitialized.
inherited
doInsert<O>(TransactionOperation op, String entityName, String table, O o, Map<String, dynamic> fields, {String? idFieldName, PreFinishDBOperation? preFinish}) → FutureOr
doSelectAll<R>(TransactionOperation op, String entityName, String table, {int? limit, int? offset, bool? orderByID, OrderDirection? orderDirection, PreFinishDBOperation<Iterable<Map<String, dynamic>>, List<R>>? preFinish}) → FutureOr<List<R>>
Ordering and pagination:
doSelectByID<R>(TransactionOperation op, String entityName, String table, Object id, {PreFinishDBOperation<Map<String, dynamic>?, R?>? preFinish}) → FutureOr<R?>
doSelectByIDs<R>(TransactionOperation op, String entityName, String table, List<Object> ids, {int? limit, int? offset, bool? orderByID, OrderDirection? orderDirection, PreFinishDBOperation<Iterable<Map<String, dynamic>>, List<R>>? preFinish}) → FutureOr<List<R>>
Ordering and pagination:
doUpdate<O>(TransactionOperation op, String entityName, String table, O o, Object id, Map<String, dynamic> fields, {String? idFieldName, PreFinishDBOperation? preFinish, bool allowAutoInsert = false}) → FutureOr
ensureInitialized({Initializable? parent}) → FutureOr<InitializationResult>
Ensures that this instance is initialized.
inherited
ensureInitializedAsync({Initializable? parent}) → FutureOr<InitializationResult>
Ensures that this instance is initialized. If is not initialized yet it will force an asynchronous initialization and return a Future.
inherited
executeInitialized<R>(ExecuteInitializedCallback<R> callback, {Initializable? parent}) → FutureOr<R>
Executes the callback ensuring that this instance was initialized.
inherited
executeWithPool<R>(FutureOr<R> f(C o), {Duration? timeout, bool validator(C o)?, dynamic onError(Object error, StackTrace stackTrace)?}) → FutureOr<R>
inherited
filterPoolElements(FutureOr<bool> filter(C connection)) → FutureOr<List<C>>
inherited
finishOperation<T, R>(TransactionOperation op, T res, PreFinishDBOperation<T, R>? preFinish, {TransactionErrorResolver? errorResolver}) → FutureOr<R>
Finishes the operation op with the result res of its transaction execution: applies preFinish (if any) and calls op.finish.
getConnectionURL(C connection) → String
Returns the URL of the connection.
getEntityByID<O>(dynamic id, {Type? type, bool sync = false, EntityResolutionRules? resolutionRules}) → FutureOr<O?>
override
getEntityHandler<T>({String? entityName, String? tableName, Type? entityType}) → EntityHandler<T>?
getEntityID(Object entity, {String? entityName, String? tableName, Type? entityType, EntityHandler? entityHandler}) → Object?
Returns the entity ID for entityName, tableName or entityType.
override
getEntityRepositoresTables() → FutureOr<Map<EntityRepository<Object>, String>>
getEntityRepositoriesTables() → FutureOr<Map<EntityRepository<Object>, String>>
The table of each registered EntityRepository.
getEntityRepository<O extends Object>({O? obj, Type? type, String? name, String? tableName, Set<EntityRepositoryProvider>? traversed}) → EntityRepository<O>?
See EntityRepositoryProvider.lookupEntityRepository (the parentRepositoryProvider asked first).
override
getEntityRepositoryByType<O extends Object>(Type type, {Set<EntityRepositoryProvider>? traversed}) → EntityRepository<O>?
See EntityRepositoryProvider.lookupEntityRepository (the parentRepositoryProvider asked first).
override
getEntityRepositoryByTypeInfo<O extends Object>(TypeInfo typeInfo) → EntityRepository<O>?
override
getFieldType(String field, {String? entityName, String? tableName, Type? entityType}) → FutureOr<TypeInfo?>
Returns the type for the field at tableName or by entityName.
override
getRepositoryAdapterByName<O>(String name) → DBRepositoryAdapter<O>?
getRepositoryAdapterByTableName<O>(String tableName) → DBRepositoryAdapter<O>?
getRepositoryAdapterByType<O>(Type type) → DBRepositoryAdapter<O>?
getTableFieldsTypes(String table) → FutureOr<Map<String, Type>?>
Returns a TableScheme.fieldsTypes for table.
inherited
getTableFieldsTypesImpl(String table) → FutureOr<Map<String, Type>?>
inherited
getTableForEntityRepository(EntityRepository<Object> entityRepository) → String
Returns the table name for entityRepository.
inherited
getTableForType(TypeInfo type) → String?
Returns the table name for type.
override
getTableScheme(String table, {TableRelationshipReference? relationship, Object? contextID}) → FutureOr<TableScheme?>
Returns a TableScheme for table. Calls getTableSchemeImpl handling asynchronous calls.
inherited
getTableSchemeForEntityRepository(EntityRepository<Object> entityRepository, {Object? contextID}) → FutureOr<TableScheme?>
Returns a TableScheme for entityRepository.
inherited
getTableSchemeForType(TypeInfo type) → FutureOr<TableScheme?>
Returns a TableScheme for type.
inherited
getTableSchemeIfLoaded(String table) → TableScheme?
inherited
getTableSchemeImpl(String table, TableRelationshipReference? relationship, {Object? contextID}) → FutureOr<TableScheme?>
Implementation that returns a TableScheme for table.
inherited
information({bool extended = false, String? table}) → Map<String, dynamic>
initialize() → FutureOr<InitializationResult>
Initialization implementation. Do not call it directly, use doInitialization.
override
initializeDependencies() → FutureOr<List<Initializable>>
Return a List of Initializable instances that need to be initialized BEFORE initialize this instance.
inherited
instantiateRepositoryAdapter<O>(String name, String? tableName, Type? type) → DBRepositoryAdapter<O>
invalidPoolElements({bool checkUsage = true}) → FutureOr<List<C>>
inherited
isConnectionValid(C connection, {bool checkUsage = true}) → FutureOr<bool>
Returns true if connection is valid for usage.
isPoolElementInvalid(C o, {bool checkUsage = true}) → FutureOr<bool>
inherited
isPoolElementValid(C o, {bool checkUsage = true}) → FutureOr<bool>
Defaults: calls isConnectionValid.
isTransactionWithSingleOperation(TransactionOperation op) → bool
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyKnownEntityRepositoryProvider(EntityRepositoryProvider provider) → void
override
notifyTableFieldTypes(String table, Map<String, Type> fieldsTypes) → Map<String, Type>
inherited
openTransaction(Transaction transaction) → FutureOr<C>
peekFromPool() → FutureOr<C?>
inherited
populateFromSource(Object? source, {String? workingPath, EntityResolutionRules? resolutionRules, Object? variables}) → FutureOr<Map<String, List<Object>>>

Available on EntityRepositoryProvider, provided by the EntityRepositoryProviderExtension extension

populateImpl() → FutureOr<InitializationResult>
preparePoolElement(C o) → FutureOr<C?>
inherited
recyclePoolElement(C o) → FutureOr<C?>
inherited
registerEntityRepository<O extends Object>(EntityRepository<O> entityRepository) → void
override
releaseIntoPool(C o) → FutureOr<bool>
inherited
removeElementsFromPool(int amount) → int
inherited
removeFromPool(C o) → bool
inherited
removeInvalidElementsFromPool({bool checkUsage = true}) → FutureOr<bool>
inherited
resolveEntitiesSource(Object? source, {String? workingPath}) → FutureOr<Map<String, Iterable<Map<String, dynamic>>>>

Available on EntityRepositoryProvider, provided by the EntityRepositoryProviderExtension extension

resolveEntitiesSourceVariables(Map<String, Iterable<Map<String, dynamic>>> source, Map<String, dynamic> variables) → Map<String, Iterable<Map<String, dynamic>>>

Available on EntityRepositoryProvider, provided by the EntityRepositoryProviderExtension extension

resolveEntitySourceValueVariables(String key, Object? value, Map<String, dynamic> variables) → Object?

Available on EntityRepositoryProvider, provided by the EntityRepositoryProviderExtension extension

resolveEntitySourceVariables(Map<String, dynamic> entity, Map<String, dynamic> variables) → Map<String, dynamic>

Available on EntityRepositoryProvider, provided by the EntityRepositoryProviderExtension extension

resolveSource(Object? source, {String? workingPath}) → FutureOr<Map<String, dynamic>>

Available on EntityRepositoryProvider, provided by the EntityRepositoryProviderExtension extension

resolveTransactionResult(dynamic result, Transaction transaction, C? connection) → FutureOr
selectIDFieldName(String table, List<String> primaryKeyCandidates) → String
Selects the ID field name from primaryKeyCandidates candidates:
inherited
storeAllFromJson(Map<String, Iterable<Map<String, dynamic>>> entries, {Transaction? transaction, EntityResolutionRules? resolutionRules, Map<String, dynamic>? variables}) → FutureOr<Map<String, List<Object>>>

Available on EntityRepositoryProvider, provided by the EntityRepositoryProviderExtension extension

storeAllFromJsonEncoded(String jsonEncoded, {Transaction? transaction, EntityResolutionRules? resolutionRules, Map<String, dynamic>? variables}) → FutureOr<Map<String, List<Object>>>

Available on EntityRepositoryProvider, provided by the EntityRepositoryProviderExtension extension

toString() → String
A string representation of this object.
inherited
validPoolElements() → FutureOr<List<C>>
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

adapterRegister → DBAdapterRegister<Object, DBAdapter<Object>>
final
auxiliaryMode → bool
Returns true if auxiliary mode is enabled.
no setter
instances → List<DBAdapter<Object>>
no setter
registeredAdaptersNames → List<String>
no setter
registeredAdaptersTypes → List<Type>
no setter

Static Methods

boot() → void
enableAuxiliaryMode() → bool
fromConfig<C extends Object, A extends DBAdapter<C>>(Map<String, dynamic> config, {int minConnections = 1, int maxConnections = 3, EntityRepositoryProvider? parentRepositoryProvider, String? workingPath}) → FutureOr<A>
getAdapterInstantiator<C extends Object, A extends DBAdapter<C>>({String? name, Type? type}) → DBAdapterInstantiator<C, A>?
getAdapterInstantiatorsFromConfig<C extends Object, A extends DBAdapter<C>>(Map<String, dynamic> config) → List<MapEntry<DBAdapterInstantiator<C, A>, Map<String, dynamic>>>
instantiateAdaptor<C extends Object, A extends DBAdapter<C>>(List<MapEntry<DBAdapterInstantiator<C, A>, Map<String, dynamic>>> instantiators, Map<String, dynamic> config, {int minConnections = 1, int maxConnections = 3, EntityRepositoryProvider? parentRepositoryProvider, String? workingPath}) → FutureOr<A>
registerAdapter<C extends Object, A extends DBAdapter<C>>(List<String> names, Type type, DBAdapterInstantiator<C, A> adapterInstantiator) → void