IGNITE-5303 Added support for multiple RDBMS.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/0fb6d2f8 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/0fb6d2f8 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/0fb6d2f8 Branch: refs/heads/ignite-5272 Commit: 0fb6d2f8d2ac2d26be48dc5513fb6702ae680918 Parents: 4479f21 Author: vsisko <[email protected]> Authored: Fri Jun 9 15:05:34 2017 +0700 Committer: Alexey Kuznetsov <[email protected]> Committed: Fri Jun 9 15:05:34 2017 +0700 ---------------------------------------------------------------------- .../frontend/controllers/domains-controller.js | 123 ++++++++++--------- .../ignite/console/agent/db/DbSchema.java | 60 +++++++++ .../agent/handlers/DatabaseListener.java | 18 ++- 3 files changed, 140 insertions(+), 61 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/0fb6d2f8/modules/web-console/frontend/controllers/domains-controller.js ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/controllers/domains-controller.js b/modules/web-console/frontend/controllers/domains-controller.js index b8fae5d..4d59264 100644 --- a/modules/web-console/frontend/controllers/domains-controller.js +++ b/modules/web-console/frontend/controllers/domains-controller.js @@ -433,6 +433,62 @@ export default ['$rootScope', '$scope', '$http', '$state', '$filter', '$timeout' }; } + function isValidJavaIdentifier(s) { + return JavaTypes.validIdentifier(s) && !JavaTypes.isKeyword(s) && JavaTypes.nonBuiltInClass(s) && + SqlTypes.validIdentifier(s) && !SqlTypes.isKeyword(s); + } + + function toJavaIdentifier(name) { + if (_.isEmpty(name)) + return 'DB'; + + const len = name.length; + + let ident = ''; + + let capitalizeNext = true; + + for (let i = 0; i < len; i++) { + const ch = name.charAt(i); + + if (ch === ' ' || ch === '_') + capitalizeNext = true; + else if (ch === '-') { + ident += '_'; + capitalizeNext = true; + } + else if (capitalizeNext) { + ident += ch.toLocaleUpperCase(); + + capitalizeNext = false; + } + else + ident += ch.toLocaleLowerCase(); + } + + return ident; + } + + function toJavaClassName(name) { + const clazzName = toJavaIdentifier(name); + + if (isValidJavaIdentifier(clazzName)) + return clazzName; + + return 'Class' + clazzName; + } + + function toJavaFieldName(dbName) { + const javaName = toJavaIdentifier(dbName); + + const fieldName = javaName.charAt(0).toLocaleLowerCase() + javaName.slice(1); + + if (isValidJavaIdentifier(fieldName)) + return fieldName; + + return 'field' + javaName; + } + /** * Show import domain models modal. */ @@ -544,17 +600,14 @@ export default ['$rootScope', '$scope', '$http', '$state', '$filter', '$timeout' return agentMgr.schemas(preset); }) - .then(function(schemas) { - $scope.importDomain.schemas = _.map(schemas, function(schema) { - return {use: true, name: schema}; - }); - + .then((schemaInfo) => { $scope.importDomain.action = 'schemas'; + $scope.importDomain.info = INFO_SELECT_SCHEMAS; + $scope.importDomain.catalog = toJavaIdentifier(schemaInfo.catalog); + $scope.importDomain.schemas = _.map(schemaInfo.schemas, (schema) => ({use: true, name: schema})); if ($scope.importDomain.schemas.length === 0) $scope.importDomainNext(); - - $scope.importDomain.info = INFO_SELECT_SCHEMAS; }) .catch(Messages.showError) .then(() => Loading.finish('importDomainFromDb')); @@ -595,55 +648,6 @@ export default ['$rootScope', '$scope', '$http', '$state', '$filter', '$timeout' return 'Associate with ' + cacheName; }; - function isValidJavaIdentifier(s) { - return JavaTypes.validIdentifier(s) && !JavaTypes.isKeyword(s) && JavaTypes.nonBuiltInClass(s) && - SqlTypes.validIdentifier(s) && !SqlTypes.isKeyword(s); - } - - function toJavaIdentifier(name) { - const len = name.length; - - let ident = ''; - - let capitalizeNext = true; - - for (let i = 0; i < len; i++) { - const ch = name.charAt(i); - - if (ch === ' ' || ch === '_') - capitalizeNext = true; - else if (capitalizeNext) { - ident += ch.toLocaleUpperCase(); - - capitalizeNext = false; - } - else - ident += ch.toLocaleLowerCase(); - } - - return ident; - } - - function toJavaClassName(name) { - const clazzName = toJavaIdentifier(name); - - if (isValidJavaIdentifier(clazzName)) - return clazzName; - - return 'Class' + clazzName; - } - - function toJavaFieldName(dbName) { - const javaName = toJavaIdentifier(dbName); - - const fieldName = javaName.charAt(0).toLocaleLowerCase() + javaName.slice(1); - - if (isValidJavaIdentifier(fieldName)) - return fieldName; - - return 'field' + javaName; - } - function _fillCommonCachesOrTemplates(item) { return function(action) { if (item.cachesOrTemplates) @@ -968,9 +972,14 @@ export default ['$rootScope', '$scope', '$http', '$state', '$filter', '$timeout' if (!newCache.cacheStoreFactory || newCache.cacheStoreFactory.kind !== 'CacheJdbcPojoStoreFactory') { const dialect = $scope.importDomain.demo ? 'H2' : $scope.selectedPreset.db; + const catalog = $scope.importDomain.catalog; + newCache.cacheStoreFactory = { kind: 'CacheJdbcPojoStoreFactory', - CacheJdbcPojoStoreFactory: {dataSourceBean: 'ds' + dialect, dialect}, + CacheJdbcPojoStoreFactory: { + dataSourceBean: 'ds' + dialect + '_' + catalog, + dialect + }, CacheJdbcBlobStoreFactory: { connectVia: 'DataSource' } }; } http://git-wip-us.apache.org/repos/asf/ignite/blob/0fb6d2f8/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/db/DbSchema.java ---------------------------------------------------------------------- diff --git a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/db/DbSchema.java b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/db/DbSchema.java new file mode 100644 index 0000000..1c89ceb --- /dev/null +++ b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/db/DbSchema.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.console.agent.db; + +import java.util.Collection; +import org.apache.ignite.internal.util.typedef.internal.S; + +/** + * Database schema names with catalog name. + */ +public class DbSchema { + /** Catalog name. */ + private final String catalog; + + /** Schema names. */ + private final Collection<String> schemas; + + /** + * @param catalog Catalog name. + * @param schemas Schema names. + */ + public DbSchema(String catalog, Collection<String> schemas) { + this.catalog = catalog; + this.schemas = schemas; + } + + /** + * @return Catalog name. + */ + public String getCatalog() { + return catalog; + } + + /** + * @return Schema names. + */ + public Collection<String> getSchemas() { + return schemas; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(DbSchema.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/0fb6d2f8/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/DatabaseListener.java ---------------------------------------------------------------------- diff --git a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/DatabaseListener.java b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/DatabaseListener.java index d1394c9..9da118d 100644 --- a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/DatabaseListener.java +++ b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/agent/handlers/DatabaseListener.java @@ -33,9 +33,10 @@ import java.util.List; import java.util.Map; import java.util.Properties; import org.apache.ignite.console.agent.AgentConfiguration; -import org.apache.ignite.console.demo.AgentMetadataDemo; import org.apache.ignite.console.agent.db.DbMetadataReader; +import org.apache.ignite.console.agent.db.DbSchema; import org.apache.ignite.console.agent.db.DbTable; +import org.apache.ignite.console.demo.AgentMetadataDemo; import org.apache.log4j.Logger; import static java.nio.charset.StandardCharsets.UTF_8; @@ -211,19 +212,28 @@ public class DatabaseListener { * @return Collection of schema names. * @throws SQLException If failed to collect schemas. */ - protected Collection<String> schemas(String jdbcDriverJarPath, String jdbcDriverCls, String jdbcUrl, + protected DbSchema schemas(String jdbcDriverJarPath, String jdbcDriverCls, String jdbcUrl, Properties jdbcInfo) throws SQLException { if (log.isDebugEnabled()) log.debug("Start collecting database schemas [drvJar=" + jdbcDriverJarPath + ", drvCls=" + jdbcDriverCls + ", jdbcUrl=" + jdbcUrl + "]"); try (Connection conn = connect(jdbcDriverJarPath, jdbcDriverCls, jdbcUrl, jdbcInfo)) { + String catalog = conn.getCatalog(); + + if (catalog == null) { + String[] parts = jdbcUrl.split("[/:=]"); + + catalog = parts.length > 0 ? parts[parts.length - 1] : "NONE"; + } + Collection<String> schemas = dbMetaReader.schemas(conn); if (log.isDebugEnabled()) - log.debug("Finished collection of schemas [jdbcUrl=" + jdbcUrl + ", count=" + schemas.size() + "]"); + log.debug("Finished collection of schemas [jdbcUrl=" + jdbcUrl + ", catalog=" + catalog + + ", count=" + schemas.size() + "]"); - return schemas; + return new DbSchema(catalog, schemas); } catch (Throwable e) { log.error("Failed to collect schemas", e);
