ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject ignite git commit: GNITE-2346 WIP on code generation for Datasources.
Date Wed, 13 Jan 2016 09:59:47 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-843-rc2 5231fc7f9 -> 537b7c914


GNITE-2346 WIP on code generation for Datasources.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/537b7c91
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/537b7c91
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/537b7c91

Branch: refs/heads/ignite-843-rc2
Commit: 537b7c9147d9ac226cee6d3a2f7e603289e817c0
Parents: 5231fc7
Author: vsisko <vsisko@gridgain.com>
Authored: Wed Jan 13 16:59:29 2016 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Wed Jan 13 16:59:29 2016 +0700

----------------------------------------------------------------------
 .../main/js/controllers/metadata-controller.js  |  13 +-
 .../src/main/js/controllers/models/caches.json  |  13 +-
 .../main/js/helpers/generator/generator-java.js | 137 ++++++++-----------
 .../main/js/helpers/generator/generator-pom.js  |   2 +-
 .../helpers/generator/generator-properties.js   |   4 +-
 .../main/js/helpers/generator/generator-xml.js  |   6 +-
 6 files changed, 82 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/537b7c91/modules/control-center-web/src/main/js/controllers/metadata-controller.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/controllers/metadata-controller.js b/modules/control-center-web/src/main/js/controllers/metadata-controller.js
index d123c5e..0c784d6 100644
--- a/modules/control-center-web/src/main/js/controllers/metadata-controller.js
+++ b/modules/control-center-web/src/main/js/controllers/metadata-controller.js
@@ -419,6 +419,15 @@ consoleModule.controller('metadataController', function ($filter, $http,
$timeou
                             .success(function (drivers) {
                                 onSuccess();
 
+                                if ($scope.loadMeta.demo) {
+                                    $scope.ui.packageNamePrev = $scope.ui.packageName;
+                                    $scope.ui.packageName = 'org.apache.ignite.console.demo.model';
+                                }
+                                else if ($scope.ui.packageNamePrev) {
+                                    $scope.ui.packageName = $scope.ui.packageNamePrev;
+                                    $scope.ui.packageNamePrev = null;
+                                }
+
                                 if (drivers && drivers.length > 0) {
                                     drivers = _.sortBy(drivers, 'jdbcDriverJar');
 
@@ -763,10 +772,8 @@ consoleModule.controller('metadataController', function ($filter, $http,
$timeou
                     meta.demo = $scope.loadMeta.demo;
 
                     // Use Java built-in type for key.
-                    if ($scope.ui.builtinKeys && meta.keyFields.length === 1) {
+                    if ($scope.ui.builtinKeys && meta.keyFields.length === 1)
                         meta.keyType = meta.keyFields[0].jdbcType.javaType;
-                        meta.keyFields = [];
-                    }
 
                     // Prepare caches for generation.
                     if ($scope.ui.generateCaches)

http://git-wip-us.apache.org/repos/asf/ignite/blob/537b7c91/modules/control-center-web/src/main/js/controllers/models/caches.json
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/controllers/models/caches.json b/modules/control-center-web/src/main/js/controllers/models/caches.json
index 34dd284..2c21f0b 100644
--- a/modules/control-center-web/src/main/js/controllers/models/caches.json
+++ b/modules/control-center-web/src/main/js/controllers/models/caches.json
@@ -464,7 +464,11 @@
                   "placeholder": "Choose connection",
                   "items": "jdbcBlobStoreConnections",
                   "tip": [
-                    "Select variant of connection to database"
+                    "You can connect to database via:",
+                    "<ul>",
+                    "  <li>JDBC URL, for example: jdbc:h2:mem:myDatabase</li>",
+                    "  <li>–°onfigured data source</li>",
+                    "</ul>"
                   ]
                 },
                 {
@@ -476,7 +480,7 @@
                   "required": true,
                   "hide": "backupItem.cacheStoreFactory.CacheJdbcBlobStoreFactory.connectVia
== 'DataSource'",
                   "tip": [
-                    "URL for database access, for example: TODO"
+                    "URL for database access, for example: jdbc:h2:mem:myDatabase"
                   ]
                 },
                 {
@@ -492,8 +496,9 @@
                   ]
                 },
                 {
-                  "label": "Note, password is not stored for security reasons TODO",
-                  "type": "label"
+                  "label": "Note, password will be generated as stubs.",
+                  "type": "label",
+                  "hide": "backupItem.cacheStoreFactory.CacheJdbcBlobStoreFactory.connectVia
== 'DataSource'"
                 },
                 {
                   "label": "Data source bean name",

http://git-wip-us.apache.org/repos/asf/ignite/blob/537b7c91/modules/control-center-web/src/main/js/helpers/generator/generator-java.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/helpers/generator/generator-java.js b/modules/control-center-web/src/main/js/helpers/generator/generator-java.js
index 044c6c3..469c0ba 100644
--- a/modules/control-center-web/src/main/js/helpers/generator/generator-java.js
+++ b/modules/control-center-web/src/main/js/helpers/generator/generator-java.js
@@ -189,8 +189,6 @@ $generatorJava.property = function (res, varName, obj, propName, dataType,
sette
 
         // Add to result if no default provided or value not equals to default.
         if (!hasDflt || (hasDflt && val !== dflt)) {
-            res.emptyLineIfNeeded();
-
             res.line(varName + '.' + $generatorJava.setterName(propName, setterName) +
                 '(' + $generatorJava.toJavaCode(val, dataType ? res.importClass(dataType)
: null) + ');');
 
@@ -201,6 +199,16 @@ $generatorJava.property = function (res, varName, obj, propName, dataType,
sette
     return false;
 };
 
+// Add property for class name.
+$generatorJava.classNameProperty = function (res, varName, obj, propName) {
+    var val = obj[propName];
+
+    if ($commonUtils.isDefined(val)) {
+        res.line(varName + '.' + $generatorJava.setterName(propName) +
+            '("' + $dataStructures.fullClassName(val) + '");');
+    }
+};
+
 /**
  * Add list property.
  *
@@ -1011,9 +1019,11 @@ $generatorJava.cacheQuery = function (cache, varName, res) {
  * @param res Resulting output with generated code.
  */
 $generatorJava.cacheStoreDataSource = function (storeFactory, res) {
-    var dialect = storeFactory.dialect || (storeFactory.connectBy === 'DataSource' ? storeFactory.database
: undefined);
+    var dialect = storeFactory.dialect || (storeFactory.connectVia === 'DataSource' ? storeFactory.database
: undefined);
 
     if (dialect) {
+        var varName = 'dataSource';
+
         var dataSourceBean = storeFactory.dataSourceBean;
 
         var dsClsName = $generatorCommon.dataSourceClassName(dialect);
@@ -1023,96 +1033,63 @@ $generatorJava.cacheStoreDataSource = function (storeFactory, res)
{
         var beanClassName = $commonUtils.toJavaName(varType, dataSourceBean);
 
         res.line('/** Helper class for datasource creation. */');
-        if (dialect !== 'Generic') {
-            res.startBlock('public static class ' + beanClassName + ' extends ' + varType
+ ' {');
-            res.startBlock('private ' + beanClassName + '() ' + (dialect === 'Oracle' ? 'throws
' + res.importClass('java.sql.SQLException') : '') + ' {');
-
-            switch (dialect) {
-                case 'DB2':
-                    res.line('setServerName(props.getProperty("' + dataSourceBean + '.jdbc.server_name"));');
-                    res.line('setPortNumber(Integer.valueOf(props.getProperty("' + dataSourceBean
+ '.jdbc.port_number")));');
-                    res.line('setDatabaseName(props.getProperty("' + dataSourceBean + '.jdbc.database_name"));');
-                    res.line('setDriverType(Integer.valueOf(props.getProperty("' + dataSourceBean
+ '.jdbc.driver_type")));');
-
-                    break;
-
-                case 'PostgreSQL':
-                    res.line('setDataSourceName("' + dataSourceBean + '");');
-                    res.line('setServerName(props.getProperty("' + dataSourceBean + '.jdbc.server_name"));');
-                    res.line('setDatabaseName(props.getProperty("' + dataSourceBean + '.jdbc.database_name"));');
+        res.startBlock('public static class ' + beanClassName + ' {');
+        res.line('public static final ' + varType + ' INSTANCE = createInstance();');
 
-                    break;
-
-                default:
-                    res.line('setURL(props.getProperty("' + dataSourceBean + '.jdbc.url"));');
-            }
-
-            res.line('setUser(props.getProperty("' + dataSourceBean + '.jdbc.username"));');
-            res.line('setPassword(props.getProperty("' + dataSourceBean + '.jdbc.password"));');
+        res.needEmptyLine = true;
 
-            res.endBlock('}');
+        res.startBlock('private static ' + varType + ' createInstance() {');
+        if (dialect === 'Oracle')
+            res.startBlock('try {');
 
-            res.needEmptyLine = true;
+        $generatorJava.resetVariables(res);
 
-            if (dialect !== 'Oracle')
-                res.line('public static final ' + beanClassName + ' INSTANCE = new ' + beanClassName
+ '();');
-            else {
-                res.line('public static final ' + beanClassName + ' INSTANCE = createInstance();');
+        $generatorJava.declareVariable(res, varName, varType);
 
-                res.needEmptyLine = true;
+        switch (dialect) {
+            case 'Generic':
+                res.line(varName + '.setJdbcUrl(props.getProperty("' + dataSourceBean + '.jdbc.url"));');
+                res.line(varName + '.setUser(props.getProperty("' + dataSourceBean + '.jdbc.username"));');
+                res.line(varName + '.setPassword(props.getProperty("' + dataSourceBean +
'.jdbc.password"));');
 
-                res.startBlock('private static ' + beanClassName + ' createInstance() {');
-                res.startBlock('try {');
-                res.line('return new ' + beanClassName + '();');
-                res.endBlock('}');
-                res.startBlock('catch (SQLException ex) {');
-                res.line('throw new Error(ex);');
-                res.endBlock('}');
-                res.endBlock('}');
-            }
+                break;
 
-            switch (dialect) {
-                case 'H2':
-                case 'Oracle':
-                case 'MySQL':
-                    res.needEmptyLine = true;
+            case 'DB2':
+                res.line(varName + '.setServerName(props.getProperty("' + dataSourceBean
+ '.jdbc.server_name"));');
+                res.line(varName + '.setPortNumber(Integer.valueOf(props.getProperty("' +
dataSourceBean + '.jdbc.port_number")));');
+                res.line(varName + '.setDatabaseName(props.getProperty("' + dataSourceBean
+ '.jdbc.database_name"));');
+                res.line(varName + '.setDriverType(Integer.valueOf(props.getProperty("' +
dataSourceBean + '.jdbc.driver_type")));');
 
-                    res.startBlock('@Override public ' + res.importClass('java.util.logging.Logger')
+ ' getParentLogger() throws ' + res.importClass('java.sql.SQLFeatureNotSupportedException')
+ ' {');
-                    res.line('return null; // TODO: CODE: implement.');
-                    res.endBlock('}');
+                break;
 
-                    if (dialect === 'MySQL') {
-                        res.needEmptyLine = true;
+            case 'PostgreSQL':
+                res.line(varName + '.setDataSourceName("' + dataSourceBean + '");');
+                res.line(varName + '.setServerName(props.getProperty("' + dataSourceBean
+ '.jdbc.server_name"));');
+                res.line(varName + '.setDatabaseName(props.getProperty("' + dataSourceBean
+ '.jdbc.database_name"));');
 
-                        res.startBlock('@Override public <T> T unwrap(Class<T>
iface) throws ' + res.importClass('java.sql.SQLException') + ' {');
-                        res.line('return null; // TODO: CODE: implement.');
-                        res.endBlock('}');
+                break;
 
-                        res.needEmptyLine = true;
+            default:
+                res.line(varName + '.setURL(props.getProperty("' + dataSourceBean + '.jdbc.url"));');
+        }
 
-                        res.startBlock('@Override public boolean isWrapperFor(Class<?>
iface) throws SQLException {');
-                        res.line('return false; // TODO: CODE: implement.');
-                        res.endBlock('}');
-                    }
+        res.line(varName + '.setUser(props.getProperty("' + dataSourceBean + '.jdbc.username"));');
+        res.line(varName + '.setPassword(props.getProperty("' + dataSourceBean + '.jdbc.password"));');
 
-                    break;
+        res.needEmptyLine = true;
 
-                default:
-            }
+        res.line('return dataSource;');
 
+        if (dialect === 'Oracle') {
             res.endBlock('}');
-        }
-        else {
-            res.startBlock('public static class ' + beanClassName + ' {');
-            res.line('public static final ' + varType + ' INSTANCE = new ' + varType + '();');
-            res.startBlock('static {');
-            res.line('INSTANCE.setJdbcUrl(props.getProperty("' + dataSourceBean + '.jdbc.url"));');
-            res.line('INSTANCE.setUser(props.getProperty("' + dataSourceBean + '.jdbc.username"));');
-            res.line('INSTANCE.setPassword(props.getProperty("' + dataSourceBean + '.jdbc.password"));');
-            res.endBlock('}');
+            res.startBlock('catch (' + res.importClass('java.sql.SQLException') + ' ex) {');
+            res.line('throw new Error(ex);');
             res.endBlock('}');
         }
 
+        res.endBlock('}');
+        res.endBlock('}');
+
         res.needEmptyLine = true;
 
         return dataSourceBean;
@@ -1218,9 +1195,9 @@ $generatorJava.cacheStore = function (cache, metadatas, cacheVarName,
res) {
             }
             else if (factoryKind === 'CacheJdbcBlobStoreFactory') {
                 // Generate POJO store factory.
-                $generatorJava.declareVariable(res, varName, 'org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStoreFactory',
null, null, null, storeFactory.connectBy === 'DataSource');
+                $generatorJava.declareVariable(res, varName, 'org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStoreFactory',
null, null, null, storeFactory.connectVia === 'DataSource');
 
-                if (storeFactory.connectBy === 'DataSource') {
+                if (storeFactory.connectVia === 'DataSource') {
                     res.deep++;
 
                     res.line('/** {@inheritDoc} */');
@@ -1499,7 +1476,7 @@ $generatorJava.metadataGeneral = function (meta, res) {
     if (!res)
         res = $generatorCommon.builder();
 
-    $generatorJava.property(res, 'typeMeta', meta, 'keyType');
+    $generatorJava.classNameProperty(res, 'typeMeta', meta, 'keyType');
     $generatorJava.property(res, 'typeMeta', meta, 'valueType');
 
     res.needEmptyLine = true;
@@ -1532,7 +1509,7 @@ $generatorJava.metadataStore = function (meta, withTypes, res) {
     $generatorJava.property(res, 'jdbcType', meta, 'databaseTable');
 
     if (withTypes) {
-        $generatorJava.property(res, 'jdbcType', meta, 'keyType');
+        $generatorJava.classNameProperty(res, 'jdbcType', meta, 'keyType');
         $generatorJava.property(res, 'jdbcType', meta, 'valueType');
     }
 
@@ -1646,7 +1623,7 @@ $generatorJava.clusterMetadatas = function (caches, res) {
 
                     $generatorJava.declareVariable(res, metaVarName, 'org.apache.ignite.cache.QueryEntity');
 
-                    $generatorJava.property(res, metaVarName, meta, 'keyType');
+                    $generatorJava.classNameProperty(res, metaVarName, meta, 'keyType');
                     $generatorJava.property(res, metaVarName, meta, 'valueType');
 
                     res.needEmptyLine = true;
@@ -2490,7 +2467,7 @@ $generatorJava.cluster = function (cluster, pkg, javaClass, clientNearCfg)
{
  * @returns {*} Data source class name.
  */
 $generatorJava.dataSourceClassName = function (res, storeFactory) {
-    var dialect = storeFactory.dialect || (storeFactory.connectBy === 'DataSource' ? storeFactory.database
: undefined);
+    var dialect = storeFactory.dialect || (storeFactory.connectVia === 'DataSource' ? storeFactory.database
: undefined);
 
     if (dialect) {
         var dataSourceBean = storeFactory.dataSourceBean;

http://git-wip-us.apache.org/repos/asf/ignite/blob/537b7c91/modules/control-center-web/src/main/js/helpers/generator/generator-pom.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/helpers/generator/generator-pom.js b/modules/control-center-web/src/main/js/helpers/generator/generator-pom.js
index db39fd7..cac9c2e 100644
--- a/modules/control-center-web/src/main/js/helpers/generator/generator-pom.js
+++ b/modules/control-center-web/src/main/js/helpers/generator/generator-pom.js
@@ -82,7 +82,7 @@ $generatorPom.pom = function (cluster, igniteVersion, mvnRepositories, res)
{
         }
 
         if (cache.cacheStoreFactory && cache.cacheStoreFactory.kind === 'CacheJdbcBlobStoreFactory')
{
-            if (cache.cacheStoreFactory.CacheJdbcBlobStoreFactory && cache.cacheStoreFactory.CacheJdbcBlobStoreFactory.connectBy
=== 'DataSource') {
+            if (cache.cacheStoreFactory.CacheJdbcBlobStoreFactory && cache.cacheStoreFactory.CacheJdbcBlobStoreFactory.connectVia
=== 'DataSource') {
                 dialect[cache.cacheStoreFactory.CacheJdbcBlobStoreFactory.database] = true;
             }
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/537b7c91/modules/control-center-web/src/main/js/helpers/generator/generator-properties.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/helpers/generator/generator-properties.js
b/modules/control-center-web/src/main/js/helpers/generator/generator-properties.js
index 87bbb90..16d892d 100644
--- a/modules/control-center-web/src/main/js/helpers/generator/generator-properties.js
+++ b/modules/control-center-web/src/main/js/helpers/generator/generator-properties.js
@@ -52,7 +52,7 @@ $generatorProperties.dataSourcesProperties = function (cluster, res) {
             if (cache.cacheStoreFactory && cache.cacheStoreFactory.kind) {
                 var storeFactory = cache.cacheStoreFactory[cache.cacheStoreFactory.kind];
 
-                var dialect = storeFactory.dialect || (storeFactory.connectBy === 'DataSource'
? storeFactory.database : undefined);
+                var dialect = storeFactory.dialect || (storeFactory.connectVia === 'DataSource'
? storeFactory.database : undefined);
 
                 if (dialect) {
                     if (!res) {
@@ -99,7 +99,7 @@ $generatorProperties.dataSourcesProperties = function (cluster, res) {
                     }
                 }
 
-                if (cache.cacheStoreFactory.kind === 'CacheJdbcBlobStoreFactory' &&
storeFactory.connectBy === 'URL') {
+                if (cache.cacheStoreFactory.kind === 'CacheJdbcBlobStoreFactory' &&
storeFactory.connectVia === 'URL') {
                     res.line('ds.' + storeFactory.user + '.password=YOUR_PASSWORD');
                 }
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/537b7c91/modules/control-center-web/src/main/js/helpers/generator/generator-xml.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/helpers/generator/generator-xml.js b/modules/control-center-web/src/main/js/helpers/generator/generator-xml.js
index 9039d2c..77316ac 100644
--- a/modules/control-center-web/src/main/js/helpers/generator/generator-xml.js
+++ b/modules/control-center-web/src/main/js/helpers/generator/generator-xml.js
@@ -838,7 +838,7 @@ $generatorXml.cacheStore = function(cache, metadatas, res) {
                 res.startBlock('<property name="cacheStoreFactory">');
                 res.startBlock('<bean class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory">');
 
-                if (storeFactory.connectBy === 'DataSource')
+                if (storeFactory.connectVia === 'DataSource')
                     $generatorXml.property(res, storeFactory, 'dataSourceBean');
                 else {
                     $generatorXml.property(res, storeFactory, 'connectionUrl');
@@ -859,7 +859,7 @@ $generatorXml.cacheStore = function(cache, metadatas, res) {
             else
                 $generatorXml.beanProperty(res, storeFactory, 'cacheStoreFactory', $generatorCommon.STORE_FACTORIES[factoryKind],
true);
 
-            if (storeFactory.dataSourceBean && (storeFactory.dialect || (storeFactory.connectBy
=== 'DataSource' ? storeFactory.database : undefined))) {
+            if (storeFactory.dataSourceBean && (storeFactory.dialect || (storeFactory.connectVia
=== 'DataSource' ? storeFactory.database : undefined))) {
                 if (_.findIndex(res.datasources, function (ds) {
                         return ds.dataSourceBean === storeFactory.dataSourceBean;
                     }) < 0) {
@@ -1150,7 +1150,7 @@ $generatorXml.cacheQueryMetadata = function(meta, res) {
 
     res.startBlock('<bean class="org.apache.ignite.cache.QueryEntity">');
 
-    $generatorXml.property(res, meta, 'keyType');
+    $generatorXml.classNameProperty(res, meta, 'keyType');
     $generatorXml.property(res, meta, 'valueType');
 
     $generatorXml.metadataQuery(meta, res);


Mime
View raw message