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, 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
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() → void
Checks if this instance is initialized.
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) TableScheme?
Disposes a TableScheme for table. Forces refresh of previous scheme.
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>
doInitialization({Initializable? parent}) FutureOr<InitializationResult>
Initialize this instance if is not initialized yet.
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, {PreFinishDBOperation<Iterable<Map<String, dynamic>>, List<R>>? preFinish}) FutureOr<List<R>>
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, {PreFinishDBOperation<Iterable<Map<String, dynamic>>, List<R>>? preFinish}) FutureOr<List<R>>
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 instances was fully 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 o)) FutureOr<List<C>>
inherited
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>>
getEntityRepository<O extends Object>({O? obj, Type? type, String? name, String? tableName}) EntityRepository<O>?
override
getEntityRepositoryByType<O extends Object>(Type type) EntityRepository<O>?
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
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
resolveTransactionResult(dynamic result, Transaction transaction, C? connection) FutureOr
selectIDFieldName(String table, List<String> primaryKeyCandidates) String
Selects the ID field name from primaryKeyCandidates candidates:
inherited
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