DBSQLAdapter<C extends Object> class abstract

Base class for SQL DB adapters.

A DBSQLAdapter implementation is responsible to connect to the database and adjust the generated SQLs to the correct dialect.

All DBSQLAdapters comes with a built-in connection pool.

Inheritance
Mixed in types
Implementers
Available Extensions

Constructors

DBSQLAdapter(String name, int minConnections, int maxConnections, DBSQLAdapterCapability capability, {bool generateTables = false, bool checkTables = true, Object? populateTables, EntityRepositoryProvider? parentRepositoryProvider, Object? populateSource, Object? populateSourceVariables, String? workingPath, bool logSQL = false})

Properties

callCloseTransactionRequired bool
no setterinherited
cancelTransactionResultWithError bool
no setterinherited
capability DBSQLAdapterCapability
The DBSQLAdapter capability.
no setteroverride
checkedTables bool
Return true if DB tables where successfully checked.
no setter
connectionInactivityLimit Duration
The maximum allowed duration of inactivity for a connection in the pool. Default: 15min
getter/setter pairinherited
dialect DBDialect
The DB dialect of this adapter.
no setterinherited
dialectName String
The DB dialect name of this adapter.
no setterinherited
entityRepositories List<EntityRepository<Object>>
no setterinherited
entityRepositoriesBuildOrder List<EntityRepository<Object>>
no setteroverride
generatedTables bool
Return true if DB tables where successfully generated.
no setter
hashCode int
The hash code for this object.
no setterinherited
initializationStatus InitializationStatus
Returns the current InitializationStatus.
no setterinherited
instanceID int
finalinherited
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
logSQL bool
final
maxConnections int
The maximum number of connections in the pool of this adapter.
finalinherited
minConnections int
The minimum number of connections in the pool of this adapter.
finalinherited
name String
The name of the adapter.
finalinherited
onClose Stream<DBAdapter<C>>
On close events.
latefinalinherited
parentRepositoryProvider EntityRepositoryProvider?
finalinherited
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 setterinherited
poolYieldTimeout Duration
no setterinherited
registeredEntityRepositories List<EntityRepository<Object>>
no setterinherited
registeredEntityRepositoriesInformation Map<EntityRepository<Object>, Object>
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
throwTransactionResultWithError bool
no setterinherited

Methods

allRepositories({Map<Type, EntityRepository<Object>>? allRepositories, Set<EntityRepositoryProvider>? traversedProviders}) Map<Type, EntityRepository<Object>>
inherited
callCheckPool() FutureOr<bool>
inherited
cancelTransaction(Transaction transaction, C? connection, Object? error, StackTrace? stackTrace) FutureOr<bool>
inherited
catchFromPool({Duration? timeout}) FutureOr<C>
inherited
catchFromPopulatedPool() FutureOr<C?>
inherited
checkConnections() FutureOr<bool>
Checks the connections of the pool. Defaults: calls removeInvalidElementsFromPool.
inherited
checkDB() FutureOr<bool>
override
checkDBTableField(Type entityType, String fieldName, Type? schemeType, TypeInfo? fieldType) bool
checkDBTables() FutureOr<bool>
checkEntityFields<O>(O o, String entityName, String table, {EntityHandler<O>? entityHandler}) → void
inherited
checkInitialized() → void
Checks if this instance is initialized.
inherited
checkNotClosed() → void
inherited
checkPool() FutureOr<bool>
Checks the pool connections and limits.
inherited
checkPoolSize(int minSize, int maxSize, int checkInvalidsIntervalMs) FutureOr<bool>
inherited
clearPool() FutureOr<bool>
inherited
close() bool
inherited
closeConnection(C connection) FutureOr<bool>
inherited
closePoolElement(C o) FutureOr<bool>
Defaults: calls closeConnection.
inherited
closeTransaction(Transaction transaction, C? connection) FutureOr<void>
inherited
countSQL(TransactionOperation op, String entityName, String table, SQL sql) FutureOr<int>
createConnection() FutureOr<C>
Creates a connection C for this adapte
inherited
createPoolElement({bool force = false}) FutureOr<C?>
Defaults: calls createConnection.
inherited
createPoolElementForced() FutureOr<C>
inherited
createRepositoryAdapter<O>(String name, {String? tableName, Type? type}) DBSQLRepositoryAdapter<O>?
override
deleteSQL(TransactionOperation op, String entityName, String table, SQL sql) FutureOr<Iterable<Map<String, dynamic>>>
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>
override
doCountSQL(String entityName, String table, SQL sql, Transaction transaction, C connection) 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>
override
doDeleteSQL(String entityName, String table, SQL sql, Transaction transaction, C connection) FutureOr<Iterable<Map<String, dynamic>>>
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
override
doInsertRelationship(TransactionOperation op, String entityName, String table, String field, dynamic id, String otherTableName, List otherIds, [PreFinishDBOperation<bool, bool>? preFinish]) FutureOr<bool>
override
doInsertRelationshipSQL(String entityName, String table, SQL sql, Transaction transaction, C connection) FutureOr
doInsertSQL(String entityName, String table, SQL sql, Transaction transaction, C connection) FutureOr
doSelect<R>(TransactionOperation op, String entityName, String table, EntityMatcher matcher, {Object? parameters, List? positionalParameters, Map<String, Object?>? namedParameters, int? limit, PreFinishDBOperation<Iterable<Map<String, dynamic>>, R>? preFinish}) FutureOr<R>
override
doSelectAll<R>(TransactionOperation op, String entityName, String table, {PreFinishDBOperation<Iterable<Map<String, dynamic>>, List<R>>? preFinish}) FutureOr<List<R>>
override
doSelectByID<R>(TransactionOperation op, String entityName, String table, Object id, {PreFinishDBOperation<Map<String, dynamic>?, R?>? preFinish}) FutureOr<R?>
override
doSelectByIDs<R>(TransactionOperation op, String entityName, String table, List<Object> ids, {PreFinishDBOperation<Iterable<Map<String, dynamic>>, List<R>>? preFinish}) FutureOr<List<R>>
override
doSelectRelationship<R>(TransactionOperation op, String entityName, String table, String field, dynamic id, String otherTableName, [PreFinishDBOperation<Iterable<Map<String, dynamic>>, R>? preFinish]) FutureOr<R>
override
doSelectRelationships<R>(TransactionOperation op, String entityName, String table, String field, List ids, String otherTableName, [PreFinishDBOperation<Iterable<Map<String, dynamic>>, R>? preFinish]) FutureOr<R>
override
doSelectSQL(String entityName, String table, SQL sql, Transaction transaction, C connection) FutureOr<Iterable<Map<String, dynamic>>>
doUpdate<O>(TransactionOperation op, String entityName, String table, O o, Object id, Map<String, dynamic> fields, {String? idFieldName, PreFinishDBOperation? preFinish, bool allowAutoInsert = false}) FutureOr
override
doUpdateSQL(String entityName, String table, SQL sql, Object id, Transaction transaction, C connection, {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
entityTypeToSQLType(TypeInfo type, String? column, {List<EntityField>? entityFieldAnnotations}) MapEntry<String, MapEntry<String, String>>?
Returns info for the column: table -> idName: sqlType
inherited
enumTypeToSQLType(Type type, String column, {List<EntityField>? entityFieldAnnotations}) MapEntry<String, List<String>>?
Returns: ENUM: valuesNames
inherited
executeInitialized<R>(ExecuteInitializedCallback<R> callback, {Initializable? parent}) FutureOr<R>
Executes the callback ensuring that this instances was fully initialized.
inherited
executeTableSQL(String createTableSQL) FutureOr<bool>
executeTransactionOperation<R>(TransactionOperation op, SQLWrapper sql, FutureOr<R> f(C connection)) FutureOr<R>
executeWithPool<R>(FutureOr<R> f(C o), {Duration? timeout, bool validator(C o)?, dynamic onError(Object error, StackTrace stackTrace)?}) FutureOr<R>
inherited
fieldValueToSQL(EncodingContext context, TableScheme tableScheme, String fieldName, Object? value, Map<String, Object?> fieldsValues) FutureOr<String>
filterPoolElements(FutureOr<bool> filter(C o)) FutureOr<List<C>>
inherited
foreignKeyTypeToSQLType(TypeInfo idType, String idName, {List<EntityField>? entityFieldAnnotations}) String?
inherited
generateAddColumnAlterTableSQL(String table, String fieldName, TypeInfo fieldType, {List<EntityField>? entityFieldAnnotations}) AlterTableSQL
inherited
generateAddEnumConstraintAlterTableSQL(String table, String fieldName, TypeInfo fieldType, {List<EntityField>? entityFieldAnnotations}) AlterTableSQL
inherited
generateAddUniqueConstraintAlterTableSQL(String table, String fieldName, TypeInfo fieldType, {List<EntityField>? entityFieldAnnotations}) AlterTableSQL
inherited
generateCountSQL(Transaction transaction, String entityName, String table, {EntityMatcher? matcher, Object? parameters, List? positionalParameters, Map<String, Object?>? namedParameters}) FutureOr<SQL>
generateCreateTableSQL({EntityRepository<Object>? entityRepository, Object? obj, Type? type, String? name, String? tableName, bool ifNotExists = true, bool sortColumns = true}) CreateTableSQL
inherited
generateCreateTableSQLs({bool ifNotExists = true, bool sortColumns = true}) List<SQLBuilder>
Generate all the SQLs to create the tables.
override
generateDeleteSQL(Transaction transaction, String entityName, String table, EntityMatcher matcher, {Object? parameters, List? positionalParameters, Map<String, Object?>? namedParameters}) FutureOr<SQL>
generateEntityRepositoresCreateTableSQLs({bool ifNotExists = true, bool sortColumns = true, bool verbose = false}) Map<EntityRepository<Object>, CreateTableSQL>
Generates the CreateTableSQL for each EntityRepository. See entityRepositories.
generateFullCreateTableSQLs({String? title, bool withDate = true, bool ifNotExists = true, bool sortColumns = true}) Future<String>
Generate a full text with all the SQLs to create the tables.
inherited
generateInsertRelationshipSQLs(Transaction transaction, String entityName, String table, String field, dynamic id, String otherTableName, List otherIds) FutureOr<List<SQL>>
generateInsertSQL(Transaction transaction, String entityName, String table, Map<String, Object?> fields) FutureOr<SQL>
generateSelectRelationshipSQL(Transaction transaction, String entityName, String table, String field, dynamic id, String otherTableName) FutureOr<SQL>
generateSelectRelationshipsSQL(Transaction transaction, String entityName, String table, String field, List ids, String otherTableName) FutureOr<SQL>
generateSelectSQL(Transaction transaction, String entityName, String table, EntityMatcher matcher, {Object? parameters, List? positionalParameters, Map<String, Object?>? namedParameters, int? limit}) FutureOr<SQL>
generateTables() FutureOr<List<String>>
generateUpdateSQL(Transaction transaction, String entityName, String table, Object id, Map<String, Object?> fields) FutureOr<SQL>
getConnectionURL(C connection) String
Returns the URL of the connection.
inherited
getEntityByID<O>(dynamic id, {Type? type, bool sync = false, EntityResolutionRules? resolutionRules}) FutureOr<O?>
inherited
getEntityHandler<T>({String? entityName, String? tableName, Type? entityType}) EntityHandler<T>?
inherited
getEntityID(Object entity, {String? entityName, String? tableName, Type? entityType, EntityHandler? entityHandler}) Object?
Returns the entity ID for entityName, tableName or entityType.
inherited
getEntityRepositoresTables() FutureOr<Map<EntityRepository<Object>, String>>
inherited
getEntityRepository<O extends Object>({O? obj, Type? type, String? name, String? tableName}) EntityRepository<O>?
inherited
getEntityRepositoryByType<O extends Object>(Type type) EntityRepository<O>?
inherited
getEntityRepositoryByTypeInfo<O extends Object>(TypeInfo typeInfo) EntityRepository<O>?
inherited
getFieldType(String field, {String? entityName, String? tableName, Type? entityType}) FutureOr<TypeInfo?>
Returns the type for the field at tableName or by entityName.
inherited
getRepositoriesSchemes() Future<Map<EntityRepository<Object>, TableScheme?>>
getRepositoryAdapterByName<O>(String name) DBSQLRepositoryAdapter<O>?
override
getRepositoryAdapterByTableName<O>(String tableName) DBSQLRepositoryAdapter<O>?
override
getRepositoryAdapterByType<O>(Type type) DBSQLRepositoryAdapter<O>?
override
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.
inherited
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
getVarcharPreferredSize(String? column) int
Returns the preferred VARCHAR size for a column name.
inherited
information({bool extended = false, String? table}) Map<String, dynamic>
inherited
initialize() FutureOr<InitializationResult>
Initialization implementation. Do not call it directly, use doInitialization.
inherited
initializeDependencies() FutureOr<List<Initializable>>
Return a List of Initializable instances that need to be initialized BEFORE initialize this instance.
inherited
insertRelationshipSQLs(TransactionOperation op, String entityName, String table, List<SQL> sqls, dynamic id, String otherTable, List otherIds) FutureOr<bool>
insertSQL(TransactionOperation op, String entityName, String table, SQL sql, Map<String, Object?> fields) FutureOr
instantiateRepositoryAdapter<O>(String name, String? tableName, Type? type) DBSQLRepositoryAdapter<O>
override
invalidPoolElements({bool checkUsage = true}) FutureOr<List<C>>
inherited
isConnectionValid(C connection, {bool checkUsage = true}) FutureOr<bool>
Returns true if connection is valid for usage.
inherited
isPoolElementInvalid(C o, {bool checkUsage = true}) FutureOr<bool>
inherited
isPoolElementValid(C o, {bool checkUsage = true}) FutureOr<bool>
Defaults: calls isConnectionValid.
inherited
isSiblingEntityType(EntityRepository<Object> tableRepository, Type columnType, {EntityRepository<Object>? columnRepository}) bool
Returns true if columnType is a sibling of the tableRepository.
inherited
isTransactionWithSingleOperation(TransactionOperation op, [SQLWrapper? sql]) bool
override
normalizeColumnName(String fieldName) String
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyKnownEntityRepositoryProvider(EntityRepositoryProvider provider) → void
inherited
notifyTableFieldTypes(String table, Map<String, Type> fieldsTypes) Map<String, Type>
inherited
openTransaction(Transaction transaction) FutureOr<C>
inherited
peekFromPool() FutureOr<C?>
inherited
populateImpl() FutureOr<InitializationResult>
override
populateTables(Object? tables) FutureOr<List<String>>
populateTablesFromSQLs(String sqls) FutureOr<List<String>>
preparePoolElement(C o) FutureOr<C?>
inherited
primaryKeyTypeToSQLType(Type type, {List<EntityField>? entityFieldAnnotations}) String?
inherited
recyclePoolElement(C o) FutureOr<C?>
inherited
registerEntityRepository<O extends Object>(EntityRepository<O> entityRepository) → void
inherited
releaseIntoPool(C o) FutureOr<bool>
inherited
removeElementsFromPool(int amount) int
inherited
removeFromPool(C o) bool
inherited
removeInvalidElementsFromPool({bool checkUsage = true}) FutureOr<bool>
inherited
resolveError(Object error, StackTrace stackTrace, Object? operation, Object? previousError) Object
resolveTransactionResult(dynamic result, Transaction transaction, C? connection) FutureOr
inherited
selectIDFieldName(String table, List<String> primaryKeyCandidates) String
Selects the ID field name from primaryKeyCandidates candidates:
inherited
selectRelationshipSQL(TransactionOperation op, String entityName, String table, SQL sql, dynamic id, String otherTable) FutureOr<Iterable<Map<String, dynamic>>>
selectRelationshipsSQL(TransactionOperation op, String entityName, String table, SQL sql, List ids, String otherTable) FutureOr<Iterable<Map<String, dynamic>>>
selectSQL(TransactionOperation op, String entityName, String table, SQL sql) FutureOr<Iterable<Map<String, dynamic>>>
toString() String
A string representation of this object.
inherited
typeToSQLType(TypeInfo type, String column, {List<EntityField>? entityFieldAnnotations}) String?
inherited
updateSQL(TransactionOperation op, String entityName, String table, SQL sql, Object id, Map<String, Object?> fields, {bool allowAutoInsert = false}) FutureOr
validPoolElements() FutureOr<List<C>>
inherited
valueToSQL(Object? value) Object?
Converts value to an acceptable SQL value for the adapter.

Operators

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

Static Properties

adapterRegister DBAdapterRegister<Object, DBSQLAdapter<Object>>
final
registeredAdaptersNames List<String>
no setter
registeredAdaptersTypes List<Type>
no setter
temporaryTableIdCount int
getter/setter pair

Static Methods

boot() → void
override
createTemporaryTableName(String prefix) String
extractSQLs(String sqls, RegExp commandPrefixPattern) List<String>
extractTableNameInSQL(String tableSQL) String?
extractTableSQLs(String sqls) List<String>
fromConfig<C extends Object, A extends DBSQLAdapter<C>>(Map<String, dynamic> config, {int minConnections = 1, int maxConnections = 3, EntityRepositoryProvider? parentRepositoryProvider, String? workingPath}) FutureOr<A>
override
getAdapterInstantiator<C extends Object, A extends DBSQLAdapter<C>>({String? name, Type? type}) DBSQLAdapterInstantiator<C, A>?
override
getAdapterInstantiatorsFromConfig<C extends Object, A extends DBSQLAdapter<C>>(Map<String, dynamic> config) List<MapEntry<DBSQLAdapterInstantiator<C, A>, Map<String, dynamic>>>
override
parseConfigDBGenerateTablesAndCheckTables(Map<String, dynamic>? config) List<bool>
parseConfigLogSQL(Map<String, dynamic>? config) bool?
registerAdapter<C extends Object, A extends DBSQLAdapter<C>>(List<String> names, Type type, DBSQLAdapterInstantiator<C, A> adapterInstantiator) → void
override
removeSQLsComments(String sqls) String