-
+
+
diff --git a/dal-dao-gen/src/main/webapp/static/js/dbview.js b/dal-dao-gen/src/main/webapp/static/js/dbview.js
index a6c6d453b..39754fedd 100644
--- a/dal-dao-gen/src/main/webapp/static/js/dbview.js
+++ b/dal-dao-gen/src/main/webapp/static/js/dbview.js
@@ -1,745 +1,923 @@
-(function ($, window, document, undefined) {
- var Render = function () {
- };
-
- function refreshAllDB() {
- w2ui['grid'].clear();
- cblock($("body"));
- $.get("/rest/groupdb/allgroupdbs", {rand: Math.random()}, function (data) {
- var allGroupDbs = [];
- $.each(data, function (index, value) {
- value.recid = allGroupDbs.length + 1;
- allGroupDbs.push(value);
- });
- w2ui['grid'].add(allGroupDbs);
- $("body").unblock();
- }).fail(function (data) {
- $("body").unblock();
- alert("获取所有Group失败!");
- });
- };
-
- function addDB() {
- $.get("/rest/project/userGroups", {root: true, rand: Math.random()}).done(function (data) {
- if (data.length > 0 && data[0]['id'] > 0) {
- $("#error_msg").html('');
- $("#add_new_db_step1").show();
- $("#add_new_db_step2").hide();
- $("#conn_test").show();
- $("#add_new_db_next").show();
- $("#add_new_db_prev").hide();
- $("#add_new_db_save").hide();
- var dbcatalog = $("#dbcatalog");
- if (dbcatalog[0] != undefined && dbcatalog[0].selectize != undefined) {
- dbcatalog[0].selectize.clearOptions();
- } else {
- dbcatalog.selectize({
- valueField: 'id',
- labelField: 'title',
- searchField: 'title',
- sortField: 'title',
- options: [],
- create: false
- });
- }
- var dalgroup = $("#dalgroup");
- if (dalgroup[0] != undefined && dalgroup[0].selectize != undefined) {
- dalgroup[0].selectize.clearOptions();
- }
- else {
- dalgroup.selectize({
- valueField: 'id',
- labelField: 'title',
- searchField: 'title',
- sortField: 'title',
- options: [],
- create: false
- });
- }
- $("#addDbModal").modal({"backdrop": "static"});
- } else {
- alert("请先加入一个DAL Team.");
- }
- $("body").unblock();
- }).fail(function (data) {
- alert('获取用户加入的所有DAL Team失败.');
- $("body").unblock();
- });
- };
-
- function editDB() {
- $("#update_error_msg").html('');
- $("#update_db_step1").show();
- $("#update_db_step2").hide();
- $("#update_conn_test").show();
- $("#update_db_next").show();
- $("#update_db_prev").hide();
- $("#update_db_save").hide();
- var records = w2ui['grid'].getSelection();
- var record = w2ui['grid'].get(records[0]);
- if (record == null) {
- alert('请先选择一个 database');
- return;
- }
- cblock($("body"));
- $.post("/rest/db/getOneDB", {allinonename: record['dbname']}, function (data) {
- if (data.code == "OK") {
- var db = $.parseJSON(data.info);
- $("#dbtype_up").val(db['db_providerName']);
- $("#dbaddress_up").val(db['db_address']);
- $("#dbport_up").val(db['db_port']);
- $("#dbuser_up").val(db['db_user']);
- $("#dbpassword_up").val(db['db_password']);
- $("#allinonename_up").val(db['dbname']);
- if ($("#dbcatalog_up")[0] != undefined && $("#dbcatalog_up")[0].selectize != undefined) {
- $("#dbcatalog_up")[0].selectize.clearOptions();
- } else {
- $("#dbcatalog_up").selectize({
- valueField: 'id',
- labelField: 'title',
- searchField: 'title',
- sortField: 'title',
- options: [],
- create: false
- });
- }
- $("#updateDbModal").modal({"backdrop": "static"});
- } else {
- $("#errorMess").html(data.info);
- $("#errorNoticeDiv").modal({"backdrop": "static"});
- }
- $("body").unblock();
- }).fail(function (data) {
- alert("执行异常");
- $("body").unblock();
- });
- };
-
- function delDB() {
- var records = w2ui['grid'].getSelection();
- var record = w2ui['grid'].get(records[0]);
- if (record != null) {
- if (confirm("您确定要删除吗?")) {
- $.post("/rest/db/deleteAllInOneDB", {allinonename: record['dbname']}, function (data) {
- if (data.code == "OK") {
- refreshAllDB();
- } else {
- $("#errorMess").html(data.info);
- $("#errorNoticeDiv").modal({"backdrop": "static"});
- }
- }).fail(function (data) {
- alert("执行异常");
- $("body").unblock();
- });
- }
- } else {
- alert('请选择一个database!');
- }
- };
-
- function isDefaultUser() {
- cblock($("body"));
- $.get("/rest/user/isDefaultUser", {rand: Math.random()}, function (data) {
- if (data == "true") {
- $("#validateKeyname").hide();
- }
- $("body").unblock();
- });
- }
-
- Render.prototype = {
- render_layout: function (render_obj) {
- $(render_obj).w2layout({
- name: 'main_layout',
- panels: [{type: 'main'}]
- });
- },
- render_grid: function () {
- var existsGrid = w2ui['grid'];
- if (existsGrid != undefined) {
- return;
- }
-
- w2ui['main_layout'].content('main', $().w2grid({
- name: 'grid',
- show: {
- toolbar: true,
- footer: true,
- toolbarReload: false,
- toolbarColumns: false,
- toolbarAdd: false,
- toolbarDelete: false,
- toolbarEdit: false
- },
- toolbar: {
- items: [{
- type: 'break'
- }, {
- type: 'button',
- id: 'refreshAllDB',
- caption: '刷新',
- icon: 'glyphicon glyphicon-refresh'
- }, {
- type: 'button',
- id: 'addDB',
- caption: '添加DB',
- icon: 'glyphicon glyphicon-plus'
- }, {
- type: 'button',
- id: 'editDB',
- caption: '修改DB',
- icon: 'glyphicon glyphicon-edit'
- }, {
- type: 'button',
- id: 'delDB',
- caption: '删除DB',
- icon: 'glyphicon glyphicon-remove'
- }],
- onClick: function (target, data) {
- switch (target) {
- case 'refreshAllDB':
- refreshAllDB();
- break;
- case 'addDB':
- addDB();
- break;
- case 'editDB':
- editDB();
- break;
- case 'delDB':
- delDB();
- break;
- }
- }
- },
- searches: [{
- field: 'dbname',
- caption: 'DB Name',
- type: 'text'
- }, {
- field: 'comment',
- caption: '所属 DAL Team',
- type: 'text'
- }, {
- field: 'db_address',
- caption: 'DB Address',
- type: 'text'
- }, {
- field: 'db_catalog',
- caption: 'DB Catalog',
- type: 'text'
- }, {
- field: 'db_providerName',
- caption: '数据库类型',
- type: 'text'
- }],
- columns: [{
- field: 'dbname',
- caption: 'DB All-In-One Name',
- size: '20%',
- attr: 'align=center',
- sortable: true,
- resizable: true
- }, {
- field: 'comment',
- caption: '所属 DAL Team',
- size: '15%',
- attr: 'align=center',
- sortable: true,
- resizable: true
- }, {
- field: 'db_address',
- caption: 'DB Address',
- size: '15%',
- attr: 'align=center',
- sortable: true,
- resizable: true
- }, {
- field: 'db_port',
- caption: 'DB Port',
- size: '5%',
- attr: 'align=center',
- sortable: true,
- resizable: true
- }, {
- field: 'db_user',
- caption: 'DB User',
- size: '10%',
- attr: 'align=center',
- sortable: true,
- resizable: true
- }, {
- field: 'db_password',
- caption: 'DB Password',
- size: '10%',
- attr: 'align=center',
- sortable: true,
- resizable: true
- }, {
- field: 'db_catalog',
- caption: 'DB Catalog',
- size: '15%',
- attr: 'align=center',
- sortable: true,
- resizable: true
- }, {
- field: 'db_providerName',
- caption: '数据库类型',
- size: '10%',
- attr: 'align=center',
- sortable: true,
- resizable: true
- }],
- records: []
- }));
-
- refreshAllDB();
- }
- };
-
- window.render = new Render();
- $('#main_layout').height($(document).height() - 50);
- window.render.render_layout($('#main_layout'));
- window.render.render_grid();
-
- $(window).resize(function () {
- $('#main_layout').height($(document).height() - 50);
- });
-
- $(function () {
- var setDefaultDbVal = function () {
- $("#error_msg").html(" ");
- var dbType = $.trim($("#dbtype").val());
-
- $.post("/rest/user/getDefaultDBInfo", {
- dbType: dbType
- }, function (data) {
- $("#dbaddress").val(data.db_address);
- $("#dbport").val(data.db_port);
- $("#dbuser").val(data.db_user);
- $("#dbpassword").val(data.db_password);
- });
- };
-
- var getAllCatalog = function (successInfo) {
- var dbType = $("#dbtype").val();
- var dbAddress = $("#dbaddress").val();
- var dbPort = $("#dbport").val();
- var dbUser = $("#dbuser").val();
- var dbPassword = $("#dbpassword").val();
- var dbcatalog = $("#dbcatalog");
- var error_msg = $("#error_msg");
- error_msg.html("正在连接数据库,请稍等...");
- var result = true;
-
- $.ajax({
- type: "POST",
- url: "/rest/db/connectionTest",
- data: {
- dbtype: dbType,
- dbaddress: dbAddress,
- dbport: dbPort,
- dbuser: dbUser,
- dbpassword: dbPassword
- },
- async: false,
- success: function (data) {
- if (data.code == "OK") {
- var allCatalog = [];
- $.each($.parseJSON(data.info), function (index, value) {
- allCatalog.push({
- id: value, title: value
- });
- });
- dbcatalog[0].selectize.clearOptions();
- dbcatalog[0].selectize.addOption(allCatalog);
- dbcatalog[0].selectize.refreshOptions(false);
- error_msg.html(successInfo);
- } else {
- error_msg.html("连接失败:" + data.info);
- result = false;
- }
- }
- });
-
- return result;
- };
-
- var getUserGroups = function () {
- var dalgroup = $("#dalgroup");
- $.get("/rest/member", function (data) {
- if (data != undefined && data != null) {
- if (data.length > 1) {
- var groups = [];
- $.each(data, function (index, value) {
- groups.push({
- id: value.id, title: value.group_name
- });
- });
- dalgroup[0].selectize.clearOptions();
- dalgroup[0].selectize.addOption(groups);
- dalgroup[0].selectize.refreshOptions(false);
- }
- else {
- $("#dalgroupspan").hide();
- }
- }
- });
- };
-
- $(document.body).on("change", "#dbtype", function () {
- $.get("/rest/user/isDefaultUser", {rand: Math.random()}, function (data) {
- if (data == "false") {
- setDefaultDbVal();
- }
- });
- });
-
- $(document.body).on("click", "#add_new_db_next", function () {
- var dbType = $("#dbtype").val();
- var dbAddress = $("#dbaddress").val();
- var dbPort = $("#dbport").val();
- var dbUser = $("#dbuser").val();
- var dbPassword = $("#dbpassword").val();
- var error_msg = $("#error_msg");
-
- if (dbType == "no") {
- error_msg.html("请选择数据库类型");
- return;
- }
- if (dbAddress == null || dbAddress.length == 0) {
- error_msg.html("请选择数据库");
- return;
- }
- if (dbPort == null || dbPort.length == 0) {
- error_msg.html("请输入数据库端口");
- return;
- }
- if (dbUser == null || dbUser.length == 0) {
- error_msg.html("请输入数据库登陆用户");
- return;
- }
- if (dbPassword == null || dbPassword.length == 0) {
- error_msg.html("请输入数据库登陆用户密码");
- return;
- }
-
- var result = getAllCatalog("");
- if (!result) {
- return;
- }
-
- $("#add_new_db_step1").hide();
- $("#add_new_db_step2").show();
- $("#conn_test").hide();
- $("#add_new_db_next").hide();
- $("#add_new_db_prev").show();
- $("#add_new_db_save").show();
- getUserGroups();
- });
-
- $(document.body).on("click", "#add_new_db_prev", function () {
- $("#add_new_db_step1").show();
- $("#add_new_db_step2").hide();
- $("#conn_test").show();
- $("#add_new_db_next").show();
- $("#add_new_db_prev").hide();
- $("#add_new_db_save").hide();
- $("#error_msg").html("");
- });
-
- $(document.body).on("click", "#conn_test", function () {
- getAllCatalog("连接成功");
- });
-
- $(document.body).on("click", "#add_new_db_save", function () {
- var dbType = $("#dbtype").val();
- var all_In_One_Name = $("#allinonename").val();
- var dbAddress = $("#dbaddress").val();
- var dbPort = $("#dbport").val();
- var dbUser = $("#dbuser").val();
- var dbPassword = $("#dbpassword").val();
- var dbCatalog = $("#dbcatalog").val();
- var dalGroup = $("#dalgroup").val();
- var error_msg = $("#error_msg");
-
- if (dbType == "no") {
- error_msg.html("请选择数据库类型");
- return;
- }
- if (all_In_One_Name == "" || null == all_In_One_Name) {
- error_msg.html("请输入All-In-One Name");
- return;
- }
-
- var result = validateKeyName($("#allinonename"), error_msg);
- if (!result) {
- return;
- }
-
- if (dbAddress == null || dbAddress.length == 0) {
- error_msg.html("请选择数据库");
- return;
- }
- if (dbPort == null || dbPort.length == 0) {
- error_msg.html("请输入数据库端口");
- return;
- }
- if (dbUser == null || dbUser.length == 0) {
- error_msg.html("请输入数据库登陆用户");
- return;
- }
- if (dbPassword == null || dbPassword.length == 0) {
- error_msg.html("请输入数据库登陆用户密码");
- return;
- }
- if (dbCatalog == null || dbCatalog.length == 0) {
- error_msg.html("请输入数据库");
- return;
- }
-
- $.post("/rest/db/addNewAllInOneDB", {
- dbtype: dbType,
- allinonename: all_In_One_Name,
- dbaddress: dbAddress,
- dbport: dbPort,
- dbuser: dbUser,
- dbpassword: dbPassword,
- dbcatalog: dbCatalog,
- addtogroup: $("#add_to_group").is(":checked"),
- dalgroup: dalGroup == undefined ? "" : dalGroup,
- gen_default_dbset: $("#gen_default_dbset").is(":checked")
- }, function (data) {
- if (data.code == "OK") {
- error_msg.html("保存成功");
- refreshAllDB();
- } else {
- error_msg.html(data.info);
- }
- });
- });
-
- $(document.body).on("click", "#add_to_group", function () {
- var flag = $(this).is(":checked");
- var genDefault = $("#gen_default_dbset");
- genDefault.prop({"checked": flag, "disabled": !flag});
- });
-
- $(document.body).on("change", "#dbtype_up", function () {
- $("#error_msg").html(" ");
- var dbType = $.trim($("#dbtype_up").val());
-
- $.post("/rest/user/getDefaultDBInfo", {
- dbType: dbType
- }, function (data) {
- $("#dbaddress_up").val(data.db_address);
- $("#dbport_up").val(data.db_port);
- $("#dbuser_up").val(data.db_user);
- $("#dbpassword_up").val(data.db_password);
- });
- });
-
- var getUpdateCatalog = function (successInfo) {
- $("#update_error_msg").html("正在连接数据库,请稍等...");
- var dbType = $("#dbtype_up").val();
- var dbAddress = $("#dbaddress_up").val();
- var dbPort = $("#dbport_up").val();
- var dbUser = $("#dbuser_up").val();
- var dbPassword = $("#dbpassword_up").val();
- var result = true;
-
- $.ajax({
- type: "POST",
- url: "/rest/db/connectionTest",
- data: {
- dbtype: dbType,
- dbaddress: dbAddress,
- dbport: dbPort,
- dbuser: dbUser,
- dbpassword: dbPassword
- },
- async: false,
- success: function (data) {
- if (data.code == "OK") {
- var allCatalog = [];
- $.each($.parseJSON(data.info), function (index, value) {
- allCatalog.push({
- id: value, title: value
- });
- });
- $("#dbcatalog_up")[0].selectize.clearOptions();
- $("#dbcatalog_up")[0].selectize.addOption(allCatalog);
- $("#dbcatalog_up")[0].selectize.refreshOptions(false);
- $("#update_error_msg").html(successInfo);
- var records = w2ui['grid'].getSelection();
- var record = w2ui['grid'].get(records[0]);
- $.post("/rest/db/getOneDB", {
- allinonename: record['dbname']
- },
- function (data) {
- if (data.code == "OK") {
- var db = $.parseJSON(data.info);
- $("#dbcatalog_up")[0].selectize.setValue(db['db_catalog']);
- }
- });
- } else {
- $("#update_error_msg").html("连接错误:" + data.info);
- result = false;
- }
- }
- });
-
- return result;
- };
-
- var validateKeyName = function (obj, msg) {
- var result = true;
- var key = obj.val();
- if (key.length == 0)
- return false;
-
- $.ajax({
- type: "GET",
- dataType: "json",
- url: "/rest/db/validation",
- data: {"key": key},
- async: false,
- success: function (data) {
- if (data.info.length > 0) {
- $(msg).html(data.info);
- result = false;
- }
- }
- });
- return result;
- };
-
- $(document.body).on("click", "#update_conn_test", function () {
- getUpdateCatalog("连接成功");
- });
-
- $(document.body).on("click", "#update_db_next", function () {
- var dbType = $("#dbtype_up").val();
- var dbAddress = $("#dbaddress_up").val();
- var dbPort = $("#dbport_up").val();
- var dbUser = $("#dbuser_up").val();
- var dbPassword = $("#dbpassword_up").val();
- var update_error_msg = $("#update_error_msg");
-
- if (dbType == "no") {
- update_error_msg.html("请选择数据库类型");
- return;
- }
- if (dbAddress == null || dbAddress.length == 0) {
- update_error_msg.html("请选择数据库");
- return;
- }
- if (dbPort == null || dbPort.length == 0) {
- update_error_msg.html("请输入数据库端口");
- return;
- }
- if (dbUser == null || dbUser.length == 0) {
- update_error_msg.html("请输入数据库登陆用户");
- return;
- }
- if (dbPassword == null || dbPassword.length == 0) {
- update_error_msg.html("请输入数据库登陆用户密码");
- return;
- }
-
- var result = getUpdateCatalog("");
- if (!result) {
- return;
- }
-
- $("#update_db_step1").hide();
- $("#update_db_step2").show();
- $("#update_conn_test").hide();
- $("#update_db_next").hide();
- $("#update_db_prev").show();
- $("#update_db_save").show();
- });
-
- $(document.body).on("click", "#update_db_prev", function () {
- $("#update_db_step1").show();
- $("#update_db_step2").hide();
- $("#update_conn_test").show();
- $("#update_db_next").show();
- $("#update_db_prev").hide();
- $("#update_db_save").hide();
- $("#update_error_msg").html("");
- });
-
- $(document.body).on("click", "#update_db_save", function () {
- var dbType = $("#dbtype_up").val();
- var all_In_One_Name = $("#allinonename_up").val();
- var dbAddress = $("#dbaddress_up").val();
- var dbPort = $("#dbport_up").val();
- var dbUser = $("#dbuser_up").val();
- var dbPassword = $("#dbpassword_up").val();
- var dbCatalog = $("#dbcatalog_up").val();
- var update_error_msg = $("#update_error_msg");
-
- if (dbType == "no") {
- update_error_msg.html("请选择数据库类型");
- return;
- }
- if (all_In_One_Name == null || all_In_One_Name.length == 0) {
- update_error_msg.html("请输入All-In-One Name");
- return;
- }
-
- var result = validateKeyName($("#allinonename_up"), update_error_msg);
- if (!result) {
- return;
- }
-
- if (dbAddress == null || dbAddress.length == 0) {
- update_error_msg.html("请选择数据库");
- return;
- }
- if (dbPort == null || dbPort.length == 0) {
- update_error_msg.html("请输入数据库端口");
- return;
- }
- if (dbUser == null || dbUser.length == 0) {
- update_error_msg.html("请输入数据库登陆用户");
- return;
- }
- if (dbPassword == null || dbPassword.length == 0) {
- update_error_msg.html("请输入数据库登陆用户密码");
- return;
- }
- if (dbCatalog == null || dbCatalog.length == 0) {
- update_error_msg.html("请输入数据库");
- return;
- }
-
- var records = w2ui['grid'].getSelection();
- var record = w2ui['grid'].get(records[0]);
- $.post("/rest/db/updateDB", {
- "id": record['id'],
- "dbtype": dbType,
- "allinonename": all_In_One_Name,
- "dbaddress": dbAddress,
- "dbport": dbPort,
- "dbuser": dbUser,
- "dbpassword": dbPassword,
- "dbcatalog": dbCatalog
- }, function (data) {
- if (data.code == "OK") {
- update_error_msg.html("更新成功.");
- refreshAllDB();
- } else {
- update_error_msg.html(data.info);
- }
- });
- });
-
- $(document.body).on("click", "#validateKeyname", function () {
- validateKeyName($("#allinonename"), $("#error_msg"));
- });
-
- isDefaultUser();
- });
+(function ($, window, document, undefined) {
+ var Render = function () {
+ };
+
+ var catalogChangeCount_up = 0;
+
+ function refreshAllDB() {
+ w2ui['grid'].clear();
+ cblock($("body"));
+ $.get("/rest/groupdb/allgroupdbs", {rand: Math.random()}, function (data) {
+ var allGroupDbs = [];
+ $.each(data, function (index, value) {
+ value.recid = allGroupDbs.length + 1;
+ allGroupDbs.push(value);
+ });
+ w2ui['grid'].add(allGroupDbs);
+ $("body").unblock();
+ }).fail(function (data) {
+ $("body").unblock();
+ alert("获取所有Group失败!");
+ });
+ };
+
+ function addDB() {
+ $.get("/rest/project/userGroups", {root: true, rand: Math.random()}).done(function (data) {
+ if (data.length > 0 && data[0]['id'] > 0) {
+ $("#error_msg").html('');
+ $("#add_new_db_step1").show();
+ $("#add_new_db_step2").hide();
+ $("#conn_test").show();
+ $("#add_new_db_next").show();
+ $("#add_new_db_prev").hide();
+ $("#add_new_db_save").hide();
+ var dbcatalog = $("#dbcatalog");
+ if (dbcatalog[0] != undefined && dbcatalog[0].selectize != undefined) {
+ dbcatalog[0].selectize.clearOptions();
+ } else {
+ dbcatalog.selectize({
+ valueField: 'id',
+ labelField: 'title',
+ searchField: 'title',
+ sortField: 'title',
+ options: [],
+ create: true
+ });
+ }
+ var dalgroup = $("#dalgroup");
+ if (dalgroup[0] != undefined && dalgroup[0].selectize != undefined) {
+ dalgroup[0].selectize.clearOptions();
+ }
+ else {
+ dalgroup.selectize({
+ valueField: 'id',
+ labelField: 'title',
+ searchField: 'title',
+ sortField: 'title',
+ options: [],
+ create: false
+ });
+ }
+ $("#addDbModal").modal({"backdrop": "static"});
+ var dbcatalog = $("#dbcatalog");
+ var db_providerName = $.trim($("#dbtype").val());
+ if (db_providerName !== null || db_providerName.length > 0) {
+ $.post("/rest/db/getAllDB", {
+ dbType: db_providerName
+ }, function (data) {
+ var allCatalog_up = [];
+ $.each($.parseJSON(data.info), function (index, value) {
+ allCatalog_up.push({
+ id: value, title: value
+ });
+ });
+ dbcatalog[0].selectize.clearOptions();
+ dbcatalog[0].selectize.addOption(allCatalog_up);
+ dbcatalog[0].selectize.refreshOptions(false);
+ });
+ }
+ } else {
+ alert("请先加入一个DAL Team.");
+ }
+ $("body").unblock();
+ }).fail(function (data) {
+ alert('获取用户加入的所有DAL Team失败.');
+ $("body").unblock();
+ });
+ };
+
+ var getAllInOneKeyByDbName_up = function (allInOneName) {
+ var dbcatalog = $("#dbcatalog_up").val();
+ var allinonename = $("#allinonename_up");
+ if (allinonename[0] != undefined && allinonename[0].selectize != undefined) {
+ allinonename[0].selectize.clearOptions();
+ } else {
+ allinonename.selectize({
+ valueField: 'id',
+ labelField: 'title',
+ searchField: 'title',
+ sortField: 'title',
+ options: [],
+ create: true
+ });
+ }
+ $.post("/rest/db/getTitanKeyByDBName",{
+ dbName: dbcatalog
+ }, function (data) {
+ var allInOneNames = [];
+ if(data.info!="null"){
+ $.each($.parseJSON(data.info), function (index, value) {
+ allInOneNames.push({
+ id: value, title: value
+ });
+ });
+ }
+ allinonename[0].selectize.clearOptions();
+ allinonename[0].selectize.addOption(allInOneNames);
+ allinonename[0].selectize.refreshOptions(false);
+
+ if (allInOneName!=""){
+ allinonename[0].selectize.addOption({
+ id : allInOneName,
+ title : allInOneName,
+ });
+ allinonename[0].selectize.setValue(allInOneName);
+ }
+ });
+ };
+ var record=null;
+ function editDB() {
+ $("#update_error_msg").html('');
+ $("#update_db_step1").show();
+ $("#update_db_step2").hide();
+ $("#update_conn_test").show();
+ $("#update_db_next").show();
+ $("#update_db_prev").hide();
+ $("#update_db_save").hide();
+ var records = w2ui['grid'].getSelection();
+ record= w2ui['grid'].get(records[0]);
+ if (record == null) {
+ alert('请先选择一个 database');
+ return;
+ }
+ cblock($("body"));
+ $.post("/rest/db/getOneDB", {allinonename: record['dbname']}, function (data) {
+ if (data.code == "OK") {
+ var db = $.parseJSON(data.info);
+ $("#dbtype_up").val(db['db_providerName']);
+ $("#dbaddress_up").val(db['db_address']);
+ $("#dbport_up").val(db['db_port']);
+ $("#dbuser_up").val(db['db_user']);
+ $("#dbpassword_up").val(db['db_password']);
+ // $("#allinonename_up").val(db['dbname']);
+ if ($("#dbcatalog_up")[0] != undefined && $("#dbcatalog_up")[0].selectize != undefined) {
+ $("#dbcatalog_up")[0].selectize.clearOptions();
+ } else {
+ $("#dbcatalog_up").selectize({
+ valueField: 'id',
+ labelField: 'title',
+ searchField: 'title',
+ sortField: 'title',
+ options: [],
+ create: true
+ });
+ }
+ $("#updateDbModal").modal({"backdrop": "static"});
+ var dbcatalog_up = $("#dbcatalog_up");
+ $.post("/rest/db/getAllDB", {
+ dbType: db['db_providerName']
+ }, function (data) {
+ var allCatalog_up = [];
+ $.each($.parseJSON(data.info), function (index, value) {
+ allCatalog_up.push({
+ id: value, title: value
+ });
+ });
+ dbcatalog_up[0].selectize.clearOptions();
+ dbcatalog_up[0].selectize.addOption(allCatalog_up);
+ dbcatalog_up[0].selectize.refreshOptions(false);
+ $("#dbcatalog_up")[0].selectize.addOption({
+ id : db['db_catalog'],
+ title : db['db_catalog']
+ });
+ catalogChangeCount_up = 0;
+ $("#dbcatalog_up")[0].selectize.setValue(db['db_catalog']);
+ getAllInOneKeyByDbName_up(db['dbname']);
+ });
+ } else {
+ $("#errorMess").html(data.info);
+ $("#errorNoticeDiv").modal({"backdrop": "static"});
+ }
+ $("body").unblock();
+ }).fail(function (data) {
+ alert("执行异常");
+ $("body").unblock();
+ });
+ };
+
+ function delDB() {
+ var records = w2ui['grid'].getSelection();
+ var record = w2ui['grid'].get(records[0]);
+ if (record != null) {
+ if (confirm("您确定要删除吗?")) {
+ $.post("/rest/db/deleteAllInOneDB", {allinonename: record['dbname']}, function (data) {
+ if (data.code == "OK") {
+ refreshAllDB();
+ } else {
+ $("#errorMess").html(data.info);
+ $("#errorNoticeDiv").modal({"backdrop": "static"});
+ }
+ }).fail(function (data) {
+ alert("执行异常");
+ $("body").unblock();
+ });
+ }
+ } else {
+ alert('请选择一个database!');
+ }
+ };
+
+ function isDefaultUser() {
+ cblock($("body"));
+ $.get("/rest/user/isDefaultUser", {rand: Math.random()}, function (data) {
+ if (data == "true") {
+ $("#validateKeyname").hide();
+ }
+ $("body").unblock();
+ });
+ }
+
+ Render.prototype = {
+ render_layout: function (render_obj) {
+ $(render_obj).w2layout({
+ name: 'main_layout',
+ panels: [{type: 'main'}]
+ });
+ },
+ render_grid: function () {
+ var existsGrid = w2ui['grid'];
+ if (existsGrid != undefined) {
+ return;
+ }
+
+ w2ui['main_layout'].content('main', $().w2grid({
+ name: 'grid',
+ show: {
+ toolbar: true,
+ footer: true,
+ toolbarReload: false,
+ toolbarColumns: false,
+ toolbarAdd: false,
+ toolbarDelete: false,
+ toolbarEdit: false
+ },
+ toolbar: {
+ items: [{
+ type: 'break'
+ }, {
+ type: 'button',
+ id: 'refreshAllDB',
+ caption: '刷新',
+ icon: 'glyphicon glyphicon-refresh'
+ }, {
+ type: 'button',
+ id: 'addDB',
+ caption: '添加DB',
+ icon: 'glyphicon glyphicon-plus'
+ }, {
+ type: 'button',
+ id: 'editDB',
+ caption: '修改DB',
+ icon: 'glyphicon glyphicon-edit'
+ }, {
+ type: 'button',
+ id: 'delDB',
+ caption: '删除DB',
+ icon: 'glyphicon glyphicon-remove'
+ }],
+ onClick: function (target, data) {
+ switch (target) {
+ case 'refreshAllDB':
+ refreshAllDB();
+ break;
+ case 'addDB':
+ addDB();
+ break;
+ case 'editDB':
+ editDB();
+ break;
+ case 'delDB':
+ delDB();
+ break;
+ }
+ }
+ },
+ searches: [{
+ field: 'dbname',
+ caption: 'DB Name',
+ type: 'text'
+ }, {
+ field: 'comment',
+ caption: '所属 DAL Team',
+ type: 'text'
+ }, {
+ field: 'db_address',
+ caption: 'DB Address',
+ type: 'text'
+ }, {
+ field: 'db_catalog',
+ caption: 'DB Catalog',
+ type: 'text'
+ }, {
+ field: 'db_providerName',
+ caption: '数据库类型',
+ type: 'text'
+ }],
+ columns: [{
+ field: 'dbname',
+ caption: 'DB All-In-One Name',
+ size: '20%',
+ attr: 'align=center',
+ sortable: true,
+ resizable: true
+ }, {
+ field: 'comment',
+ caption: '所属 DAL Team',
+ size: '15%',
+ attr: 'align=center',
+ sortable: true,
+ resizable: true
+ }, {
+ field: 'db_address',
+ caption: 'DB Address',
+ size: '15%',
+ attr: 'align=center',
+ sortable: true,
+ resizable: true
+ }, {
+ field: 'db_port',
+ caption: 'DB Port',
+ size: '5%',
+ attr: 'align=center',
+ sortable: true,
+ resizable: true
+ }, {
+ field: 'db_user',
+ caption: 'DB User',
+ size: '10%',
+ attr: 'align=center',
+ sortable: true,
+ resizable: true
+ }, {
+ field: 'db_password',
+ caption: 'DB Password',
+ size: '10%',
+ attr: 'align=center',
+ sortable: true,
+ resizable: true
+ }, {
+ field: 'db_catalog',
+ caption: 'DB Catalog',
+ size: '15%',
+ attr: 'align=center',
+ sortable: true,
+ resizable: true
+ }, {
+ field: 'db_providerName',
+ caption: '数据库类型',
+ size: '10%',
+ attr: 'align=center',
+ sortable: true,
+ resizable: true
+ }],
+ records: []
+ }));
+
+ refreshAllDB();
+ }
+ };
+
+ window.render = new Render();
+ $('#main_layout').height($(document).height() - 50);
+ window.render.render_layout($('#main_layout'));
+ window.render.render_grid();
+
+ $(window).resize(function () {
+ $('#main_layout').height($(document).height() - 50);
+ });
+
+ $(function () {
+ var setDefaultDbVal = function () {
+ var dbcatalog = $("#dbcatalog");
+ $("#error_msg").html(" ");
+ var dbType = $.trim($("#dbtype").val());
+
+ $.post("/rest/db/getAllDB", {
+ dbType: dbType
+ }, function (data) {
+ var allCatalog = [];
+ $.each($.parseJSON(data.info), function (index, value) {
+ allCatalog.push({
+ id: value, title: value
+ });
+ });
+ dbcatalog[0].selectize.clearOptions();
+ dbcatalog[0].selectize.addOption(allCatalog);
+ dbcatalog[0].selectize.refreshOptions(false);
+ });
+ var dbName = $("#dbcatalog").val();
+ $.post("/rest/user/getDefaultDBInfo", {
+ dbType: dbType,
+ dbName: dbName
+ }, function (data) {
+ $("#dbaddress").val(data.db_address);
+ $("#dbport").val(data.db_port);
+ $("#dbuser").val(data.db_user);
+ $("#dbpassword").val(data.db_password);
+ });
+
+ };
+
+ var getAllCatalog = function (successInfo) {
+ var dbType = $("#dbtype").val();
+ var dbAddress = $("#dbaddress").val();
+ var dbPort = $("#dbport").val();
+ var dbUser = $("#dbuser").val();
+ var dbPassword = $("#dbpassword").val();
+ var dbCatalog = $("#dbcatalog").val();
+
+ var error_msg = $("#error_msg");
+ error_msg.html("正在连接数据库,请稍等...");
+ var result = true;
+
+ $.ajax({
+ type: "POST",
+ url: "/rest/db/connectionTest",
+ data: {
+ dbtype: dbType,
+ dbaddress: dbAddress,
+ dbport: dbPort,
+ dbuser: dbUser,
+ dbpassword: dbPassword,
+ dbName: dbCatalog
+ },
+ async: false,
+ success: function (data) {
+ if (data.code == "OK") {
+ /*var allCatalog = [];
+ $.each($.parseJSON(data.info), function (index, value) {
+ allCatalog.push({
+ id: value, title: value
+ });
+ });
+ dbcatalog[0].selectize.clearOptions();
+ dbcatalog[0].selectize.addOption(allCatalog);
+ dbcatalog[0].selectize.refreshOptions(false);*/
+ error_msg.html(successInfo);
+ } else {
+ error_msg.html("连接失败:" + data.info);
+ result = false;
+ }
+ }
+ });
+
+ return result;
+ };
+
+
+
+ var getAllInOneKeyByDbName = function () {
+ var dbcatalog = $("#dbcatalog").val();
+ var allinonename = $("#allinonename");
+ if (allinonename[0] != undefined && allinonename[0].selectize != undefined) {
+ allinonename[0].selectize.clearOptions();
+ } else {
+ allinonename.selectize({
+ valueField: 'id',
+ labelField: 'title',
+ searchField: 'title',
+ sortField: 'title',
+ options: [],
+ create: true
+ });
+ }
+ $.post("/rest/db/getTitanKeyByDBName",{
+ dbName: dbcatalog
+ }, function (data) {
+ var allInOneNames = [];
+ $.each($.parseJSON(data.info), function (index, value) {
+ allInOneNames.push({
+ id: value, title: value
+ });
+ });
+ allinonename[0].selectize.clearOptions();
+ allinonename[0].selectize.addOption(allInOneNames);
+ allinonename[0].selectize.refreshOptions(false);
+ });
+ };
+
+ var getUserGroups = function () {
+ var dalgroup = $("#dalgroup");
+ $.get("/rest/member", function (data) {
+ if (data != undefined && data != null) {
+ if (data.length > 1) {
+ var groups = [];
+ $.each(data, function (index, value) {
+ groups.push({
+ id: value.id, title: value.group_name
+ });
+ });
+ dalgroup[0].selectize.clearOptions();
+ dalgroup[0].selectize.addOption(groups);
+ dalgroup[0].selectize.refreshOptions(false);
+ }
+ else {
+ $("#dalgroupspan").hide();
+ }
+ }
+ });
+ };
+
+ $(document.body).on("change", "#dbtype", function () {
+ $.get("/rest/user/isDefaultUser", {rand: Math.random()}, function (data) {
+ if (data == "false") {
+ setDefaultDbVal();
+ }
+ });
+ });
+
+ $(document.body).on("change", "#dbcatalog", function () {
+ var dbcatalog = $("#dbcatalog").val();
+ var dbType = $.trim($("#dbtype").val());
+ if (dbType === "MySQL") {
+ $.post("/rest/user/getDefaultDBInfo", {
+ dbType: dbType,
+ dbName: dbcatalog
+ }, function (data) {
+ $("#dbaddress").val(data.db_address);
+ $("#dbport").val(data.db_port);
+ $("#dbuser").val(data.db_user);
+ $("#dbpassword").val(data.db_password);
+ });
+ }
+ });
+
+ $(document.body).on("click", "#add_new_db_next", function () {
+ var dbType = $("#dbtype").val();
+ var dbAddress = $("#dbaddress").val();
+ var dbPort = $("#dbport").val();
+ var dbUser = $("#dbuser").val();
+ var dbPassword = $("#dbpassword").val();
+ var error_msg = $("#error_msg");
+
+ if (dbType == "no") {
+ error_msg.html("请选择数据库类型");
+ return;
+ }
+ if (dbAddress == null || dbAddress.length == 0) {
+ error_msg.html("请选择数据库");
+ return;
+ }
+ if (dbPort == null || dbPort.length == 0) {
+ error_msg.html("请输入数据库端口");
+ return;
+ }
+ if (dbUser == null || dbUser.length == 0) {
+ error_msg.html("请输入数据库登陆用户");
+ return;
+ }
+ if (dbPassword == null || dbPassword.length == 0) {
+ error_msg.html("请输入数据库登陆用户密码");
+ return;
+ }
+
+ var result = getAllCatalog("");
+ if (!result) {
+ return;
+ }
+
+ $("#add_new_db_step1").hide();
+ $("#add_new_db_step2").show();
+ $("#conn_test").hide();
+ $("#add_new_db_next").hide();
+ $("#add_new_db_prev").show();
+ $("#add_new_db_save").show();
+ getUserGroups();
+
+ getAllInOneKeyByDbName();
+ });
+
+ $(document.body).on("click", "#add_new_db_prev", function () {
+ $("#add_new_db_step1").show();
+ $("#add_new_db_step2").hide();
+ $("#conn_test").show();
+ $("#add_new_db_next").show();
+ $("#add_new_db_prev").hide();
+ $("#add_new_db_save").hide();
+ $("#error_msg").html("");
+ });
+
+ $(document.body).on("click", "#conn_test", function () {
+ getAllCatalog("连接成功");
+ });
+
+ $(document.body).on("click", "#add_new_db_save", function () {
+ var dbType = $("#dbtype").val();
+ var all_In_One_Name = $("#allinonename").val();
+ var dbAddress = $("#dbaddress").val();
+ var dbPort = $("#dbport").val();
+ var dbUser = $("#dbuser").val();
+ var dbPassword = $("#dbpassword").val();
+ var dbCatalog = $("#dbcatalog").val();
+ var dalGroup = $("#dalgroup").val();
+ var error_msg = $("#error_msg");
+
+ if (dbType == "no") {
+ error_msg.html("请选择数据库类型");
+ return;
+ }
+ if (all_In_One_Name == "" || null == all_In_One_Name) {
+ error_msg.html("请输入All-In-One Name");
+ return;
+ }
+
+ var result = validateKeyName($("#allinonename"), dbCatalog, error_msg);
+ if (!result) {
+ return;
+ }
+
+ if (dbAddress == null || dbAddress.length == 0) {
+ error_msg.html("请选择数据库");
+ return;
+ }
+ if (dbPort == null || dbPort.length == 0) {
+ error_msg.html("请输入数据库端口");
+ return;
+ }
+ if (dbUser == null || dbUser.length == 0) {
+ error_msg.html("请输入数据库登陆用户");
+ return;
+ }
+ if (dbPassword == null || dbPassword.length == 0) {
+ error_msg.html("请输入数据库登陆用户密码");
+ return;
+ }
+ if (dbCatalog == null || dbCatalog.length == 0) {
+ error_msg.html("请输入数据库");
+ return;
+ }
+
+ $.post("/rest/db/addNewAllInOneDB", {
+ dbtype: dbType,
+ allinonename: all_In_One_Name,
+ dbaddress: dbAddress,
+ dbport: dbPort,
+ dbuser: dbUser,
+ dbpassword: dbPassword,
+ dbcatalog: dbCatalog,
+ addtogroup: $("#add_to_group").is(":checked"),
+ dalgroup: dalGroup == undefined ? "" : dalGroup,
+ gen_default_dbset: $("#gen_default_dbset").is(":checked")
+ }, function (data) {
+ if (data.code == "OK") {
+ error_msg.html("保存成功");
+ refreshAllDB();
+ } else {
+ error_msg.html(data.info);
+ }
+ });
+ });
+
+ $(document.body).on("click", "#add_to_group", function () {
+ var flag = $(this).is(":checked");
+ var genDefault = $("#gen_default_dbset");
+ genDefault.prop({"checked": flag, "disabled": !flag});
+ });
+
+ $(document.body).on("change", "#dbtype_up", function () {
+ $("#error_msg").html(" ");
+ var dbType = $.trim($("#dbtype_up").val());
+ var dbCatalog = $("#dbcatalog_up").val();
+
+ $.post("/rest/user/getDefaultDBInfo", {
+ dbType: dbType,
+ dbName: dbCatalog
+ }, function (data) {
+ $("#dbaddress_up").val(data.db_address);
+ $("#dbport_up").val(data.db_port);
+ $("#dbuser_up").val(data.db_user);
+ $("#dbpassword_up").val(data.db_password);
+ });
+
+ });
+
+ $(document.body).on("change", "#dbcatalog_up", function () {
+ var dbcatalog = $("#dbcatalog_up").val();
+ var dbType = $.trim($("#dbtype_up").val());
+ var dbaddress = $("#dbaddress_up").val();
+ catalogChangeCount_up = catalogChangeCount_up + 1;
+ if (dbType === "MySQL") {
+ $.post("/rest/user/getDefaultDBInfo", {
+ dbType: dbType,
+ dbName: dbcatalog
+ }, function (data) {
+ if (catalogChangeCount_up > 1 && data.db_address !== "") {
+ $("#dbaddress_up").val(data.db_address);
+ $("#dbport_up").val(data.db_port);
+ $("#dbuser_up").val(data.db_user);
+ $("#dbpassword_up").val(data.db_password);
+ }
+ });
+
+ }
+ getAllInOneKeyByDbName_up(record['dbname']);
+
+ });
+
+ var getUpdateCatalog = function (successInfo) {
+ $("#update_error_msg").html("正在连接数据库,请稍等...");
+ var dbType = $("#dbtype_up").val();
+ var dbAddress = $("#dbaddress_up").val();
+ var dbPort = $("#dbport_up").val();
+ var dbUser = $("#dbuser_up").val();
+ var dbPassword = $("#dbpassword_up").val();
+ var dbName=$("#dbcatalog_up").val();
+ var result = true;
+
+ $.ajax({
+ type: "POST",
+ url: "/rest/db/connectionTest",
+ data: {
+ dbtype: dbType,
+ dbaddress: dbAddress,
+ dbport: dbPort,
+ dbuser: dbUser,
+ dbpassword: dbPassword,
+ dbName:dbName
+ },
+ async: false,
+ success: function (data) {
+ if (data.code == "OK") {
+ /*var allCatalog = [];
+ $.each($.parseJSON(data.info), function (index, value) {
+ allCatalog.push({
+ id: value, title: value
+ });
+ });
+ $("#dbcatalog_up")[0].selectize.clearOptions();
+ $("#dbcatalog_up")[0].selectize.addOption(allCatalog);
+ $("#dbcatalog_up")[0].selectize.refreshOptions(false);*/
+ $("#update_error_msg").html(successInfo);
+ /*var records = w2ui['grid'].getSelection();
+ var record = w2ui['grid'].get(records[0]);
+ $.post("/rest/db/getOneDB", {
+ allinonename: record['dbname']
+ },
+ function (data) {
+ if (data.code == "OK") {
+ var db = $.parseJSON(data.info);
+ $("#dbcatalog_up")[0].selectize.setValue(db['db_catalog']);
+ }
+ });*/
+ } else {
+ $("#update_error_msg").html("连接错误:" + data.info);
+ result = false;
+ }
+ }
+ });
+
+ return result;
+ };
+
+ var validateKeyName = function (obj, dbCatalog, msg) {
+ var result = true;
+ var key = obj.val();
+ if (key.length == 0)
+ return false;
+
+ $.ajax({
+ type: "GET",
+ dataType: "json",
+ url: "/rest/db/validation",
+ data: {"key": key, "dbName": dbCatalog},
+ async: false,
+ success: function (data) {
+ if (data.info.length > 0) {
+ $(msg).html(data.info);
+ result = false;
+ }
+ }
+ });
+ return result;
+ };
+
+ $(document.body).on("click", "#update_conn_test", function () {
+ getUpdateCatalog("连接成功");
+ });
+
+ $(document.body).on("click", "#update_db_next", function () {
+ var dbType = $("#dbtype_up").val();
+ var dbAddress = $("#dbaddress_up").val();
+ var dbPort = $("#dbport_up").val();
+ var dbUser = $("#dbuser_up").val();
+ var dbPassword = $("#dbpassword_up").val();
+ var dbCatalog = $("#dbcatalog").val();
+ var update_error_msg = $("#update_error_msg");
+
+ if (dbType == "no") {
+ update_error_msg.html("请选择数据库类型");
+ return;
+ }
+ if (dbAddress == null || dbAddress.length == 0) {
+ update_error_msg.html("请选择数据库");
+ return;
+ }
+ if (dbPort == null || dbPort.length == 0) {
+ update_error_msg.html("请输入数据库端口");
+ return;
+ }
+ if (dbUser == null || dbUser.length == 0) {
+ update_error_msg.html("请输入数据库登陆用户");
+ return;
+ }
+ if (dbPassword == null || dbPassword.length == 0) {
+ update_error_msg.html("请输入数据库登陆用户密码");
+ return;
+ }
+
+ var result = getUpdateCatalog("");
+ if (!result) {
+ return;
+ }
+ $("#update_db_step1").hide();
+ $("#update_db_step2").show();
+ $("#update_conn_test").hide();
+ $("#update_db_next").hide();
+ $("#update_db_prev").show();
+ $("#update_db_save").show();
+
+ });
+
+ $(document.body).on("click", "#update_db_prev", function () {
+ $("#update_db_step1").show();
+ $("#update_db_step2").hide();
+ $("#update_conn_test").show();
+ $("#update_db_next").show();
+ $("#update_db_prev").hide();
+ $("#update_db_save").hide();
+ $("#update_error_msg").html("");
+ });
+
+ $(document.body).on("click", "#update_db_save", function () {
+ var dbType = $("#dbtype_up").val();
+ var all_In_One_Name = $("#allinonename_up").val();
+ var dbAddress = $("#dbaddress_up").val();
+ var dbPort = $("#dbport_up").val();
+ var dbUser = $("#dbuser_up").val();
+ var dbPassword = $("#dbpassword_up").val();
+ var dbCatalog = $("#dbcatalog_up").val();
+ var update_error_msg = $("#update_error_msg");
+
+ if (dbType == "no") {
+ update_error_msg.html("请选择数据库类型");
+ return;
+ }
+ if (all_In_One_Name == null || all_In_One_Name.length == 0) {
+ update_error_msg.html("请输入All-In-One Name");
+ return;
+ }
+
+ var result = validateKeyName($("#allinonename_up"), dbCatalog, update_error_msg);
+ if (!result) {
+ return;
+ }
+
+ if (dbAddress == null || dbAddress.length == 0) {
+ update_error_msg.html("请选择数据库");
+ return;
+ }
+ if (dbPort == null || dbPort.length == 0) {
+ update_error_msg.html("请输入数据库端口");
+ return;
+ }
+ if (dbUser == null || dbUser.length == 0) {
+ update_error_msg.html("请输入数据库登陆用户");
+ return;
+ }
+ if (dbPassword == null || dbPassword.length == 0) {
+ update_error_msg.html("请输入数据库登陆用户密码");
+ return;
+ }
+ if (dbCatalog == null || dbCatalog.length == 0) {
+ update_error_msg.html("请输入数据库");
+ return;
+ }
+
+ var records = w2ui['grid'].getSelection();
+ var record = w2ui['grid'].get(records[0]);
+ $.post("/rest/db/updateDB", {
+ "id": record['id'],
+ "dbtype": dbType,
+ "allinonename": all_In_One_Name,
+ "dbaddress": dbAddress,
+ "dbport": dbPort,
+ "dbuser": dbUser,
+ "dbpassword": dbPassword,
+ "dbcatalog": dbCatalog
+ }, function (data) {
+ if (data.code == "OK") {
+ update_error_msg.html("更新成功.");
+ refreshAllDB();
+ } else {
+ update_error_msg.html(data.info);
+ }
+ });
+ });
+
+ $(document.body).on("click", "#validateKeyname", function () {
+ validateKeyName($("#allinonename"), $("#dbcatalog").val(), $("#error_msg"));
+ });
+
+ isDefaultUser();
+ });
})(jQuery, window, document);
\ No newline at end of file
diff --git a/dal-dao-gen/src/main/webapp/static/js/wizzard.js b/dal-dao-gen/src/main/webapp/static/js/wizzard.js
index 65a3b485b..ceb8f62e4 100644
--- a/dal-dao-gen/src/main/webapp/static/js/wizzard.js
+++ b/dal-dao-gen/src/main/webapp/static/js/wizzard.js
@@ -491,7 +491,7 @@
nextStep.text("正在加载...");
nextStep.removeClass("btn-primary");
var data = undefined;
- $.get("/rest/task/table/apiList", {
+ $.post("/rest/task/table/apiList", {
db_name: $("#databases").val(),
table_names: tableList.join(","),
sql_style: $("#sql_style").val(),
diff --git a/dal-dao-gen/src/test/java/com/ctrip/platform/dal/daogen/AllTests.java b/dal-dao-gen/src/test/java/com/ctrip/platform/dal/daogen/AllTests.java
new file mode 100644
index 000000000..af1354904
--- /dev/null
+++ b/dal-dao-gen/src/test/java/com/ctrip/platform/dal/daogen/AllTests.java
@@ -0,0 +1,17 @@
+package com.ctrip.platform.dal.daogen;
+
+import com.ctrip.platform.dal.daogen.sql.builder.SQLBuilderTests;
+import com.ctrip.platform.dal.daogen.sql.validate.SQLValidationTests;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author c7ch23en
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ SQLBuilderTests.class,
+ SQLValidationTests.class
+})
+public class AllTests {
+}
diff --git a/dal-dao-gen/src/test/java/com/ctrip/platform/dal/daogen/sql/builder/SQLBuilderTests.java b/dal-dao-gen/src/test/java/com/ctrip/platform/dal/daogen/sql/builder/SQLBuilderTests.java
index 49e670199..ef02accce 100644
--- a/dal-dao-gen/src/test/java/com/ctrip/platform/dal/daogen/sql/builder/SQLBuilderTests.java
+++ b/dal-dao-gen/src/test/java/com/ctrip/platform/dal/daogen/sql/builder/SQLBuilderTests.java
@@ -20,4 +20,5 @@ public void testJava2Java() {
String sql2 = SqlBuilder.net2Java(sql);
assertEquals(sql, sql2);
}
+
}
diff --git a/dao-gen-core/pom.xml b/dao-gen-core/pom.xml
index 523cca9cc..a7a3f2093 100644
--- a/dao-gen-core/pom.xml
+++ b/dao-gen-core/pom.xml
@@ -3,234 +3,106 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
-
com.ctrip.platform
+
+ com.ctrip.platform
+ dal-client-parent
+ 2.1.6
+
dao-gen-core
-
1.16.17
-
- UTF-8
- 1.18.3
- 3.1.0
- 4.5.3
- 2.0.1
- 2.25.1
- 21.0
- 7.0.76
- 5.1.41
- 1.4
- 2.5
- 1.7.21
- 1.2.2
- 1.2.67
- 2.9.9
- 1.2
- 4.12
- 3.16
- 2.1.1
-
-
-
-
- org.apache.poi
- poi-ooxml
- ${poi-version}
-
-
- org.apache.xmlbeans
- xmlbeans
-
-
-
-
-
+
jar
+
com.ctrip.platform
dal-client
- ${dal-client-version}
javax.servlet
javax.servlet-api
- ${javax-servlet-version}
org.apache.httpcomponents
httpclient
- ${httpclient-version}
javax.ws.rs
javax.ws.rs-api
- ${ws-rs-version}
org.glassfish.jersey.containers
jersey-container-servlet
- ${jersey-version}
org.glassfish.jersey.media
jersey-media-moxy
- ${jersey-version}
org.glassfish.jersey.ext
jersey-entity-filtering
- ${jersey-version}
com.google.guava
guava
- ${guava-version}
org.apache.tomcat
tomcat-jdbc
- ${tomcat-jdbc-version}
mysql
mysql-connector-java
- ${mysql-connector-version}
org.apache.commons
commons-email
- ${commons-email-version}
commons-io
commons-io
- ${commons-io-version}
org.slf4j
jcl-over-slf4j
- ${jcl-over-slf4j}
ch.qos.logback
logback-classic
- ${logback-version}
ch.qos.logback
logback-core
- ${logback-version}
ch.qos.logback
logback-access
- ${logback-version}
- com.alibaba
- fastjson
- ${fastjson-version}
+ com.google.code.gson
+ gson
com.fasterxml.jackson.core
jackson-core
- ${jackson-version}
com.fasterxml.jackson.core
jackson-databind
- ${jackson-version}
com.github.jsqlparser
jsqlparser
- ${jsqlparser-version}
org.apache.velocity
velocity
- 1.7
org.dom4j
dom4j
- ${dom4j-version}
-
-
- junit
- junit
- ${junit-version}
org.apache.poi
poi-ooxml
-
-
-
- maven-deploy-plugin
- 2.8.1
-
- internal.repo::default::file://${project.build.directory}/mvn-repo
-
-
-
-
- com.github.github
- site-maven-plugin
- 0.11
-
- Maven artifacts for ${project.artifactId}, ${project.version}
- true
- ${project.build.directory}/mvn-repo
-
- refs/heads/mvn-repo
-
- **/*
-
- dal
- ctripcorp
- github
- true
-
-
-
-
- site
-
- deploy
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.8.0
-
-
- 1.8
- ${file_encoding}
- true
- true
-
-
-
- org.apache.maven.plugins
- maven-resources-plugin
- 2.7
-
- ${file_encoding}
-
-
-
-
-
-
- internal.repo
- Temporary Staging Repository
- file://${project.build.directory}/mvn-repo
-
- true
- always
-
-
-
-
\ No newline at end of file
+
diff --git a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/UserInfo.java b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/UserInfo.java
index 1d4dc3193..7838e1efa 100644
--- a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/UserInfo.java
+++ b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/UserInfo.java
@@ -15,5 +15,5 @@ public interface UserInfo {
void logOut(HttpServletRequest request, HttpServletResponse response);
- DalGroupDB getDefaultDBInfo(String dbType);
+ DalGroupDB getDefaultDBInfo(String dbType, String name);
}
diff --git a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/dao/DaoOfProject.java b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/dao/DaoOfProject.java
index ed82f69a2..dc7f706d7 100644
--- a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/dao/DaoOfProject.java
+++ b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/dao/DaoOfProject.java
@@ -34,7 +34,7 @@ public Project getProjectByID(int id) throws SQLException {
public List
getProjectByGroupId(int groupId) throws SQLException {
FreeSelectSqlBuilder> builder = new FreeSelectSqlBuilder<>(dbCategory);
builder.setTemplate(
- "SELECT id, name, namespace,dal_group_id,dal_config_name,update_user_no,update_time FROM project WHERE dal_group_id = ?");
+ "SELECT id, name, namespace,dal_group_id,dal_config_name,update_user_no,update_time FROM project WHERE dal_group_id = ? order by id desc");
StatementParameters parameters = new StatementParameters();
int i = 1;
parameters.set(i++, "dal_group_id", Types.INTEGER, groupId);
diff --git a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/entity/DBLevelInfo.java b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/entity/DBLevelInfo.java
new file mode 100644
index 000000000..2b91894ce
--- /dev/null
+++ b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/entity/DBLevelInfo.java
@@ -0,0 +1,93 @@
+package com.ctrip.platform.dal.daogen.entity;
+
+public class DBLevelInfo {
+ private int organization_id;
+
+ private String organization_name;
+
+ private int level;
+
+ private String db_type;
+
+ private String db_name_base;
+
+ private int dns_port;
+
+ private String db_name;
+
+ private String dns;
+
+ private String dbowners;
+
+ public int getOrganization_id() {
+ return organization_id;
+ }
+
+ public void setOrganization_id(int organization_id) {
+ this.organization_id = organization_id;
+ }
+
+ public String getOrganization_name() {
+ return organization_name;
+ }
+
+ public void setOrganization_name(String organization_name) {
+ this.organization_name = organization_name;
+ }
+
+ public int getLevel() {
+ return level;
+ }
+
+ public void setLevel(int level) {
+ this.level = level;
+ }
+
+ public String getDb_type() {
+ return db_type;
+ }
+
+ public void setDb_type(String db_type) {
+ this.db_type = db_type;
+ }
+
+ public String getDb_name_base() {
+ return db_name_base;
+ }
+
+ public void setDb_name_base(String db_name_base) {
+ this.db_name_base = db_name_base;
+ }
+
+ public int getDns_port() {
+ return dns_port;
+ }
+
+ public void setDns_port(int dns_port) {
+ this.dns_port = dns_port;
+ }
+
+ public String getDb_name() {
+ return db_name;
+ }
+
+ public void setDb_name(String db_name) {
+ this.db_name = db_name;
+ }
+
+ public String getDns() {
+ return dns;
+ }
+
+ public void setDns(String dns) {
+ this.dns = dns;
+ }
+
+ public String getDbowners() {
+ return dbowners;
+ }
+
+ public void setDbowners(String dbowners) {
+ this.dbowners = dbowners;
+ }
+}
diff --git a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/entity/DefaultUserInfo.java b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/entity/DefaultUserInfo.java
index 85c33fdf9..726c28b0c 100644
--- a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/entity/DefaultUserInfo.java
+++ b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/entity/DefaultUserInfo.java
@@ -70,7 +70,7 @@ public void logOut(HttpServletRequest request, HttpServletResponse response) {
}
@Override
- public DalGroupDB getDefaultDBInfo(String dbType) {
+ public DalGroupDB getDefaultDBInfo(String dbType, String dbName) {
DalGroupDB db = new DalGroupDB();
if (dbType == null || dbType.isEmpty())
return db;
diff --git a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/resource/CustomizedResource.java b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/resource/CustomizedResource.java
index 3794b4cfe..e96f90965 100644
--- a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/resource/CustomizedResource.java
+++ b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/resource/CustomizedResource.java
@@ -20,6 +20,8 @@ public class CustomizedResource {
private ClassLoader classLoader = null;
private final String CONF_PROPERTIES = "conf.properties";
private final String USER_INFO_CLASS_NAME = "userinfo_class";
+ private final String DB_LEVEL_INFO_API_CLASS_NAME = "db_level_info_api";
+ private final String ALL_IN_ONE_KEY_API_CLASS_NAME = "all_in_one_key_api";
private UserInfo userInfo = null;
private Boolean isDefaultUser = null;
@@ -116,6 +118,14 @@ public String getConfigClassName() throws IOException {
return getClassNameFromConf(CONFIG_CLASS_NAME);
}
+ public String getDBLevelInfoApiClassName() throws IOException {
+ return getClassNameFromConf(DB_LEVEL_INFO_API_CLASS_NAME);
+ }
+
+ public String getAllInOneKeyApiClassName() throws IOException {
+ return getClassNameFromConf(ALL_IN_ONE_KEY_API_CLASS_NAME);
+ }
+
private String getClassNameFromConf(String className) throws IOException {
if (className == null || className.isEmpty())
return null;
@@ -134,8 +144,8 @@ public void logOut(HttpServletRequest request, HttpServletResponse response) {
userInfo.logOut(request, response);
}
- public DalGroupDB getDefaultDBInfo(String dbType) {
- return userInfo.getDefaultDBInfo(dbType);
+ public DalGroupDB getDefaultDBInfo(String dbType, String dbName) {
+ return userInfo.getDefaultDBInfo(dbType, dbName);
}
}
diff --git a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/AllInOneKeyApi.java b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/AllInOneKeyApi.java
new file mode 100644
index 000000000..cad9083d0
--- /dev/null
+++ b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/AllInOneKeyApi.java
@@ -0,0 +1,7 @@
+package com.ctrip.platform.dal.daogen.utils;
+
+import java.util.List;
+
+public interface AllInOneKeyApi {
+ public List getAllInOneKeys(String dbName);
+}
diff --git a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/DBInfoApi.java b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/DBInfoApi.java
new file mode 100644
index 000000000..3f82dcb46
--- /dev/null
+++ b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/DBInfoApi.java
@@ -0,0 +1,9 @@
+package com.ctrip.platform.dal.daogen.utils;
+
+import com.ctrip.platform.dal.daogen.entity.DBLevelInfo;
+
+import java.util.List;
+
+public interface DBInfoApi {
+ public List getDBLevelInfo(String dbType);
+}
diff --git a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/DataSourceUtil.java b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/DataSourceUtil.java
index 6937e4051..777dda929 100644
--- a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/DataSourceUtil.java
+++ b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/DataSourceUtil.java
@@ -3,6 +3,7 @@
import com.ctrip.platform.dal.daogen.dao.DalGroupDBDao;
import com.ctrip.platform.dal.daogen.entity.DalGroupDB;
import com.ctrip.platform.dal.daogen.enums.DatabaseType;
+import com.ctrip.platform.dal.daogen.log.LoggerManager;
import org.apache.tomcat.jdbc.pool.PoolProperties;
import javax.sql.DataSource;
@@ -32,7 +33,31 @@ public class DataSourceUtil {
private static volatile Map cache2 = new ConcurrentHashMap<>();
public static Connection getConnection(String address, String port, String userName, String password,
- String driverClass) throws Exception {
+ String driverClass, String dbName) throws Exception {
+ validateParam(address, port, userName, password, driverClass);
+ String key = address.trim() +dbName.trim()+ port.trim() + userName.trim() + password.trim();
+ DataSource ds = cache1.get(key);
+ if (ds != null) {
+ Connection conn = ds.getConnection();
+ return conn;
+ }
+ synchronized (DataSourceUtil.class) {
+ ds = cache1.get(key);
+ if (ds != null) {
+ Connection conn = ds.getConnection();
+ return conn;
+ } else {
+ DataSource newDS = createDataSource(address.trim(), port.trim(), dbName.trim(), userName.trim(), password.trim(),
+ driverClass.trim());
+ cache1.put(key, newDS);
+ Connection conn = newDS.getConnection();
+ return conn;
+ }
+ }
+ }
+
+ public static Connection getConnection(String address, String port, String userName, String password,
+ String driverClass) throws Exception {
validateParam(address, port, userName, password, driverClass);
String key = address.trim() + port.trim() + userName.trim() + password.trim();
DataSource ds = cache1.get(key);
diff --git a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/HttpUtil.java b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/HttpUtil.java
index af360a7ac..56a5f8568 100644
--- a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/HttpUtil.java
+++ b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/HttpUtil.java
@@ -1,7 +1,6 @@
package com.ctrip.platform.dal.daogen.utils;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
+
import com.ctrip.platform.dal.daogen.enums.HttpMethod;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -15,6 +14,7 @@
import org.apache.http.util.EntityUtils;
import java.net.URI;
+import java.util.HashMap;
import java.util.Map;
public class HttpUtil {
@@ -42,11 +42,11 @@ public static T getJSONEntity(Class clazz, String url, Map 0) {
- JSONObject json = new JSONObject();
+ Map map = new HashMap();
for (Map.Entry parameter : parameters.entrySet()) {
- json.put(parameter.getKey(), parameter.getValue());
+ map.put(parameter.getKey(), parameter.getValue());
}
- StringEntity stringEntity = new StringEntity(json.toString());
+ StringEntity stringEntity = new StringEntity(JsonUtils.toJson(map));
request.setEntity(stringEntity);
}
@@ -55,7 +55,7 @@ public static T getJSONEntity(Class clazz, String url, Map T fromJson(String json, Class clazz) {
+ return getInstance().gson.fromJson(json, clazz);
+ }
+
+ public static JsonObject parseObject(String json) {
+ return getInstance().parser.parse(json).getAsJsonObject();
+ }
+
+ public static JsonArray parseArray(String json) {
+ return getInstance().parser.parse(json).getAsJsonArray();
+ }
+
+ public static JsonElement parse(String json) {
+ return getInstance().parser.parse(json);
+ }
+
+}
\ No newline at end of file
diff --git a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/WebUtil.java b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/WebUtil.java
index b35d679e2..8a0db4769 100644
--- a/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/WebUtil.java
+++ b/dao-gen-core/src/main/java/com/ctrip/platform/dal/daogen/utils/WebUtil.java
@@ -1,6 +1,5 @@
package com.ctrip.platform.dal.daogen.utils;
-import com.alibaba.fastjson.JSON;
import com.ctrip.platform.dal.daogen.entity.Response;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@@ -55,7 +54,7 @@ public static Response getAllInOneResponse(String keyname, String environment) t
HttpResponse response = sslClient.execute(httpGet);
HttpEntity entity = response.getEntity();
String content = EntityUtils.toString(entity);
- res = JSON.parseObject(content, Response.class);
+ res = JsonUtils.fromJson(content, Response.class);
}
return res;
diff --git a/pom.xml b/pom.xml
index 1fb4300f3..95ca2e918 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,18 +10,25 @@
com.ctrip.platform
dal-client-parent
- 2.0.19
+ 2.1.6
pom
dal-cluster-client
dal-client
+ dao-gen-core
+ dal-dao-gen
1.8
+ 1.1.1
+
${project.version}
- 3.1-b09
+ ${project.version}
+ ${project.version}
+
+ 3.1.0
3.0.0.v201103241009
4.3.8.RELEASE
2.1_3
@@ -38,6 +45,19 @@
2.8.2
4.12
2.3
+
+ 4.5.3
+ 2.0.1
+ 2.25.1
+ 21.0
+ 1.4
+ 2.5
+ 2.9.6
+ 3.16
+ 2.1.1
+ 1.7
+ 1.2.2
+
3.8.1
2.5
3.0.0
@@ -46,16 +66,34 @@
2.19.1
2.8.1
0.11
+
UTF-8
+
+ javax.activation
+ activation
+ ${javax.activation.version}
+
+
com.ctrip.framework.dal
dal-cluster-client
${dal-cluster-client.version}
+
+ com.ctrip.platform
+ dal-client
+ ${dal-client.version}
+
+
+ com.ctrip.platform
+ dao-gen-core
+ ${dao-gen-core.version}
+
+
javax.servlet
javax.servlet-api
@@ -134,12 +172,12 @@
org.apache.logging.log4j
- log4j-slf4j-impl
+ log4j-core
${log4j.version}
org.apache.logging.log4j
- log4j-core
+ log4j-slf4j-impl
${log4j.version}
@@ -151,16 +189,112 @@
junit
junit
${junit.version}
+ test
org.easymock
easymockclassextension
${easymock.version}
+ test
org.springframework
spring-test
${spring.version}
+ test
+
+
+
+ org.apache.httpcomponents
+ httpclient
+ ${httpclient.version}
+
+
+ commons-logging
+ commons-logging
+
+
+
+
+ javax.ws.rs
+ javax.ws.rs-api
+ ${ws-rs.version}
+
+
+ org.glassfish.jersey.containers
+ jersey-container-servlet
+ ${jersey.version}
+
+
+ org.glassfish.jersey.media
+ jersey-media-moxy
+ ${jersey.version}
+
+
+ org.glassfish.jersey.ext
+ jersey-entity-filtering
+ ${jersey.version}
+
+
+ com.google.guava
+ guava
+ ${guava.version}
+
+
+ org.apache.commons
+ commons-email
+ ${commons-email.version}
+
+
+ commons-io
+ commons-io
+ ${commons-io.version}
+
+
+ com.fasterxml.jackson.core
+ jackson-core
+ ${jackson.version}
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ ${jackson.version}
+
+
+ org.apache.poi
+ poi-ooxml
+ ${poi.version}
+
+
+ org.apache.xmlbeans
+ xmlbeans
+
+
+
+
+ org.dom4j
+ dom4j
+ ${dom4j.version}
+
+
+ org.apache.velocity
+ velocity
+ ${velocity.version}
+
+
+ ch.qos.logback
+ logback-core
+ ${logback.version}
+
+
+ ch.qos.logback
+ logback-classic
+ ${logback.version}
+
+
+ ch.qos.logback
+ logback-access
+ ${logback.version}
@@ -360,8 +494,8 @@
-