|
Krita Source Code Documentation
|
The KisResourceCacheDb class encapsulates the database that caches information about the resources available to the user. More...
#include <KisResourceCacheDb.h>
Static Public Member Functions | |
| static void | deleteTemporaryResources () |
| Delete all storages that are Unknown or Memory and all resources that are marked temporary or belong to Unknown or Memory storages. | |
| static bool | getForeignKeysStateImpl () |
| static bool | initialize (const QString &location) |
| initializes the database and updates the scheme if necessary. Does not actually fill the database with pointers to resources. | |
| static bool | isValid () |
| isValid | |
| static QString | lastError () |
| lastError returns the last SQL error. | |
| static void | performHouseKeepingOnExit () |
| perform optimize and vacuum when necessary | |
| static void | setForeignKeysStateImpl (bool isEnabled) |
| static void | synchronizeForeignKeysState () |
Static Public Attributes | |
| static const QString | databaseVersion { "0.0.18" } |
| current schema version | |
| static QStringList | disabledBundles { QStringList() << "Krita_3_Default_Resources.bundle" } |
| the list of compatibility bundles that need to inactive by default | |
| static const QString | resourceCacheDbFilename { "resourcecache.sqlite" } |
| filename of the database | |
| static QStringList | storageTypes { QStringList() } |
| kinds of places where resources can be stored | |
Private Member Functions | |
| KisResourceCacheDb () | |
| KisResourceCacheDb | operator= (const KisResourceCacheDb &) |
| ~KisResourceCacheDb () | |
Static Private Member Functions | |
| static bool | addMetaDataForId (const QMap< QString, QVariant > map, int id, const QString &tableName) |
| static bool | addResource (KisResourceStorageSP storage, QDateTime timestamp, KoResourceSP resource, const QString &resourceType) |
| static bool | addResources (KisResourceStorageSP storage, QString resourceType) |
| static bool | addResourceVersion (int resourceId, QDateTime timestamp, KisResourceStorageSP storage, KoResourceSP resource) |
| addResourceVersion adds a new version of the resource to the database. The resource itself already should be updated with the updated filename and version. | |
| static bool | addResourceVersionImpl (int resourceId, QDateTime timestamp, KisResourceStorageSP storage, KoResourceSP resource) |
| static bool | addStorage (KisResourceStorageSP storage, bool preinstalled) |
| static bool | addStorageTags (KisResourceStorageSP storage) |
| static bool | addTag (const QString &resourceType, const QString storageLocation, KisTagSP tag) |
| static bool | addTags (KisResourceStorageSP storage, QString resourceType) |
| static bool | deleteStorage (KisResourceStorageSP storage) |
| Actually delete the storage and all its resources from the database (i.e., nothing is set to inactive, it's deleted) | |
| static bool | deleteStorage (QString location) |
| static bool | getAllVersionsLocations (int resourceId, QStringList &outVersionsLocationsList) |
| static bool | getResourceIdFromFilename (QString filename, QString resourceType, QString storageLocation, int &outResourceId) |
| The function will find the resource only if it is the latest version. | |
| static bool | getResourceIdFromVersionedFilename (QString filename, QString resourceType, QString storageLocation, int &outResourceId) |
| Note that here you can put even the original filename - any filename from the versioned_resources - and it will still find it. | |
| static bool | hasTag (const QString &url, const QString &resourceType) |
| static bool | linkTagToStorage (const QString &url, const QString &resourceType, const QString &storageLocation) |
| static bool | makeResourceTheCurrentVersion (int resourceId, KoResourceSP resource) |
| static QMap< QString, QVariant > | metaDataForId (int id, const QString &tableName) |
| metaDataForId | |
| static bool | registerResourceType (const QString &resourceType) |
| registerResourceType registers this resource type in the database | |
| static bool | registerStorageType (const KisResourceStorage::StorageType storageType) |
| registerStorageType registers this storage type in the database | |
| static bool | removeOrphanedMetaData () |
| removeOrphanedMetaData Previous versions of Krita never removed metadata, so this function doublechecks and removes any orphaned metadata for either storages or resources from the database. | |
| static bool | removeResourceCompletely (int resourceId) |
| static bool | removeResourceVersionImpl (int resourceId, int version, KisResourceStorageSP storage) |
| static int | resourceIdForResource (const QString &resourceFileName, const QString &resourceType, const QString &storageLocation) |
| static bool | resourceNeedsUpdating (int resourceId, QDateTime timestamp) |
| static QVector< int > | resourcesForStorage (const QString &resourceType, const QString &storageLocation) |
| static bool | setResourceActive (int resourceId, bool active=false) |
| Make this resource active or inactive; this does not remove the resource from disk or from the database. | |
| static bool | synchronizeStorage (KisResourceStorageSP storage) |
| static bool | tagResource (const QString &resourceFileName, KisTagSP tag, const QString &resourceType) |
| static bool | updateMetaDataForId (const QMap< QString, QVariant > map, int id, const QString &tableName) |
| setMetaDataForId removes all metadata for the given id and table name, and inserts the metadata in the metadata table. | |
| static bool | updateResourceTableForResourceIfNeeded (int resourceId, const QString &resourceType, KisResourceStorageSP storage) |
Static Private Attributes | |
| static QString | s_lastError {QString()} |
| static bool | s_valid {false} |
Friends | |
| class | KisAllResourcesModel |
| class | KisAllTagsModel |
| class | KisDocument |
| class | KisResourceLoaderRegistry |
| class | KisResourceLocator |
| class | KisResourceUserOperations |
| class | TestResourceCacheDb |
| class | TestResourceLocator |
The KisResourceCacheDb class encapsulates the database that caches information about the resources available to the user.
KisApplication creates and initializes the database. All other methods are static and can be used from anywhere.
Definition at line 23 of file KisResourceCacheDb.h.
|
explicitprivate |
|
private |
|
staticprivate |
Definition at line 2414 of file KisResourceCacheDb.cpp.
References v.
|
staticprivate |
Definition at line 1063 of file KisResourceCacheDb.cpp.
References addResourceVersionImpl(), KisResourceStorage::Bundle, changeToEmptyIfNull(), KisResourceLocator::instance(), KisResourceLocator::makeStorageLocationRelative(), KisResourceStorage::Memory, METADATA_RESOURCES, resourceIdForResource(), s_valid, and updateMetaDataForId().
|
staticprivate |
Definition at line 1183 of file KisResourceCacheDb.cpp.
References addResource(), and addResourceVersion().
|
staticprivate |
addResourceVersion adds a new version of the resource to the database. The resource itself already should be updated with the updated filename and version.
| resourceId | unique identifier for the resource |
| timestamp | |
| storage | |
| resource |
Definition at line 646 of file KisResourceCacheDb.cpp.
References addResourceVersionImpl(), and makeResourceTheCurrentVersion().
|
staticprivate |
Definition at line 660 of file KisResourceCacheDb.cpp.
References changeToEmptyIfNull(), KisResourceLocator::instance(), and KIS_SAFE_ASSERT_RECOVER_NOOP.
|
staticprivate |
Definition at line 1583 of file KisResourceCacheDb.cpp.
References addResources(), changeToEmptyIfNull(), debugResource, disabledBundles, KisResourceLoaderRegistry::instance(), KisResourceLocator::instance(), METADATA_STORAGES, s_valid, and updateMetaDataForId().
|
staticprivate |
Definition at line 1683 of file KisResourceCacheDb.cpp.
References addTags(), and KisResourceLoaderRegistry::instance().
|
staticprivate |
Definition at line 1406 of file KisResourceCacheDb.cpp.
References hasTag(), and linkTagToStorage().
|
staticprivate |
Definition at line 1518 of file KisResourceCacheDb.cpp.
References addTag(), and tagResource().
|
staticprivate |
Actually delete the storage and all its resources from the database (i.e., nothing is set to inactive, it's deleted)
Definition at line 1808 of file KisResourceCacheDb.cpp.
References deleteStorage(), and KisResourceLocator::instance().
|
staticprivate |
Actually delete the storage and all its resources from the database (i.e., nothing is set to inactive, it's deleted) location - relative
Definition at line 1696 of file KisResourceCacheDb.cpp.
References changeToEmptyIfNull(), detail::KisDatabaseTransactionLockAdapter::commit(), KisSqlQueryLoader::exec(), KisSqlQueryLoader::FileException::fileErrorString, KisSqlQueryLoader::FileException::filePath, KisSqlQueryLoader::FileException::message, METADATA_RESOURCES, METADATA_STORAGES, KisSqlQueryLoader::query(), and KisSqlQueryLoader::single_statement_mode.
|
static |
Delete all storages that are Unknown or Memory and all resources that are marked temporary or belong to Unknown or Memory storages.
Remove all temporary resources
Remove all temporary storages
Definition at line 2123 of file KisResourceCacheDb.cpp.
References detail::KisDatabaseTransactionLockAdapter::commit(), KisSqlQueryLoader::exec(), KisSqlQueryLoader::SQLException::filePath, KisResourceStorage::Memory, KisSqlQueryLoader::SQLException::message, METADATA_RESOURCES, METADATA_STORAGES, KisSqlQueryLoader::query(), KisSqlQueryLoader::single_statement_mode, KisSqlQueryLoader::SQLException::sqlError, and KisSqlQueryLoader::SQLException::statementIndex.
|
staticprivate |
Definition at line 1036 of file KisResourceCacheDb.cpp.
|
static |
get the foreign_keys feature state of the database (the function may throw SQL exceptions, call in a try-block only!)
Definition at line 2253 of file KisResourceCacheDb.cpp.
References KisSqlQueryLoader::exec(), and KisSqlQueryLoader::query().
|
staticprivate |
The function will find the resource only if it is the latest version.
Definition at line 961 of file KisResourceCacheDb.cpp.
References changeToEmptyIfNull().
|
staticprivate |
Note that here you can put even the original filename - any filename from the versioned_resources - and it will still find it.
Definition at line 997 of file KisResourceCacheDb.cpp.
References changeToEmptyIfNull().
|
staticprivate |
Definition at line 1351 of file KisResourceCacheDb.cpp.
|
static |
initializes the database and updates the scheme if necessary. Does not actually fill the database with pointers to resources.
| location | the location of the database |
Definition at line 480 of file KisResourceCacheDb.cpp.
References createDatabase(), deleteTemporaryResources(), s_lastError, and s_valid.
|
static |
isValid
Definition at line 53 of file KisResourceCacheDb.cpp.
References s_valid.
|
static |
lastError returns the last SQL error.
Definition at line 58 of file KisResourceCacheDb.cpp.
References s_lastError.
|
staticprivate |
Definition at line 1371 of file KisResourceCacheDb.cpp.
References changeToEmptyIfNull(), and KisResourceLocator::instance().
|
staticprivate |
Definition at line 838 of file KisResourceCacheDb.cpp.
References METADATA_RESOURCES, and updateMetaDataForId().
|
staticprivate |
metaDataForId
| id | |
| tableName |
Definition at line 2342 of file KisResourceCacheDb.cpp.
References value().
|
private |
|
static |
perform optimize and vacuum when necessary
Definition at line 2233 of file KisResourceCacheDb.cpp.
|
staticprivate |
registerResourceType registers this resource type in the database
| resourceType | the string that represents the type |
Definition at line 2304 of file KisResourceCacheDb.cpp.
|
staticprivate |
registerStorageType registers this storage type in the database
| storageType | the enum value that represents the type |
Definition at line 1543 of file KisResourceCacheDb.cpp.
References KisResourceStorage::storageTypeToUntranslatedString().
|
staticprivate |
removeOrphanedMetaData Previous versions of Krita never removed metadata, so this function doublechecks and removes any orphaned metadata for either storages or resources from the database.
Definition at line 2452 of file KisResourceCacheDb.cpp.
References detail::KisDatabaseTransactionLockAdapter::commit(), KisSqlQueryLoader::exec(), KisSqlQueryLoader::SQLException::filePath, KisSqlQueryLoader::SQLException::message, METADATA_RESOURCES, METADATA_STORAGES, KisSqlQueryLoader::query(), KisSqlQueryLoader::SQLException::sqlError, and KisSqlQueryLoader::SQLException::statementIndex.
|
staticprivate |
Definition at line 880 of file KisResourceCacheDb.cpp.
References METADATA_RESOURCES.
|
staticprivate |
Definition at line 709 of file KisResourceCacheDb.cpp.
References changeToEmptyIfNull(), and KisResourceLocator::instance().
|
staticprivate |
Definition at line 543 of file KisResourceCacheDb.cpp.
References changeToEmptyIfNull().
|
staticprivate |
Definition at line 611 of file KisResourceCacheDb.cpp.
|
staticprivate |
Definition at line 509 of file KisResourceCacheDb.cpp.
References changeToEmptyIfNull().
|
static |
set the foreign_keys feature state of the database (the function may throw SQL exceptions, call in a try-block only!)
Definition at line 2246 of file KisResourceCacheDb.cpp.
References KisSqlQueryLoader::exec().
|
staticprivate |
Make this resource active or inactive; this does not remove the resource from disk or from the database.
Definition at line 1221 of file KisResourceCacheDb.cpp.
|
static |
Called in the end of the database creation step to enable or disable the foreign_keys state depending on the release status of Krita. Currently, only developer's builds of Krita have foreign_keys constraint enabled.
Definition at line 2267 of file KisResourceCacheDb.cpp.
References KisSqlQueryLoader::SQLException::filePath, getForeignKeysStateImpl(), KisUsageLogger::log(), KisSqlQueryLoader::SQLException::message, setForeignKeysStateImpl(), KisSqlQueryLoader::SQLException::sqlError, and KisSqlQueryLoader::SQLException::statementIndex.
|
staticprivate |
Start the transaction that will add all the resources
We compare resource versions one-by-one because the storage may have multiple versions of them
Firstly, fetch information about the existing resources in the storage
A fake resourceId to group resources which are not yet present in the database. This value is always negative, therefore it cannot overlap with normal ids.
Assign the detected resource id to all the versions of this resource (if they are not present in the database). If no id has been detected, then a fake one will be assigned.
Secondly, fetch the resources present in the database
The head of itA array contains some resources with fake (negative) resourceId. These resources are obviously new resources and should be added to the cache database.
Now both arrays are sorted in resourceId/version/timestamp order. It lets us easily find the resources that are unique to the storage or database. If *itA < *itB, then the resource is present in the storage only and should be added to the database. If *itA > *itB, then the resource is present in the database only and should be removed (because it has been removed from the storage);
In the main loop we modified the versioned_resource table only, now we should update the head resources table with the latest version of the resource (and upload the thumbnail as well)
Definition at line 1848 of file KisResourceCacheDb.cpp.
References addResource(), addResourceVersion(), addResourceVersionImpl(), addStorage(), changeToEmptyIfNull(), debugResource, KisResourceLoaderRegistry::instance(), KisResourceLocator::instance(), KIS_SAFE_ASSERT_RECOVER, KIS_SAFE_ASSERT_RECOVER_NOOP, KisUsageLogger::log(), KisResourceLocator::makeStorageLocationRelative(), removeResourceVersionImpl(), resourceIdForResource(), s_valid, and updateResourceTableForResourceIfNeeded().
|
staticprivate |
Definition at line 1244 of file KisResourceCacheDb.cpp.
|
staticprivate |
setMetaDataForId removes all metadata for the given id and table name, and inserts the metadata in the metadata table.
| id | |
| tableName |
Definition at line 2380 of file KisResourceCacheDb.cpp.
References addMetaDataForId().
|
staticprivate |
Definition at line 743 of file KisResourceCacheDb.cpp.
References KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, makeResourceTheCurrentVersion(), and removeResourceCompletely().
|
friend |
Definition at line 83 of file KisResourceCacheDb.h.
|
friend |
Definition at line 79 of file KisResourceCacheDb.h.
|
friend |
Definition at line 82 of file KisResourceCacheDb.h.
|
friend |
Definition at line 80 of file KisResourceCacheDb.h.
|
friend |
Definition at line 76 of file KisResourceCacheDb.h.
|
friend |
Definition at line 81 of file KisResourceCacheDb.h.
|
friend |
Definition at line 78 of file KisResourceCacheDb.h.
|
friend |
Definition at line 77 of file KisResourceCacheDb.h.
|
static |
current schema version
Definition at line 46 of file KisResourceCacheDb.h.
|
static |
the list of compatibility bundles that need to inactive by default
Definition at line 48 of file KisResourceCacheDb.h.
|
static |
filename of the database
Definition at line 45 of file KisResourceCacheDb.h.
|
staticprivate |
Definition at line 51 of file KisResourceCacheDb.h.
|
staticprivate |
Definition at line 50 of file KisResourceCacheDb.h.
|
static |
kinds of places where resources can be stored
Definition at line 47 of file KisResourceCacheDb.h.