Repository: ignite Updated Branches: refs/heads/ignite-843-rc2 97f2ab9d0 -> 87df9d4a5
IGNITE-2284 Update store on save of cache or domain. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/87df9d4a Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/87df9d4a Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/87df9d4a Branch: refs/heads/ignite-843-rc2 Commit: 87df9d4a589bc452bc9cbca28ce7edd1ed90ef36 Parents: 97f2ab9 Author: Andrey <[email protected]> Authored: Thu Jan 21 10:06:27 2016 +0700 Committer: Andrey <[email protected]> Committed: Thu Jan 21 10:06:27 2016 +0700 ---------------------------------------------------------------------- .../main/js/controllers/caches-controller.js | 30 +-------------- .../src/main/js/controllers/common-module.js | 40 ++++++++++++++++---- .../main/js/controllers/domains-controller.js | 32 ++++++++++++++-- modules/control-center-web/src/main/js/db.js | 2 +- .../src/main/js/routes/domains.js | 21 +++++++++- 5 files changed, 83 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/87df9d4a/modules/control-center-web/src/main/js/controllers/caches-controller.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/controllers/caches-controller.js b/modules/control-center-web/src/main/js/controllers/caches-controller.js index e9e0fb2..f0732db 100644 --- a/modules/control-center-web/src/main/js/controllers/caches-controller.js +++ b/modules/control-center-web/src/main/js/controllers/caches-controller.js @@ -379,33 +379,6 @@ consoleModule.controller('cachesController', [ $scope.preview.statistics.allDefaults = $common.isEmptyString($scope.preview.statistics.xml); } }, true); - - $scope.$watchCollection('backupItem.domains', function (val) { - if ($scope.selectedItemWatchGuard) - $scope.selectedItemWatchGuard = false; - else { - var item = $scope.backupItem; - - var cacheStoreFactory = $common.isDefined(item) && - $common.isDefined(item.cacheStoreFactory) && - $common.isDefined(item.cacheStoreFactory.kind); - - if (val && !cacheStoreFactory) { - if (_.findIndex(cacheDomains(item), $common.domainForStoreConfigured) >= 0) { - item.cacheStoreFactory.kind = 'CacheJdbcPojoStoreFactory'; - - if (!item.readThrough && !item.writeThrough) { - item.readThrough = true; - item.writeThrough = true; - } - - $timeout(function () { - $common.ensureActivePanel($scope.panels, 'store'); - }); - } - } - } - }); }) .error(function (errMsg) { $common.showError(errMsg); @@ -629,9 +602,10 @@ consoleModule.controller('cachesController', [ // Save cache. $scope.saveItem = function () { if ($scope.tableReset(true)) { - var item = $scope.backupItem; + angular.extend(item, $common.autoCacheStoreConfiguration(item, cacheDomains(item))); + if (validate(item)) save(item); } http://git-wip-us.apache.org/repos/asf/ignite/blob/87df9d4a/modules/control-center-web/src/main/js/controllers/common-module.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/controllers/common-module.js b/modules/control-center-web/src/main/js/controllers/common-module.js index 1399f58..ba7e58a 100644 --- a/modules/control-center-web/src/main/js/controllers/common-module.js +++ b/modules/control-center-web/src/main/js/controllers/common-module.js @@ -695,6 +695,15 @@ consoleModule.service('$common', [ {value: 'H2', label: 'H2 database'} ]; + function domainForStoreConfigured(domain) { + var isEmpty = !isDefined(domain) || (isEmptyString(domain.databaseSchema) && + isEmptyString(domain.databaseTable) && + isEmptyArray(domain.keyFields) && + isEmptyArray(domain.valueFields)); + + return !isEmpty; + } + return { getModel: getModel, joinTip: function (arr) { @@ -788,14 +797,7 @@ consoleModule.service('$common', [ return !isEmpty; }, - domainForStoreConfigured: function (domain) { - var isEmpty = !isDefined(domain) || (isEmptyString(domain.databaseSchema) && - isEmptyString(domain.databaseTable) && - isEmptyArray(domain.keyFields) && - isEmptyArray(domain.valueFields)); - - return !isEmpty; - }, + domainForStoreConfigured: domainForStoreConfigured, /** * Cut class name by width in pixel or width in symbol count. * @@ -1061,6 +1063,28 @@ consoleModule.service('$common', [ })); return res; + }, + autoCacheStoreConfiguration: function (cache, domains) { + var change; + + var cacheStoreFactory = isDefined(cache.cacheStoreFactory) && + isDefined(cache.cacheStoreFactory.kind); + + if (!cacheStoreFactory && _.findIndex(domains, domainForStoreConfigured) >= 0) { + var dflt = !cache.readThrough && !cache.writeThrough; + + return { + cacheStoreFactory: { + kind: 'CacheJdbcPojoStoreFactory', + CacheJdbcPojoStoreFactory: { + dataSourceBean: cache.name + 'DS', + dialect: 'Generic' + } + }, + readThrough: dflt || cache.readThrough, + writeThrough: dflt || cache.writeThrough + }; + } } }; }]); http://git-wip-us.apache.org/repos/asf/ignite/blob/87df9d4a/modules/control-center-web/src/main/js/controllers/domains-controller.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/controllers/domains-controller.js b/modules/control-center-web/src/main/js/controllers/domains-controller.js index a3a982d..bd88bbf 100644 --- a/modules/control-center-web/src/main/js/controllers/domains-controller.js +++ b/modules/control-center-web/src/main/js/controllers/domains-controller.js @@ -816,6 +816,7 @@ consoleModule.controller('domainsController', function ($filter, $http, $timeout var batch = []; var tables = []; + var checkedCaches = []; var dupCnt = 0; var containKey = true; @@ -942,14 +943,28 @@ consoleModule.controller('domainsController', function ($filter, $http, $timeout newDomain.newCache.cacheStoreFactory = { kind: 'CacheJdbcPojoStoreFactory', CacheJdbcPojoStoreFactory: { - dataSourceBean: 'dataSource' + dialect, + dataSourceBean: newDomain.newCache.name + 'DS', dialect: dialect } }; } } - else if (table.cache !== IMPORT_DM_DO_NOT_GENERATE._id) - newDomain.caches = [table.cache]; + else if (table.cache !== IMPORT_DM_DO_NOT_GENERATE._id) { + var cacheId = table.cache; + + newDomain.caches = [cacheId]; + + if (!_.contains(checkedCaches, cacheId)) { + var cache = _.find($scope.caches, {value: cacheId}).cache; + + var change = $common.autoCacheStoreConfiguration(cache, [newDomain]); + + if (change) + newDomain.cacheStoreChanges = [{cacheId: cacheId, change: change}]; + + checkedCaches.push(cacheId) + } + } } batch.push(newDomain); @@ -1324,6 +1339,17 @@ consoleModule.controller('domainsController', function ($filter, $http, $timeout if ($scope.tableReset(true)) { var item = $scope.backupItem; + item.cacheStoreChanges = []; + + _.forEach(item.caches, function (cacheId) { + var cache = _.find($scope.caches, {value: cacheId}).cache; + + var change = $common.autoCacheStoreConfiguration(cache, [item]); + + if (change) + item.cacheStoreChanges.push({cacheId: cacheId, change: change}); + }); + if (validate(item)) save(item); } http://git-wip-us.apache.org/repos/asf/ignite/blob/87df9d4a/modules/control-center-web/src/main/js/db.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/db.js b/modules/control-center-web/src/main/js/db.js index 8ecb71e..6d5ad65 100644 --- a/modules/control-center-web/src/main/js/db.js +++ b/modules/control-center-web/src/main/js/db.js @@ -74,7 +74,7 @@ exports.Space = mongoose.model('Space', new Schema({ var DomainModelSchema = new Schema({ space: {type: ObjectId, ref: 'Space'}, caches: [{type: ObjectId, ref: 'Cache'}], - queryMetadata: {type: String, enum: ['Annotations', 'Config']}, + queryMetadata: {type: String, enum: ['Annotations', 'Configuration']}, kind: {type: String, enum: ['query', 'store', 'both']}, databaseSchema: String, databaseTable: String, http://git-wip-us.apache.org/repos/asf/ignite/blob/87df9d4a/modules/control-center-web/src/main/js/routes/domains.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/routes/domains.js b/modules/control-center-web/src/main/js/routes/domains.js index 4867807..e52f7ee 100644 --- a/modules/control-center-web/src/main/js/routes/domains.js +++ b/modules/control-center-web/src/main/js/routes/domains.js @@ -76,6 +76,8 @@ function _saveDomainModel(domain, savedDomains, callback) { var domainId = domain._id; var caches = domain.caches; + var cacheStoreChanges = domain.cacheStoreChanges; + if (domainId) db.DomainModel.update({_id: domain._id}, domain, {upsert: true}, function (err) { if (err) @@ -91,7 +93,7 @@ function _saveDomainModel(domain, savedDomains, callback) { else { savedDomains.push(domain); - callback(); + _updateCacheStore(cacheStoreChanges, callback); } }); }); @@ -115,7 +117,7 @@ function _saveDomainModel(domain, savedDomains, callback) { else { savedDomains.push(domain); - callback(); + _updateCacheStore(cacheStoreChanges, callback); } }); } @@ -123,6 +125,21 @@ function _saveDomainModel(domain, savedDomains, callback) { }); } +function _updateCacheStore(cacheStoreChanges, callback) { + if (cacheStoreChanges && cacheStoreChanges.length > 0) { + async.forEachOf(cacheStoreChanges, function (change, idx, callback) { + db.Cache.update({_id: {$eq: change.cacheId}}, change.change, {}, function (err) { + if (err) + callback(err); + else + callback(); + }); + }, callback); + } + else + callback(); +} + function _save(domains, res) { var savedDomains = []; var generatedCaches = [];
