-- --------------------------------------------------------
-- 호스트:                          127.0.0.1
-- 서버 버전:                        5.5.62 - MySQL Community Server (GPL)
-- 서버 OS:                        Win64
-- HeidiSQL 버전:                  11.0.0.5919
-- --------------------------------------------------------

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;


-- nerv_icde_xxxx 데이터베이스 구조 내보내기
CREATE DATABASE IF NOT EXISTS `nerv_icde_xxxx` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `nerv_icde_xxxx`;

-- 테이블 nerv_icde_xxxx.component 구조 내보내기
CREATE TABLE IF NOT EXISTS `component` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `systemdomain_id` int(10) unsigned DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `seq` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `description` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `FK_component_systemdomain_id` (`systemdomain_id`) USING BTREE,
  CONSTRAINT `FK_component_1` FOREIGN KEY (`systemdomain_id`) REFERENCES `domain_system` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1129 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;

-- 테이블 데이터 nerv_icde_xxxx.component:~0 rows (대략적) 내보내기
DELETE FROM `component`;
/*!40000 ALTER TABLE `component` DISABLE KEYS */;
/*!40000 ALTER TABLE `component` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.custum_proxy 구조 내보내기
CREATE TABLE IF NOT EXISTS `custum_proxy` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `deploy_id` int(11) unsigned DEFAULT NULL,
  `proxy_interface_id` int(10) unsigned NOT NULL,
  `object_name` varchar(100) NOT NULL,
  `object_id` int(11) unsigned DEFAULT '0',
  `stub_object_id` int(11) unsigned DEFAULT NULL,
  `stub_ip` varchar(255) DEFAULT '0.0.0.0',
  `public` int(11) unsigned NOT NULL DEFAULT '0',
  `original_id` int(11) NOT NULL DEFAULT '0',
  `original_deployment_id` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`Id`),
  KEY `FK_custum_proxy_deployments` (`deploy_id`),
  KEY `FK_custum_proxy_proxy_interface_object` (`proxy_interface_id`,`object_name`),
  CONSTRAINT `FK_custum_proxy_deployments` FOREIGN KEY (`deploy_id`) REFERENCES `deployments` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_custum_proxy_proxy_interface_object` FOREIGN KEY (`proxy_interface_id`, `object_name`) REFERENCES `proxy_interface_object` (`proxy_interface_id`, `object_name`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2305 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;

-- 테이블 데이터 nerv_icde_xxxx.custum_proxy:~0 rows (대략적) 내보내기
DELETE FROM `custum_proxy`;
/*!40000 ALTER TABLE `custum_proxy` DISABLE KEYS */;
/*!40000 ALTER TABLE `custum_proxy` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.custum_stub 구조 내보내기
CREATE TABLE IF NOT EXISTS `custum_stub` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `deploy_id` int(11) unsigned NOT NULL,
  `stub_interface_id` int(10) unsigned NOT NULL,
  `object_name` varchar(100) NOT NULL,
  `object_id` int(11) unsigned DEFAULT '0',
  `public` int(11) unsigned NOT NULL DEFAULT '0',
  `original_id` int(11) unsigned NOT NULL DEFAULT '0',
  `original_deployment_id` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`Id`),
  KEY `FK_custum_stub_deployments` (`deploy_id`),
  KEY `FK_custum_stub_stub_interface_object` (`stub_interface_id`,`object_name`),
  CONSTRAINT `FK_custum_stub_deployments` FOREIGN KEY (`deploy_id`) REFERENCES `deployments` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_custum_stub_stub_interface_object` FOREIGN KEY (`stub_interface_id`, `object_name`) REFERENCES `stub_interface_object` (`stub_interface_id`, `object_name`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1401 DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.custum_stub:~0 rows (대략적) 내보내기
DELETE FROM `custum_stub`;
/*!40000 ALTER TABLE `custum_stub` DISABLE KEYS */;
/*!40000 ALTER TABLE `custum_stub` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.data 구조 내보내기
CREATE TABLE IF NOT EXISTS `data` (
  `data_auto_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `domain_id` int(10) unsigned NOT NULL,
  `name` varchar(100) NOT NULL,
  `type` enum('struct','alias','enum8_t','enum16_t','enum32_t','char_t','wchar_t','int8_t','int16_t','int32_t','int64_t','u_int8_t','u_int16_t','u_int32_t','u_int64_t','scaled8_t','scaled16_t','scaled32_t','scaled64_t','u_scaled8_t','u_scaled16_t','u_scaled32_t','u_scaled64_t','ieee754_32_t','ieee754_64_t','ieee754_80_t','ip_t','port_t','domain_t','pksize_t','second_t','psecond_t','packed_node_addr_t','packed_client_addr_t','packed_server_addr_t') NOT NULL,
  `real_data_auto_id` int(10) unsigned DEFAULT NULL,
  `scmin` varchar(100) NOT NULL DEFAULT '',
  `scmax` varchar(100) NOT NULL DEFAULT '',
  `seq` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `description` mediumtext NOT NULL,
  `user_id` varchar(45) NOT NULL,
  `depth` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`data_auto_id`),
  UNIQUE KEY `domain_id_name` (`domain_id`,`name`),
  KEY `FK_data_data` (`real_data_auto_id`),
  KEY `type` (`type`),
  CONSTRAINT `FK_data_data` FOREIGN KEY (`real_data_auto_id`) REFERENCES `data` (`data_auto_id`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `FK_data_domain_data` FOREIGN KEY (`domain_id`) REFERENCES `domain_data` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=528 DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.data:~0 rows (대략적) 내보내기
DELETE FROM `data`;
/*!40000 ALTER TABLE `data` DISABLE KEYS */;
/*!40000 ALTER TABLE `data` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.data_field 구조 내보내기
CREATE TABLE IF NOT EXISTS `data_field` (
  `data_auto_id` int(10) unsigned NOT NULL DEFAULT '0',
  `member_name` varchar(100) NOT NULL,
  `type` enum('const','alias','char_t','wchar_t','int8_t','int16_t','int32_t','int64_t','u_int8_t','u_int16_t','u_int32_t','u_int64_t','scaled8_t','scaled16_t','scaled32_t','scaled64_t','u_scaled8_t','u_scaled16_t','u_scaled32_t','u_scaled64_t','ieee754_32_t','ieee754_64_t','ieee754_80_t','ip_t','port_t','domain_t','pksize_t','second_t','psecond_t','packed_node_addr_t','packed_client_addr_t','packed_server_addr_t') DEFAULT NULL,
  `real_data_auto_id` int(10) unsigned DEFAULT NULL,
  `user_id` varchar(45) NOT NULL,
  `bitsize` int(10) unsigned DEFAULT '0',
  `scimin` varchar(100) DEFAULT '''''',
  `scimax` varchar(100) DEFAULT '''''',
  `arraytype` enum('NO','FIX','VARIABLE') NOT NULL DEFAULT 'NO',
  `arraysize` int(11) unsigned NOT NULL DEFAULT '0',
  `seq` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `description` mediumtext NOT NULL,
  PRIMARY KEY (`data_auto_id`,`member_name`),
  KEY `FK_data_field_data_2` (`real_data_auto_id`),
  KEY `type` (`type`),
  CONSTRAINT `FK_data_field_data` FOREIGN KEY (`data_auto_id`) REFERENCES `data` (`data_auto_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_data_field_data_2` FOREIGN KEY (`real_data_auto_id`) REFERENCES `data` (`data_auto_id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.data_field:~0 rows (대략적) 내보내기
DELETE FROM `data_field`;
/*!40000 ALTER TABLE `data_field` DISABLE KEYS */;
/*!40000 ALTER TABLE `data_field` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.deployments 구조 내보내기
CREATE TABLE IF NOT EXISTS `deployments` (
  `Id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `node_id` int(11) unsigned NOT NULL,
  `component_id` int(11) unsigned NOT NULL,
  `systemdomain_id` int(11) unsigned NOT NULL DEFAULT '0',
  `original_id` int(11) unsigned DEFAULT NULL,
  PRIMARY KEY (`Id`),
  KEY `FK_deployments_1` (`node_id`),
  KEY `FK_deployments_2` (`component_id`),
  KEY `deployments_ibfk_1` (`systemdomain_id`),
  KEY `Id_node_id` (`Id`,`node_id`),
  KEY `FK_deployments_deployments` (`original_id`),
  CONSTRAINT `deployments_ibfk_1` FOREIGN KEY (`systemdomain_id`) REFERENCES `domain_system` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `deployments_ibfk_2` FOREIGN KEY (`node_id`) REFERENCES `node` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_deployments_1` FOREIGN KEY (`node_id`) REFERENCES `node` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_deployments_2` FOREIGN KEY (`component_id`) REFERENCES `component` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_deployments_deployments` FOREIGN KEY (`original_id`) REFERENCES `deployments` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=723 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;

-- 테이블 데이터 nerv_icde_xxxx.deployments:~0 rows (대략적) 내보내기
DELETE FROM `deployments`;
/*!40000 ALTER TABLE `deployments` DISABLE KEYS */;
/*!40000 ALTER TABLE `deployments` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.deployments_bind 구조 내보내기
CREATE TABLE IF NOT EXISTS `deployments_bind` (
  `deployment_id` int(11) unsigned NOT NULL,
  `node_id` int(11) unsigned NOT NULL,
  `port` int(11) unsigned NOT NULL,
  `ip` varchar(255) NOT NULL DEFAULT '0',
  PRIMARY KEY (`deployment_id`,`node_id`,`port`,`ip`),
  KEY `FK_deployments_bind_network` (`node_id`,`port`,`ip`),
  CONSTRAINT `FK_deployments_bind_deployments` FOREIGN KEY (`deployment_id`, `node_id`) REFERENCES `deployments` (`Id`, `node_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_deployments_bind_network` FOREIGN KEY (`node_id`, `port`, `ip`) REFERENCES `network` (`node_id`, `port`, `ip`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.deployments_bind:~0 rows (대략적) 내보내기
DELETE FROM `deployments_bind`;
/*!40000 ALTER TABLE `deployments_bind` DISABLE KEYS */;
/*!40000 ALTER TABLE `deployments_bind` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.diagrame 구조 내보내기
CREATE TABLE IF NOT EXISTS `diagrame` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `domain_id` int(11) unsigned NOT NULL DEFAULT '0',
  `type` int(11) unsigned NOT NULL DEFAULT '0',
  `name` varchar(255) NOT NULL DEFAULT '',
  `description` mediumtext,
  PRIMARY KEY (`Id`),
  KEY `diagrame_ibfk_1` (`domain_id`),
  CONSTRAINT `diagrame_ibfk_1` FOREIGN KEY (`domain_id`) REFERENCES `domain_system` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_diagrame_domainid` FOREIGN KEY (`domain_id`) REFERENCES `domain_system` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.diagrame:~0 rows (대략적) 내보내기
DELETE FROM `diagrame`;
/*!40000 ALTER TABLE `diagrame` DISABLE KEYS */;
/*!40000 ALTER TABLE `diagrame` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.domain_data 구조 내보내기
CREATE TABLE IF NOT EXISTS `domain_data` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `uuid` char(36) NOT NULL,
  `upper_id` int(10) unsigned DEFAULT '0',
  `name` varchar(100) NOT NULL DEFAULT '',
  `user_id` varchar(45) NOT NULL,
  `public` tinyint(1) unsigned NOT NULL,
  `create_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `description` mediumtext,
  PRIMARY KEY (`id`),
  KEY `FK_upper_id` (`upper_id`) USING BTREE,
  KEY `FK_user_id` (`user_id`),
  CONSTRAINT `FK_domain_data_upper_id` FOREIGN KEY (`upper_id`) REFERENCES `domain_data` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_domain_data_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE NO ACTION ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=190 DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.domain_data:~1 rows (대략적) 내보내기
DELETE FROM `domain_data`;
/*!40000 ALTER TABLE `domain_data` DISABLE KEYS */;
INSERT INTO `domain_data` (`id`, `uuid`, `upper_id`, `name`, `user_id`, `public`, `create_date`, `last_update`, `description`) VALUES
	(0, '', 0, '', 'root', 0, '0000-00-00 00:00:00', '2017-11-06 09:46:30', NULL);
/*!40000 ALTER TABLE `domain_data` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.domain_method 구조 내보내기
CREATE TABLE IF NOT EXISTS `domain_method` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `uuid` char(36) NOT NULL,
  `upper_id` int(10) unsigned DEFAULT '0',
  `name` varchar(100) NOT NULL,
  `user_id` varchar(45) NOT NULL,
  `public` tinyint(1) unsigned NOT NULL,
  `standard_port` smallint(5) unsigned NOT NULL,
  `description` mediumtext NOT NULL,
  `create_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `FK_upper_id` (`upper_id`),
  KEY `FK_user_id` (`user_id`),
  CONSTRAINT `FK_domain_method_upper_id` FOREIGN KEY (`upper_id`) REFERENCES `domain_method` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_domain_method_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE NO ACTION ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=224 DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.domain_method:~1 rows (대략적) 내보내기
DELETE FROM `domain_method`;
/*!40000 ALTER TABLE `domain_method` DISABLE KEYS */;
INSERT INTO `domain_method` (`id`, `uuid`, `upper_id`, `name`, `user_id`, `public`, `standard_port`, `description`, `create_date`, `last_update`) VALUES
	(0, '', NULL, '', 'root', 0, 0, '', '0000-00-00 00:00:00', '2017-11-06 09:47:11');
/*!40000 ALTER TABLE `domain_method` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.domain_system 구조 내보내기
CREATE TABLE IF NOT EXISTS `domain_system` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `uuid` char(36) NOT NULL DEFAULT '',
  `upper_id` int(10) unsigned DEFAULT NULL,
  `name` varchar(100) NOT NULL,
  `user_id` varchar(45) NOT NULL,
  `type` enum('router','switch','computer','sensor','system') NOT NULL,
  `public` tinyint(1) unsigned NOT NULL,
  `create_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `description` mediumtext NOT NULL,
  PRIMARY KEY (`id`),
  KEY `FK_upper_id` (`upper_id`),
  KEY `FK_user_id` (`user_id`),
  CONSTRAINT `FK_domain_system_2` FOREIGN KEY (`upper_id`) REFERENCES `domain_system` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_domain_system_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE NO ACTION ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=341 DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.domain_system:~1 rows (대략적) 내보내기
DELETE FROM `domain_system`;
/*!40000 ALTER TABLE `domain_system` DISABLE KEYS */;
INSERT INTO `domain_system` (`id`, `uuid`, `upper_id`, `name`, `user_id`, `type`, `public`, `create_date`, `last_update`, `description`) VALUES
	(0, '', NULL, '', 'root', 'router', 0, '0000-00-00 00:00:00', '2017-11-06 09:47:42', '');
/*!40000 ALTER TABLE `domain_system` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.domain_system_logical_port 구조 내보내기
CREATE TABLE IF NOT EXISTS `domain_system_logical_port` (
  `domain_system_id` int(11) unsigned NOT NULL DEFAULT '0',
  `port_group` int(11) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`domain_system_id`,`port_group`) USING BTREE,
  CONSTRAINT `domain_system_logical_port_ibfk_1` FOREIGN KEY (`domain_system_id`) REFERENCES `domain_system` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;

-- 테이블 데이터 nerv_icde_xxxx.domain_system_logical_port:~1 rows (대략적) 내보내기
DELETE FROM `domain_system_logical_port`;
/*!40000 ALTER TABLE `domain_system_logical_port` DISABLE KEYS */;
INSERT INTO `domain_system_logical_port` (`domain_system_id`, `port_group`) VALUES
	(0, 0);
/*!40000 ALTER TABLE `domain_system_logical_port` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.domain_system_port 구조 내보내기
CREATE TABLE IF NOT EXISTS `domain_system_port` (
  `domain_system_id` int(11) unsigned NOT NULL DEFAULT '0',
  `port_num` int(11) unsigned NOT NULL DEFAULT '0',
  `port_group` int(11) unsigned NOT NULL DEFAULT '0',
  `description` text,
  PRIMARY KEY (`domain_system_id`,`port_num`,`port_group`) USING BTREE,
  KEY `FK_domain_system_port_1` (`domain_system_id`,`port_group`),
  CONSTRAINT `FK_domain_system_port_1` FOREIGN KEY (`domain_system_id`, `port_group`) REFERENCES `domain_system_logical_port` (`domain_system_id`, `port_group`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.domain_system_port:~0 rows (대략적) 내보내기
DELETE FROM `domain_system_port`;
/*!40000 ALTER TABLE `domain_system_port` DISABLE KEYS */;
/*!40000 ALTER TABLE `domain_system_port` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.inheritance_data_data 구조 내보내기
CREATE TABLE IF NOT EXISTS `inheritance_data_data` (
  `domain_id` int(10) unsigned NOT NULL,
  `parent_domain_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`domain_id`,`parent_domain_id`),
  KEY `FK_inheritance_data_data_2` (`parent_domain_id`),
  CONSTRAINT `FK_inheritance_data_data_1` FOREIGN KEY (`domain_id`) REFERENCES `domain_data` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_inheritance_data_data_2` FOREIGN KEY (`parent_domain_id`) REFERENCES `domain_data` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.inheritance_data_data:~1 rows (대략적) 내보내기
DELETE FROM `inheritance_data_data`;
/*!40000 ALTER TABLE `inheritance_data_data` DISABLE KEYS */;
INSERT INTO `inheritance_data_data` (`domain_id`, `parent_domain_id`) VALUES
	(0, 0);
/*!40000 ALTER TABLE `inheritance_data_data` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.inheritance_method_data 구조 내보내기
CREATE TABLE IF NOT EXISTS `inheritance_method_data` (
  `domain_id` int(10) unsigned NOT NULL,
  `parent_domain_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`domain_id`,`parent_domain_id`),
  KEY `FK_inheritance_method_data_parent_domain_in` (`parent_domain_id`),
  CONSTRAINT `FK_inheritance_method_data_domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain_method` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_inheritance_method_data_parent_domain_in` FOREIGN KEY (`parent_domain_id`) REFERENCES `domain_data` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.inheritance_method_data:~0 rows (대략적) 내보내기
DELETE FROM `inheritance_method_data`;
/*!40000 ALTER TABLE `inheritance_method_data` DISABLE KEYS */;
/*!40000 ALTER TABLE `inheritance_method_data` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.inheritance_method_method 구조 내보내기
CREATE TABLE IF NOT EXISTS `inheritance_method_method` (
  `domain_id` int(10) unsigned NOT NULL,
  `parent_domain_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`domain_id`,`parent_domain_id`),
  KEY `FK_inheritance_method_method_parent_domain_id` (`parent_domain_id`),
  CONSTRAINT `FK_inheritance_method_method_domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain_method` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_inheritance_method_method_parent_domain_id` FOREIGN KEY (`parent_domain_id`) REFERENCES `domain_method` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.inheritance_method_method:~0 rows (대략적) 내보내기
DELETE FROM `inheritance_method_method`;
/*!40000 ALTER TABLE `inheritance_method_method` DISABLE KEYS */;
/*!40000 ALTER TABLE `inheritance_method_method` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.inheritance_system_method 구조 내보내기
CREATE TABLE IF NOT EXISTS `inheritance_system_method` (
  `domain_id` int(10) unsigned NOT NULL,
  `parent_domain_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`domain_id`,`parent_domain_id`),
  KEY `FK_inheritance_system_method_parent_domain_id` (`parent_domain_id`),
  CONSTRAINT `FK_inheritance_system_method_domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain_system` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_inheritance_system_method_parent_domain_id` FOREIGN KEY (`parent_domain_id`) REFERENCES `domain_method` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.inheritance_system_method:~0 rows (대략적) 내보내기
DELETE FROM `inheritance_system_method`;
/*!40000 ALTER TABLE `inheritance_system_method` DISABLE KEYS */;
/*!40000 ALTER TABLE `inheritance_system_method` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.interface 구조 내보내기
CREATE TABLE IF NOT EXISTS `interface` (
  `domain_id` int(10) unsigned NOT NULL DEFAULT '0',
  `name` varchar(100) NOT NULL,
  `user_id` varchar(45) NOT NULL,
  `seq` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `description` mediumtext NOT NULL,
  PRIMARY KEY (`domain_id`,`name`),
  KEY `FK_user_id` (`user_id`),
  CONSTRAINT `FK_interface_domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain_method` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_interface_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE NO ACTION ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.interface:~0 rows (대략적) 내보내기
DELETE FROM `interface`;
/*!40000 ALTER TABLE `interface` DISABLE KEYS */;
/*!40000 ALTER TABLE `interface` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.interface_member 구조 내보내기
CREATE TABLE IF NOT EXISTS `interface_member` (
  `domain_id` int(10) unsigned NOT NULL DEFAULT '0',
  `interface` varchar(100) NOT NULL,
  `method_domain_id` int(10) unsigned NOT NULL,
  `method_name` varchar(45) NOT NULL,
  `description` mediumtext NOT NULL,
  PRIMARY KEY (`domain_id`,`interface`,`method_domain_id`,`method_name`),
  KEY `FK_interface_member_method` (`domain_id`,`method_name`),
  KEY `interface_member_ibfk_1` (`method_domain_id`,`method_name`),
  CONSTRAINT `FK_interface_member_interface` FOREIGN KEY (`domain_id`, `interface`) REFERENCES `interface` (`domain_id`, `name`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `interface_member_ibfk_1` FOREIGN KEY (`method_domain_id`, `method_name`) REFERENCES `method` (`domain_id`, `name`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.interface_member:~0 rows (대략적) 내보내기
DELETE FROM `interface_member`;
/*!40000 ALTER TABLE `interface_member` DISABLE KEYS */;
/*!40000 ALTER TABLE `interface_member` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.interface_parent 구조 내보내기
CREATE TABLE IF NOT EXISTS `interface_parent` (
  `domain_id` int(10) unsigned NOT NULL,
  `interface` varchar(100) NOT NULL,
  `parent_domain_id` int(10) unsigned NOT NULL,
  `parent_interface` varchar(100) NOT NULL,
  PRIMARY KEY (`domain_id`,`interface`,`parent_domain_id`,`parent_interface`),
  KEY `FK_interface_parent_parent` (`parent_domain_id`,`parent_interface`),
  CONSTRAINT `FK_interface_parent_interface` FOREIGN KEY (`domain_id`, `interface`) REFERENCES `interface` (`domain_id`, `name`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_interface_parent_parent` FOREIGN KEY (`parent_domain_id`, `parent_interface`) REFERENCES `interface` (`domain_id`, `name`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.interface_parent:~0 rows (대략적) 내보내기
DELETE FROM `interface_parent`;
/*!40000 ALTER TABLE `interface_parent` DISABLE KEYS */;
/*!40000 ALTER TABLE `interface_parent` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.members_domain_data 구조 내보내기
CREATE TABLE IF NOT EXISTS `members_domain_data` (
  `domain_id` int(10) unsigned NOT NULL DEFAULT '0',
  `user_id` varchar(45) NOT NULL,
  `member_type` enum('manager','member','guest') NOT NULL,
  PRIMARY KEY (`domain_id`,`user_id`),
  KEY `FK_user_id` (`user_id`),
  CONSTRAINT `FK_members_domain_data_domain` FOREIGN KEY (`domain_id`) REFERENCES `domain_data` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_members_domain_data_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.members_domain_data:~0 rows (대략적) 내보내기
DELETE FROM `members_domain_data`;
/*!40000 ALTER TABLE `members_domain_data` DISABLE KEYS */;
/*!40000 ALTER TABLE `members_domain_data` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.members_domain_method 구조 내보내기
CREATE TABLE IF NOT EXISTS `members_domain_method` (
  `domain_id` int(10) unsigned NOT NULL,
  `user_id` varchar(45) NOT NULL,
  `member_type` enum('manager','member','guest') NOT NULL,
  PRIMARY KEY (`domain_id`,`user_id`),
  KEY `FK_user_id` (`user_id`),
  CONSTRAINT `FK_members_domain_method_domain` FOREIGN KEY (`domain_id`) REFERENCES `domain_method` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_members_domain_method_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.members_domain_method:~0 rows (대략적) 내보내기
DELETE FROM `members_domain_method`;
/*!40000 ALTER TABLE `members_domain_method` DISABLE KEYS */;
/*!40000 ALTER TABLE `members_domain_method` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.members_domain_system 구조 내보내기
CREATE TABLE IF NOT EXISTS `members_domain_system` (
  `domain_id` int(10) unsigned NOT NULL,
  `user_id` varchar(45) NOT NULL,
  `member_type` enum('manager','member','guest') NOT NULL,
  PRIMARY KEY (`domain_id`,`user_id`),
  KEY `FK_user_id` (`user_id`),
  CONSTRAINT `FK_members_domain_system_domain` FOREIGN KEY (`domain_id`) REFERENCES `domain_system` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_members_domain_system_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.members_domain_system:~0 rows (대략적) 내보내기
DELETE FROM `members_domain_system`;
/*!40000 ALTER TABLE `members_domain_system` DISABLE KEYS */;
/*!40000 ALTER TABLE `members_domain_system` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.member_system 구조 내보내기
CREATE TABLE IF NOT EXISTS `member_system` (
  `domain_id` int(10) unsigned NOT NULL,
  `member_domain_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`domain_id`,`member_domain_id`),
  KEY `FK_member_system_member` (`member_domain_id`),
  CONSTRAINT `FK_member_system_domain` FOREIGN KEY (`domain_id`) REFERENCES `domain_system` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_member_system_member` FOREIGN KEY (`member_domain_id`) REFERENCES `domain_system` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.member_system:~0 rows (대략적) 내보내기
DELETE FROM `member_system`;
/*!40000 ALTER TABLE `member_system` DISABLE KEYS */;
/*!40000 ALTER TABLE `member_system` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.method 구조 내보내기
CREATE TABLE IF NOT EXISTS `method` (
  `domain_id` int(10) unsigned NOT NULL DEFAULT '0',
  `name` varchar(100) NOT NULL,
  `type` enum('CALL','SIGNAL','EVENT','INFORMATION','COMMAND','BROADCAST') NOT NULL DEFAULT 'CALL',
  `code` smallint(5) unsigned NOT NULL DEFAULT '0',
  `in_data_auto_id` int(10) unsigned DEFAULT NULL,
  `out_data_auto_id` int(10) unsigned DEFAULT NULL,
  `user_id` varchar(45) NOT NULL,
  `description` mediumtext NOT NULL,
  PRIMARY KEY (`domain_id`,`name`),
  KEY `UQ_method` (`domain_id`,`type`,`code`),
  KEY `FK_method_user` (`user_id`),
  KEY `FK_method_in_data` (`in_data_auto_id`),
  KEY `FK_method_out_data` (`out_data_auto_id`),
  CONSTRAINT `FK_method_domain` FOREIGN KEY (`domain_id`) REFERENCES `domain_method` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_method_in_data` FOREIGN KEY (`in_data_auto_id`) REFERENCES `data` (`data_auto_id`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `FK_method_out_data` FOREIGN KEY (`out_data_auto_id`) REFERENCES `data` (`data_auto_id`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `FK_method_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE NO ACTION ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.method:~0 rows (대략적) 내보내기
DELETE FROM `method`;
/*!40000 ALTER TABLE `method` DISABLE KEYS */;
/*!40000 ALTER TABLE `method` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.network 구조 내보내기
CREATE TABLE IF NOT EXISTS `network` (
  `node_id` int(10) unsigned NOT NULL DEFAULT '0',
  `port` int(11) unsigned NOT NULL DEFAULT '0',
  `ip` varchar(255) NOT NULL DEFAULT '',
  `mask` varchar(255) DEFAULT '',
  `net` varchar(50) NOT NULL DEFAULT '',
  `gateway` varchar(255) DEFAULT NULL,
  `dns` varchar(255) NOT NULL DEFAULT '',
  `description` varchar(255) DEFAULT NULL,
  `collision` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `original_node_id` int(10) unsigned DEFAULT '0',
  `original_node_port` int(11) unsigned DEFAULT '0',
  `original_node_ip` varchar(255) DEFAULT '',
  PRIMARY KEY (`node_id`,`port`,`ip`),
  KEY `network_ibfk_3` (`original_node_id`,`original_node_port`,`original_node_ip`),
  CONSTRAINT `network_ibfk_1` FOREIGN KEY (`node_id`, `port`) REFERENCES `node_port` (`Id`, `port_group`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `network_ibfk_2` FOREIGN KEY (`node_id`) REFERENCES `node_port` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `network_ibfk_3` FOREIGN KEY (`original_node_id`, `original_node_port`, `original_node_ip`) REFERENCES `network` (`node_id`, `port`, `ip`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.network:~0 rows (대략적) 내보내기
DELETE FROM `network`;
/*!40000 ALTER TABLE `network` DISABLE KEYS */;
/*!40000 ALTER TABLE `network` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.network_link 구조 내보내기
CREATE TABLE IF NOT EXISTS `network_link` (
  `s_node_id` int(11) unsigned NOT NULL DEFAULT '0',
  `s_sub_system_id` int(11) unsigned NOT NULL DEFAULT '0',
  `s_port_id` int(11) unsigned NOT NULL DEFAULT '0',
  `d_node_id` int(11) unsigned DEFAULT NULL,
  `d_sub_system_id` int(11) unsigned NOT NULL DEFAULT '0',
  `d_port_id` int(11) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`s_node_id`,`s_sub_system_id`,`s_port_id`),
  UNIQUE KEY `d_node_id` (`d_node_id`,`d_sub_system_id`,`d_port_id`),
  KEY `s_sub_system_id` (`s_sub_system_id`,`s_port_id`),
  KEY `d_sub_system_id` (`d_sub_system_id`,`d_port_id`),
  CONSTRAINT `FK_network_link_4` FOREIGN KEY (`d_node_id`) REFERENCES `node` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `network_link_ibfk_1` FOREIGN KEY (`s_sub_system_id`, `s_port_id`) REFERENCES `domain_system_port` (`domain_system_id`, `port_num`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `network_link_ibfk_2` FOREIGN KEY (`d_sub_system_id`, `d_port_id`) REFERENCES `domain_system_port` (`domain_system_id`, `port_num`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `network_link_ibfk_3` FOREIGN KEY (`s_node_id`) REFERENCES `node` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.network_link:~0 rows (대략적) 내보내기
DELETE FROM `network_link`;
/*!40000 ALTER TABLE `network_link` DISABLE KEYS */;
/*!40000 ALTER TABLE `network_link` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.network_temp 구조 내보내기
CREATE TABLE IF NOT EXISTS `network_temp` (
  `node_id` int(10) unsigned NOT NULL DEFAULT '0',
  `port` int(11) unsigned NOT NULL DEFAULT '0',
  `ip` varchar(255) NOT NULL DEFAULT '',
  `mask` varchar(255) DEFAULT '',
  `net` varchar(50) NOT NULL DEFAULT '',
  `gateway` varchar(255) DEFAULT NULL,
  `dns` varchar(255) NOT NULL DEFAULT '',
  `description` varchar(255) DEFAULT NULL,
  `collision` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `original_node_id` int(10) unsigned DEFAULT '0',
  `original_node_port` int(11) unsigned DEFAULT '0',
  `original_node_ip` varchar(255) DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;

-- 테이블 데이터 nerv_icde_xxxx.network_temp:~0 rows (대략적) 내보내기
DELETE FROM `network_temp`;
/*!40000 ALTER TABLE `network_temp` DISABLE KEYS */;
/*!40000 ALTER TABLE `network_temp` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.node 구조 내보내기
CREATE TABLE IF NOT EXISTS `node` (
  `Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `systemdomain_id` int(10) unsigned NOT NULL,
  `sub_system_domain_id` int(11) unsigned DEFAULT '0',
  `name` varchar(255) NOT NULL DEFAULT '',
  `type` varchar(45) NOT NULL DEFAULT '',
  `description` varchar(255) DEFAULT NULL,
  `complete` enum('Y','N') NOT NULL DEFAULT 'N',
  PRIMARY KEY (`Id`),
  KEY `FK_node_1` (`systemdomain_id`),
  KEY `package_domain_id` (`sub_system_domain_id`),
  KEY `Id_systemdomain_id` (`Id`,`systemdomain_id`),
  CONSTRAINT `node_ibfk_1` FOREIGN KEY (`systemdomain_id`) REFERENCES `domain_system` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `node_ibfk_2` FOREIGN KEY (`sub_system_domain_id`) REFERENCES `domain_system` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1199 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;

-- 테이블 데이터 nerv_icde_xxxx.node:~1 rows (대략적) 내보내기
DELETE FROM `node`;
/*!40000 ALTER TABLE `node` DISABLE KEYS */;
INSERT INTO `node` (`Id`, `systemdomain_id`, `sub_system_domain_id`, `name`, `type`, `description`, `complete`) VALUES
	(0, 0, 0, '', 'sub_system', NULL, 'N');
/*!40000 ALTER TABLE `node` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.node_port 구조 내보내기
CREATE TABLE IF NOT EXISTS `node_port` (
  `Id` int(10) unsigned NOT NULL,
  `systemdomain_id` int(10) unsigned NOT NULL,
  `sub_system_domain_id` int(11) unsigned NOT NULL DEFAULT '0',
  `port_group` int(11) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`Id`,`systemdomain_id`,`sub_system_domain_id`,`port_group`),
  KEY `Id_port_group` (`Id`,`port_group`),
  KEY `FK_node_port_domain_system_logical_port` (`sub_system_domain_id`,`port_group`),
  CONSTRAINT `FK_node_port_domain_system_logical_port` FOREIGN KEY (`sub_system_domain_id`, `port_group`) REFERENCES `domain_system_logical_port` (`domain_system_id`, `port_group`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_node_port_node` FOREIGN KEY (`Id`, `systemdomain_id`) REFERENCES `node` (`Id`, `systemdomain_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;

-- 테이블 데이터 nerv_icde_xxxx.node_port:~0 rows (대략적) 내보내기
DELETE FROM `node_port`;
/*!40000 ALTER TABLE `node_port` DISABLE KEYS */;
/*!40000 ALTER TABLE `node_port` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.protocol_standard_port 구조 내보내기
CREATE TABLE IF NOT EXISTS `protocol_standard_port` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) DEFAULT NULL,
  `port` varchar(255) DEFAULT NULL,
  `discription` text,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=10746 DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.protocol_standard_port:~0 rows (대략적) 내보내기
DELETE FROM `protocol_standard_port`;
/*!40000 ALTER TABLE `protocol_standard_port` DISABLE KEYS */;
/*!40000 ALTER TABLE `protocol_standard_port` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.proxy_interface_object 구조 내보내기
CREATE TABLE IF NOT EXISTS `proxy_interface_object` (
  `proxy_interface_id` int(10) unsigned NOT NULL,
  `object_name` varchar(100) NOT NULL,
  `component_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`proxy_interface_id`,`object_name`),
  UNIQUE KEY `object_name_component_id` (`object_name`,`component_id`),
  KEY `FK_proxy_interface_object_proxy_interface_relation` (`proxy_interface_id`,`component_id`),
  CONSTRAINT `FK_proxy_interface_object_proxy_interface_relation` FOREIGN KEY (`proxy_interface_id`, `component_id`) REFERENCES `proxy_interface_relation` (`id`, `component_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.proxy_interface_object:~0 rows (대략적) 내보내기
DELETE FROM `proxy_interface_object`;
/*!40000 ALTER TABLE `proxy_interface_object` DISABLE KEYS */;
/*!40000 ALTER TABLE `proxy_interface_object` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.proxy_interface_relation 구조 내보내기
CREATE TABLE IF NOT EXISTS `proxy_interface_relation` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `component_id` int(10) unsigned NOT NULL DEFAULT '0',
  `method_domain_id` int(10) unsigned NOT NULL DEFAULT '0',
  `interface_name` varchar(100) NOT NULL DEFAULT '',
  `class_name` varchar(255) DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_key` (`component_id`,`method_domain_id`,`interface_name`,`class_name`),
  KEY `FK_proxy_interface_relation_1` (`component_id`),
  KEY `FK_proxy_interface_relation_2` (`method_domain_id`,`interface_name`),
  KEY `id_component_id` (`id`,`component_id`),
  CONSTRAINT `FK_proxy_interface_relation_1` FOREIGN KEY (`component_id`) REFERENCES `component` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_proxy_interface_relation_2` FOREIGN KEY (`method_domain_id`, `interface_name`) REFERENCES `interface` (`domain_id`, `name`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1099 DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.proxy_interface_relation:~0 rows (대략적) 내보내기
DELETE FROM `proxy_interface_relation`;
/*!40000 ALTER TABLE `proxy_interface_relation` DISABLE KEYS */;
/*!40000 ALTER TABLE `proxy_interface_relation` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.server_information 구조 내보내기
CREATE TABLE IF NOT EXISTS `server_information` (
  `field_name` varchar(100) NOT NULL,
  `description` mediumtext NOT NULL,
  `seq` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`field_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.server_information:~0 rows (대략적) 내보내기
DELETE FROM `server_information`;
/*!40000 ALTER TABLE `server_information` DISABLE KEYS */;
/*!40000 ALTER TABLE `server_information` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.stub_interface_object 구조 내보내기
CREATE TABLE IF NOT EXISTS `stub_interface_object` (
  `stub_interface_id` int(10) unsigned NOT NULL,
  `object_name` varchar(100) NOT NULL,
  `component_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`stub_interface_id`,`object_name`),
  UNIQUE KEY `object_name_component_id` (`object_name`,`component_id`),
  KEY `FK_stub_interface_object_stub_interface_relation` (`stub_interface_id`,`component_id`),
  CONSTRAINT `FK_stub_interface_object_stub_interface_relation` FOREIGN KEY (`stub_interface_id`, `component_id`) REFERENCES `stub_interface_relation` (`Id`, `component_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.stub_interface_object:~0 rows (대략적) 내보내기
DELETE FROM `stub_interface_object`;
/*!40000 ALTER TABLE `stub_interface_object` DISABLE KEYS */;
/*!40000 ALTER TABLE `stub_interface_object` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.stub_interface_relation 구조 내보내기
CREATE TABLE IF NOT EXISTS `stub_interface_relation` (
  `Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `component_id` int(10) unsigned NOT NULL DEFAULT '0',
  `method_domain_id` int(10) unsigned NOT NULL DEFAULT '0',
  `interface_name` varchar(100) NOT NULL DEFAULT '',
  `class_name` varchar(255) DEFAULT '',
  `domain_port` varchar(255) DEFAULT NULL,
  `text` text,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `unique_key` (`component_id`,`method_domain_id`,`interface_name`,`class_name`),
  KEY `FK_stub_interface_ralation_1` (`component_id`),
  KEY `FK_stub_interface_ralation_2` (`method_domain_id`,`interface_name`),
  KEY `Id_component_id` (`Id`,`component_id`),
  CONSTRAINT `FK_stub_interface_ralation_1` FOREIGN KEY (`component_id`) REFERENCES `component` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_stub_interface_ralation_2` FOREIGN KEY (`method_domain_id`, `interface_name`) REFERENCES `interface` (`domain_id`, `name`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=866 DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.stub_interface_relation:~0 rows (대략적) 내보내기
DELETE FROM `stub_interface_relation`;
/*!40000 ALTER TABLE `stub_interface_relation` DISABLE KEYS */;
/*!40000 ALTER TABLE `stub_interface_relation` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.temp_history 구조 내보내기
CREATE TABLE IF NOT EXISTS `temp_history` (
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `userid` varchar(45) NOT NULL,
  PRIMARY KEY (`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.temp_history:~0 rows (대략적) 내보내기
DELETE FROM `temp_history`;
/*!40000 ALTER TABLE `temp_history` DISABLE KEYS */;
/*!40000 ALTER TABLE `temp_history` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.umlcomponent 구조 내보내기
CREATE TABLE IF NOT EXISTS `umlcomponent` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `diagrame_id` int(11) NOT NULL DEFAULT '0',
  `component_id` int(11) unsigned NOT NULL DEFAULT '0',
  `position_x` int(11) unsigned NOT NULL DEFAULT '0',
  `position_y` int(11) unsigned NOT NULL DEFAULT '0',
  `size` int(11) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`Id`),
  KEY `FK_umlcomponent_diagrame_id` (`diagrame_id`),
  KEY `component_id` (`component_id`),
  CONSTRAINT `FK_umlcomponent_component_id` FOREIGN KEY (`component_id`) REFERENCES `component` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_umlcomponent_diagrame_id` FOREIGN KEY (`diagrame_id`) REFERENCES `diagrame` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `umlcomponent_ibfk_1` FOREIGN KEY (`component_id`) REFERENCES `component` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.umlcomponent:~0 rows (대략적) 내보내기
DELETE FROM `umlcomponent`;
/*!40000 ALTER TABLE `umlcomponent` DISABLE KEYS */;
/*!40000 ALTER TABLE `umlcomponent` ENABLE KEYS */;

-- 테이블 nerv_icde_xxxx.users 구조 내보내기
CREATE TABLE IF NOT EXISTS `users` (
  `user_id` varchar(45) NOT NULL,
  `password` varchar(45) NOT NULL,
  `description` mediumtext NOT NULL,
  `supermanager` tinyint(1) unsigned NOT NULL,
  `newacount` tinyint(1) unsigned NOT NULL,
  `newdomain` tinyint(1) unsigned NOT NULL,
  PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 테이블 데이터 nerv_icde_xxxx.users:~2 rows (대략적) 내보내기
DELETE FROM `users`;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
INSERT INTO `users` (`user_id`, `password`, `description`, `supermanager`, `newacount`, `newdomain`) VALUES
	('anonymous', '', '', 0, 1, 0),
	('root', '', '', 1, 1, 1);
/*!40000 ALTER TABLE `users` ENABLE KEYS */;

-- 뷰 nerv_icde_xxxx.view_a 구조 내보내기
-- VIEW 종속성 오류를 극복하기 위해 임시 테이블을 생성합니다.
CREATE TABLE `view_a` (
	`s_node_id` INT(11) UNSIGNED NOT NULL,
	`s_sub_system_id` INT(11) UNSIGNED NOT NULL,
	`s_port_id` INT(11) UNSIGNED NOT NULL,
	`d_node_id` INT(11) UNSIGNED NULL,
	`d_sub_system_id` INT(11) UNSIGNED NOT NULL,
	`d_port_id` INT(11) UNSIGNED NOT NULL
) ENGINE=MyISAM;

-- 뷰 nerv_icde_xxxx.view_b 구조 내보내기
-- VIEW 종속성 오류를 극복하기 위해 임시 테이블을 생성합니다.
CREATE TABLE `view_b` (
	`s_node_id` INT(11) UNSIGNED NOT NULL,
	`s_sub_system_id` INT(11) UNSIGNED NOT NULL,
	`s_port_id` INT(11) UNSIGNED NOT NULL,
	`d_node_id` INT(11) UNSIGNED NULL,
	`d_sub_system_id` INT(11) UNSIGNED NOT NULL,
	`d_port_id` INT(11) UNSIGNED NOT NULL
) ENGINE=MyISAM;

-- 프로시저 nerv_icde_xxxx.acountInfoAccessUser 구조 내보내기
DELIMITER //
CREATE PROCEDURE `acountInfoAccessUser`()
BEGIN
        declare sm bool;
        if loginTest() then
                select 1 as test;               
                       select user_id,supermanager,newacount,newdomain,description from users where user_id = @nervuser;                              
       else
                select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.acountlistViewAcountList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `acountlistViewAcountList`(IN `userkey` varchar(100))
BEGIN
        declare sm bool;
        if loginTest() then
                select 1 as test;
                if( supermanagerTest(@nervuser) ) then
                        select user_id,supermanager,newacount,newdomain,description from users
								 where user_id like userkey;
                else
                        select user_id,supermanager,newacount,newdomain,description from users
								 where (user_id = 'anonymous' or user_id=@nervuser) and user_id like userkey;
                end if;
       else
                select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.acountlistViewDeleteAcount 구조 내보내기
DELIMITER //
CREATE PROCEDURE `acountlistViewDeleteAcount`(IN `acountkey` varchar(100))
BEGIN
        declare targetsm bool;
        if acountkey != 'anonymous' and acountkey != 'root'
		  	and acountkey != @nervuser and loginTest() 
			  and supermanagerTest(@nervuser) and !supermanagerTest(acountkey) then
                select 1 as test;
                delete from users where user_id=acountkey;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.acountlistViewNewAcount 구조 내보내기
DELIMITER //
CREATE PROCEDURE `acountlistViewNewAcount`(acountidvalue varchar(100),passwordvalue varchar(100) ,descriptionvalue text)
BEGIN
        declare newacountpriv bool;
        declare anonymousnewacount bool;
        declare anonymousnewdomain bool;
        declare anonymoussupermanager bool;

        if loginTest() then
                select newacount into newacountpriv from users where user_id=@nervuser;
                if newacountpriv then
                        select 1 as test;
                        select supermanager into anonymoussupermanager from users where user_id='anonymous';
                        select newacount into anonymousnewacount from users where user_id='anonymous';
                        select newdomain into anonymousnewdomain from users where user_id='anonymous';
                        insert into users(user_id, password,supermanager,newacount,newdomain, description)
                                   values(acountidvalue,password(passwordvalue),anonymoussupermanager,anonymousnewacount,anonymousnewdomain,descriptionvalue);
                else
                        select 0 as test;
                end if;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.acountlistViewToggleNewAcount 구조 내보내기
DELIMITER //
CREATE PROCEDURE `acountlistViewToggleNewAcount`(acountkey varchar(100))
BEGIN
        if acountkey != 'root' and loginTest() and supermanagerTest(@nervuser) and !supermanagerTest(acountkey) then
                select 1 as test;
                update users set newacount = !newacount where user_id=acountkey;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.acountlistViewToggleNewDomain 구조 내보내기
DELIMITER //
CREATE PROCEDURE `acountlistViewToggleNewDomain`(acountkey varchar(100))
BEGIN
        if acountkey != 'root' and loginTest() and supermanagerTest(@nervuser) and !supermanagerTest(acountkey) then
                select 1 as test;
                update users set newdomain = !newdomain where user_id=acountkey;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.acountlistViewToggleSupermanager 구조 내보내기
DELIMITER //
CREATE PROCEDURE `acountlistViewToggleSupermanager`(acountkey varchar(100))
BEGIN
        if acountkey != 'root' and @nervuser = 'root' and loginTest() then
                select 1 as test;
                update users set supermanager = !supermanager where user_id=acountkey;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.acountViewEditAcount 구조 내보내기
DELIMITER //
CREATE PROCEDURE `acountViewEditAcount`(IN `oldpasswordedit` varchar(100), IN `passwordedit` varchar(100), IN `descriptionedit` text)
BEGIN
        declare pwd varchar(100);
        if @nervuser != 'anonymous' then
                if loginTest() then
                        select users.password into pwd from users where user_id=@nervuser;
                        if pwd = [REDACTED] then
                                select 1 as test;
                                update users set password=[REDACTED] description=descriptionedit
										   where user_id=@nervuser;
                                set @nervpassword = [REDACTED]
                        else
                                select 0 as test;
                        end if;
                else
                        select 0 as test;
                end if;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.acountViewSecedeAcount 구조 내보내기
DELIMITER //
CREATE PROCEDURE `acountViewSecedeAcount`()
BEGIN
        declare pwd varchar(100);
        if @nervuser != 'anonymous' then
                if loginTest() then
                        select 1 as test;
                        delete from users where user_id=@nervuser;
                else
                        select 0 as test;
                end if;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.acountViewUserinfo 구조 내보내기
DELIMITER //
CREATE PROCEDURE `acountViewUserinfo`()
BEGIN
       if loginTest() then
               select 1 as test;
               select user_id,supermanager,newacount,newdomain,description from users where user_id=@nervuser;
       else
               select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.auto_update_data_field_path 구조 내보내기
DELIMITER //
CREATE PROCEDURE `auto_update_data_field_path`()
BEGIN
	declare my_data_id int;
	declare my_real_data_auto_id int;		
	declare my_domain_id int;
	declare my_real_domain_id int;
	declare my_real_data_name varchar(50);	
	declare my_depth int;	
	declare my_real_data_path int;	
	declare no_more_rows bool default false;
	
		DECLARE my_list CURSOR FOR 
		select data_field.data_auto_id, data_field.real_data_auto_id  from data_field where data_field.`type`='alias';		
		declare continue handler for not found set no_more_rows := TRUE;		
		
			open my_list;
			my_loop : loop		
				fetch my_list into my_data_id, my_real_data_auto_id;
				if no_more_rows then
					close my_list;
					leave my_loop;
				end if;					
				   select  data.domain_id into my_domain_id from data where data.data_auto_id = my_data_id;
        			select  data.domain_id into my_real_domain_id from data where data.data_auto_id = my_real_data_auto_id; 
        			select  data.name into my_real_data_name from data where data.data_auto_id = my_real_data_auto_id; 
        			
        			
        			
        			if my_domain_id=my_real_domain_id then
               		select data.depth into my_depth from data where data.data_auto_id=my_data_id;
               		select data.depth into my_real_data_path from data where data.data_auto_id=my_real_data_auto_id;
               		
               		        			
               		        			
               		if my_depth <= my_real_data_path then               		
               			set my_real_data_path = my_real_data_path + 1;
               			               			
               			  update data set data.depth = my_real_data_path where data.data_auto_id = my_data_id;               			
               			  call update_child_depth(my_real_data_auto_id,my_real_domain_id,my_real_data_path);
               		end if;               		
               	end if;               	
   		end loop my_loop;	
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.auto_update_data_path 구조 내보내기
DELIMITER //
CREATE PROCEDURE `auto_update_data_path`()
BEGIN

	declare my_data_id int;
	declare my_domain_id int;
	declare my_depth int;
	declare my_real_data_auto_id int;	
	declare my_real_data_path int;
	
	declare no_more_rows bool default false;
	
		DECLARE my_list CURSOR FOR 
		select data.data_auto_id, data.domain_id, data.depth, data.real_data_auto_id  from data where data.`type`='alias';
		
		declare continue handler for not found set no_more_rows := TRUE;		
		
			open my_list;
			my_loop : loop		
				fetch my_list into my_data_id, my_domain_id, my_depth, my_real_data_auto_id;
				if no_more_rows then
					close my_list;
					leave my_loop;
				end if;	
        			
               		select data.depth into my_real_data_path from data where data.data_auto_id=my_real_data_auto_id;
               		if my_depth <= my_real_data_path then
								set my_depth = my_real_data_path +1;               		               									

               			call update_child_depth(my_data_id,my_domain_id,my_depth);               
								
								 update data set data.depth = my_depth where data.data_auto_id=my_data_id;			
							end if;               	
   		end loop my_loop;	

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.check_child_depth_limit_loop 구조 내보내기
DELIMITER //
CREATE PROCEDURE `check_child_depth_limit_loop`(
	IN `in_domain_id` INT,
	IN `in_data_name` VARCHAR(100),
	IN `in_real_auto_id` INT
)
BEGIN
	declare no_more_rows bool default false;		
	declare data_type varchar(100);
	declare data_domain_id int;
	declare data_name varchar(100);
	declare child_data_auto_id int;
	declare limit_count int default 0;
	declare check_data_auto_id int;	
	
	DECLARE my_list CURSOR FOR 	
	select data.`type`, data.real_data_auto_id from data where data.data_auto_id = in_real_auto_id and data.domain_id=in_domain_id
 	union 
	select data.`type`, data.real_data_auto_id from data where data.domain_id=in_domain_id and data.data_auto_id in
 		(select data_field.real_data_auto_id from data_field where  data_field.data_auto_id = in_real_auto_id);			
 
	declare continue handler for not found set no_more_rows := TRUE;
	
	set max_sp_recursion_depth = 50;		 
	
	   select data.data_auto_id into check_data_auto_id from data where data.domain_id=in_domain_id and data.name=in_data_name;
   
		open my_list;	
		my_loop : loop
		
			fetch my_list into data_type, child_data_auto_id;
		
			 if no_more_rows then
				 close my_list;
				 leave my_loop;
			 end if;			
			if check_data_auto_id = child_data_auto_id then
				   select 1 into limit_count;	
				   select child_data_auto_id;				
				 close my_list;
				 leave my_loop;
			end if;				
			 if data_type = 'alias' and limit_count = 0 then				 		
			 	   call check_child_depth_limit_loop( in_domain_id, in_data_name, child_data_auto_id);
			 end if;					
		end loop my_loop;					
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.check_clone_component 구조 내보내기
DELIMITER //
CREATE PROCEDURE `check_clone_component`(IN `in_system_domain_id` INT, IN `in_component_id` INT)
BEGIN
select b.name, c.name from
(
	select * from deployments where id in
		(select deploy_id from custum_proxy where id != original_id and original_id in
			( select id from custum_proxy where deploy_id in
				 (select id from deployments where component_id=in_component_id and systemdomain_id=in_system_domain_id)
			)
		)
) as a
join
domain_system as b on b.id = a.systemdomain_id
join
node as c on c.Id = a.node_id;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.check_method_code 구조 내보내기
DELIMITER //
CREATE PROCEDURE `check_method_code`(
	IN `in_domain_id` INT,
	IN `in_code` INT,
	IN `in_type` ENUM('CALL','SIGNAL','EVENT','INFORMATION','COMMAND','BROADCAST'),
	IN `in_method_name` VARCHAR(50)

)
BEGIN
	if logintest() then
		select 1 as test;
		select method.name from method where method.domain_id=in_domain_id and method.code=in_code and method.`type`= in_type and method.name != in_method_name;
	else
	 	select 0 as test;
	end if;

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.check_overlap_ip 구조 내보내기
DELIMITER //
CREATE PROCEDURE `check_overlap_ip`(IN `in_system_domain_id` INT, IN `in_node_id` INT, IN `in_port_id` INT)
BEGIN		
	declare logical_port int;
	declare sub_domain_id int;
	declare lock_state int;
	
	delete from network_temp;	
	Select sub_system_domain_id into sub_domain_id from node where id = in_node_id;	
	select port_group into logical_port from domain_system_port as A where A.domain_system_id = sub_domain_id and A.port_num = in_port_id;

	call check_overlap_ip_recursion( in_node_id , logical_port , in_node_id , logical_port , 10 );	
	
	update network set collision = 1 where (node_id , ip , port)
	 in ( select node_id , ip , port from network_temp where ip in ( select ip from network_temp as A group by ip having count(*) > 1  ) );	
	update network set collision = 0 where (node_id , ip , port)
	 in ( select node_id , ip , port from network_temp where ip in ( select ip from network_temp as A group by ip having count(*) = 1  ) );

	select node.name,  network.port, network.ip, network.mask, network.description from network
	 join node on network.node_id = node.Id where collision = 1 and node.systemdomain_id = in_system_domain_id 
	 and (network.node_id , network.ip) in (select node_id , ip from network_temp);	
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.check_overlap_ip_recursion 구조 내보내기
DELIMITER //
CREATE PROCEDURE `check_overlap_ip_recursion`(IN `in_parent_node_id` INT, IN `in_parent_port_group` INT, IN `in_node_id` INT, IN `in_port_group` INT, IN `in_depth` INT)
BEGIN
	declare domain_id int;	
	declare no_more_rows bool default false;		
	declare child_node_id int;
	declare child_port_group int;	
	
	DECLARE my_list CURSOR FOR select K.node_id , domain_system_port.port_group from
		 		(
				 	(
					 	select s_node_id as node_id , s_sub_system_id as sub_system_id , s_port_id as port_id from network_link where
						 							( d_node_id , d_port_id ) in ( select in_node_id, port_num from domain_system_port as A 
													 where A.domain_system_id = domain_id and A.port_group = in_port_group )
					)
						union
				 	(
					 	select d_node_id , d_sub_system_id , d_port_id  from network_link where
						 							( s_node_id , s_port_id ) in ( select in_node_id, port_num from domain_system_port as A
													  where A.domain_system_id = domain_id and A.port_group = in_port_group )
					) 
				) as K
				
			join			
				domain_system_port on K.sub_system_id = domain_system_port.domain_system_id and K.port_id = domain_system_port.port_num					
	where
			not ( K.node_id = in_parent_node_id and domain_system_port.port_group = in_parent_port_group );

	declare continue handler for not found set no_more_rows := TRUE;	
	set max_sp_recursion_depth = 50;
	
	insert into network_temp select * from network where node_id = in_node_id and port = in_port_group;
	
	if in_depth > 0 then
		select node.sub_system_domain_id into domain_id from node where node.Id = in_node_id; 	 

		open my_list;	
		my_loop : loop		
			fetch my_list into child_node_id , child_port_group;
			if no_more_rows then
				close my_list;
				leave my_loop;
			end if;		
				
			call check_overlap_ip_recursion( in_node_id, in_port_group , child_node_id , child_port_group , in_depth - 1 );
		
		end loop my_loop;		
	end if;	
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.check_system_lock_component 구조 내보내기
DELIMITER //
CREATE PROCEDURE `check_system_lock_component`(IN `in_domain_id` INT, IN `in_component_id` INT)
BEGIN

	if(check_system_lock_domain(in_domain_id)) then
		if(check_system_lock_component_f(in_component_id)) then
			select 1 as return_value;
		else
			select 0 as return_value;
		end if;
	else
		select 0 as return_value;
	end if;

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.check_system_lock_domain 구조 내보내기
DELIMITER //
CREATE PROCEDURE `check_system_lock_domain`(IN `in_domain_id` INT)
BEGIN

	if(check_system_lock_domain(in_domain_id)) then
		select 1 as return_value;
	else
		select 0 as return_value;
	end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.check_system_lock_interface 구조 내보내기
DELIMITER //
CREATE PROCEDURE `check_system_lock_interface`(IN `in_domain_id` INT, IN `in_interface_name` VARCHAR(50))
BEGIN

	if(check_system_lock_interface(in_domain_id, in_interface_name)) then
		select 1 as return_value;
	else
		select 0 as return_value;
	end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.check_system_lock_networklink 구조 내보내기
DELIMITER //
CREATE PROCEDURE `check_system_lock_networklink`(IN `in_node_id` INT, IN `in_port` INT, IN `in_domain_id` INT)
BEGIN

declare sub_domain_id int default 0;

select node.sub_system_domain_id into sub_domain_id from node where node.Id=in_node_id;

	if(check_system_lock_domain(in_domain_id)) then
		if(check_system_lock_domainport(in_node_id,sub_domain_id,in_port)) then
			select 1 as return_value;
		else
			select 0 as return_value;
		end if;
	else
		select 0 as return_value;
	end if;

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.check_system_lock_node_port 구조 내보내기
DELIMITER //
CREATE PROCEDURE `check_system_lock_node_port`(IN `in_node_id` INT, IN `in_node_port` INT)
BEGIN

	if(check_system_lock_node_port_f(in_node_id, in_node_port)) then
		select 1 as return_value;
	else
		select 0 as return_value;
	end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.check_system_lock_objct 구조 내보내기
DELIMITER //
CREATE PROCEDURE `check_system_lock_objct`(IN `in_deploy_id` INT)
BEGIN

	declare deploy_system_domain_id int default 0;
	
	select deployments.systemdomain_id into deploy_system_domain_id from deployments where id=in_deploy_id;
	
	if(check_system_lock_domain(deploy_system_domain_id)) then
		select 1 as return_value;
	else
		select 0 as return_value;
	end if;
	
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.check_system_lock_proxy_class 구조 내보내기
DELIMITER //
CREATE PROCEDURE `check_system_lock_proxy_class`(IN `in_proxy_id` INT)
BEGIN	
	if(check_system_lock_proxy_class(in_proxy_id)) then	
			select 1 as return_value;	
	else
		select 0 as return_value;
	end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.check_system_lock_proxy_object 구조 내보내기
DELIMITER //
CREATE PROCEDURE `check_system_lock_proxy_object`(IN `in_proxy_id` INT, IN `in_proxy_object_name` VARCHAR(50))
BEGIN
	if(check_system_lock_proxy_object_f(in_proxy_id, in_proxy_object_name)) then	
			select 1 as return_value;	
	else
		select 0 as return_value;
	end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.check_system_lock_proxy_stub_ip 구조 내보내기
DELIMITER //
CREATE PROCEDURE `check_system_lock_proxy_stub_ip`(IN `in_custum_proxy_id` INT, IN `in_deploy_id` INT)
BEGIN

	declare deploy_system_domain_id int default 0;
	
	select deployments.systemdomain_id into deploy_system_domain_id from deployments where id=in_deploy_id;
	
	if(check_system_lock_domain(deploy_system_domain_id)) then
	  if(check_system_lock_proxy_public(in_custum_proxy_id)) then	  
			select 1 as return_value;
		else
		 	select 0 as return_value;
	   end if;
	else
		select 0 as return_value;
	end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.check_system_lock_stub_class 구조 내보내기
DELIMITER //
CREATE PROCEDURE `check_system_lock_stub_class`(IN `in_stub_id` INT)
BEGIN

	if(check_system_lock_stub_class_f(in_stub_id)) then	
			select 1 as return_value;	
	else
		select 0 as return_value;
	end if;

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.check_system_lock_stub_object 구조 내보내기
DELIMITER //
CREATE PROCEDURE `check_system_lock_stub_object`(IN `in_stub_id` INT, IN `in_stub_object_name` VARCHAR(50))
BEGIN
	if(check_system_lock_stub_object_f(in_stub_id, in_stub_object_name)) then	
			select 1 as return_value;	
	else
		select 0 as return_value;
	end if;

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.componentEntityViewcomponentinfoList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `componentEntityViewcomponentinfoList`(in_componentid int)
BEGIN
          
     if loginTest() then
         select 1 as test;
         select id, systemdomain_id, name, seq, description  from component where id = in_componentid;         
         
     else
         select 0 as test;
     end if; 
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.componentEntityViewNewcomponentEntity 구조 내보내기
DELIMITER //
CREATE PROCEDURE `componentEntityViewNewcomponentEntity`(in_diagrame_id int,
                                                                            in_component_id int,
                                                                            in_position_x   int,
                                                                            in_position_y   int,
                                                                            in_size         int)
BEGIN        
        if loginTest() then
                select 1 as test;
                                
                if componentEntityCheck(in_diagrame_id, in_component_id) then
                  update umlcomponent set position_x=in_position_x,position_y=in_position_y,size=in_size where diagrame_id=in_diagrame_id and component_id=in_component_id;
                else      
                  insert into umlcomponent(diagrame_id, component_id, position_x, position_y, size)
                                  values(in_diagrame_id, in_component_id, in_position_x, in_position_y,in_size);
                end if;
                
                select LAST_INSERT_ID();               
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.componentsNewcomponent 구조 내보내기
DELIMITER //
CREATE PROCEDURE `componentsNewcomponent`(insystemdomainid int,
                                                             inname varchar(50),
                                                             indescription text)
BEGIN


     if loginTest() then
         select 1 as test;
         insert into component(systemdomain_id, name, description)
                        values(insystemdomainid, inname, indescription);
         select LAST_INSERT_ID();
         
     else
         select 0 as test;
     end if;
     
     
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.componentViewDeletecomponent 구조 내보내기
DELIMITER //
CREATE PROCEDURE `componentViewDeletecomponent`(in_component_id int, in_systemdomain_id int)
BEGIN

 
        if loginTest() then
                select 1 as test;
                delete from component where
                 id=in_component_id and systemdomain_id = in_systemdomain_id;                       
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.ComponentViewEditComponent 구조 내보내기
DELIMITER //
CREATE PROCEDURE `ComponentViewEditComponent`(in_component_id int, 
                                                                 in_systemdomain_id int,                
                                                                      in_name varchar(100),
                                                                      in_description  varchar(100))
BEGIN

        if loginTest() then
                select 1 as test;
                       update component set name=in_name, description=in_description
                                    where id=in_component_id and systemdomain_id=in_systemdomain_id;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.componentViewList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `componentViewList`(indomainid int)
BEGIN



     if loginTest() then
         select 1 as test;
         select Id, systemdomain_id, name, seq, description from component where systemdomain_id = indomainid;         
         
     else
         select 0 as test;
     end if;
     
     
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.copy_node_port_talble 구조 내보내기
DELIMITER //
CREATE PROCEDURE `copy_node_port_talble`(IN `in_copy_node_id` INT, IN `in_copy_domain_id` INT, IN `in_copy_subsystem_id` INT, IN `in_new_node_id` INT, IN `in_new_domain_id` INT)
BEGIN

	if logintest() then
  		select 1 as test;
		insert into node_port (node_port.id, node_port.systemdomain_id, node_port.sub_system_domain_id, node_port.port_group)
   	select in_new_node_id, in_new_domain_id, in_copy_subsystem_id, node_port.port_group from node_port where id=in_copy_node_id and systemdomain_id=in_copy_domain_id; 
  	else 
    	select 0 as test;
   end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.coustim_proxyViewlistinfo 구조 내보내기
DELIMITER //
CREATE PROCEDURE `coustim_proxyViewlistinfo`(IN `in_node_id` int, IN `in_component_id` int)
BEGIN
        if loginTest() then
                select 1 as test;
                  select a.id, a.deploy_id, a.proxy_interface_id, b.interface_name, b.class_name,
						       a.object_id, a.stub_object_id, a.stub_ip, c.name, c.id, c.standard_port,
								 a.object_name, a.public, a.original_id from 
                    ((select id, deploy_id, proxy_interface_id, object_id, stub_object_id, stub_ip, object_name, public, original_id
						   FROM custum_proxy where deploy_id in (select Id from deployments where node_id = in_node_id and component_id =in_component_id)) as a
                    join
                    (select id, interface_name, class_name, method_domain_id from proxy_interface_relation) as b on b.id = a.proxy_interface_id)
                    join
                    (select id, name, standard_port from domain_method) as c on c.id = b.method_domain_id;						  
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.coustim_stubViewlistinfo 구조 내보내기
DELIMITER //
CREATE PROCEDURE `coustim_stubViewlistinfo`(IN `in_node_id` int, IN `in_component_id` int)
BEGIN
        if loginTest() then
                select 1 as test;
                  select a.id, a.deploy_id, a.stub_interface_id, a.object_id, b.interface_name, b.class_name,
						 c.name, c.id, c.standard_port, a.object_name, a.public, a.original_id from 
                    (select id, deploy_id, stub_interface_id, object_id, object_name, public, original_id FROM custum_stub
						   where deploy_id in (select Id from deployments where node_id = in_node_id and component_id =in_component_id)) as a
                    join
                    (select id, interface_name, class_name, method_domain_id from stub_interface_relation) as b on b.id = a.stub_interface_id
                    join
                    (select id, name, standard_port from domain_method) as c on c.id = b.method_domain_id;                 
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.coustum_proxyViewDeleteInterface 구조 내보내기
DELIMITER //
CREATE PROCEDURE `coustum_proxyViewDeleteInterface`(in_deploy_id int,
                                                              in_interface_id int)
BEGIN
        if loginTest() then
                select 1 as test;
                delete from custum_proxy where deploy_id = in_deploy_id and proxy_interface_id = in_interface_id;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.coustum_proxyViewNewobjectid 구조 내보내기
DELIMITER //
CREATE PROCEDURE `coustum_proxyViewNewobjectid`(in_deploy_id int,
                                                                  in_interface_id int,
                                                                  in_object_id int,
                                                                  in_object_name varchar(100))
BEGIN
        if loginTest() then
                select 1 as test;
                insert into custum_proxy (deploy_id, proxy_interface_id, object_id, object_name)
                                values(in_deploy_id, in_interface_id, in_object_id, in_object_name);
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.coustum_stubViewDeleteInterface 구조 내보내기
DELIMITER //
CREATE PROCEDURE `coustum_stubViewDeleteInterface`(in_deploy_id int,
                                                              in_interface_id int)
BEGIN
        if loginTest() then
                select 1 as test;
                delete from custum_stub where deploy_id = in_deploy_id and proxy_interface_id = in_interface_id;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.coustum_stubViewNewobjectid 구조 내보내기
DELIMITER //
CREATE PROCEDURE `coustum_stubViewNewobjectid`(in_deploy_id int,
                                                                  in_interface_id int,
                                                                  in_object_id int,
                                                                  in_object_name varchar(100))
BEGIN
        if loginTest() then
                select 1 as test;
                insert into custum_stub (deploy_id, stub_interface_id, object_id, object_name)
                                values(in_deploy_id, in_interface_id, in_object_id, in_object_name);
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.coustum_ViewEditobjectid 구조 내보내기
DELIMITER //
CREATE PROCEDURE `coustum_ViewEditobjectid`(IN `in_id` int, IN `in_object_id` int, IN `in_type` int, IN `in_public` int)
BEGIN
        if loginTest() then
                select 1 as test;
               if (in_type = 0) then
                   update custum_proxy set object_id=in_object_id, public=in_public where id = in_id;
               else
                   update custum_stub set object_id=in_object_id, public=in_public where id = in_id;
               end if;                
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.data_field_auto_seq 구조 내보내기
DELIMITER //
CREATE PROCEDURE `data_field_auto_seq`()
BEGIN

	declare no_more_rows bool default false;
	declare find_data_auto_id int;
	declare find_membername varchar(50);
	declare find_seq timestamp;

	DECLARE my_list CURSOR FOR 	
	select data_field.data_auto_id, data_field.member_name, data_field.seq from data_field;
 
	declare continue handler for not found set no_more_rows := TRUE;
	
	set max_sp_recursion_depth = 50;		 	
   
		open my_list;	
		my_loop : loop		
			fetch my_list into find_data_auto_id, find_membername, find_seq;
		
			 if no_more_rows then
				 close my_list;
				 leave my_loop;
			 end if;			 		
			 		 
			 	    call data_field_auto_seq_update(find_data_auto_id, find_membername, find_seq);
					
		end loop my_loop;		
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.data_field_auto_seq_update 구조 내보내기
DELIMITER //
CREATE PROCEDURE `data_field_auto_seq_update`(IN `in_data_auto_id` INT, IN `in_member_name` VARCHAR(50), IN `in_seq` TIMESTAMP)
BEGIN
	declare seq_count int default 0;	
	
	select count(data_field.seq) into seq_count from data_field
	 where data_field.data_auto_id = in_data_auto_id and data_field.seq = in_seq;
         
   if seq_count > 1 then
      select seq_count;
		 update data_field set data_field.seq = DATE_ADD(in_seq, INTERVAL -seq_count second)
		  where data_field.data_auto_id = in_data_auto_id and data_field.member_name=in_member_name;
	end if;	
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.delete_subsystem_object 구조 내보내기
DELIMITER //
CREATE PROCEDURE `delete_subsystem_object`(IN `in_custum_id` INT, IN `in_custum_deploy_id` INT, IN `in_type` INT)
BEGIN
   declare subsystem_deploy_id int;
	declare subsystem_proxy_count int;
	declare subsystem_stub_count int;
	declare subsystem_component_id int;	
	declare no_more_rows bool default false;	
	DECLARE my_list CURSOR FOR 
			select deployments.id from deployments where deployments.node_id in (
			select node.id from node where node.sub_system_domain_id in(
			 select deployments.systemdomain_id from deployments where deployments.Id=in_custum_deploy_id));
	declare continue handler for not found set no_more_rows := TRUE;		

	 if in_type = 0 then
  		select 1 as test;	
		 delete from custum_proxy where custum_proxy.original_id=in_custum_id
		  and custum_proxy.original_deployment_id=in_custum_deploy_id
		   and custum_proxy.Id !=in_custum_id and custum_proxy.deploy_id != in_custum_deploy_id;
 else
  	select 1 as test;
 		 delete from custum_stub where custum_stub.original_id=in_custum_id
		   and custum_stub.original_deployment_id=in_custum_deploy_id
			 and custum_stub.Id !=in_custum_id and custum_stub.deploy_id != in_custum_deploy_id;
 end if; 

set max_sp_recursion_depth = 50;

	open my_list;
			my_loop : loop						
				fetch my_list into subsystem_deploy_id;
				if no_more_rows then				
					close my_list;
					leave my_loop;
				end if;
				
				select count(custum_proxy.deploy_id) into subsystem_proxy_count from custum_proxy
				 where custum_proxy.deploy_id = subsystem_deploy_id;
 				select count(custum_stub.deploy_id) into subsystem_stub_count from custum_stub
				  where custum_stub.deploy_id =subsystem_deploy_id; 				
 				
 				if subsystem_proxy_count = 0 and subsystem_stub_count=0 then 
				 	select deployments.component_id into subsystem_component_id from deployments
					  where deployments.Id = 	subsystem_deploy_id;
 	 				  delete from component where component.id = subsystem_component_id;
 	 			end if;
	end loop my_loop;			
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.deployComponentViewInterfaceinfo 구조 내보내기
DELIMITER //
CREATE PROCEDURE `deployComponentViewInterfaceinfo`(IN `in_component_id` INT)
BEGIN

 	if logintest() then
 		select 1 as test;
 		
 		select a.id, a.method_domain_id, a.component_id, a.interface_name, b.name, a.class_name from
  		(select stub_interface_relation.Id, stub_interface_relation.method_domain_id, stub_interface_relation.component_id
		  , stub_interface_relation.interface_name, stub_interface_relation.class_name from stub_interface_relation where id in
			(select stub_interface_id from custum_stub where deploy_id in
			 (select id from deployments where component_id = in_component_id))) as a
		join domain_method as b on a.method_domain_id = b.id;
   else
   	select 0 as test;
   end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.deploymentsViewDeploymentslist 구조 내보내기
DELIMITER //
CREATE PROCEDURE `deploymentsViewDeploymentslist`(
	IN `in_systemdomainid` int,
	IN `in_componentid` int

)
BEGIN
     if loginTest() then
    select 1 as test;
         select Id, node_id, component_id, systemdomain_id from deployments
                     where systemdomain_id = in_systemdomainid and component_id = in_componentid;
         
     else
         select 0 as test;
     end if;       
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.deploymentsViewIdInfo 구조 내보내기
DELIMITER //
CREATE PROCEDURE `deploymentsViewIdInfo`(in_nodeid int,
                                                            in_componentid int)
BEGIN

     if loginTest() then
    select 1 as test;
         select Id from deployments where node_id = in_nodeid and component_id = in_componentid;
         
     else
         select 0 as test;
     end if;
     
     
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.deployments_bindTableNewBind 구조 내보내기
DELIMITER //
CREATE PROCEDURE `deployments_bindTableNewBind`(IN `in_deployment_id` INT, IN `in_node_id` INT, IN `in_port` INT, IN `in_ip` VARCHAR(255))
BEGIN

declare total_num int;

set total_num = 0;

	if logintest() then
		select 1 as test;
		select count(*) into total_num from deployments_bind where deployments_bind.deployment_id = in_deployment_id;
		
		if total_num = 0 then
			insert into deployments_bind (deployments_bind.deployment_id, deployments_bind.node_id, deployments_bind.port, deployments_bind.ip)
			       values(in_deployment_id,in_node_id,in_port,in_ip);
		else
			update deployments_bind set deployments_bind.port = in_port, deployments_bind.ip = in_ip
			 where deployments_bind.deployment_id = in_deployment_id;
		end if;
   else
      select 0 as test;
   end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.deployments_bind_table_info 구조 내보내기
DELIMITER //
CREATE PROCEDURE `deployments_bind_table_info`(IN `in_deployment_id` INT)
BEGIN
	if logintest() then
		select 1 as test;
		select deployments_bind.node_id, deployments_bind.port, deployments_bind.ip from deployments_bind
		 where deployments_bind.deployment_id = in_deployment_id;
	else 
		select 0 as test;
	end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.diagramViewList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `diagramViewList`(IN `indomainid` int)
BEGIN
     if loginTest() then
         select 1 as test;
         select Id, domain_id, type, name, description
          from diagrame where domain_id = indomainid;          
     else
         select 0 as test;
     end if;      
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.diagramViewNewDiagram 구조 내보내기
DELIMITER //
CREATE PROCEDURE `diagramViewNewDiagram`(in_domainid int,
                                                            in_type  int,
                                                            in_name  varchar(100),
                                                            in_description  text)
BEGIN        
        if loginTest() then
                select 1 as test;                
                insert into diagrame(domain_id, type, name, description )
                                 values(in_domainid, in_type, in_name, in_description);
                select LAST_INSERT_ID();               
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainAccountViewJoinPrivateDomain 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainAccountViewJoinPrivateDomain`(IN `in_domainname` varchar(100), IN `in_domainupperid` int, IN `in_domaintype` varchar(100))
BEGIN
     DECLARE domain_id int;
     DECLARE flag tinyint;
     set domain_id = 0;
     set flag =0;
     
        if loginTest() then
           select 1 as test;           
           select exitDomainId(in_domainname, in_domainupperid, in_domaintype) into domain_id;           
           select existMemberDomain(domain_id, @nervuser, in_domaintype) into flag;
           
           if(flag <= 0) then         
                   if(in_domaintype ='data') then
                     insert into members_domain_data(domain_id, user_id, member_type) values(domain_id,@nervuser,'guest');
                   end if;
                   if(in_domaintype ='method') then
                      insert into members_domain_method(domain_id, user_id, member_type) values(domain_id,@nervuser,'guest');              
                   end if;
                   if(in_domaintype ='system') then
                       insert into members_domain_system(domain_id, user_id, member_type) values(domain_id,@nervuser,'guest');
                   end if;                      
           end if;           
           select domain_id as test;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainDataInfo 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainDataInfo`(domain_idkey int, domaintype varchar(50))
BEGIN
        if loginTest() and domainReadTest(domain_idkey, domaintype) then
                select 1 as test;
                  select id , upper_id, name , user_id, public, create_date, last_update, description
                    from domain_data where id=domain_idkey;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainId 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainId`(domainnamekey varchar(100), domaintype varchar(100))
BEGIN
        
        if loginTest() then
                select 1 as test;

                       if(domaintype='data') then
                        select id from domain_data where name = domainnamekey;
                       end if;
                       if(domaintype='method') then
                        select id from domain_method where name = domainnamekey;
                       end if;
                       if(domaintype='system') then
                        select id from domain_system where name = domainnamekey; 
                       end if;

       else
               select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainLogicalPortViewDeletePort 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainLogicalPortViewDeletePort`(IN `in_system_domain_id` int, IN `in_port_group` int)
BEGIN
     if loginTest() and logical_port_group_count(in_system_domain_id, in_port_group)=0 then
         select 1 as test;
         delete from domain_system_logical_port where domain_system_id = in_system_domain_id and port_group = in_port_group;
     else
         select 2 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainLogicalPortViewNewPortGroup 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainLogicalPortViewNewPortGroup`(in_domain_id int, in_group int)
BEGIN
     if loginTest() and logical_port_group_count(in_domain_id, in_group)=0 then
         select 1 as test;
         insert into domain_system_logical_port(domain_system_id, port_group)
                           values(in_domain_id, in_group);
     else
         select 0 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainLogicalViewlist 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainLogicalViewlist`(IN `in_domain_id` INT)
BEGIN

  if logintest() then
  select 1 as test;
  	select port_group from domain_system_logical_port where domain_system_id = in_domain_id;
  else
    select 0 as test;
  end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainMethodInfo 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainMethodInfo`(domain_idkey int, domaintype varchar(50))
BEGIN
        if loginTest() and domainReadTest(domain_idkey, domaintype) then
                select 1 as test;
                  select id , upper_id, name , user_id, public, standard_port, create_date, last_update, description
                    from domain_method where id=domain_idkey;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainName 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainName`(idkey varchar(100), domaintype varchar(100))
BEGIN
        
        if loginTest() then
                select 1 as test;
                       if(domaintype='data') then
                        select name from domain_data where id = idkey;
                       end if;
                       if(domaintype='method') then
                        select name from domain_method where id = idkey;
                       end if;
                       if(domaintype='system') then
                        select name from domain_system where id = idkey; 
                       end if;

       else
               select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainnametoid 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainnametoid`(domain_name varchar(100), domaintype varchar(100))
BEGIN
        
        if loginTest() then
                select 1 as test;
                       if(domaintype='data') then
                        select id from domain_data where name = domain_name;
                       end if;
                       if(domaintype='method') then
                        select id from domain_method where name = domain_name;
                       end if;
                       if(domaintype='system') then
                        select id from domain_system where name = domain_name;
                       end if;

       else
               select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainPortViewDeletePort 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainPortViewDeletePort`(in_system_domain_id int, in_port_num int)
BEGIN
     if loginTest() then
         select 1 as test;
         delete from domain_system_port where domain_system_id = in_system_domain_id and port_num = in_port_num;
     else
         select 0 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainPortViewEditPort 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainPortViewEditPort`(IN `in_system_domain_id` int, IN `in_port_key` int, IN `in_port_edit` int, IN `in_port_group` int, IN `in_description_edit` varchar(100))
BEGIN
     if loginTest() then
         select 1 as test;
         UPDATE domain_system_port set port_num=in_port_edit, port_group=in_port_group, description=in_description_edit
			 where domain_system_id = in_system_domain_id and port_num = in_port_key;
     else
         select 0 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainPortViewNewPort 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainPortViewNewPort`(in_domain_id int, in_port int, in_port_group int, in_description varchar(100))
BEGIN
     if loginTest() then
         select 1 as test;
         insert into domain_system_port(domain_system_id, port_num, port_group, description)
                           values(in_domain_id, in_port, in_port_group, in_description);
     else
         select 0 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainviewCheckOverlapDomainName 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainviewCheckOverlapDomainName`(IN `in_domain_id` INT, IN `in_upper_id` INT, IN `in_domain_name` VARCHAR(50), IN `in_domain_type` VARCHAR(50))
BEGIN
  if loginTest() then
     select 1 as test;
     if in_domain_type='data' then
     		select * from domain_data where domain_data.upper_id=in_upper_id and domain_data.name=in_domain_name and domain_data.id != in_domain_id;
     end if;
     
     if in_domain_type='method' then
     	   select * from domain_method where domain_method.upper_id=in_upper_id and domain_method.name=in_domain_name and domain_method.id != in_domain_id;
     end if;
     
     if in_domain_type='system' then
         select * from domain_system where domain_system.upper_id=in_upper_id and domain_system.name=in_domain_name and domain_system.id != in_domain_id;
     end if;
  else
  		select 0 as test;
  end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainViewDeleteDomain 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainViewDeleteDomain`(domain_id int, domain_type varchar(50) )
BEGIN
        if loginTest() and domainWriteTest(domain_id, domain_type) then
                select 1 as test;
                
                if(domain_type = 'method') then
                        delete from domain_method where id=domain_id;
               end if;

                if (domain_type = 'data') then
                        delete from domain_data where id=domain_id;
               end if;

                if (domain_type = 'system') then
                        delete from domain_system where id=domain_id;
                end if;  

        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainViewDeleteParentDomain 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainViewDeleteParentDomain`(domain_idvalue int, domaintype varchar(100), parentdomain_idvalue int, parentdomain_type int)
BEGIN

        if loginTest() and domainWriteTest(domain_idvalue, domaintype) then
                select 1 as test;
                if parentdomain_type = 0 then
                   delete from inheritance_data_data where domain_id = domain_idvalue and parent_domain_id = parentdomain_idvalue;
               end if;
                if parentdomain_type = 1 then
                   delete from inheritance_method_data where domain_id = domain_idvalue and parent_domain_id = parentdomain_idvalue;
               end if;
                if parentdomain_type = 2 then
                   delete from inheritance_method_method where domain_id = domain_idvalue and parent_domain_id = parentdomain_idvalue;
               end if;
                if parentdomain_type = 3 then
                   delete from inheritance_system_method where domain_id = domain_idvalue and parent_domain_id = parentdomain_idvalue;
               end if;
         else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainViewDomainInfo 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainViewDomainInfo`(domain_idkey int, domaintype varchar(50))
BEGIN
        if loginTest() and domainReadTest(domain_idkey, domaintype) then
                select 1 as test;
                
                if(domaintype = 'data') then
                   select a.name , u.user_id, u.userdesc , b.* , c.mcnt, d.*, a.public, a.description, a.create_date, a.last_update  from
                                ( select * from domain_data where id=domain_idkey) as a
                   join        ( select user_id,description as userdesc from users ) as u on a.user_id = u.user_id
                   join        ( select count(name) as scnt from data where domain_id=domain_idkey ) as b
                   join        ( select count(domain_id) as mcnt from inheritance_method_data where parent_domain_id=domain_idkey ) as c
                   join        ( select count(name) as icnt from interface where domain_id=domain_idkey ) as d;
                end if;
                if(domaintype = 'method') then
                   select a.name , u.user_id, u.userdesc , a.standard_port,  b.* , c.mcnt,d.*, a.public, a.description, a.create_date, a.last_update from
                                 ( select * from domain_method where id=domain_idkey) as a
                   join        ( select user_id,description as userdesc from users ) as u on a.user_id = u.user_id
                   join        ( select count(domain_id) as scnt from inheritance_method_data where domain_id=domain_idkey ) as b
                   join        ( select count(name) as mcnt from method where domain_id=domain_idkey ) as c
                   join        ( select count(domain_id) as icnt from interface where domain_id=domain_idkey ) as d;
                end if;
                if(domaintype = 'system') then
                   select a.name , u.user_id, u.userdesc , b.* , c.mcnt,d.*, a.public, a.description,a.create_date, a.last_update  from
                                ( select * from domain_system where id=domain_idkey) as a
                   join        ( select user_id,description as userdesc from users ) as u on a.user_id = u.user_id
                   join        ( select count(name) as scnt from data where domain_id=domain_idkey ) as b
                   join        ( select count(name) as mcnt from method where domain_id=domain_idkey ) as c
                   join        ( select count(name) as icnt from interface where domain_id=domain_idkey ) as d;
                end if;

        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainViewEditDomain 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainViewEditDomain`(IN `domain_idkey` int, IN `domaintypevalue` varchar(50), IN `edit_domain_name` varchar(100), IN `standardportvalue` smallint(5) unsigned, IN `publicvalue` bool, IN `descriptionvalue` text)
BEGIN
        declare cnt int;
        set cnt = 0;

        if loginTest() and domainWriteTest(domain_idkey, domaintypevalue) then
                select 1 as test;
                if (domaintypevalue='data') then
                        update domain_data set name=edit_domain_name, public=publicvalue,description=descriptionvalue where id=domain_idkey;
                end if;
                if (domaintypevalue='method') then
                        update domain_method set  name=edit_domain_name, standard_port=standardportvalue, public=publicvalue,description=descriptionvalue
								 where id=domain_idkey;
                end if;
                if (domaintypevalue='system') then
                        update domain_system set  name=edit_domain_name, public=publicvalue,description=descriptionvalue where id=domain_idkey;
                end if;
                       
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainViewEditDomainName 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainViewEditDomainName`(domain_idkey int,
                                                               domaintypevalue varchar(50),
                                                               edit_domain_name varchar(100))
BEGIN
        declare cnt int;
        set cnt = 0;

        if loginTest() and domainWriteTest(domain_idkey, domaintypevalue) then
                select 1 as test;
                if (domaintypevalue='data') then
                        update domain_data set name=edit_domain_name where id=domain_idkey;
                end if;
                if (domaintypevalue='method') then
                        update domain_method set  name=edit_domain_name where id=domain_idkey;
                end if;
                if (domaintypevalue='system') then
                        update domain_system set  name=edit_domain_name where id=domain_idkey;
                end if;                       
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainViewEditUpperIDDomain 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainViewEditUpperIDDomain`(in_domain_id_key int, in_edit_upper_id int, in_domain_type varchar(50))
BEGIN
       if loginTest() and domainWriteTest(in_domain_id_key, in_domain_type) then
                select 1 as test;
                if (in_domain_type='data') then
                        update domain_data set upper_id=in_edit_upper_id where id=in_domain_id_key;
                end if;
                if (in_domain_type='method') then
                        update domain_method set  upper_id=in_edit_upper_id where id=in_domain_id_key;
                end if;
                if (in_domain_type='system') then
                        update domain_system set  upper_id=in_edit_upper_id where id=in_domain_id_key;
                end if;
                       
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainViewNewDomain 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainViewNewDomain`(domaintype varchar(50),
                                                          upper_idvalue  int,
                                                           namevalue varchar(100),
                                                           standardportvalue int,
                                                           publicvalue bool,
                                                           descriptionvalue text)
BEGIN
        declare nd bool;
        declare cnt int default 0;
        
        set nd = false;
        set @logdate = DATE_FORMAT(DATE_ADD(SYSDATE(), INTERVAL 0 DAY), '%Y%m%d%H%i%s');
        
        
        if loginTest() and newDomainTest() then
                select 1 as test;
                if (domaintype='data') then
                insert into domain_data(upper_id, name, user_id, public, create_date, last_update,description )
                                 values(upper_idvalue, namevalue, @nervuser, publicvalue, @logdate, @logdate,descriptionvalue);
                select LAST_INSERT_ID(); 
                end if;
                if (domaintype='method') then
                insert into domain_method(upper_id, name, user_id, public,  standard_port, create_date, last_update,description )
                                 values(upper_idvalue, namevalue, @nervuser, publicvalue, standardportvalue, @logdate, @logdate,descriptionvalue);
                select LAST_INSERT_ID();
                end if;
                if (domaintype='system') then
                 select count(name) into cnt from domain_system where name=namevalue and upper_id = upper_idvalue;
                 if cnt > 0 then
                        select 0 as test;
                else
                       insert into domain_system(upper_id, name, user_id, public, create_date, last_update,description )
                                          values(upper_idvalue, namevalue, @nervuser, publicvalue, @logdate, @logdate,descriptionvalue);
                       select LAST_INSERT_ID();                
                end if;
               end if;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainViewNewParentCandidateList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainViewNewParentCandidateList`(IN `domain_idkey` int, IN `domaintype` varchar(50), IN `parentdomain_type` int)
BEGIN
        if loginTest() and domainWriteTest(domain_idkey, domaintype) then
                select 1 as test;
                if( supermanagerTest(@nervuser) ) then
                       if(parentdomain_type=0) then                                    
                                select * from domain_data where id not in
                                 (select parent_domain_id from inheritance_data_data where domain_id=domain_idkey) order by id desc;
                        end if;
                           if(parentdomain_type=1) then                                    
                                select * from domain_data where id not in
                                 (select parent_domain_id from inheritance_method_data where domain_id=domain_idkey) order by id desc;
                        end if;
                           if(parentdomain_type=2) then                                    
                                select * from domain_method where id not in
                                 (select parent_domain_id from inheritance_method_method where domain_id=domain_idkey) order by id desc;
                        end if;
                           if(parentdomain_type=3) then                                    
                                select * from domain_system where id not in
                                 (select parent_domain_id from inheritance_system_method where domain_id=domain_idkey) order by id desc;
                        end if;
                else
                        if(parentdomain_type=0) then
                         select * from domain_data where (user_id=@nervuser or public =1)
                                                     and (id not in (select parent_domain_id FROM inheritance_data_data where domain_id= domain_idkey))
                                                     and (id != 0);
                        end if;
                        if(parentdomain_type=1) then
                          select * from domain_data where (user_id=@nervuser or public =1)
                                                     and (id not in (select parent_domain_id FROM inheritance_method_data where domain_id= domain_idkey))
                                                     and (id != 0);
                        end if;
                        if(parentdomain_type=2) then
                          select * from domain_method where (user_id=@nervuser or public =1)
                                                     and (id not in (select parent_domain_id FROM inheritance_method_method where domain_id= domain_idkey));                               
                        end if;
                        if(parentdomain_type=3) then
                                select * from
                                (
                                        (
                                          select domain_id from members_domain_system where user_id=@nervuser 
														and (member_type='manager' or member_type='member')
                                        )
                                        union distinct
                                        (
                                                select domain_id from domain_system where (user_id=@nervuser or public=true )
                                        ) order by domain_id desc
                                ) as a
                                where  domain_id not in
                                        (select parent_domain_id from inheritance_system_method where domain_id=domain_idkey);
                        end if;
                end if;
       else
               select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainViewNewParentDomain 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainViewNewParentDomain`(IN `domain_idkey` int, IN `domaintype` varchar(50), IN `parent_domain_idkey` int, IN `parentdomaintype` int)
BEGIN
        declare uid varchar(100);

        if loginTest() and domainWriteTest(domain_idkey, domaintype)
                       and existDomain(domain_idkey, domaintype) then
            select 1 as test;
                if parentdomaintype=0 then
                   if(domain_idkey != parent_domain_idkey and existDomain(parent_domain_idkey, domaintype)) then
                          insert into inheritance_data_data(domain_id,parent_domain_id) values(domain_idkey,parent_domain_idkey);
                   else
                       select 0;
                   end if;
                end if;
                if parentdomaintype=1 then
                   if(existDomain(parent_domain_idkey, 'data')) then
                          insert into inheritance_method_data(domain_id,parent_domain_id) values(domain_idkey,parent_domain_idkey);
                    else
                       select 0;
                   end if;
                end if;
                if parentdomaintype=2 then
                   if (method_domainCompatibleTest(domain_idkey,parent_domain_idkey, parentdomaintype)
						  and domain_idkey != parent_domain_idkey and existDomain(parent_domain_idkey, domaintype)) then
                      insert into inheritance_method_method(domain_id,parent_domain_id) values(domain_idkey,parent_domain_idkey);
                   else
                        select 2 as test;
                   end if;
                end if;
                if parentdomaintype=3 then
                if(domain_idkey != parent_domain_idkey and existDomain(parent_domain_idkey, domaintype)) then
                   insert into inheritance_system_method(domain_id,parent_domain_id) values(domain_idkey,parent_domain_idkey);
                 else
                       select 0;
                 end if;
                end if;

        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domainViewUpperList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domainViewUpperList`(in_upper_idkey varchar(100), domaintype varchar(100))
BEGIN
        
        if loginTest() then
                select 1 as test;
                       if(domaintype='data') then
                        select id,name, upper_id, user_id,create_date, last_update, description from domain_data where upper_id = in_upper_idkey;
                       end if;
                       if(domaintype='method') then
                        select id, name, upper_id, user_id, public, create_date, last_update, description from domain_method where upper_id = in_upper_idkey;
                       end if;
                       if(domaintype='system') then
                        select id,name, upper_id, user_id, create_date, last_update, description from domain_system where upper_id = in_upper_idkey;
                       end if;

       else
               select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.domain_table_Info 구조 내보내기
DELIMITER //
CREATE PROCEDURE `domain_table_Info`(domain_idkey int, domaintype varchar(50))
BEGIN
        if loginTest() and domainReadTest(domain_idkey, domaintype) then
                select 1 as test;
                
                if(domaintype = 'data') then
                   select id , upper_id, name , user_id, public, create_date, last_update, description  from domain_data where id=domain_idkey;
                end if;
                if(domaintype = 'method') then
                 select id , upper_id, name , user_id, public, standard_port, create_date, last_update, description  from domain_method where id=domain_idkey;
                end if;
                if(domaintype = 'system') then
                                 select id , upper_id, name , user_id, public, create_date, last_update, description  from domain_system where id=domain_idkey;
                end if;

        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.draw_deployComponentProxyInterfaceList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `draw_deployComponentProxyInterfaceList`(IN `in_systemdomain_id` INT, IN `in_node_id` INT, IN `in_component_id` INT)
BEGIN

        if loginTest() then
                select 1 as test;
                 select a.id, a.deploy_id, a.proxy_interface_id, b.interface_name, b.class_name, a.object_id, a.stub_object_id, a.stub_ip,
					   c.name, c.id, c.standard_port, a.object_name, a.public, a.original_id, g.component_id from 
						(
    						((select id, deploy_id, proxy_interface_id, object_id, stub_object_id, stub_ip, object_name, public, original_id FROM custum_proxy
							  where deploy_id in(select Id from deployments where node_id = in_node_id and component_id = in_component_id)) as a
       						join
       					(select id, interface_name, class_name, method_domain_id from proxy_interface_relation) as b on b.id = a.proxy_interface_id)
       						join
       					(select id, name, standard_port from domain_method) as c on c.id = b.method_domain_id                    
       						join		 					
							(select deployments_bind.deployment_id, deployments_bind.ip from deployments_bind) as d on d.ip = a.stub_ip                    
					       	join
					      (select id, node_id, systemdomain_id from deployments) as e on e.id = d.deployment_id and e.systemdomain_id = in_systemdomain_id                    
					       	join
					      (select deploy_id, object_id from custum_stub) as f on f.object_id = a.stub_object_id and f.deploy_id = e.id                    
					       	join
					      (select id, component_id from deployments) as g on g.id = f.deploy_id                   
						) group by g.component_id, a.id,a.deploy_id,a.proxy_interface_id;                
						  
        else
                select 0 as test;
        end if;



END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.ExposedInterfaceViewInterfaceList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `ExposedInterfaceViewInterfaceList`(in_component_id int)
BEGIN
        if loginTest() then
                select 1 as test;
                select method_domain_id, interface_name from proxy_interface_relation where component_id = in_component_id
                UNION
                SELECT method_domain_id, interface_name from stub_interface_relation where component_id = in_component_id;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.get_domain_path 구조 내보내기
DELIMITER //
CREATE PROCEDURE `get_domain_path`(IN `in_domain_id_key` INT, IN `in_domain_type` VARCHAR(50))
BEGIN

	if in_domain_type = 'method' then
		select 1 as test;
		select(domainMethodPath(in_domain_id_key,''))  As path;
	end if;
	
	if in_domain_type = 'data' then
		select 1 as test;
		select(domainDataPath(in_domain_id_key,''))  As path;
	end if;
	
		if in_domain_type = 'system' then
   	select 1 as test;
		select(domainSystemPath(in_domain_id_key,''))  As path;
	end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.inheritanceSystemMethodViewDeleteparent 구조 내보내기
DELIMITER //
CREATE PROCEDURE `inheritanceSystemMethodViewDeleteparent`(in_domain_id int,
                                                                              in_parent_domain_id int)
BEGIN
        if loginTest() then
                select 1 as test;
                delete from inheritance_system_method where domain_id = in_domain_id and parent_domain_id = in_parent_domain_id;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.inheritanceSystemMethodViewNewparent 구조 내보내기
DELIMITER //
CREATE PROCEDURE `inheritanceSystemMethodViewNewparent`(in_domain_id int,
                                                                           in_parent_domain_id int)
BEGIN
        if loginTest() and inheritanceSystemMehtodParentOverlapCheck(in_domain_id, in_parent_domain_id) then
                select 1 as test;
                insert into inheritance_system_method(domain_id, parent_domain_id)
                                      values(in_domain_id, in_parent_domain_id);
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.inheritance_data_dataViewDomainList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `inheritance_data_dataViewDomainList`(IN `domain_idkey` int)
BEGIN

        if loginTest() and domainReadTest(domain_idkey, 'data') then
           select 1 as test;
				
				
				select d.* from 
				(
					select domain_id from data where data.data_auto_id in (select data.real_data_auto_id from data where data.domain_id=domain_idkey and data.`type`='alias')
					union 
					select domain_id from data where data.data_auto_id in(select data_field.real_data_auto_id from data_field
					 where data_field.`type`='alias' and data_field.data_auto_id in
					  (select data.data_auto_id from data where data.domain_id=domain_idkey))
				)as m join domain_data as d on m.domain_id=d.id and d.id != domain_idkey;
			
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.inheritance_method_dataViewDomainList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `inheritance_method_dataViewDomainList`(IN `domain_idkey` int)
BEGIN

        if loginTest() and domainReadTest(domain_idkey, 'method') then
           select 1 as test;
           select d.* from
			  (
					select domain_id from data where data.data_auto_id in (select method.in_data_auto_id from method where method.domain_id=domain_idkey)
					union
					select domain_id from data where data.data_auto_id in	(select method.out_data_auto_id from method where method.domain_id=domain_idkey)
				)as m join domain_data as d on m.domain_id=d.id;



        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.inheritance_method_methodViewDomainList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `inheritance_method_methodViewDomainList`(domain_idkey int)
BEGIN

        if loginTest() and domainReadTest(domain_idkey, 'method') then
           select 1 as test;

            SELECT b.* from 
            (select * from inheritance_method_method where domain_id=domain_idkey) as a
             join
            (select * from domain_method ) as b on a.parent_domain_id = b.id ;

        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.inheritance_system_methodViewDomainList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `inheritance_system_methodViewDomainList`(domain_idkey int)
BEGIN

        if loginTest() and domainReadTest(domain_idkey, 'method') then
           select 1 as test;

            SELECT b.* from 
            (select * from inheritance_system_method where domain_id=domain_idkey) as a
             join
            (select * from domain_method ) as b on a.parent_domain_id = b.id ;

        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.insertProxyInserfaceRelation 구조 내보내기
DELIMITER //
CREATE PROCEDURE `insertProxyInserfaceRelation`(IN `in_system_domain_id` VARCHAR(255), IN `in_component_id` INT, IN `in_method_domain_id` INT, IN `in_interface_name` VARCHAR(255), IN `in_class_name` VARCHAR(255), IN `in_object_name` VARCHAR(255))
BEGIN
 declare select_interface_realation_id_key int;
 declare new_proxy_interface_realation_id int;
 set select_interface_realation_id_key=0;		 
		 
		  select id into select_interface_realation_id_key from proxy_interface_relation
		 		 where  component_id=in_component_id and method_domain_id=in_method_domain_id and interface_name=in_interface_name and class_name=in_class_name;
		 
		  if select_interface_realation_id_key = 0 then
 			select 1 as check_count;
 			insert into proxy_interface_relation (component_id, method_domain_id, interface_name, class_name)
                                values(in_component_id, in_method_domain_id, in_interface_name, in_class_name);
                                
         select last_insert_id() into new_proxy_interface_realation_id;
         
          insert into proxy_interface_object (proxy_interface_id, object_name, component_id)
                                values(new_proxy_interface_realation_id, in_object_name, in_component_id);
          
          insert into custum_proxy (deploy_id, proxy_interface_id, object_name)
                     select id, new_proxy_interface_realation_id, in_object_name from deployments where systemdomain_id = in_system_domain_id and component_id = in_component_id;
 		  else
 		   select 2 as check_count;
 		   insert into proxy_interface_object (proxy_interface_id, object_name, component_id)
                                values( select_interface_realation_id_key, in_object_name, in_component_id);
										   
			insert into custum_proxy (deploy_id, proxy_interface_id, object_name)
                     select id, select_interface_realation_id_key, in_object_name from deployments where systemdomain_id = in_system_domain_id and component_id = in_component_id;
		  end if; 	
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.insertStubInserfaceRelation 구조 내보내기
DELIMITER //
CREATE PROCEDURE `insertStubInserfaceRelation`(IN `in_system_domain_id` VARCHAR(255), IN `in_component_id` INT, IN `in_method_domain_id` INT, IN `in_interface_name` VARCHAR(255), IN `in_class_name` VARCHAR(255), IN `in_object_name` VARCHAR(255))
BEGIN
 declare select_interface_realation_id_key int;
 declare new_stub_interface_realation_id int;
 
 set select_interface_realation_id_key=0;
 		 
		  select id into select_interface_realation_id_key from stub_interface_relation
		 		 where  component_id=in_component_id and method_domain_id=in_method_domain_id and interface_name=in_interface_name and class_name=in_class_name;
		 
		  if select_interface_realation_id_key = 0 then
 			select 1 as check_count;
 			insert into stub_interface_relation (component_id, method_domain_id, interface_name, class_name)
                                values(in_component_id, in_method_domain_id, in_interface_name, in_class_name);
                                
         select last_insert_id() into new_stub_interface_realation_id;
         
          insert into stub_interface_object (stub_interface_id, object_name, component_id)
                                values(new_stub_interface_realation_id, in_object_name, in_component_id);
          
          insert into custum_stub (deploy_id, stub_interface_id, object_name)
                     select id, new_stub_interface_realation_id, in_object_name from deployments
							 where systemdomain_id = in_system_domain_id and component_id = in_component_id;
 		  else
 		   select 2 as check_count;
 		   insert into stub_interface_object (stub_interface_id, object_name, component_id)
                                values( select_interface_realation_id_key, in_object_name, in_component_id);
										   
			insert into custum_stub (deploy_id, stub_interface_id, object_name)
                     select id, select_interface_realation_id_key, in_object_name from deployments
							 where systemdomain_id = in_system_domain_id and component_id = in_component_id;
		  end if; 	
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.insert_component_deployments_custum 구조 내보내기
DELIMITER //
CREATE PROCEDURE `insert_component_deployments_custum`(IN `in_deployment_id` INT, IN `in_subsystem_domain_id` int, IN `in_node_id` int, IN `in_component_id` int, IN `in_systemdomain_id` int, IN `in_component_name` varchar(100), IN `in_component_description` varchar(100), IN `in_original_node_id` INT)
BEGIN
declare new_component_id int;
declare new_deployment_id int;
declare proxy_object_count int;
declare stub_object_count int;
declare computer_node_id int;

select count(id) into proxy_object_count from custum_proxy where custum_proxy.public=1 and custum_proxy.deploy_id = in_deployment_id;
select count(id) into stub_object_count from custum_stub where custum_stub.public=1 and custum_stub.deploy_id = in_deployment_id;

if (proxy_object_count !=0 or stub_object_count !=0) then
	insert into component (systemdomain_id, name, description)
	values (in_subsystem_domain_id, in_component_name, in_component_description);
	select Last_INSERT_ID() into new_component_id;
	
	insert into deployments (node_id, component_id, systemdomain_id, original_id)
	values(in_node_id, new_component_id, in_subsystem_domain_id, in_deployment_id);
	select Last_INSERT_ID() into new_deployment_id;

	insert into custum_proxy (deploy_id, proxy_interface_id, object_name, object_id, stub_object_id, stub_ip, original_id, original_deployment_id)
 	select new_deployment_id, proxy_interface_id, object_name, object_id, stub_object_id, stub_ip, Id, deploy_id from custum_proxy where custum_proxy.public=1 and deploy_id in
 	(select id from deployments where component_id = in_component_id and systemdomain_id = in_systemdomain_id);
 
 	insert into custum_stub (deploy_id, stub_interface_id, object_name, object_id, original_id, original_deployment_id)
 	select new_deployment_id, stub_interface_id, object_name, object_id, Id, deploy_id from custum_stub where custum_stub.public=1 and deploy_id in
 	(select id from deployments where component_id = in_component_id and systemdomain_id = in_systemdomain_id); 	

	 	insert into deployments_bind (deployments_bind.deployment_id, deployments_bind.node_id, deployments_bind.port, deployments_bind.ip)						
			select new_deployment_id, b.node_id, b.port, b.ip from	
			(   		
				(select deployments_bind.node_id, deployments_bind.port, deployments_bind.ip from deployments_bind where node_id =in_original_node_id and deployment_id=in_deployment_id) as a 
				join
				(select network.node_id, network.port, network.ip from network where node_id =in_node_id) as b on b.ip = a.ip 
			) where b.node_id is not NULL;				
	
end if;	
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.insert_subsystem_component 구조 내보내기
DELIMITER //
CREATE PROCEDURE `insert_subsystem_component`(IN `in_node_id` int)
BEGIN
	declare domain_id int;
 	declare sub_domain_id int; 	
 	declare depth int;	
	declare no_more_rows bool default false;
	declare deployment_id int;
	declare component_id int;
 	declare component_system_domain_id int;
   declare component_name varchar(100);
   declare component_description varchar(100);	   
	
	DECLARE my_list CURSOR FOR select a.id, c.id, c.systemdomain_id, c.name, c.description from
	
  (select deployments.Id, deployments.component_id from deployments where (node_id,systemdomain_id)
   in (select id,systemdomain_id from node where systemdomain_id=sub_domain_id)) as a
  join  
  (select * from component) as c on c.id = a.component_id group by c.id;

	declare continue handler for not found set no_more_rows := TRUE;
	
	set max_sp_recursion_depth = 50;
	set depth=10;
		
	if depth > 0 then
	Select node.systemdomain_id into domain_id from node where node.id = in_node_id;
   Select node.sub_system_domain_id into sub_domain_id from node where node.id = in_node_id;      

		open my_list;	
			my_loop : loop		
			fetch my_list into deployment_id, component_id, component_system_domain_id, component_name, component_description;
			if no_more_rows then
				close my_list;
				leave my_loop;
			end if;					
	
	  call insert_component_deployments_custum(deployment_id, domain_id, in_node_id, component_id, component_system_domain_id, component_name, component_description);

			set depth = depth -1;
		end loop my_loop;		
	 end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.insert_subsystem_custum_interface 구조 내보내기
DELIMITER //
CREATE PROCEDURE `insert_subsystem_custum_interface`(IN `in_subsystem_deployment_id` INT, IN `in_original_custum_id` INT, IN `in_original_custum_deployment_id` INT, IN `in_object_type` INT)
BEGIN
 if(in_object_type = 0) then
	 insert into custum_proxy (custum_proxy.deploy_id, custum_proxy.proxy_interface_id, custum_proxy.object_name,
	 									 custum_proxy.object_id, custum_proxy.stub_object_id, custum_proxy.stub_ip, custum_proxy.public,
										  custum_proxy.original_id, custum_proxy.original_deployment_id)
 	  select in_subsystem_deployment_id, custum_proxy.proxy_interface_id, custum_proxy.object_name, custum_proxy.object_id,
		 custum_proxy.stub_object_id, custum_proxy.stub_ip, 0, in_original_custum_id, in_original_custum_deployment_id
     from custum_proxy where custum_proxy.Id = in_original_custum_id and custum_proxy.deploy_id = in_original_custum_deployment_id;
 else 	
	 insert into custum_stub (custum_stub.deploy_id, custum_stub.stub_interface_id, custum_stub.object_name,
	 									 custum_stub.object_id, custum_stub.public, custum_stub.original_id,
										   custum_stub.original_deployment_id)
 	  select in_subsystem_deployment_id, custum_stub.stub_interface_id, custum_stub.object_name,
		 custum_stub.object_id, 0, in_original_custum_id, in_original_custum_deployment_id
     from custum_stub where custum_stub.Id = in_original_custum_id and custum_stub.deploy_id = in_original_custum_deployment_id; 
 end if;

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.insert_subsystem_custum_interface_loop 구조 내보내기
DELIMITER //
CREATE PROCEDURE `insert_subsystem_custum_interface_loop`(IN `in_custum_id` INT, IN `in_deployments_id` INT, IN `in_object_type` INT)
BEGIN
	declare sub_system_deploy_id int;
	declare subsystem_node_id int;
	declare no_more_rows bool default false;
	declare deploy_sub_component int default 0;	 	
	declare 	orginal_domain_id int;		
	declare 	orginal_component_id int;
	declare 	orginal_node_id int;
   declare subsystem_domain_id int;
   declare component_id int;
   declare component_system_domain_id int;
   declare component_name varchar(100);
   declare component_description varchar(100);		

		DECLARE my_list CURSOR FOR 
			select node.id from node where node.sub_system_domain_id in( select deployments.systemdomain_id from deployments where deployments.Id=in_deployments_id);
		declare continue handler for not found set no_more_rows := TRUE;

		set max_sp_recursion_depth = 50;

			open my_list;
			my_loop : loop						
				fetch my_list into subsystem_node_id;
				if no_more_rows then				
					close my_list;
					leave my_loop;
				end if;				
				
				select count(deployments.Id) into deploy_sub_component from deployments where deployments.node_id = subsystem_node_id and deployments.original_id = in_deployments_id;
	      	
	      	if deploy_sub_component = 0 then					
					 select deployments.systemdomain_id into orginal_domain_id from deployments where deployments.Id=in_deployments_id;					
					 select deployments.component_id into orginal_component_id from deployments where deployments.Id=in_deployments_id;										
					 select deployments.node_id into orginal_node_id from deployments where deployments.Id=in_deployments_id;	
					 select systemdomain_id into subsystem_domain_id  from node where node.Id = subsystem_node_id;								
			 		 select component.id into component_id from component where id = orginal_component_id;
			 		 select component.systemdomain_id into component_system_domain_id from component where id = orginal_component_id;
			 		 select component.name into component_name from component where id = orginal_component_id;
					 select component.description into component_description from component where id = orginal_component_id;			   				
					 	 				 
 					 call insert_component_deployments_custum(in_deployments_id,  subsystem_domain_id, subsystem_node_id, component_id, component_system_domain_id, component_name, component_description,orginal_node_id);			
 					 
 				else
 				   select deployments.Id into sub_system_deploy_id from deployments where deployments.node_id = subsystem_node_id and deployments.original_id = in_deployments_id;
 				   
					call insert_subsystem_custum_interface( sub_system_deploy_id, in_custum_id, in_deployments_id, in_object_type);		
				end if;		
			
			end loop my_loop;	
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.insert_subsystem_custum_interface_loop_new_subsystem 구조 내보내기
DELIMITER //
CREATE PROCEDURE `insert_subsystem_custum_interface_loop_new_subsystem`(IN `in_custum_id` INT, IN `in_deployments_id` INT, IN `in_object_type` INT)
BEGIN
	declare sub_system_deploy_id int;
	declare subsystem_node_id int;
	declare no_more_rows bool default false;
	declare deploy_sub_component int default 0;	 	
	declare 	orginal_domain_id int;		
	declare 	orginal_component_id int;
	declare 	orginal_node_id int;
   declare subsystem_domain_id int;
   declare component_id int;
   declare component_system_domain_id int;
   declare component_name varchar(100);
   declare component_description varchar(100);		

		DECLARE my_list CURSOR FOR 
			select node.id from node where node.sub_system_domain_id in
			( select deployments.systemdomain_id from deployments where deployments.Id=in_deployments_id);
		declare continue handler for not found set no_more_rows := TRUE;

		set max_sp_recursion_depth = 50;
			open my_list;
			my_loop : loop						
				fetch my_list into subsystem_node_id;
				if no_more_rows then				
					close my_list;
					leave my_loop;
				end if;				
				
				select count(deployments.Id) into deploy_sub_component from deployments where deployments.node_id = subsystem_node_id and deployments.original_id = in_deployments_id;	      	
	      	
	      	if deploy_sub_component = 0 then					
					 select deployments.systemdomain_id into orginal_domain_id from deployments where deployments.Id=in_deployments_id;					
					 select deployments.component_id into orginal_component_id from deployments where deployments.Id=in_deployments_id;										
					 select deployments.node_id into orginal_node_id from deployments where deployments.Id=in_deployments_id;	
					 select systemdomain_id into subsystem_domain_id  from node where node.Id = subsystem_node_id;								
			 		 select component.id into component_id from component where id = orginal_component_id;
			 		 select component.systemdomain_id into component_system_domain_id from component where id = orginal_component_id;
			 		 select component.name into component_name from component where id = orginal_component_id;
					 select component.description into component_description from component where id = orginal_component_id;			   				
	 				 
 					 call insert_component_deployments_custum(in_deployments_id,  subsystem_domain_id, subsystem_node_id, component_id, component_system_domain_id, component_name, component_description,orginal_node_id);			
				end if;
			
			end loop my_loop;	
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.insert_subsystem_public_proxy_interface_loop 구조 내보내기
DELIMITER //
CREATE PROCEDURE `insert_subsystem_public_proxy_interface_loop`(IN `in_subsystem_domain_id` INT)
BEGIN

	declare in_custum_id int;
	declare in_deploy_id int;
	declare no_more_rows bool default false;	 

		DECLARE my_list CURSOR FOR 
		select custum_proxy.Id, custum_proxy.deploy_id from custum_proxy where custum_proxy.public=1 and custum_proxy.deploy_id in (
		select id from deployments where deployments.systemdomain_id=in_subsystem_domain_id);		
		
		declare continue handler for not found set no_more_rows := TRUE;		
		select 1 as test;
			open my_list;
			my_loop : loop		
				fetch my_list into in_custum_id, in_deploy_id;
				if no_more_rows then
					close my_list;
					leave my_loop;
				end if;	 			   
 			
  				call insert_subsystem_custum_interface_loop_new_subsystem(in_custum_id, in_deploy_id, 0);	
			end loop my_loop;		
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.insert_subsystem_public_stub_interface_loop 구조 내보내기
DELIMITER //
CREATE PROCEDURE `insert_subsystem_public_stub_interface_loop`(IN `in_subsystem_domain_id` INT)
BEGIN

	declare in_custum_id int;
	declare in_deploy_id int;
	declare no_more_rows bool default false;
		
	DECLARE my_list_stub CURSOR FOR 
	select custum_stub.Id, custum_stub.deploy_id from custum_stub where custum_stub.public=1 and custum_stub.deploy_id in (
		select id from deployments where deployments.systemdomain_id=in_subsystem_domain_id);

	declare continue handler for not found set no_more_rows := TRUE;
					select 1 as test;
			open my_list_stub;
			my_loop : loop		
				fetch my_list_stub into in_custum_id, in_deploy_id;
				if no_more_rows then
					close my_list_stub;
					leave my_loop;
				end if;	
 		 		
 				call insert_subsystem_custum_interface_loop_new_subsystem(in_custum_id, in_deploy_id, 1);				
			end loop my_loop;	

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewDeleteInterface 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewDeleteInterface`(domain_idkey int,interface_name varchar(100))
BEGIN
        if loginTest() and domainManageTest(domain_idkey) then
                select 1 as test;
                delete from interface where domain_id=domain_idkey and name=interface_name;
                        
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewDeleteMemberMethod 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewDeleteMemberMethod`(IN `domain_idkey` int, IN `interfacename` varchar(100), IN `methoddomain_id` int, IN `methodname` varchar(100))
BEGIN
        if loginTest() and domainManageTest(domain_idkey) then
                select 1 as test;
                delete from interface_member where domain_id=domain_idkey
					  and interface=interfacename and method_domain_id=methoddomain_id and method_name=methodname;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewDeleteParentInterface 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewDeleteParentInterface`(domain_idkey int,
                                                                        interface_name varchar(100),
                                                                        parentdomain_idkey int,
                                                                        parentinterface_name varchar(100))
BEGIN

        if loginTest() and domainManageTest(domain_idkey) then
                select 1 as test;
                delete from interface_parent where domain_id=domain_idkey and interface=interface_name and parent_domain_id=parentdomain_idkey and parent_interface=parentinterface_name;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewEditInterface 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewEditInterface`(domain_idkey int, interface_name varchar(100),interfacevalue varchar(100),descriptionvalue varchar(100))
BEGIN

        if loginTest() and domainManageTest(domain_idkey) then
                select 1 as test;
                       update interface set name=interfacevalue,description=descriptionvalue where domain_id=domain_idkey and name=interface_name;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewEditInterfaceSeq 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewEditInterfaceSeq`(domain_idkey int, domaintype varchar(50),
                                                                        interfacekey1 varchar(100),
                                                                        interfacekey2 varchar(100))
BEGIN
        declare t1 timestamp;
        declare t2 timestamp;

        if loginTest() and domainManageTest(domain_idkey, domaintype) then
                select 1 as test;
                       select seq into t1 from interface where domain_id=domain_idkey and name=interfacekey1;
                       select seq into t2 from interface where domain_id=domain_idkey and name=interfacekey2;
                update interface set seq = t2 where domain_id=domain_idkey and name=interfacekey1;
                update interface set seq = t1 where domain_id=domain_idkey and name=interfacekey2;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewEditMemberMethod 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewEditMemberMethod`(domain_idkey int,
                                                                     interfacekey varchar(100),
                                                                     method_domain_idkey int,
                                                                     method_namekey varchar(100),
                                                                     method_domain_idvalue int,
                                                                     methodvalue varchar(100),
                                                                     descriptionvalue text)
BEGIN
        if loginTest() and domainManageTest(domain_idkey) and existMethod(method_domain_idvalue,methodvalue) then
                select 1 as test;
                update interface_member set method_domain_id=method_domain_idvalue,
                                            method_name=methodvalue,
                                            description=descriptionvalue
                                        where domain_id=domain_idkey
                                         and  interface=interfacekey
                                         and  method_domain_id=method_domain_idkey
                                         and  method_name=method_namekey;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewEditMemberMethodRealdomainList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewEditMemberMethodRealdomainList`(domain_idkey int)
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;

        set sa = '';
        if loginTest() then
                    select supermanager into sm from users where user_id=@nervuser;
                    select member_type into sa from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
                    select user_id into acount from domain_method where id=domain_idkey;
                    select public into pbc from domain_method where id=domain_idkey;

                    if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                        (select id, name from domain_method where id in (select parent_domain_id from inheritance_method_method where domain_id=domain_idkey))
                         union
                        (select id, name from domain_method where id=domain_idkey);
                                
                    else
                        select 0 as test;
                     end if;
               else
                 select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewEditMemberMethodRealmethodList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewEditMemberMethodRealmethodList`(domain_idkey int, interfacekey varchar(100))
BEGIN
       declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;
    
        set sa = '';
        if loginTest() then
                     select supermanager into sm from users where user_id = @nervuser;
                     select member_type into sa from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
                     select user_id into acount from domain_method where id = domain_idkey;
                     select public into pbc from domain_method where id = domain_idkey;
                     

                     if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                        select domain_id, name from method where domain_id=domain_idkey and name not in
                                        (select method_name from interface_member where domain_id = domain_idkey and interface=interfacekey);
                     else
                        select 0 as test;
                     end if;               
       else
                select 0 as test;
       end if;

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewInterfaceList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewInterfaceList`(domain_idkey int, domaintype varchar(100), interface_namekey varchar(100))
BEGIN


       if loginTest() and domainReadTest(domain_idkey, domaintype) then
               select 1 as test;
               select name,user_id,description, domain_id, seq from interface where domain_id=domain_idkey and name like interface_namekey order by seq asc;
       else
               select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewMemberMethodList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewMemberMethodList`(
	IN `domain_idkey` int,
	IN `domaintype` varchar(50),
	IN `interface_namekey` VARCHAR(100) 

)
BEGIN

       if loginTest() and domainReadTest(domain_idkey, domaintype) then
               select 1 as test;
               select c.name as method_domain, a.name as method_name, type, code, i.domain_id as in_domain_id, d.name as in_domain , i.name as in_data, o.domain_id as out_domain_id, e.name as out_domain, o.name as out_data, user_id, a.description, c.id as method_domain_id from
               (select id, name from domain_method) as c
               	join
               ( select * from method ) as a
                    left outer join
  					(select data.data_auto_id, data.domain_id, data.name from data) as i on a.in_data_auto_id=i.data_auto_id
     					left outer join
  					(select data.data_auto_id, data.domain_id, data.name from data) as o on a.out_data_auto_id=o.data_auto_id
              		left outer join
               (select id, name from domain_data) as d on i.domain_id = d.id
              		left outer join
            	(select id, name from domain_data) as e on o.domain_id = e.id            
             		 join
              ( select method_domain_id, method_name , description from interface_member where domain_id=domain_idkey and interface=interface_namekey) as b
                                                      on a.domain_id=b.method_domain_id and a.name = b.method_name  and a.domain_id = c.id order by type desc;
       else
               select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewNewInterface 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewNewInterface`(domain_idkey int, domaintype varchar (100),interface_namekey varchar(100),descriptionvalue text)
BEGIN
        if loginTest() and domainManageTest(domain_idkey) and existDomain(domain_idkey, domaintype) then
                select 1 as test;
                insert into interface (domain_id,                name,  user_id, description)
                                values(domain_idkey, interface_namekey, @nervuser, descriptionvalue );
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewNewMemberMethod 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewNewMemberMethod`(domain_idkey int,
                                                                   interface_namekey varchar(100),
                                                                   methoddomain_idvalue int,
                                                                   method_namevalue varchar(100),
                                                                   descriptionvalue text)
BEGIN
        if loginTest() and domainManageTest(domain_idkey) and existMethod(methoddomain_idvalue,method_namevalue) then
                select 1 as test;
                insert into interface_member(domain_id,        interface,     method_domain_id,   method_name, description)
                                    values(domain_idkey,interface_namekey,methoddomain_idvalue,method_namevalue,descriptionvalue);
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewNewMemberMethodRealdomainList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewNewMemberMethodRealdomainList`(domain_idkey int)
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;

        set sa = '';
        if loginTest() then
                    select supermanager into sm from users where user_id=@nervuser;
                    select member_type into sa from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
                    select user_id into acount from domain_method where id=domain_idkey;
                    select public into pbc from domain_method where id=domain_idkey;

                    if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                        (select id, name from domain_method where id in
                                 (select parent_domain_id from inheritance_method_method where domain_id=domain_idkey))
                         union
                        (select id, name from domain_method where id=domain_idkey);
                        
                   else
                        select 0 as test;
                     end if;
               else
                 select 0 as test;
        end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewNewMemberMethodRealmethodList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewNewMemberMethodRealmethodList`(in_interface_domain_idkey int, in_method_domain_idkey int,interfacekey varchar(100))
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;
    
        set sa = '';
        if loginTest() then
                     select supermanager into sm from users where user_id = @nervuser;
                     select member_type into sa from members_domain_method where domain_id=in_method_domain_idkey and user_id=@nervuser;
                     select user_id into acount from domain_method where id = in_method_domain_idkey;
                     select public into pbc from domain_method where id = in_method_domain_idkey;
                     

                     if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                        select domain_id, name,type from method where domain_id=in_method_domain_idkey and name not in
                                        (select method_name from interface_member where domain_id = in_interface_domain_idkey and interface=interfacekey);
                     else
                        select 0 as test;
                     end if;               
       else
                select 0 as test;
       end if;

              
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewNewParentInterface 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewNewParentInterface`(domain_idkey int,
                                                                        interface_namekey varchar(100),
                                                                        parentdomain_id int,
                                                                        parent_namevalue varchar(100))
BEGIN
        if loginTest() and domainManageTest(domain_idkey) and existInterface(parentdomain_id,parent_namevalue) then
                select 1 as test;
                insert into interface_parent(domain_id,          interface,parent_domain_id,parent_interface) 
                                      values(domain_idkey,interface_namekey,parentdomain_id,parent_namevalue);
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewNewParentInterfaceRealdomainList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewNewParentInterfaceRealdomainList`(domain_idkey int)
BEGIN
         declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;
  
        set sa = '';
        if loginTest() then
        
                    select supermanager into sm from users where user_id=@nervuser;
                    select member_type into sa from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
                    select user_id into acount from domain_method where id=domain_idkey;
                    select public into pbc from domain_method where id=domain_idkey;

                    if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                        (select id, name from domain_method where id in (select parent_domain_id from inheritance_method_method where domain_id=domain_idkey))
                         union
                        (select id, name from domain_method where id=domain_idkey);
                                
                    else
                        select 0 as test;
                     end if;
               else
                 select 0 as test;
        end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewNewParentInterfaceRealinterfaceList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewNewParentInterfaceRealinterfaceList`(domain_idkey int, interfacekey varchar(100))
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;

        set sa = '';
        if loginTest() then       
                     select supermanager into sm from users where user_id=@nervuser;
                     select member_type into sa from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
                     select user_id into acount from domain_method where id=domain_idkey;
                     select public into pbc from domain_method where id=domain_idkey;

                     if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                        select domain_id, name, user_id, seq, description from interface where domain_id=domain_idkey and name != interfacekey and name not in
                                        (select parent_interface from interface_parent where parent_domain_id=domain_idkey and interface=interfacekey);
                     else
                        select 0 as test;
                     end if;               

        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.interfaceViewParentInterfaceList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `interfaceViewParentInterfaceList`(domain_idkey int, domaintype varchar(100), interface_namekey varchar(100 ) )
BEGIN


       if loginTest() and domainReadTest(domain_idkey, domaintype) then
               select 1 as test;
               select b.name, a.parent_interface, a.parent_domain_id from
               (select parent_domain_id,parent_interface from interface_parent where domain_id=domain_idkey and interface = interface_namekey) As a
               join
               (select id, name from domain_method) as b on a.parent_domain_id = b.id;
       else
               select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.loginResult 구조 내보내기
DELIMITER //
CREATE PROCEDURE `loginResult`()
BEGIN
       select loginTest() as test;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.mainViewDomainAllList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `mainViewDomainAllList`(
	IN `idkey` VARCHAR(50),
	IN `domaintype` VARCHAR(50)
)
BEGIN

        declare sm bool;


        if loginTest() then
                select 1 as test;
                if( supermanagerTest(@nervuser) ) then
                       if(domaintype='data') then
                       	select id, name, upper_id, user_id, public, 0, create_date, last_update, description from domain_data where id like idkey order by id desc;                       
                       end if;
                       
                       if(domaintype='method') then
                        select id,name, upper_id, user_id, public, standard_port, create_date, last_update, description  from domain_method where id like idkey order by id desc;								
                       end if;
                       
                       if(domaintype='system') then
                        select id, name, upper_id, user_id, public, 0, create_date, last_update, description from domain_system where id like idkey order by id desc;                        
                       end if;
                else
                      if(domaintype='data') then                       
                         select id, name, upper_id, user_id, public, 0, create_date, last_update, description FROM domain_data where id in
                         (select domain_id from members_domain_data where user_id=@nervuser and (member_type='manager' or member_type='member'))
                         union distinct
                         select id, name, upper_id, user_id, public, 0, create_date, last_update, description FROM domain_data where (user_id=@nervuser or public = 1);
                      end if;
                                                
                        if(domaintype='method') then
                        select id,name, upper_id, user_id, public, standard_port, create_date, last_update, description  FROM domain_method where id in
                        (select domain_id from members_domain_method where user_id=@nervuser and (member_type='manager' or member_type='member'))
                        union distinct
                        select id,name, upper_id, user_id, public, standard_port, create_date, last_update, description  FROM domain_method where (user_id=@nervuser or public = 1);
                         
                        end if;
                        if(domaintype='system') then
                        select id, name, upper_id, user_id, public, 0, create_date, last_update, description FROM domain_system where id in
                        (select domain_id from members_domain_system where user_id=@nervuser and (member_type='manager' or member_type='member'))
                        union distinct
                        select id, name, upper_id, user_id, public, 0, create_date, last_update, description FROM domain_system where (user_id=@nervuser or public = 1);
                        end if;
                end if;
       else
               select 0 as test;
       end if;

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.mainViewDomainList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `mainViewDomainList`(
	IN `idkey` varchar(100),
	IN `domaintype` varchar(100)
)
BEGIN
        declare sm bool;
        if loginTest() then
                select 1 as test;
                if( supermanagerTest(@nervuser) ) then
                       if(domaintype='data') then                        
                        select * from ( select id, name, upper_id, user_id, public, 0, create_date, last_update, description from domain_data where domain_data.upper_id=idkey 
								union
								select id, name, upper_id, user_id, public, 0, create_date, last_update, description from domain_data where domain_data.upper_id in
																(select domain_data.id from domain_data where domain_data.upper_id=idkey)
								) as uuu order by name desc;
                       end if;
                       if(domaintype='method') then                       
                        select * from (select id,name, upper_id, user_id, public, standard_port, create_date, last_update, description from domain_method where domain_method.upper_id=idkey 
								 union
								 select id,name, upper_id, user_id, public, standard_port, create_date, last_update, description from domain_method where domain_method.upper_id in
																(select domain_method.id from domain_method where domain_method.upper_id=idkey)
								) as uuu order by name desc;
                       end if;
                       if(domaintype='system') then
                        select * from ( select id, name, upper_id, user_id, public, 0, create_date, last_update, description from domain_system where domain_system.upper_id=idkey 
								union
								select id, name, upper_id, user_id, public, 0, create_date, last_update, description from domain_system where domain_system.upper_id in
																(select domain_system.id from domain_system where domain_system.upper_id=idkey)
								) as uuu order by name desc;
                       end if;
                else
                      if(domaintype='data') then                       
                        select * from (
						      select id, name, upper_id, user_id, public, 0, create_date, last_update, description FROM domain_data where id in
                         (select domain_id from members_domain_data where user_id=@nervuser and (member_type='manager' or member_type='member')) 
                        union distinct
                        select id, name, upper_id, user_id, public, 0, create_date, last_update, description FROM domain_data where (user_id=@nervuser or public = 1)
                        ) as uuu order by name desc;
                      end if;
                      if(domaintype='method') then
                        select * from (
                        select id,name, upper_id, user_id, public, standard_port, create_date, last_update, description  FROM domain_method where id in
                        (select domain_id from members_domain_method where user_id=@nervuser and (member_type='manager' or member_type='member'))
                        union distinct
                        select id,name, upper_id, user_id, public, standard_port, create_date, last_update, description  FROM domain_method where (user_id=@nervuser or public = 1)
                        ) as uuu order by name desc;
                      end if;
                      if(domaintype='system') then
                        select * from (
                        select id, name, upper_id, user_id, public, 0, create_date, last_update, description FROM domain_system where id in
                        (select domain_id from members_domain_system where user_id=@nervuser and (member_type='manager' or member_type='member'))
                        union distinct
                        select id, name, upper_id, user_id, public, 0, create_date, last_update, description FROM domain_system where (user_id=@nervuser or public = 1)
                        ) as uuu order by name desc;
                      end if;
                end if;
       else
               select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewCopyData 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewCopyData`(IN `copy_data_auto_id` INT, IN `paste_domain_id` INT)
BEGIN

	declare new_data_auto_id int default null;
	
   if loginTest() and newDomainTest() then
      select 1 as test;
      
	   insert into data (data.domain_id, data.name, data.`type`, data.real_data_auto_id, data.scmin, data.scmax, data.seq, data.description, data.user_id)
		select paste_domain_id, data.name, data.`type`, data.real_data_auto_id, data.scmin, data.scmax, data.seq, data.description,@nervuser from data where data_auto_id=copy_data_auto_id;
	
	   select LAST_INSERT_ID() into new_data_auto_id;    
   
		insert into data_field (data_field.data_auto_id, data_field.member_name, data_field.`type`, data_field.real_data_auto_id, data_field.user_id, data_field.bitsize, data_field.scimin, data_field.scimax, data_field.arraytype, data_field.description,data_field.seq )
		select new_data_auto_id, data_field.member_name, data_field.`type`, data_field.real_data_auto_id, @nervuser, data_field.bitsize, data_field.scimin, data_field.scimax, data_field.arraytype, data_field.description, data_field.seq from data_field
				 where data_field.data_auto_id=copy_data_auto_id;
	else
      select 0 as test;
	end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewDeleteMetadata 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewDeleteMetadata`(domain_idkey int,metadata_namekey varchar(100))
BEGIN
        if loginTest() and domainManageTest(domain_idkey) then
                select 1 as test;
                delete from data where domain_id=domain_idkey and name=metadata_namekey;
                        
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewDeleteMetafield 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewDeleteMetafield`(IN `domain_idkey` int, IN `metadata_namekey` varchar(100), IN `member_namekey` varchar(100))
BEGIN

	declare datakey_auto_id int default 0;
	
        if loginTest() and domainManageTest(domain_idkey) then
                select 1 as test;
                
                delete from data_field where member_name=member_namekey and data_field.data_auto_id in
					  (select data.data_auto_id from data where data.domain_id=domain_idkey and data.name=metadata_namekey);
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewEditMetadata 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewEditMetadata`(
	IN `domain_idkey` int,
	IN `metadatakey` varchar(100),
	IN `data_namevalue` varchar(100),
	IN `typevalue` varchar(100),
	IN `in_real_data_auto_id` varchar(100),
	IN `scminvalue` varchar(100),
	IN `scmaxvalue` varchar(100),
	IN `descriptionvalue` TEXT
)
BEGIN
       declare data_depth int default 0;
       declare real_data_domain_id int default 0;
       declare data_id int;
       declare real_data_path int;      
       
        if loginTest() and domainManageTest(domain_idkey) and ( typevalue!='alias' or existMetadata(in_real_data_auto_id) )then
                if typevalue='alias' then
					 	select data.domain_id into real_data_domain_id from data where data.data_auto_id=in_real_data_auto_id;                        
					 else
                	set in_real_data_auto_id=null;
                end if;                
                	
               select data.data_auto_id into data_id from data where data.domain_id=domain_idkey and data.name=metadatakey;
               select data.depth into data_depth from data where data.data_auto_id=data_id;
                	
               if domain_idkey=real_data_domain_id then
               	if typevalue ='alias' then               		
               		select data.depth into real_data_path from data where data.data_auto_id=in_real_data_auto_id;
               		if data_depth <= real_data_path then
								set data_depth = real_data_path +1;               		               		
               			call update_child_depth(data_id,domain_idkey,data_depth);
               			
							end if;	      		   	
               	end if;
               end if;   
                
                select 1 as test;
                
                update data set name=data_namevalue,
                                type=typevalue,
                                data.real_data_auto_id=in_real_data_auto_id,
                                scmin=scminvalue,
                                scmax=scmaxvalue,
                                description=descriptionvalue,
                                data.depth = data_depth
                                where data.data_auto_id=data_id;                                
                        
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewEditMetadataRealdomainList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewEditMetadataRealdomainList`(domain_idkey int)
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;

        set sa = '';
        if loginTest() then
                    select supermanager into sm from users where user_id=@nervuser;
                    select member_type into sa from members_domain_data where domain_id=domain_idkey and user_id=@nervuser;
                    select user_id into acount from domain_data where id=domain_idkey;
                    select public into pbc from domain_data where id=domain_idkey;

                    if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                         (select id, upper_id, name, user_id, public, create_date, last_update, description from domain_data where id in (select parent_domain_id from inheritance_data_data where domain_id=domain_idkey))
                           union
                        (select id, upper_id, name, user_id, public, create_date, last_update, description from domain_data where id=domain_idkey);
                                          

                     else
                        select 0 as test;
                     end if;
              
        else
                select 0 as test;
        end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewEditMetadataRealmetadataList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewEditMetadataRealmetadataList`(domain_idkey int)
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;
    
        set sa = '';
        if loginTest() then
                     select supermanager into sm from users where user_id=@nervuser;
                     select member_type into sa from members_domain_data where domain_id=domain_idkey and user_id=@nervuser;
                     select user_id into acount from domain_data where id=domain_idkey;
                     select public into pbc from domain_data where id=domain_idkey;

                     if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                         select * from data where domain_id=domain_idkey order by seq asc;
                     else
                        select 0 as test;
                     end if;        
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewEditMetadataSeq 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewEditMetadataSeq`(IN `domain_idkey` int, IN `metadatakey1` varchar(100), IN `metadatakey2` varchar(100))
BEGIN
        declare t1 timestamp;
        declare t2 timestamp;
        


        if loginTest() and domainManageTest(domain_idkey) then
                select 1 as test;
                       select seq into t1 from data where domain_id=domain_idkey and name=metadatakey1;
                       select seq into t2 from data where domain_id=domain_idkey and name=metadatakey2;
                       update data set seq = t2 where domain_id=domain_idkey and name=metadatakey1;
                       update data set seq = t1 where domain_id=domain_idkey and name=metadatakey2;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewEditMetafield 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewEditMetafield`(IN `domain_idkey` int, IN `metadatakey` varchar(100), IN `metafieldkey` varchar(100), IN `metafieldvalue` varchar(100), IN `bitsizevalue` int unsigned, IN `typevalue` varchar(100), IN `realdomainvalue` int, IN `realmetadatavalue` varchar(100), IN `minvalue` varchar(100), IN `in_maxvalue` varchar(100), IN `arraytypevalue` varchar(100), IN `arraysizevalue` int unsigned, IN `descriptionvalue` text)
BEGIN
		 declare data_depth int default 0;
		 declare data_field_depth int default 0;
 		 declare datakey_auto_id int default 0;
 		 declare real_data_auto_id int default 0;
		 
		 if typevalue!='alias' then
       	set real_data_auto_id=null;
       else
       	select data.data_auto_id into real_data_auto_id from data where data.domain_id=realdomainvalue and data.name=realmetadatavalue;
       end if;
		 
       if loginTest() and domainManageTest(domain_idkey) and ( typevalue!='alias' or existMetadata(real_data_auto_id) ) then                
                	
           	 select 1 as test;
       			select data.data_auto_id into datakey_auto_id from data where data.domain_id=domain_idkey and data.name=metadatakey; 

            	if typevalue ='alias' then            		
  						if domain_idkey=realdomainvalue then
               		select data.depth into data_depth from data where data.data_auto_id=datakey_auto_id;
               		select data.depth into data_field_depth from data where data.data_auto_id=real_data_auto_id;
               		
               		if data_depth <= data_field_depth then               		
               			set data_field_depth = data_field_depth + 1;
               			
               			update data set data.depth = data_field_depth where data.domain_id=domain_idkey and data.name=metadatakey;               			
               			
               			call update_child_depth(real_data_auto_id,realdomainvalue,data_field_depth);
               		end if;               		
               	end if;
               end if;     
                update data_field set member_name=metafieldvalue,
                                      bitsize=bitsizevalue,
                                      type=typevalue,
                                      data_field.real_data_auto_id=real_data_auto_id,
                                      scimin=minvalue,
                                      scimax=in_maxvalue,
                                      arraytype=arraytypevalue,
                                      arraysize=arraysizevalue,
                                      description=descriptionvalue,
                                      seq=seq
                                 where data_field.data_auto_id=datakey_auto_id and data_field.member_name=metafieldkey;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewEditMetafieldRealdomainList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewEditMetafieldRealdomainList`(IN `domain_idkey` int )
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;

        set sa = '';
        if loginTest() then
                    select supermanager into sm from users where user_id=@nervuser;
                    select member_type into sa from members_domain_data where domain_id=domain_idkey and user_id=@nervuser;
                    select user_id into acount from domain_data where id=domain_idkey;
                    select public into pbc from domain_data where id=domain_idkey;

                    if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                         (select id, upper_id, name, user_id, public, create_date, last_update, description from domain_data where id in
								  (select parent_domain_id from inheritance_data_data where domain_id=domain_idkey))
                           union
                        (select id, upper_id, name, user_id, public, create_date, last_update, description from domain_data where id=domain_idkey);
                                          

                     else
                        select 0 as test;
                     end if;
              
        else
                select 0 as test;
        end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewEditMetafieldRealmetadataList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewEditMetafieldRealmetadataList`(domain_idkey int)
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;
    
        set sa = '';
        if loginTest() then
                     select supermanager into sm from users where user_id=@nervuser;
                     select member_type into sa from members_domain_data where domain_id=domain_idkey and user_id=@nervuser;
                     select user_id into acount from domain_data where id=domain_idkey;
                     select public into pbc from domain_data where id=domain_idkey;

                     if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                         select * from data where domain_id=domain_idkey order by domain_id asc;
                         
                     else
                        select 0 as test;
                     end if;        
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewEditMetafieldSeq 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewEditMetafieldSeq`(IN `domain_idkey` int, IN `domaintype` varchar(50), IN `metadatakey` varchar(100), IN `metadatakey1` varchar(100), IN `metadatakey2` varchar(100))
BEGIN
        declare t1 timestamp;
        declare t2 timestamp;

        declare data_auto_id_key int default null;
        
        if loginTest() and domainManageTest(domain_idkey) then
                select 1 as test;
                select data.data_auto_id into data_auto_id_key from data where data.domain_id=domain_idkey and data.name=metadatakey;
                
                  select seq into t1 from data_field where data_field.data_auto_id=data_auto_id_key and member_name=metadatakey1;
                  select seq into t2 from data_field where data_field.data_auto_id=data_auto_id_key and member_name=metadatakey2;
                update data_field set seq = t2 where data_field.data_auto_id=data_auto_id_key and member_name=metadatakey1;
                update data_field set seq = t1 where data_field.data_auto_id=data_auto_id_key and member_name=metadatakey2;
        else
                select 0 as test;
        end if;

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewMetadataList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewMetadataList`(
	IN `domain_idkey` int,
	IN `metadatakey` varchar(100),
	IN `domain_idtype` varchar(50)

)
BEGIN

        if loginTest() and domainReadTest(domain_idkey, domain_idtype) then
                select 1 as test;
                
                
                select a.data_auto_id, a.domain_id, a.name, a.user_id, a.type, b.domain_id as real_domain_id, b.name as real_data_name, a.scmin, a.scmax, a.description, c.name as real_domain_name, a.real_data_auto_id from
                
    					(select * from data where domain_id=domain_idkey and name like metadatakey order by depth asc) as a
    						left join
    					(select data.data_auto_id, data.domain_id, data.name from data) as b on a.real_data_auto_id = b.data_auto_id
        					left join
    					(select id, name from domain_data) as c on b.domain_id = c.id;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewMetadataListByTypeSort 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewMetadataListByTypeSort`(IN `domain_idkey` int, IN `metadatakey` varchar(100), IN `domain_idtype` varchar(50))
BEGIN

        if loginTest() and domainReadTest(domain_idkey, domain_idtype) then
                select 1 as test;
                select a.data_auto_id, a.domain_id, a.name, a.user_id, a.type, b.domain_id, b.name, a.scmin, a.scmax, a.description, c.name, a.real_data_auto_id from                
    					(select * from data where domain_id=domain_idkey and name like metadatakey order by type asc) as a
    						left join
    					(select data.data_auto_id, data.domain_id, data.name from data) as b on a.real_data_auto_id = b.data_auto_id
        					left join
    					(select id, name from domain_data) as c on b.domain_id = c.id;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewMetafieldList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewMetafieldList`(
	IN `domain_idkey` int,
	IN `metadatakey` varchar(100 ),
	IN `domain_idtype` varchar(100) 
)
BEGIN

        if loginTest() and domainReadTest(domain_idkey, domain_idtype) then
                select 1 as test;
                
                select o.domain_id, o.name, a.member_name, i.domain_id as real_domain_id,b.name as real_domain_name, i.name as real_data_name, a.user_id , a.type, a.bitsize, a.scimin, a.scimax, a.arraytype, a.arraysize, a.seq, a.description  from
					(select * from data_field where data_field.data_auto_id in (select data_auto_id from data where data.domain_id=domain_idkey and data.name = metadatakey) order by seq asc) as a
						left outer join
					(select data.data_auto_id, data.domain_id, data.name from data) as o on o.data_auto_id=a.data_auto_id    
						left outer join
					(select data.data_auto_id, data.domain_id, data.name from data) as i on a.real_data_auto_id=i.data_auto_id   
					  left outer join
               (select id, name from domain_data) as b on i.domain_id = b.id order by seq asc;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewNewMetadata 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewNewMetadata`(
	IN `domain_idkey` int,
	IN `metadatakey` varchar(100),
	IN `typevalue` varchar(100),
	IN `real_data_auto_id` int,
	IN `scminvalue` varchar(100),
	IN `scmaxvalue` varchar(100),
	IN `descriptionvalue` text
)
BEGIN
       declare cnt int default 0;
       declare depth int default 0;       
       declare real_data_domain_id int default null;
       declare real_data_name varchar(100) default null;
       
       if typevalue ='alias' then                     
       	select data.domain_id into real_data_domain_id from data where data.data_auto_id=real_data_auto_id;
       	select data.name into real_data_name from data where data.data_auto_id=real_data_auto_id;
      else
      	set real_data_auto_id = NULL;
       end if;     

        if loginTest() and domainManageTest(domain_idkey) and ( typevalue!='alias' or existMetadata(real_data_auto_id) )then
 					
					
					
               if domain_idkey=real_data_domain_id then
               	if typevalue ='alias' then
               		select data.depth into depth from data where data.data_auto_id=real_data_auto_id;
               		set depth = depth +1;
               	end if;
               end if;             
              
                select 1 as test;
                insert into data (domain_id   ,name       ,user_id     ,type     , real_data_auto_id     , scmin     ,scmax     ,description, depth)
                              values(domain_idkey,metadatakey,@nervuser,typevalue, real_data_auto_id, scminvalue,scmaxvalue,descriptionvalue, depth);                  
              
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewNewMetadataRealdomainList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewNewMetadataRealdomainList`(IN `domain_idkey` int)
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;
        
        set sa = '';

        if loginTest() then
                    select supermanager into sm from users where user_id=@nervuser;
                    select member_type into sa from members_domain_data where domain_id=domain_idkey and user_id=@nervuser;
                    select user_id into acount from domain_data where id=domain_idkey;
                    select public into pbc from domain_data where id=domain_idkey;

                    if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                        (select id, upper_id, name, user_id, public, create_date, last_update, description from domain_data
								 where id in (select parent_domain_id from inheritance_data_data where domain_id=domain_idkey))
                         union
                        (select id, upper_id, name, user_id, public, create_date, last_update, description from domain_data
								 where id=domain_idkey);                                
                    else
                        select 0 as test;
                     end if;
               else
                 select 0 as test;
        end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewNewMetadataRealmetadataList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewNewMetadataRealmetadataList`(domain_idkey int)
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;
    
        set sa = '';
        if loginTest() then
                     select supermanager into sm from users where user_id=@nervuser;
                     select member_type into sa from members_domain_data where domain_id=domain_idkey and user_id=@nervuser;
                     select user_id into acount from domain_data where id=domain_idkey;
                     select public into pbc from domain_data where id=domain_idkey;

                     if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                         select * from data where domain_id=domain_idkey order by domain_id asc;
                     else
                        select 0 as test;
                     end if;        
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewNewMetafield 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewNewMetafield`(
	IN `domain_idkey` int,
	IN `metadatakey` varchar(100),
	IN `metafieldkey` varchar(100),
	IN `bitsizevalue` int unsigned,
	IN `typevalue` varchar(100),
	IN `real_domain_id_value` INT,
	IN `real_data_value` VARCHAR(100),
	IN `minvalue` varchar(100),
	IN `in_maxvalue` varchar(100),
	IN `arraytypevalue` varchar(100),
	IN `arraysizevalue` int unsigned,
	IN `descriptionvalue` text




)
BEGIN
		 declare datakey_auto_id int default 0;
		 declare real_data_auto_id int default 0;
		 declare data_depth int default 0;
		 declare data_field_depth int default 0;
		 
		 if typevalue!='alias' then
       	set real_data_auto_id=null;
       else
       	select data.data_auto_id into real_data_auto_id from data where data.domain_id=real_domain_id_value and data.name=real_data_value;
       end if;
                        
        if loginTest() and domainManageTest(domain_idkey) and ( typevalue!='alias' or existMetadata(real_data_auto_id) ) then

        			select data.data_auto_id into datakey_auto_id from data where data.domain_id=domain_idkey and data.name=metadatakey;      				 
					
               if typevalue ='alias' then               	
                  if real_data_auto_id != datakey_auto_id then
							if domain_idkey=real_domain_id_value then
	               		select data.depth into data_depth from data where data.domain_id=domain_idkey and data.name=metadatakey;
	               		select data.depth into data_field_depth from data where data.data_auto_id=real_data_auto_id;               		
	               		
	               		 if data_depth <= data_field_depth then
	               			set data_depth = data_field_depth + 1;
			                             			
									update data set data.depth = data_depth where data.data_auto_id=datakey_auto_id;
									
	               			call update_child_depth(datakey_auto_id, domain_idkey, data_depth);
	               		 end if;               		               	
							end if;
                     select 1 as test;
							insert into data_field( data_auto_id, member_name,       bitsize,      type, real_data_auto_id,   user_id,scimin,  scimax,      arraytype,     arraysize, description)
											values(datakey_auto_id, metafieldkey, bitsizevalue, typevalue, real_data_auto_id, @nervuser,minvalue,in_maxvalue,arraytypevalue,arraysizevalue,descriptionvalue);
							
						else
							select 0 as test;
                  end if;
               else
                 select 1 as test;
                 insert into data_field( data_auto_id, member_name,       bitsize,      type, real_data_auto_id,   user_id,scimin,  scimax,      arraytype,     arraysize, description)
                               values(datakey_auto_id, metafieldkey, bitsizevalue, typevalue, real_data_auto_id, @nervuser,minvalue,in_maxvalue,arraytypevalue,arraysizevalue,descriptionvalue);               
               end if; 

        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewNewMetafieldRealdomainList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewNewMetafieldRealdomainList`(domain_idkey int)
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;

        set sa = '';
        if loginTest() then
                    select supermanager into sm from users where user_id=@nervuser;
                    select member_type into sa from members_domain_data where domain_id=domain_idkey and user_id=@nervuser;
                    select user_id into acount from domain_data where id=domain_idkey;
                    select public into pbc from domain_data where id=domain_idkey;

                    if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                        (select id, upper_id, name, user_id, public, create_date, last_update, description from domain_data where id
                                in (select parent_domain_id from inheritance_data_data where domain_id=domain_idkey))
                         union
                        (select id, upper_id, name, user_id, public, create_date, last_update, description from domain_data where id=domain_idkey);
                    else
                        select 0 as test;
                     end if;
               else
                 select 0 as test;
        end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.metadataViewNewMetafieldRealmetadataList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `metadataViewNewMetafieldRealmetadataList`(IN `domain_idkey` int, IN `domain_name` varchar(100))
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;
    
        set sa = '';
        if loginTest() then
                     select supermanager into sm from users where user_id=@nervuser;
                     select member_type into sa from members_domain_data where domain_id=domain_idkey and user_id=@nervuser;
                     select user_id into acount from domain_data where id=domain_idkey;
                     select public into pbc from domain_data where id=domain_idkey;

                     if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                        select data.data_auto_id, data.domain_id, data.name, data.`type`, data.real_data_auto_id, data.scmin, data.scmax, data.seq, data.description, data.user_id from data where domain_id=domain_idkey order by domain_id asc;
                         
                     else
                        select 0 as test;
                     end if;        
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.methodInfoList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `methodInfoList`(domain_idkey int, methodkey varchar(100))
BEGIN

        if loginTest() then
                select 1 as test;
                       select a.type, a.code, a.name,a.in_domain_id, a.in_data, a.out_domain_id, a.out_data, a.user_id, a.description, b.name, c.name from 
                           (select type,code,name,in_domain_id,in_data,out_domain_id,out_data,user_id,description from method
                              where domain_id=domain_idkey && name=methodkey) as a 
                             left outer join
                              (select id, name from domain_data) as b on a.in_domain_id = b.id
                              left outer join
                              (select id, name from domain_data) as c on a.out_domain_id = c.id;
        else
                select 0 as test;

         end if;
          
        
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.methodViewDeleteMethod 구조 내보내기
DELIMITER //
CREATE PROCEDURE `methodViewDeleteMethod`(domain_idkey int, methodkey varchar(100))
BEGIN
        if loginTest() and domainManageTest(domain_idkey) then
                select 1 as test;
                delete from method where domain_id=domain_idkey and name=methodkey;
                       
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.methodViewEditMethod 구조 내보내기
DELIMITER //
CREATE PROCEDURE `methodViewEditMethod`(IN `domain_idkey` int, IN `methodkey` varchar(100), IN `typevalue` varchar(100), IN `codevalue` varchar(100), IN `methodvalue` varchar(100), IN `inputdomainvalue` int(10) unsigned, IN `inputmetadatavalue` varchar(100), IN `outputdomainvalue` int(10) unsigned, IN `outputmetadatavalue` varchar(100), IN `descriptionvalue` text)
BEGIN

	declare in_real_data_auto_id int default null;
	declare out_real_data_auto_id int default null;

	if inputdomainvalue!=0 then
      select data.data_auto_id into in_real_data_auto_id  from data where data.domain_id=inputdomainvalue and data.name=inputmetadatavalue;
	end if;
	if outputdomainvalue!=0 then
      select data.data_auto_id into out_real_data_auto_id  from data where data.domain_id=outputdomainvalue and data.name=outputmetadatavalue;
	end if;	     

     if loginTest() and domainManageTest(domain_idkey) and (in_real_data_auto_id is NULL or existMetadata(in_real_data_auto_id) )
                                                       and (out_real_data_auto_id is NULL or existMetadata(out_real_data_auto_id)) then
                select 1 as test;
                update method set       code=codevalue,
                                        type=typevalue,
                                        name=methodvalue,
                                        method.in_data_auto_id=in_real_data_auto_id,
                                        method.out_data_auto_id=out_real_data_auto_id,
                                        description=descriptionvalue
                              where     domain_id=domain_idkey and name=methodkey;
                              
                                        
                                        
                                        
                                        
                                        
                        
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.methodViewEditMethodRealdomainList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `methodViewEditMethodRealdomainList`(domain_idkey int)
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;
        
        set sa = '';
        if loginTest() then
                    select supermanager into sm from users where user_id=@nervuser;
                    select member_type into sa from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
                    select user_id into acount from domain_method where id=domain_idkey;
                    select public into pbc from domain_method where id=domain_idkey;

                    if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                        (select name from domain_data where id in (select parent_domain_id from inheritance_method_data where domain_id=domain_idkey))
                         union
                        (select name from domain_method where id=domain_idkey);
                         
                                  
                                
                    else
                        select 0 as test;
                     end if;
               else
                 select 0 as test;
        end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.methodViewEditMethodRealmetadataList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `methodViewEditMethodRealmetadataList`(domain_idkey int, domainkey varchar(100))
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;

        set sa = '';
        if loginTest() then

                     select supermanager into sm from users where user_id = @nervuser;
                     select member_type into sa from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
                     select user_id into acount from domain_method where id = domain_idkey;
                     select public into pbc from domain_method where id = domain_idkey;
                     

                     if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                        
                        select name from data where domain_id in (select id from domain_data where name = domainkey);                                 
                      
                     else
                        select 0 as test;
                     end if;               
       else
                select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.methodViewMethodList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `methodViewMethodList`(
	IN `domain_idkey` int,
	IN `in_domaintype` varchar(100),
	IN `typekey` varchar(100),
	IN `codekey` varchar(100),
	IN `methodkey` varchar(100)

)
BEGIN
	declare domaintype varchar(20);
	set domaintype = 'method';

	if codekey='' then
      set codekey = null;    
	end if;     
         if loginTest() and domainReadTest(domain_idkey, domaintype) then
                select 1 as test;
                if typekey = 'ALL' then
                     if codekey is null then
                     	select a.type, a.code, a.name as method_name, i.domain_id as in_domain_id, i.name as in_data_name, o.domain_id as out_domain_id, o.name as out_data_name, a.user_id, a.description, a.domain_id, b.name as in_domain_name, c.name as out_domain_name from
                      	(select type, code, name, in_data_auto_id, out_data_auto_id, user_id, description, domain_id from method where domain_id=domain_idkey and name like methodkey order by code  asc) as a 
                        	left outer join
                      	(select data.data_auto_id, data.domain_id, data.name from data) as i on a.in_data_auto_id=i.data_auto_id
                        	left outer join
                       	(select data.data_auto_id, data.domain_id, data.name from data) as o on a.out_data_auto_id=o.data_auto_id
									left outer join                            
                        (select id, name from domain_data) as b on i.domain_id = b.id
                           left outer join
                        (select id, name from domain_data) as c on o.domain_id = c.id;                           
                     else
                     	select a.type, a.code, a.name as method_name, i.domain_id as in_domain_id, i.name as in_data_name, o.domain_id as out_domain_id, o.name as out_data_name, a.user_id, a.description, a.domain_id, b.name as in_domain_name, c.name as out_domain_name from
                         (select type, code, name, in_data_auto_id, out_data_auto_id, user_id, description, domain_id from method where domain_id=domain_idkey and code like codekey and name like methodkey order by code  asc) as a    
								   left outer join
                      	(select data.data_auto_id, data.domain_id, data.name from data) as i on a.in_data_auto_id=i.data_auto_id
                        	left outer join
                       	(select data.data_auto_id, data.domain_id, data.name from data) as o on a.out_data_auto_id=o.data_auto_id                       
                           left outer join
                         (select id, name from domain_data) as b on i.domain_id = b.id                           
                           left outer join
                         (select id, name from domain_data) as c on o.domain_id = c.id;
                     end if;
                else
                     if codekey is null then                     
                     	select a.type, a.code, a.name as method_name, i.domain_id as in_domain_id, i.name as in_data_name, o.domain_id as out_domain_id, o.name as out_data_name, a.user_id, a.description, a.domain_id, b.name as in_domain_name, c.name as out_domain_name from
                         (select type, code, name, in_domain_id, in_data, out_domain_id, out_data, user_id, description, domain_id from method where domain_id=domain_idkey and type=typekey and name like methodkey order by code  asc) as a
                         left outer join
                      	(select data.data_auto_id, data.domain_id, data.name from data) as i on a.in_data_auto_id=i.data_auto_id
                        	left outer join
                       	(select data.data_auto_id, data.domain_id, data.name from data) as o on a.out_data_auto_id=o.data_auto_id
                           left outer join
                        (select id, name from domain_data) as b on i.in_domain_id = b.id
                           left outer join
                        (select id, name from domain_data) as c on o.out_domain_id = c.id; 
                     else                     
                     	select a.type, a.code, a.name as method_name, i.domain_id as in_domain_id, i.name as in_data_name, o.domain_id as out_domain_id, o.name as out_data_name, a.user_id, a.description, a.domain_id, b.name as in_domain_name, c.name as out_domain_name from
                         (select type, code, name, in_domain_id, in_data, out_domain_id, out_data, user_id, description, domain_id from method where domain_id=domain_idkey and type=typekey and code like codekey and name like methodkey order by code  asc) as a
                             left outer join
                      	(select data.data_auto_id, data.domain_id, data.name from data) as i on a.in_data_auto_id=i.data_auto_id
                        	left outer join
                       	(select data.data_auto_id, data.domain_id, data.name from data) as o on a.out_data_auto_id=o.data_auto_id
                           left outer join
                        (select id, name from domain_data) as b on i.in_domain_id = b.id
                           left outer join
                        (select id, name from domain_data) as c on o.out_domain_id = c.id; 
                     end if;
                end if;
        else
          select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.methodViewNewMethod 구조 내보내기
DELIMITER //
CREATE PROCEDURE `methodViewNewMethod`(IN `domain_idkey` int, IN `typevalue` varchar(100), IN `codekey` varchar(100), IN `methodkey` varchar(100), IN `inputdomainvalue` int(100) unsigned, IN `inputmetadatavalue` varchar(100), IN `outputdomainvalue` int(100) unsigned, IN `outputmetadatavalue` varchar(100), IN `descriptionvalue` text)
BEGIN

	declare in_real_data_auto_id int default null;
	declare out_real_data_auto_id int default null;

	if inputdomainvalue!=0 then
      select data.data_auto_id into in_real_data_auto_id  from data where data.domain_id=inputdomainvalue and data.name=inputmetadatavalue;
	end if;
	if outputdomainvalue!=0 then
      select data.data_auto_id into out_real_data_auto_id  from data where data.domain_id=outputdomainvalue and data.name=outputmetadatavalue;
	end if;
	
	if  loginTest() and domainManageTest(domain_idkey) and (in_real_data_auto_id is NULL or existMetadata(in_real_data_auto_id) )
		 and (out_real_data_auto_id is NULL or existMetadata(out_real_data_auto_id)) then
                select 1 as test;                
                
                insert into method(    domain_id,    code,      type,      name,     method.in_data_auto_id,     method.out_data_auto_id,   user_id, description)
                            values( domain_idkey, codekey, typevalue, methodkey, in_real_data_auto_id, out_real_data_auto_id, @nervuser, descriptionvalue);
        else
                select 0 as test;
        end if;

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.methodViewNewMethodRealdomainList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `methodViewNewMethodRealdomainList`(IN `domain_idkey` int)
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;
        
        
        set sa = '';
        if loginTest() then
        
                    select supermanager into sm from users where user_id=@nervuser;
                    select member_type into sa from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
                    select user_id into acount from domain_method where id=domain_idkey;
                    select public into pbc from domain_method where id=domain_idkey;

                    if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                        select d.* from
								(
									select domain_id from data where data.data_auto_id in(select method.in_data_auto_id from method where method.domain_id=domain_idkey)
									union
									select domain_id from data where data.data_auto_id in(select method.out_data_auto_id from method where method.domain_id=domain_idkey)
								)as m join domain_data as d on m.domain_id=d.id;

                    else
                        select 0 as test;
                     end if;
               else
                 select 0 as test;
        end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.methodViewNewMethodRealmetadataList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `methodViewNewMethodRealmetadataList`(IN `domain_idkey` int)
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;
        
        
        

        set sa = '';
        

                     
        if loginTest() then
							
							select supermanager into sm from users where user_id = @nervuser;
       					select member_type into sa from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
       					select user_id into acount from domain_data where id = domain_idkey;
       					select public into pbc from domain_data where id = domain_idkey;

                       if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                          select 1 as test;
                          select data.data_auto_id, data.domain_id, data.name, data.`type`, data.real_data_auto_id,  data.scmin, data.scmax, data.seq, data.description, data.user_id
                                 from data where domain_id=domain_idkey order by domain_id asc;
								                    
                       else
                          select 0 as test;
                       end if;               
       else
                select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.methodViewTreeList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `methodViewTreeList`(IN `domain_idkey` int, IN `domaintype` varchar(100), IN `typekey` varchar(100), IN `codekey` varchar(100), IN `methodkey` varchar(100))
BEGIN
        if loginTest() and domainReadTest(domain_idkey, domaintype) then
                select 1 as test;
                if typekey = 'ALL' then
                        if codekey = ' ' then
                                select domain_id, name, type,code,in_domain_id,in_data,out_domain_id,out_data,user_id,description from method
										   where domain_id=domain_idkey and method like methodkey order by code  asc;
                        else
                                select domain_id, name, type,code,in_domain_id,in_data,out_domain_id,out_data,user_id,description from method
										   where domain_id=domain_idkey and code like codekey and method like methodkey order by code  asc;
                        end if;
                else
                        if codekey = ' ' then
                                select domain_id, name, type,code,in_domain_id,in_data,out_domain_id,out_data,user_id,description from method
										   where domain_id=domain_idkey and type=typekey and method like methodkey order by code asc;
                        else
                                select domain_id, name, type,code,in_domain_id,in_data,out_domain_id,out_data,user_id,description from method
										   where domain_id=domain_idkey and type=typekey and code like codekey and method like methodkey order by code asc;
                        end if;
                end if;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.networkLinkViewConnectSwitch 구조 내보내기
DELIMITER //
CREATE PROCEDURE `networkLinkViewConnectSwitch`(in_node_id int)
BEGIN
     if loginTest() then
         select 1 as test;
         select b.node_id, b.ip, b.mask, b.port, b.net from
         (select s_node_id, s_port_id, d_node_id, d_port_id from network_link where s_node_id=in_node_id and d_node_id !=0) as a
         join
         (select node_id, ip, mask, port, net from network) as b on b.node_id = a.d_node_id and b.port=a.d_port_id;
               
               
     else
         select 0 as test;
     end if; 
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.netWorkLinkViewDeleteNetWorkLink 구조 내보내기
DELIMITER //
CREATE PROCEDURE `netWorkLinkViewDeleteNetWorkLink`(in_s_node_id_key int, in_s_port_id_key int)
BEGIN
     if loginTest() then
         select 1 as test;
         delete from network_link where s_node_id = in_s_node_id_key and s_port_id = in_s_port_id_key;
     else
         select 0 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.NetworklinkViewEditNetworkink 구조 내보내기
DELIMITER //
CREATE PROCEDURE `NetworklinkViewEditNetworkink`(in_s_node_id_key int, in_s_node_port_key int,
                                                                    in_s_node_id_edit int, in_s_node_sub_system_domain_id int, in_s_node_port_edit int,
                                                                    in_d_node_id_edit int, in_d_node_sub_system_domain_id int, in_d_node_port_edit int)
BEGIN
     if loginTest() then
         select 1 as test;
         UPDATE network_link set s_node_id=in_s_node_id_edit, s_sub_system_id=in_s_node_sub_system_domain_id, s_port_id=in_s_node_port_edit,
                                 d_node_id=in_d_node_id_edit, d_sub_system_id=in_d_node_sub_system_domain_id, d_port_id=in_d_node_port_edit
                             where s_node_id = in_s_node_id_key and s_port_id=in_s_node_port_key;

     else
         select 0 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.NetworklinkViewNetworkinkList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `NetworklinkViewNetworkinkList`(
	IN `in_system_domain_id` int
)
BEGIN
     if loginTest() then
         select 1 as test;

			select * from          
				(
		         select a.s_node_id, b.name as sname, a.s_port_id as s_port_id, a.d_node_id, c.name as dname, a.d_port_id from
		         ((select s_node_id, s_port_id, d_node_id, d_port_id from network_link where s_node_id in (SELECT id from node where systemdomain_id = in_system_domain_id)) as a
   		      join
      		   (select id, name, node.type  from node) as b on b.id = a.s_node_id
         		join
		         (select id, name from node) as c on c.id = a.d_node_id) order by b.type
	         ) as x order by sname, s_port_id asc;
	         

        else
         select 0 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.NetworklinkViewNewNetworkink 구조 내보내기
DELIMITER //
CREATE PROCEDURE `NetworklinkViewNewNetworkink`(in_s_node_id int, in_s_sub_system_id int, in_s_port_id int,
                                                                   in_d_node_id int, in_d_sub_system_id int, in_d_port_id int)
BEGIN
     if loginTest() then
         select 1 as test;
         insert into network_link(s_node_id, s_sub_system_id, s_port_id, d_node_id, d_sub_system_id, d_port_id)
                           values(in_s_node_id, in_s_sub_system_id, in_s_port_id, in_d_node_id, in_d_sub_system_id, in_d_port_id);
     else
         select 0 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.networkNewip 구조 내보내기
DELIMITER //
CREATE PROCEDURE `networkNewip`(IN `innodeid` int, IN `inip` VARCHAR(255), IN `intmask` VARCHAR(255), IN `innet` varchar(50), IN `intgateway` VARCHAR(255), IN `indns` VARCHAR(255), IN `inport` int, IN `indescription` varchar(255))
BEGIN
     if loginTest() then
     		select 1 as test;
          insert into network (node_id,  ip,   mask,    net,   gateway,    dns,   port,   description, collision, original_node_id, original_node_port, original_node_ip)
                      values(innodeid, inip, intmask, innet, intgateway, indns, inport, indescription, 0, NULL, NULL, NULL);
		    insert into deployments_bind(deployments_bind.deployment_id, deployments_bind.node_id, deployments_bind.port, deployments_bind.ip)
		    select deployments.Id, innodeid, inport, inip from deployments where deployments.node_id = innodeid;
     else
         select 0 as test;
     end if;    
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.networkViewDeleteip 구조 내보내기
DELIMITER //
CREATE PROCEDURE `networkViewDeleteip`(in_node_id int,
                                                          in_ip varchar(100))
BEGIN
        if loginTest() then
                select 1 as test;
                delete from network where node_id=in_node_id and ip=in_ip;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.networkViewEditip 구조 내보내기
DELIMITER //
CREATE PROCEDURE `networkViewEditip`(IN `in_node_idkey` int, IN `in_ipkey` varchar(100), IN `in_edit_ip` varchar(100), IN `in_edit_mask` varchar(100), IN `in_edit_net` varchar(100), IN `in_edit_gateway` varchar(100), IN `in_edit_dns` varchar(100), IN `in_port_key` VARCHAR(100), IN `in_edit_port` varchar(100), IN `in_edit_description` varchar(100))
BEGIN
        if loginTest() then
                select 1 as test;
                       update network set ip=in_edit_ip, mask=in_edit_mask, net=in_edit_net, gateway=in_edit_gateway, dns=in_edit_dns,
                                       port=in_edit_port, description=in_edit_description 
                                    where node_id=in_node_idkey and ip=in_ipkey;
                                    
								if in_ipkey != in_edit_ip then
								  	update network set network.ip = in_edit_ip
							 			where network.original_node_id=in_node_idkey and network.original_node_port=in_edit_port and network.original_node_ip=in_ipkey;
							 			
									update deployments_bind a, (select * from deployments_bind where deployments_bind.deployment_id in
									(select deployments_bind.deployment_id from deployments_bind where deployments_bind.ip = in_ipkey and deployments_bind.node_id in(
																							select node_id from network where network.original_node_id = in_node_idkey and
																							 network.original_node_port=in_port_key and network.original_node_ip=in_ipkey))) b
									 set a.ip=in_edit_ip
									 where a.deployment_id = b.deployment_id;              

                     		update network set network.original_node_ip=in_edit_ip
							 			where network.original_node_id=in_node_idkey and network.original_node_port=in_edit_port and network.original_node_ip=in_ipkey;
							 	end if;
                      
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.networkViewList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `networkViewList`(IN `innode_id` int)
BEGIN
     if loginTest() then
         select 1 as test;
     
     	select a.ip, a.mask, a.gateway, a.dns, a.port, a.description, b.name, c.name, a.original_node_port, a.original_node_ip, a.net from 
     	(select * from network where node_id = innode_id) as a      
      
      join
      (select id, name  from node) as b on b.id = innode_id
		left join
		(select id, name  from node) as c on c.id = a.original_node_id;
     else
         select 0 as test;
     end if;     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.networkViewSubsystemList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `networkViewSubsystemList`(in_sub_system_id int)
BEGIN
     if loginTest() then
         select 1 as test;
         
         SELECT a.d_port_id , b.name, b.type, a.s_port_id, d.ip, d.mask, d.gateway, d.dns, d.description from
         (select s_node_id, s_port_id, d_port_id, d_sub_system_id from network_link where d_sub_system_id = in_sub_system_id) as a
         join
         (select id, name, type from node) as b on b.id = a.s_node_id
         join
         (select id, name from domain_system) as c on c.id = a.d_sub_system_id
         left join
         (select node_id, ip, port, mask, net, gateway, dns, description from network) as d on d.node_id = a.s_node_id and d.port = a.s_port_id;

         else
         select 0 as test;
     end if;     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.network_table_node_Ip_ist 구조 내보내기
DELIMITER //
CREATE PROCEDURE `network_table_node_Ip_ist`(IN `in_deploy_id` INT)
BEGIN
     if loginTest() then
         select 1 as test;
			select * from network where network.node_id in(select node_id from deployments where deployments.Id = in_deploy_id);
	  else
	  		select 0 as test;
	  end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeComponentViewProxyComponentList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeComponentViewProxyComponentList`(IN `in_node_id` int, IN `in_objectid` int, IN `in_interface_name` varchar(100), IN `in_domain_id` int, IN `in_component_id` INT)
BEGIN 
     if loginTest() then
     select 1 as test;
      
      	select d.*, a.stub_ip, a.stub_object_id, e.name, b.id from
		( 
			select * from custum_proxy where stub_object_id=in_objectid and stub_ip in(
				select ip from deployments_bind where deployments_bind.deployment_id in (select id from deployments where deployments.component_id = in_component_id))
		) as a
		join
		(select * from proxy_interface_relation) as c on c.id = a.proxy_interface_id and c.interface_name=in_interface_name
	   join	 
	  	(select * from deployments) as b on b.id = a.deploy_id and systemdomain_id=in_domain_id	
	  	join
	  	(select * from component) as d on d.id = b.component_id
	  	join
	  	(select * from node) as e on e.id = b.node_id
	  ;
      
     else
         select 0 as test;
     end if; 
 End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodecomponentViewstubcomponentlist 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodecomponentViewstubcomponentlist`(IN `in_objectid` int, IN `in_networkip` varchar(255), IN `in_domain_id` int)
BEGIN 
     if loginTest() then
     select 1 as test;
      select  a.stub_interface_id, a.object_id, b.component_id , b.interface_name, c.id, c.systemdomain_id, c.name, c.seq, c.description, d.name, a.deploy_id from 
      	(select id, deploy_id, stub_interface_id, object_id FROM custum_stub where object_id = in_objectid and deploy_id in 
         	(select deployments_bind.deployment_id from deployments_bind where deployments_bind.ip=in_networkip and  deployments_bind.deployment_id in
					(select id from deployments where deployments.systemdomain_id=in_domain_id and deployments.node_id in
						(select node_id from network where ip = in_networkip)))) as a
		     join
          (select id, component_id, interface_name, class_name from stub_interface_relation) as b on b.id = a.stub_interface_id
           join
          (select id, systemdomain_id, name, seq, description from component) as c on c.id = b.component_id      
			  join				  
			 (select Id, name from node where node.Id in
				 (select node_id from deployments where deployments.systemdomain_id=in_domain_id and deployments.node_id in
					(select node_id from network where ip = in_networkip)
				 )
			  ) as d ;
     
      else
         select 0 as test;
     end if; 
 End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeDeleteNodes 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeDeleteNodes`(IN `inidkey` int)
BEGIN

 declare node_type varchar(100);
 
        if loginTest() and domainManageTest(inidkey) then
                select 1 as test;
                select node.`type` into node_type from node where id=inidkey;
                
                if node_type='sub_system' then
   	             delete from component where component.id in(select deployments.component_id from deployments where deployments.node_id=inidkey);
                end if;
                
                delete from node where id=inidkey;                       
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeDeploymentViewComponentList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeDeploymentViewComponentList`(IN `in_systemdomain_id` int, IN `in_node_id` int)
BEGIN

     if loginTest() then
         select 1 as test;
         
         select Id, systemdomain_id, name, seq, description from component where systemdomain_id = in_systemdomain_id; 
         
     else
         select 0 as test;
     end if;
     
     
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeDeploymentViewDeleteComponent 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeDeploymentViewDeleteComponent`(IN `in_id` int)
BEGIN

 
        if loginTest() then
                select 1 as test;
                
                delete from deployments where deployments.Id = in_id;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeDeploymentViewInstallList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeDeploymentViewInstallList`(
	IN `in_systemdomain_id` int,
	IN `in_node_id` int
)
BEGIN

     if loginTest() then
         select 1 as test;
         
         
         select B.ID as process_id , A.Id as component_id, A.systemdomain_id, A.name, A.seq, A.description from
         
--			( select Id, systemdomain_id, name, seq, description from component  where systemdomain_id = in_systemdomain_id ) as A
			( select Id, systemdomain_id, name, seq, description from component ) as A
         
         join deployments as B
             on A.Id = B.component_id
             where node_id = in_node_id;              
         

     else
         select 0 as test;
     end if;
     
     
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeDeploymentViewNewcomponent 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeDeploymentViewNewcomponent`(IN `in_node_id` int, IN `in_component_id` int, IN `in_systemdomain_id` int, IN `in_copy_deploy_id` INT)
BEGIN

	  declare new_deployment_id int;  

 
     if loginTest() then
     		select 1 as test;
                      
	   	insert into deployments(node_id, component_id, systemdomain_id) values(in_node_id, in_component_id, in_systemdomain_id);
			select Last_INSERT_ID() into new_deployment_id;
 
			insert into custum_proxy (deploy_id, proxy_interface_id, object_name)
			select new_deployment_id, proxy_interface_object.proxy_interface_id, proxy_interface_object.object_name from proxy_interface_object where proxy_interface_id in
			(select id from proxy_interface_relation where component_id = in_component_id);
			
			insert into custum_stub (deploy_id, stub_interface_id, object_name)
			select new_deployment_id, stub_interface_object.stub_interface_id, stub_interface_object.object_name from stub_interface_object where stub_interface_id in
			(select id from stub_interface_relation where component_id = in_component_id);
			
			update custum_proxy set original_id=custum_proxy.Id where custum_proxy.deploy_id = new_deployment_id;
			update custum_stub set original_id=custum_stub.Id where custum_stub.deploy_id = new_deployment_id;
			
			update custum_proxy set original_deployment_id=custum_proxy.deploy_id where custum_proxy.deploy_id = new_deployment_id;
			update custum_stub set original_deployment_id=custum_stub.deploy_id where custum_stub.deploy_id = new_deployment_id;
			
			insert into deployments_bind (deployments_bind.deployment_id, deployments_bind.node_id, deployments_bind.port, deployments_bind.ip)
			select new_deployment_id, network.node_id, network.port, network.ip from network where network.node_id = in_node_id;
			
			
			if in_copy_deploy_id > 0 then
				update custum_proxy as a,
      		(select custum_proxy.object_name, custum_proxy.object_id, custum_proxy.stub_object_id, custum_proxy.stub_ip, custum_proxy.public from custum_proxy
				 where deploy_id = in_copy_deploy_id) as b
      			set a.object_id = b.object_id, a.stub_object_id=b.stub_object_id, a.stub_ip=b.stub_ip, a.public=b.public
      			where a.deploy_id = new_deployment_id and a.object_name=b.object_name;

				update custum_stub as a,
      		(select custum_stub.object_name, custum_stub.object_id, custum_stub.public from custum_stub where deploy_id = in_copy_deploy_id) as b
      			set a.object_id = b.object_id, a.public=b.public
      			where a.deploy_id = new_deployment_id and a.object_name=b.object_name;   
      	end if;

       else
         select 0 as test;
     end if;     
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeDeploymentViewUpdateCustumTable 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeDeploymentViewUpdateCustumTable`(IN `in_copy_deploy_id` INT, IN `in_new_component_id` INT)
BEGIN

	declare in_new_deploy_id int;
   declare new_custum_id int;
  	declare check_public int;
	
	if logintest() then
		select 1 as test;
		select id into in_new_deploy_id from deployments where deployments.component_id = in_new_component_id;		

		update custum_proxy as a,
      	(select custum_proxy.object_name, custum_proxy.object_id, custum_proxy.stub_object_id, custum_proxy.stub_ip, custum_proxy.public from custum_proxy where deploy_id = in_copy_deploy_id) as b
      set a.object_id = b.object_id, a.stub_object_id=b.stub_object_id, a.stub_ip=b.stub_ip, a.public=b.public
      where a.deploy_id = in_new_deploy_id and a.object_name=b.object_name;


		update custum_stub as a,
      	(select custum_stub.object_name, custum_stub.object_id, custum_stub.public from custum_stub where deploy_id = in_copy_deploy_id) as b
      set a.object_id = b.object_id, a.public=b.public
      where a.deploy_id = in_new_deploy_id and a.object_name=b.object_name;     

   else
   			select 0 as test;
   end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeNewNodes 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeNewNodes`(IN `insystemdomainid` int, IN `inname` varchar(50), IN `intype` varchar(50), IN `indescription` text, IN `in_sub_system_domain_id` int)
BEGIN	
	
     if loginTest() then
     		select 1 as test;
    		
			  if intype = 'router' then
     			set intype = 'urouter';
     		end if;
         
			insert into node(systemdomain_id, name, type, description, sub_system_domain_id)
                      values(insystemdomainid, inname, intype, indescription, in_sub_system_domain_id);
         
			select LAST_INSERT_ID();
         
     else
         select 0 as test;
     end if;
     
     
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeportViewNewNode 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeportViewNewNode`(in_node_id int, in_domain_system_id int, in_sub_system_domain_id int)
BEGIN
     if loginTest() then
         select 1 as test;
         insert node_port (id, systemdomain_id, sub_system_domain_id, port_group)
         select in_node_id, in_domain_system_id, domain_system_id, port_group from domain_system_logical_port where domain_system_id = in_sub_system_domain_id;

     else
         select 0 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeportViewNewPortGroup 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeportViewNewPortGroup`(in_sub_system_domain_id int, in_port_group int)
BEGIN
     if loginTest() then
         select 1 as test;
         insert into node_port (id, systemdomain_id, sub_system_domain_id, port_group)
          select id, systemdomain_id, sub_system_domain_id, in_port_group from node where sub_system_domain_id = in_sub_system_domain_id;
  
     else
         select 0 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeportViewNodeportInfo 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeportViewNodeportInfo`(in_node_id int)
BEGIN
     if loginTest() then
         select 1 as test;
        select  id, systemdomain_id, sub_system_domain_id, port_group from node_port where id =in_node_id;

     else
         select 0 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeproxyViewNewstubinfo 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeproxyViewNewstubinfo`(in_nodeid int,
                                                   in_stub_objectid       varchar(50),
                                                   in_stub_ip     varchar(255))
BEGIN
     if loginTest() then
     select 1 as test;
         update custum_proxy set stub_object_id=in_stub_objectid, stub_ip=in_stub_ip
          where id=in_nodeid;                      
     else
         select 0 as test;
     end if;    
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodesNewSwitch 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodesNewSwitch`(insystemdomainid int,
                                                     inip varchar(50),
                                                     insubnetmask varchar(50),
                                                     indescription text)
BEGIN
     if loginTest() then
         insert into network(systemdomain_id, ip, subnetmask, description)
                      values(insystemdomainid, inip, insubnetmask, indescription);
         select 1 as test;
     else
         select 0 as test;
     end if;
     
     
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeViewConnectSwitch 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeViewConnectSwitch`(in_node_id int)
BEGIN
     if loginTest() then
         select 1 as test;
                select a.node_id, a.ip, a.mask, a.mac, b. name, a.net from
                (select node_id, ip, mask, port, net from network where connect_node_id = in_node_id) as a
                join
                (select id, name from node )as b on b.id=a.node_id;
     else
         select 0 as test;
     end if; 
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.NodeViewEditNode 구조 내보내기
DELIMITER //
CREATE PROCEDURE `NodeViewEditNode`(IN `in_node_idkey` int, IN `in_systemdomain_id` int, IN `in_name` varchar(100), IN `in_type` varchar(100), IN `in_description` varchar(100), IN `in_sub_system_domain_id` int, IN `in_lock_state` INT)
BEGIN
declare cnt int;

declare enum_lock varchar(10) default 'N';
set cnt=0;
 
        if loginTest() then
          select 1 as test;
          
         if in_type = 'router' then
     			set in_type = 'urouter';
     		end if;     
			  
			if in_lock_state = 1 then
     			set enum_lock = 'Y';
     		end if;   		
                     
			  update node set name=in_name, type=in_type, description=in_description, sub_system_domain_id=in_sub_system_domain_id, complete=enum_lock
                     where id=in_node_idkey and systemdomain_id=in_systemdomain_id;
							
			   select count(*) into cnt from node_port where (id, sub_system_domain_id) in (SELECT  id, sub_system_domain_id  from node where id=241);
                       
           if cnt=0 then
	           delete from node_port where id=in_node_idkey;
              call nodeportViewNewNode(in_node_idkey, in_systemdomain_id, in_sub_system_domain_id);
           end if;       
                          
                     
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeViewList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeViewList`(
	IN `indomainid` int
)
BEGIN
     if loginTest() then
         select 1 as test;
         
         select * from
				(
		         select a.Id, a.systemdomain_id, a.name as aname, a.type, a.description, a.sub_system_domain_id,  b.name, a.complete from
      		   (select Id, systemdomain_id, name, type, description, sub_system_domain_id, complete from node where systemdomain_id=indomainid) as a 
		         left outer join
		         (select id, name from domain_system ) as b on b.id=a.sub_system_domain_id
		      ) as xxx order by aname asc;
         
     else
         select 0 as test;
     end if; 
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeViewListnodeKey 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeViewListnodeKey`(IN `in_node_id` INT)
BEGIN

     if loginTest() then
         select 1 as test;
         select a.Id, a.systemdomain_id, a.name, a.type, a.description, a.sub_system_domain_id,  b.name from
         (select Id, systemdomain_id, name, type, description, sub_system_domain_id from node where node.Id=in_node_id) as a 
         left outer join
         (select id, name from domain_system ) as b on b.id=a.sub_system_domain_id;                
     else
         select 0 as test;
     end if; 

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeViewNetworkPort 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeViewNetworkPort`(in_sub_domain_system_id int, in_node_id int)
BEGIN
        if loginTest() then
           select 1 as test;
                       
             select port_num, description from domain_system_port where domain_system_id=in_sub_domain_system_id and
                  port_num not in (SELECT s_port_id from network_link where s_node_id = in_node_id and s_sub_system_id = in_sub_domain_system_id)
            and   port_num not in (SELECT d_port_id from network_link where d_node_id = in_node_id and d_sub_system_id = in_sub_domain_system_id); 
        else
            select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.nodeViewnodeinfo 구조 내보내기
DELIMITER //
CREATE PROCEDURE `nodeViewnodeinfo`(IN `in_deploy_id` int)
BEGIN
     if loginTest() then
         select 1 as test;
         select node.Id, node.systemdomain_id, node.name, node.`type`, node.description from node where node.Id in(select node_id from deployments where id = in_deploy_id);
           
                  
     else
         select 0 as test;
     end if; 
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.node_table_node_info 구조 내보내기
DELIMITER //
CREATE PROCEDURE `node_table_node_info`(IN `in_deploy_id` INT)
BEGIN

	if logintest() then
		select 1 as test;
		select node.Id, node.systemdomain_id, node.name, node.`type`, node.description from node where node.systemdomain_id in(select systemdomain_id from deployments
		 where id = in_deploy_id);
	else
		select 0 as test;
	end if;
	
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.proxyComponentViewParentInterfaceRealdomainList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `proxyComponentViewParentInterfaceRealdomainList`(domain_idkey int)
BEGIN
         declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;
  
        set sa = '';
        if loginTest() then
        
                    select supermanager into sm from users where user_id=@nervuser;
                    select member_type into sa from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
                    select user_id into acount from domain_method where id=domain_idkey;
                    select public into pbc from domain_method where id=domain_idkey;

                    if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                        (select id, name from domain_method where id in (select parent_domain_id from inheritance_system_method where domain_id=domain_idkey))
                         union
                        (select id, name from domain_method where id=domain_idkey);
                                
                    else
                        select 0 as test;
                     end if;
               else
                 select 0 as test;
        end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.proxyComponentViewParentInterfaceRealinterfaceList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `proxyComponentViewParentInterfaceRealinterfaceList`(domain_idkey int,in_component_idkey int)
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;

        set sa = '';
        if loginTest() then       
                     select supermanager into sm from users where user_id=@nervuser;
                     select member_type into sa from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
                     select user_id into acount from domain_method where id=domain_idkey;
                     select public into pbc from domain_method where id=domain_idkey;

                     if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                        select domain_id, name, user_id, seq, description from interface where domain_id=domain_idkey and name not in
                                        (select interface_name from proxy_interface_relation where component_id=in_component_idkey);
                     else
                        select 0 as test;
                     end if;               

        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.proxyInterfaceObjectViewDelete 구조 내보내기
DELIMITER //
CREATE PROCEDURE `proxyInterfaceObjectViewDelete`(in_interface_object_id int, in_object_name varchar(100), in_component_id int)
BEGIN 
        if loginTest()then
                select 1 as test;
                delete from proxy_interface_object where proxy_interface_id=in_interface_object_id and object_name=in_object_name and component_id=in_component_id;                       
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.proxyInterfaceObjectViewEditObjectName 구조 내보내기
DELIMITER //
CREATE PROCEDURE `proxyInterfaceObjectViewEditObjectName`(in_proxy_interface_id int, in_object_name varchar (100), in_component_id int, in_edit_object_name varchar(100))
BEGIN
        if loginTest() then
                select 1 as test;
                UPDATE proxy_interface_object Set object_name=in_edit_object_name
                                where proxy_interface_id=in_proxy_interface_id and component_id=in_component_id and object_name=in_object_name;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.proxyInterfaceObjectViewList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `proxyInterfaceObjectViewList`(in_proxy_interface_relation_id int)
BEGIN
     if loginTest() then
         select 1 as test;
         select * from proxy_interface_object where proxy_interface_id=in_proxy_interface_relation_id;
     else
         select 0 as test;
     end if;     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.proxyInterfaceObjectViewNewObjectName 구조 내보내기
DELIMITER //
CREATE PROCEDURE `proxyInterfaceObjectViewNewObjectName`(in_proxy_interface_id int, in_object_name varchar (100), in_component_id int)
BEGIN
        if loginTest() then
                select 1 as test;
                insert into proxy_interface_object (proxy_interface_id, object_name, component_id)
                                values(in_proxy_interface_id, in_object_name, in_component_id);
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.proxyInterfaceRalationDeleteInterface 구조 내보내기
DELIMITER //
CREATE PROCEDURE `proxyInterfaceRalationDeleteInterface`(inidkey int)
BEGIN 
        if loginTest()then
                select 1 as test;
                delete from proxy_interface_relation where id=inidkey;                       
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.proxyInterfaceRalationViewEditInterface 구조 내보내기
DELIMITER //
CREATE PROCEDURE `proxyInterfaceRalationViewEditInterface`(in_idkey int,
                                                                              in_method_domain_id int,
                                                                              in_interface_name varchar(100),
                                                                              in_class_name varchar(255))
BEGIN
        if loginTest() then
                select 1 as test;
                update proxy_interface_relation set  method_domain_id = in_method_domain_id,
                                                     interface_name = in_interface_name,
                                                     class_name = in_class_name where id = in_idkey;


        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.proxyInterfaceRalationViewNewInterface 구조 내보내기
DELIMITER //
CREATE PROCEDURE `proxyInterfaceRalationViewNewInterface`(in_component_id int,
                                                                             in_method_domain_id int,
                                                                             in_interface_name varchar(100),
                                                                             in_class_name varchar(255))
BEGIN
        if loginTest() then
                select 1 as test;
                    insert into proxy_interface_relation (component_id, method_domain_id, interface_name, class_name)
                                values(in_component_id, in_method_domain_id, in_interface_name, in_class_name);
                    select LAST_INSERT_ID();              
        else
                select 0 as test;
                
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.proxyInterfaceRelationViewClassNameList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `proxyInterfaceRelationViewClassNameList`(in_component_id int, in_method_domain_id int, in_interface_name varchar(100))
BEGIN
     if loginTest() then
         select 1 as test;
         select class_name from proxy_interface_relation where 
                component_id=in_component_id and method_domain_id=in_method_domain_id and interface_name=in_interface_name;
     else
         select 0 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.proxyInterfaceRelationViewSearchList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `proxyInterfaceRelationViewSearchList`(in_component_id int, in_method_domain_id int, in_interface_name varchar(100), in_class_name varchar(255))
BEGIN
     if loginTest() then
         select 1 as test;
         select id from proxy_interface_relation where 
                component_id=in_component_id and method_domain_id=in_method_domain_id and interface_name=in_interface_name and class_name=in_class_name;
     else
         select 0 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.proxyInterfaceViewList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `proxyInterfaceViewList`(
	IN `incomponent_id` int
)
BEGIN
     if loginTest() then
         select 1 as test;
         
        select a.id,  a.method_domain_id, a.component_id, a.interface_name, b.name as method_domain_name, a.class_name from 
         
         (select id, component_id, method_domain_id, interface_name, class_name from proxy_interface_relation where component_id = incomponent_id) as a
         join
         (select id,name from domain_method) as b on a.method_domain_id = b.id;   
         
     else
         select 0 as test;
     end if;    
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.SelectinterfaceViewInterfaceList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `SelectinterfaceViewInterfaceList`()
BEGIN
   if loginTest() then
     select 1 as test;
     select b.id, b.name, b.upper_id, a.name, a.user_id, a.seq from
     (select  domain_id, name, user_id, seq, description from interface) As a
     join
     (select id, name, upper_id from domain_method) As b on a.domain_id = b.id;
   else
      select 0 as test;
   end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.select_all_deploy_component_only_proxy 구조 내보내기
DELIMITER //
CREATE PROCEDURE `select_all_deploy_component_only_proxy`(IN `in_domain_id` INT)
BEGIN

	if logintest() then
		select 1 as test;
select n.id, m.* from
(
select * from component WHERE id in (
SELECT component_id from deployments where systemdomain_id = in_domain_id and component_id not in (
select id from component where id in (
select component_id from deployments where id in (
select k.original_deployment_id from

(
   select a_f.original_deployment_id, b_f.interface_name, a_f.object_id, c_f.ip from
          (select * from custum_stub where deploy_id in (select id from deployments where deployments.systemdomain_id=in_domain_id)) as a_f
          join
          (select * from stub_interface_relation) as b_f on b_f.id = a_f.stub_interface_id
          join
          (select * from deployments_bind) as c_f on a_f.deploy_id = c_f.deployment_id
 ) as k
 join

(
   select a.original_deployment_id, b.interface_name, a.stub_object_id, a.stub_ip from
   (
	        (select * from custum_proxy where stub_object_id > 0 and public !=1 and deploy_id in (select id from deployments where deployments.systemdomain_id=in_domain_id)) as a
 	        join
	        (select * from proxy_interface_relation) as b on b.id = a.proxy_interface_id
   ) 
) as i
where i.interface_name = k.interface_name and i.stub_object_id=k.object_id and i.stub_ip=k.ip group by k.original_deployment_id
))))) as m
 join deployments as n on n.component_id = m.id;

	
		
	else
	   select 0 as test;
	end if;
	
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.select_all_deploy_stub_component 구조 내보내기
DELIMITER //
CREATE PROCEDURE `select_all_deploy_stub_component`(IN `in_domain_id` INT, IN `in_component_id` INT)
BEGIN

   if logintest() then
      select 1 as test;
      select d.id, c.* from
		(select * from component where component.id != in_component_id and component.id in 
			(select component_id from deployments where deployments.id in 
				(select b.deploy_id from
					(select * from deployments where deployments.systemdomain_id = in_domain_id and id in
						(select deployment_id from deployments_bind where deployments_bind.ip in 
							(select stub_ip from custum_proxy where custum_proxy.stub_object_id !=0 and custum_proxy.deploy_id in
								(select id from deployments where deployments.component_id = in_component_id)))) as a
				join custum_stub as b on b.deploy_id = a.id and b.object_id in
		 			(select stub_object_id from custum_proxy where custum_proxy.stub_object_id !=0 and custum_proxy.deploy_id in
		  				(select id from deployments where deployments.component_id = in_component_id))))) as c		  
		  join deployments as d on d.component_id=c.id;
      
      
      
	else
		select 0 as test;
	end if;

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.select_deploy_all_components 구조 내보내기
DELIMITER //
CREATE PROCEDURE `select_deploy_all_components`(IN `in_domain_id` INT)
BEGIN

   if logintest() then
   	select 1 as test;
   	select a.*, b.node_id from
		(
			(select * from component where id in(select component_id from deployments where deployments.systemdomain_id = in_domain_id)) as a
			join
			(select * from deployments) as b on b.systemdomain_id = in_domain_id
		);
	else
		select 0 as test;
	end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.select_group 구조 내보내기
DELIMITER //
CREATE PROCEDURE `select_group`(IN `in_d_subsystem_id` INT, IN `in_d_port_id` INT, IN `in_s_node_id` INT, IN `in_s_node_port` INT)
BEGIN


	
	declare logical_port int;
	declare sub_domain_id int;

	Select sub_system_domain_id into sub_domain_id from node where id = in_s_node_id;
	select port_group into logical_port from domain_system_port as A where A.domain_system_id = sub_domain_id and A.port_num = in_s_node_port;
	
	call select_group_recursion( in_d_subsystem_id , in_d_port_id , 0 , in_d_port_id , in_s_node_id , logical_port , 10 );
	
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.select_group_recursion 구조 내보내기
DELIMITER //
CREATE PROCEDURE `select_group_recursion`(IN `in_domain_system_id` INT, IN `in_export_num` INT, IN `in_parent_node_id` INT, IN `in_parent_port_group` INT, IN `in_node_id` INT, IN `in_port_group` INT, IN `in_depth` INT)
BEGIN
	declare domain_id int;	
	declare no_more_rows bool default false;		
	declare child_node_id int;
	declare child_port_group int;
	declare node_port_count int;	
	
	DECLARE my_list CURSOR FOR select K.node_id , domain_system_port.port_group from
		 		(
				 	(
					 	select s_node_id as node_id , s_sub_system_id as sub_system_id , s_port_id as port_id from network_link where
						 							( d_node_id , d_port_id ) in ( select in_node_id, port_num from domain_system_port as A where A.domain_system_id = domain_id and A.port_group = in_port_group )
					)
						union
				 	(
					 	select d_node_id , d_sub_system_id , d_port_id  from network_link where
						 							 ( s_node_id , s_port_id ) in ( select in_node_id, port_num from domain_system_port as A where A.domain_system_id = domain_id and A.port_group = in_port_group )						 							
					) 
				) as K				
			join			
				domain_system_port on K.sub_system_id = domain_system_port.domain_system_id and K.port_id = domain_system_port.port_num					
	where
			not ( K.node_id = in_parent_node_id and domain_system_port.port_group = in_parent_port_group );

	declare continue handler for not found set no_more_rows := TRUE;
		set max_sp_recursion_depth = 50;

	if in_node_id = 0 then	
		 
		 set node_port_count = 0;
		 select count(*) into node_port_count from node_port where sub_system_domain_id = in_domain_system_id and port_group = in_port_group;
		 
		 if node_port_count = 0 then
		 	 update node_port set port_group = in_port_group where sub_system_domain_id = in_domain_system_id and port_group = in_export_num;			 	
		 end if;		 
	end if;

	if in_depth > 0 then		
		select node.sub_system_domain_id into domain_id from node where node.Id = in_node_id; 
		open my_list;	
		my_loop : loop
		
			fetch my_list into child_node_id , child_port_group;
			if no_more_rows then
				close my_list;
				leave my_loop;
			end if;				
			call select_group_recursion( in_domain_system_id, in_export_num , in_node_id, in_port_group , child_node_id , child_port_group , in_depth - 1 );		
		end loop my_loop;		
	end if;	
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.select_network 구조 내보내기
DELIMITER //
CREATE PROCEDURE `select_network`(IN `in_node_id` INT)
BEGIN
	declare sub_domain_id int;
	declare export_group int;
	declare inner_node_id int;
	declare  inner_port_group int;
	declare no_more_rows bool default false;

	DECLARE my_list CURSOR FOR select D.port_group as export_group , s_node_id as inner_node_id , E.port_group as inner_port_group from 
		(
			select s_node_id , sub_system_domain_id, type, s_port_id , port_group  from  
				(
					 select s_node_id , s_port_id , port_group from
					 	(
						 	select * from network_link where d_node_id = 0 and d_sub_system_id = sub_domain_id
						) as A
							join			
						(
							select * from domain_system_port where domain_system_id = sub_domain_id
						) as B
							on  A.d_port_id = B.port_num group by port_group
				) as C
					join node on C.s_node_id = node.id
		) as D
			join domain_system_port as E on D.sub_system_domain_id = E.domain_system_id and D.s_port_id = E.port_num;
			
	declare continue handler for not found set no_more_rows := TRUE;
	
	set max_sp_recursion_depth = 50;			
	select sub_system_domain_id into sub_domain_id from node where id = in_node_id;
	
	open my_list;	
	my_loop : loop	
		fetch my_list into export_group , inner_node_id , inner_port_group;
		if no_more_rows then
			close my_list;
			leave my_loop;
		end if;		
		 call select_network_recursion( in_node_id, export_group, 0 , export_group , inner_node_id , inner_port_group , 10 );		
	end loop my_loop;	
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.select_network_recursion 구조 내보내기
DELIMITER //
CREATE PROCEDURE `select_network_recursion`(IN `in_insert_node` INT, IN `in_insert_port_group` INT, IN `in_parent_node_id` INT, IN `in_parent_port_group` INT, IN `in_node_id` INT, IN `in_port_group` INT, IN `in_depth` INT)
BEGIN
	declare domain_id int;	
	declare no_more_rows bool default false;		
	declare child_node_id int;
	declare child_port_group int;
	declare network_count int;	
	
	DECLARE my_list CURSOR FOR select K.node_id , domain_system_port.port_group from
		 		(
				 	(
					 	select s_node_id as node_id , s_sub_system_id as sub_system_id , s_port_id as port_id from network_link where ( d_node_id , d_port_id ) in
						  ( select in_node_id, port_num from domain_system_port as A where A.domain_system_id = domain_id and A.port_group = in_port_group )
					)
						union
				 	(
					 	select d_node_id , d_sub_system_id , d_port_id  from network_link where	( s_node_id , s_port_id ) in
						  ( select in_node_id, port_num from domain_system_port as A where A.domain_system_id = domain_id and A.port_group = in_port_group )
					) 
				) as K
				
			join domain_system_port	on K.sub_system_id = domain_system_port.domain_system_id and K.port_id = domain_system_port.port_num					
	where	not ( K.node_id = in_parent_node_id and domain_system_port.port_group = in_parent_port_group );

	declare continue handler for not found set no_more_rows := TRUE;
	
	select count(*) into network_count from network where node_id = in_insert_node and
	 (original_node_id, original_node_port, original_node_ip) in
	  (select node_id, port, ip from network where node_id = in_node_id and port = in_port_group); 	 
	
	  if network_count=0  then 
	       insert into network ( node_id, port , ip, mask , net , gateway , dns, description, original_node_id, original_node_port, original_node_ip )
	            select in_insert_node , in_insert_port_group , ip, mask , net , gateway , dns, description, node_id, port, ip from network
					 where node_id = in_node_id and port = in_port_group;
	  end if;

	if in_depth > 0 then
		select node.sub_system_domain_id into domain_id from node where node.Id = in_node_id; 		
		open my_list;	
		my_loop : loop		
			fetch my_list into child_node_id , child_port_group;

			if no_more_rows then
				close my_list;
				leave my_loop;
			end if;				
			call select_network_recursion( in_insert_node, in_insert_port_group, in_node_id, in_port_group , child_node_id , child_port_group , in_depth - 1 );		
		end loop my_loop;		
	end if;	
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.select_search_data_name 구조 내보내기
DELIMITER //
CREATE PROCEDURE `select_search_data_name`(IN `in_search_name` VARCHAR(50))
BEGIN
	if loginTest() then	
			select 1 as test;				
		  select id,('domain') as type, name, (select `domainDataPath`(domain_data.id, ''))as path from domain_data where name like in_search_name
				union all		
			select domain_id,('data') as type, name, (select `domainDataPath`(data.domain_id, ''))as path from data where data.name like in_search_name 
				union all
			select b.domain_id,('data_field') as type, a.member_name as name, concat((select `domainDataPath`(b.domain_id, '')),b.name) as path from
	 		(select data_field.data_auto_id, data_field.member_name from data_field where member_name like in_search_name) as a
	 		   join
	 		(select data.data_auto_id, data.domain_id,  concat(data.name,'\\')as name from data) as b on a.data_auto_id=b.data_auto_id;		 		
	else	
		select 0 as test;		
	end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.select_search_method_name 구조 내보내기
DELIMITER //
CREATE PROCEDURE `select_search_method_name`(IN `in_search_name` VARCHAR(50))
BEGIN

	if loginTest() then	
		select 1 as test;
		
		select id,('domain') as type, name, (select `domainMethodPath`(domain_method.id, ''))as path from domain_method where name like in_search_name
			  union all		
		select domain_id,('method') as type, name, (select `domainMethodPath`(method.domain_id, ''))as path from method where method.name like in_search_name 
			 union all
		select domain_id,('interface') as type, name, (select `domainMethodPath`(interface.domain_id, ''))as path from interface where interface.name like in_search_name;	 		
	else	
		select 0 as test;		
	end if;

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.select_search_system_name 구조 내보내기
DELIMITER //
CREATE PROCEDURE `select_search_system_name`(IN `in_search_name` VARCHAR(50))
BEGIN

	if loginTest() then	
		select 1 as test;
		
		 select id,('domain') as type, name, (select `domainSystemPath`(domain_system.id, ''))as path from domain_system where name like in_search_name
  			union all
		 select systemdomain_id,('node') as type, name, concat((select `domainSystemPath`(node.systemdomain_id, '')),'Nodes\\')as path from node where node.name like in_search_name		 		
  			union all
		 select systemdomain_id,('component') as type, name, concat((select `domainSystemPath`(component.systemdomain_id, '')),'Components\\')as path from component where component.name like in_search_name
 		 	union all
 		 	
 		 select b.systemdomain_id, ('proxy_class') as type, a.class_name as name, concat((select `domainSystemPath`(b.systemdomain_id, '')),b.name,'\\proxy\\')as path from
			(select * from proxy_interface_relation where proxy_interface_relation.class_name like in_search_name) as a
				join
			(select component.id, component.systemdomain_id, concat('Components\\',component.name)as name from component)as b on a.component_id=b.id
 		 
			union all
			
	   select b.systemdomain_id, ('stub_class') as type, a.class_name as name, concat((select `domainSystemPath`(b.systemdomain_id, '')),b.name,'\\stub\\')as path from
				(select * from stub_interface_relation where stub_interface_relation.class_name like in_search_name) as a
					join
				(select component.id, component.systemdomain_id, concat('Components\\',component.name)as name from component)as b on a.component_id=b.id
			union all	
			
		select b.systemdomain_id, ('proxy_object') as type, (a.object_name)as name, concat((select `domainSystemPath`(b.systemdomain_id, '')),b.name,'\\proxy\\',c.class_name,'\\')as path from
				(select * from proxy_interface_object where proxy_interface_object.object_name like in_search_name) as a
					join
				(select component.id, component.systemdomain_id, concat('Components\\',component.name)as name from component)as b on a.component_id=b.id
					join
				(select proxy_interface_relation.id, proxy_interface_relation.interface_name, proxy_interface_relation.class_name from  proxy_interface_relation)as c on a.proxy_interface_id=c.id
		  union all
		  
	  select b.systemdomain_id, ('stub_object') as type, (a.object_name)as name, concat((select `domainSystemPath`(b.systemdomain_id, '')),b.name,'\\stub\\',c.class_name,'\\')as path from
			(select * from stub_interface_object where stub_interface_object.object_name like in_search_name) as a
				join
			(select component.id, component.systemdomain_id, concat('Components\\',component.name)as name from component)as b on a.component_id=b.id
				join
			(select stub_interface_relation.id, stub_interface_relation.interface_name, stub_interface_relation.class_name from  stub_interface_relation)as c on a.stub_interface_id=c.id;

	else	
		select 0 as test;		
	end if;


END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.serverViewDeleteField 구조 내보내기
DELIMITER //
CREATE PROCEDURE `serverViewDeleteField`(fieldvalue varchar(100))
BEGIN
        if loginTest() and supermanagerTest(@nervuser) then
                select 1 as test;
                delete from server_information where field_name=fieldvalue;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.serverViewEditField 구조 내보내기
DELIMITER //
CREATE PROCEDURE `serverViewEditField`(fieldvalue varchar(100), fieldedit varchar(100), descriptionedit text)
BEGIN

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.serverViewEditFieldSeq 구조 내보내기
DELIMITER //
CREATE PROCEDURE `serverViewEditFieldSeq`(fieldkey1 varchar(100), fieldkey2 varchar(100))
BEGIN
        declare t1 timestamp;
        declare t2 timestamp;
        if loginTest() and supermanagerTest(@nervuser) then
                select 1 as test;
                select seq into t1 from server_information where field_name=fieldkey1;
                select seq into t2 from server_information where field_name=fieldkey2;
                update server_information set seq = t2 where field_name=fieldkey1;
                update server_information set seq = t1 where field_name=fieldkey2;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.serverViewNewField 구조 내보내기
DELIMITER //
CREATE PROCEDURE `serverViewNewField`(fieldvalue varchar(100), seqvalue int, descriptionvalue text)
BEGIN
        if loginTest() and supermanagerTest(@nervuser) then
                select 1 as test;
                insert into server_information(field_name,seq, description) values(fieldvalue,seqvalue, descriptionvalue);
        else
                select 0 as test;
        end if;


END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.serverViewServerInfo 구조 내보내기
DELIMITER //
CREATE PROCEDURE `serverViewServerInfo`()
BEGIN
       if loginTest() then
               select 1 as test;
               select * from server_information order by seq asc;
       else
               select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.setup_public_interface_to_subsystem 구조 내보내기
DELIMITER //
CREATE PROCEDURE `setup_public_interface_to_subsystem`(IN `in_node_id` INT, IN `in_type` INT)
BEGIN
	 if loginTest() then
          select 1 as test;
          
          if in_type = 0 then
          		select custum_proxy.Id, custum_proxy.deploy_id,custum_proxy.public from custum_proxy where public=1 and deploy_id in
					(select id from deployments where node_id=in_node_id);
			else
			 		select custum_stub.Id, custum_stub.deploy_id,custum_stub.public from custum_stub where public=1 and deploy_id in
					(select id from deployments where node_id=in_node_id);
			end if;

	 else	
			 select 0 as test;
	 end if;

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.standard_port 구조 내보내기
DELIMITER //
CREATE PROCEDURE `standard_port`(in_port varchar(100), in_idkey int)
BEGIN
        if loginTest() then
              select 1 as test;
               update protocol_standard_port set discription=in_port where id=in_idkey;
         else
                         select 0 as test;
         end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.standard_portViewCheckPort 구조 내보내기
DELIMITER //
CREATE PROCEDURE `standard_portViewCheckPort`(in_port varchar(100))
BEGIN
        if loginTest() then
           select 1 as test;
           select * from protocol_standard_port where port like in_port;        
         else
           select 0 as test;
         end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.stubComponentViewParentInterfaceRealdomainList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `stubComponentViewParentInterfaceRealdomainList`(domain_idkey int)
BEGIN
         declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;
  
        set sa = '';
        if loginTest() then
        
                    select supermanager into sm from users where user_id=@nervuser;
                    select member_type into sa from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
                    select user_id into acount from domain_method where id=domain_idkey;
                    select public into pbc from domain_method where id=domain_idkey;

                    if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                        (select id, name from domain_method where id in (select parent_domain_id from inheritance_system_method where domain_id=domain_idkey))
                         union
                        (select id, name from domain_method where id=domain_idkey);
                                
                    else
                        select 0 as test;
                     end if;
               else
                 select 0 as test;
        end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.stubComponentViewParentInterfaceRealinterfaceList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `stubComponentViewParentInterfaceRealinterfaceList`(domain_idkey int,in_component_idkey int)
BEGIN
        declare sm bool;
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;

        set sa = '';
        if loginTest() then       
                     select supermanager into sm from users where user_id=@nervuser;
                     select member_type into sa from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
                     select user_id into acount from domain_method where id=domain_idkey;
                     select public into pbc from domain_method where id=domain_idkey;

                     if( pbc or sm or sa='member' or sa='manager' or acount = @nervuser ) then
                        select 1 as test;
                        select domain_id, name, user_id, seq, description from interface where domain_id=domain_idkey and name not in
                                        (select interface_name from stub_interface_relation where component_id=in_component_idkey);
                     else
                        select 0 as test;
                     end if;               

        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.stubInterfaceObjectViewDelete 구조 내보내기
DELIMITER //
CREATE PROCEDURE `stubInterfaceObjectViewDelete`(in_interface_object_id int, in_object_name varchar(100), in_component_id int)
BEGIN 
        if loginTest()then
                select 1 as test;
                delete from stub_interface_object where stub_interface_id=in_interface_object_id and object_name=in_object_name and component_id=in_component_id;                       
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.stubInterfaceObjectViewEditObjectName 구조 내보내기
DELIMITER //
CREATE PROCEDURE `stubInterfaceObjectViewEditObjectName`(in_stub_interface_id int, in_object_name varchar (100), in_component_id int, in_edit_object_name varchar(100))
BEGIN
        if loginTest() then
                select 1 as test;
                UPDATE stub_interface_object Set object_name=in_edit_object_name
                                where stub_interface_id=in_stub_interface_id and component_id=in_component_id and object_name=in_object_name;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.stubInterfaceObjectViewList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `stubInterfaceObjectViewList`(in_stub_interface_relation_id int)
BEGIN
     if loginTest() then
         select 1 as test;
         select * from stub_interface_object where stub_interface_id=in_stub_interface_relation_id;
     else
         select 0 as test;
     end if;     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.stubInterfaceObjectViewNewObjectName 구조 내보내기
DELIMITER //
CREATE PROCEDURE `stubInterfaceObjectViewNewObjectName`(in_stub_interface_id int, in_object_name varchar (100), in_component_id int)
BEGIN
        if loginTest() then
                select 1 as test;
                insert into stub_interface_object (stub_interface_id, object_name, component_id)
                                values(in_stub_interface_id, in_object_name, in_component_id);
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.stubInterfaceRalationDeleteInterface 구조 내보내기
DELIMITER //
CREATE PROCEDURE `stubInterfaceRalationDeleteInterface`(inidkey int)
BEGIN

 
        if loginTest()then
                select 1 as test;
                delete from stub_interface_relation where id=inidkey;                       
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.stubInterfaceRalationViewEditInterface 구조 내보내기
DELIMITER //
CREATE PROCEDURE `stubInterfaceRalationViewEditInterface`(in_idkey int,
                                                                              in_method_domain_id int,
                                                                              in_interface_name varchar(100),
                                                                              in_class_name varchar(255))
BEGIN
        if loginTest() then
                select 1 as test;
                update stub_interface_relation set  method_domain_id = in_method_domain_id,
                                                     interface_name = in_interface_name,
                                                     class_name = in_class_name
                                               where id = in_idkey;


        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.stubInterfaceRalationViewNewInterface 구조 내보내기
DELIMITER //
CREATE PROCEDURE `stubInterfaceRalationViewNewInterface`(in_component_id int,
                                                                             in_method_domain_id int,
                                                                             in_interface_name varchar(100),
                                                                             in_class_name varchar(255))
BEGIN
        if loginTest() then
                select 1 as test;
                insert into stub_interface_relation (component_id, method_domain_id, interface_name, class_name)
                                values(in_component_id, in_method_domain_id, in_interface_name, in_class_name);                                 
                                
                select LAST_INSERT_ID();
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.stubInterfaceRelationViewClassNameList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `stubInterfaceRelationViewClassNameList`(in_component_id int, in_method_domain_id int, in_interface_name varchar(100))
BEGIN
     if loginTest() then
         select 1 as test;
         select class_name from stub_interface_relation where 
                component_id=in_component_id and method_domain_id=in_method_domain_id and interface_name=in_interface_name;
     else
         select 0 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.stubInterfaceRelationViewSearchList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `stubInterfaceRelationViewSearchList`(in_component_id int, in_method_domain_id int, in_interface_name varchar(100), in_class_name varchar(255))
BEGIN
     if loginTest() then
         select 1 as test;
         select id from stub_interface_relation where 
                component_id=in_component_id and method_domain_id=in_method_domain_id and interface_name=in_interface_name and class_name=in_class_name;
     else
         select 0 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.stubInterfaceViewList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `stubInterfaceViewList`(
	IN `incomponent_id` int
)
BEGIN
     if loginTest() then
         select 1 as test;
         
         select a.id,  a.method_domain_id, a.component_id, a.interface_name, b.name as method_domain_name , a.class_name from
         
         (select id, component_id, method_domain_id, interface_name, class_name from stub_interface_relation where component_id = incomponent_id) as a
         join
         (select id,name from domain_method) as b on a.method_domain_id = b.id ;
         
         
     else
         select 0 as test;
     end if;
     
     
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.switchSubComponentInfo 구조 내보내기
DELIMITER //
CREATE PROCEDURE `switchSubComponentInfo`(in_node_id int)
BEGIN

     if loginTest() then
     select 1 as test;
        select component_id from stub_interface_relation where component_id in (select component_id from deployments where node_id=in_node_id);
     else
         select 0 as test;
     end if;     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.systemDomainPortViewList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `systemDomainPortViewList`(in_system_domain_id int)
BEGIN
     if loginTest() then
         select 1 as test;
         select domain_system_id, port_num, port_group, description from domain_system_port where domain_system_id=in_system_domain_id;
     else
         select 0 as test;
     end if;
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.ten_pro 구조 내보내기
DELIMITER //
CREATE PROCEDURE `ten_pro`()
BEGIN
	select s_node_id , s_port_id , port_group from ( select * from network_link where d_node_id = 0 and d_sub_system_id in
	 (select sub_system_domain_id from node where id = 165) ) as A join domain_system_port as B on A.d_sub_system_id = B.domain_system_id  and A.d_port_id = B.port_num group by port_group;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.testpro 구조 내보내기
DELIMITER //
CREATE PROCEDURE `testpro`(IN `idkey` int , IN `domaintype` varchar(100))
BEGIN
     if( idkey != 0 ) then
         select id, upper_id, name from domain_method  where id = idkey;
   
               
         call testpro(upper_id, 'method');
     else
     
         select 0 as test;
     end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.TreeDomainChildViewList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `TreeDomainChildViewList`(
	IN `idkey` int,
	IN `domaintype` varchar(100)

)
BEGIN
        declare sm bool;
        if loginTest() then
                select 1 as test;
                if( supermanagerTest(@nervuser) ) then
                       if(domaintype='data') then
                        select id, name , upper_id from domain_data where upper_id = idkey order by name desc;
                       end if;
                       if(domaintype='method') then
                        select id, name, upper_id from domain_method where upper_id = idkey order by name desc;
                       end if;
                       if(domaintype='system') then
                        select id, name, upper_id from domain_system where upper_id = idkey order by name desc;
                       end if;
                 end if;
       else
               select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.treeViewEditItemName 구조 내보내기
DELIMITER //
CREATE PROCEDURE `treeViewEditItemName`(in_idkey int,
                                                            in_typevalue int,
                                                            in_orignalnamekey varchar(100),
                                                            in_editname varchar(100))
BEGIN    

        if loginTest() then 
               
                
                if (in_typevalue=0) then
                        update domain_system set  name=in_editname where id=in_idkey;
                        select 1 as test;
                end if;                       
                
                if (in_typevalue=1) then
                        update domain_method set  name=in_editname where id=in_idkey;
                        select 1 as test;
                end if;
                
                if (in_typevalue=2) then
                        update domain_data set name=in_editname where id=in_idkey;
                        select 1 as test;
                end if;
                
                if (in_typevalue=3) then
                        update data set  name=in_editname where domain_id=in_idkey and name = in_orignalnamekey;
                        select 1 as test;
                end if;                       
                
                if (in_typevalue=4) then
                        update method set  name=in_editname where domain_id=in_idkey and name = in_orignalnamekey;
                        select 1 as test;
                end if;
                
                if (in_typevalue=6) then
                        update interface set name=in_editname where domain_id=in_idkey and name = in_orignalnamekey;
                        select 1 as test;
                end if;
                
                if (in_typevalue=7) then
                        update node set name=in_editname where id=in_idkey and name = in_orignalnamekey;
                        select 1 as test;
                end if;
                if (in_typevalue=8) then
                        update component set name=in_editname where id=in_idkey and name = in_orignalnamekey;
                        select 1 as test;
                end if;
                
                
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.umlcomponententityViewList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `umlcomponententityViewList`(in_diagramid int)
BEGIN
     if loginTest() then
         select 1 as test;
         select id, diagrame_id, component_id, position_x, position_y, size from umlcomponent where diagrame_id = in_diagramid;        
         
     else
         select 0 as test;
     end if;
     
     
     
End//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.update_child_depth 구조 내보내기
DELIMITER //
CREATE PROCEDURE `update_child_depth`(IN `in_data_auto_id` INT, IN `in_data_domain_id` INT, IN `in_data_depth` INT)
BEGIN	
	

	declare no_more_rows bool default false;

	declare child_data_auto_id int;		
	declare child_domain_id int;
	declare child_depth int;
	
	DECLARE my_list CURSOR FOR 

		select data.data_auto_id, data.domain_id, data.depth from data where data.real_data_auto_id=in_data_auto_id and data.domain_id=in_data_domain_id and data.`type`='alias'
		union
		select data.data_auto_id, data.domain_id, data.depth from data where data.domain_id=in_data_domain_id and data.data_auto_id in
		(select data_field.data_auto_id from data_field where data_field.`type`='alias' and data_field.real_data_auto_id = in_data_auto_id);	

	declare continue handler for not found set no_more_rows := TRUE;
	
	set max_sp_recursion_depth = 50;		 

		open my_list;	
		my_loop : loop
		
			fetch my_list into child_data_auto_id, child_domain_id, child_depth;
			if no_more_rows then
				close my_list;
				leave my_loop;
			end if;					

			if child_depth <= in_data_depth then
			 	update data set data.depth=(in_data_depth+1) where data.data_auto_id=child_data_auto_id;
			 	call update_child_depth( child_data_auto_id, child_domain_id , in_data_depth+1);
			end if;
		
		end loop my_loop;
		


END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.userViewEditDomainUserGuest 구조 내보내기
DELIMITER //
CREATE PROCEDURE `userViewEditDomainUserGuest`(IN `domain_idkey` int, IN `domaintype` varchar(100), IN `acountkey` varchar(100))
BEGIN
        declare domaincreator varchar(100);
        declare mb varchar(100);
        declare targetmb varchar(100); 
        
        if(domaintype='data') then
              select user_id into domaincreator from domain_data where id=domain_idkey;
              if acountkey != domaincreator then
                  select member_type into mb from members_domain_data where domain_id=domain_idkey and user_id=@nervuser;
                  select member_type into targetmb from members_domain_data where domain_id=domain_idkey and user_id=acountkey;
                  if @nervuser = domaincreator or (mb='manager' and targetmb!='manager') or supermanagerTest(@nervuser) then
                        if loginTest() then
                                select 1 as test;
                                update members_domain_data set member_type = 'guest' where domain_id=domain_idkey and user_id=acountkey;
                        else
                                select 0 as test;
                        end if;
                  else
                        select 0 as test;
                  end if;
              else
                select 0 as test;
              end if;
        end if;
        
        if(domaintype='method') then
              select user_id into domaincreator from domain_method where id=domain_idkey;
              if acountkey != domaincreator then
                  select member_type into mb from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
                  select member_type into targetmb from members_domain_method where domain_id=domain_idkey and user_id=acountkey;
                  if @nervuser = domaincreator or (mb='manager' and targetmb!='manager') or supermanagerTest(@nervuser) then
                        if loginTest() then
                                select 1 as test;
                                update members_domain_method set member_type = 'guest' where domain_id=domain_idkey and user_id=acountkey;
                        else
                                select 0 as test;
                        end if;
                  else
                        select 0 as test;
                  end if;
              else
                select 2 as test;
              end if;
        end if;
        
        if(domaintype='system') then
              select user_id into domaincreator from domain_system where id=domain_idkey;
              if acountkey != domaincreator then
                  select member_type into mb from members_domain_system where domain_id=domain_idkey and user_id=@nervuser;
                  select member_type into targetmb from members_domain_system where domain_id=domain_idkey and user_id=acountkey;
                  if @nervuser = domaincreator or (mb='manager' and targetmb!='manager') or supermanagerTest(@nervuser) then
                        if loginTest() then
                                select 1 as test;
                                update members_domain_system set member_type = 'guest' where domain_id=domain_idkey and user_id=acountkey;
                        else
                                select 0 as test;
                        end if;
                  else
                        select 0 as test;
                  end if;
              else
                select 0 as test;
              end if;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.userViewEditDomainUserManager 구조 내보내기
DELIMITER //
CREATE PROCEDURE `userViewEditDomainUserManager`(IN `domain_idkey` int, IN `domaintype` varchar(100), IN `acountkey` varchar(100))
BEGIN
        declare domaincreator varchar(100);
        
        if(domaintype='data') then
                    select user_id into domaincreator from domain_data where id=domain_idkey;

                    if acountkey != domaincreator and @nervuser = domaincreator or supermanagerTest(@nervuser) then
                       if loginTest() then
                           select 1 as test;
                           update members_domain_data set member_type = 'manager' where domain_id=domain_idkey and user_id=acountkey;
                       else
                           select 0 as test;
                       end if;
                    else
                       select 0 as test;
                    end if;
         end if;
         
         if(domaintype='method') then
                    select user_id into domaincreator from domain_method where id=domain_idkey;

                    if acountkey != domaincreator and @nervuser = domaincreator or supermanagerTest(@nervuser) then
                       if loginTest() then
                           select 1 as test;
                           update members_domain_method set member_type = 'manager' where domain_id=domain_idkey and user_id=acountkey;
                       else
                           select 0 as test;
                       end if;
                    else
                       select 0 as test;
                    end if;
         end if;
         
         if(domaintype='system') then
                    select user_id into domaincreator from domain_system where id=domain_idkey;

                    if acountkey != domaincreator and @nervuser = domaincreator or supermanagerTest(@nervuser) then
                       if loginTest() then
                           select 1 as test;
                           update members_domain_system set member_type = 'manager' where domain_id=domain_idkey and user_id=acountkey;
                       else
                           select 0 as test;
                       end if;
                    else
                       select 0 as test;
                    end if;
         end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.userViewEditDomainUserMember 구조 내보내기
DELIMITER //
CREATE PROCEDURE `userViewEditDomainUserMember`(IN `domain_idkey` int, IN `domaintype` varchar(100), IN `acountkey` varchar(100))
BEGIN
        declare domaincreator varchar(100);
        declare mb varchar(100);
        declare targetmb varchar(100);        

        if(domaintype='data') then
                     select user_id into domaincreator from domain_data where id=domain_idkey;
                     if acountkey != domaincreator then
                        select member_type into mb from members_domain_data where domain_id=domain_idkey and user_id=@nervuser;
                        select member_type into targetmb from members_domain_data where domain_id=domain_idkey and user_id=acountkey;
                        if @nervuser = domaincreator or (mb='manager' and targetmb!='manager') or supermanagerTest(@nervuser) then
                           if loginTest() then
                                select 1 as test;
                                update members_domain_data set member_type = 'member' where  domain_id=domain_idkey and user_id=acountkey;
                           else
                                select 0 as test;
                           end if;
                        else
                           select 0 as test;
                        end if;
                      else
                         select 0 as test;
                      end if;
          end if;
          
          if(domaintype='method') then
                     select user_id into domaincreator from domain_method where id=domain_idkey;
                     if acountkey != domaincreator then
                        select member_type into mb from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
                        select member_type into targetmb from members_domain_method where domain_id=domain_idkey and user_id=acountkey;
                        if @nervuser = domaincreator or (mb='manager' and targetmb!='manager') or supermanagerTest(@nervuser) then
                           if loginTest() then
                                select 1 as test;
                                update members_domain_method set member_type = 'member' where  domain_id=domain_idkey and user_id=acountkey;
                           else
                                select 0 as test;
                           end if;
                        else
                           select 2 as test;
                        end if;
                      else
                         select -1 as test;
                      end if;                      
          end if;          
          if(domaintype='system') then
                     select user_id into domaincreator from domain_system where id=domain_idkey;

                     if acountkey != domaincreator then
                        select member_type into mb from members_domain_system where domain_id=domain_idkey and user_id=@nervuser;
                        select member_type into targetmb from members_domain_system where domain_id=domain_idkey and user_id=acountkey;
                        if @nervuser = domaincreator or (mb='manager' and targetmb!='manager') or supermanagerTest(@nervuser) then
                           if loginTest() then
                                select 1 as test;
                                update members_domain_system set member_type = 'member' where  domain_id=domain_idkey and user_id=acountkey;
                           else
                                select 0 as test;
                           end if;
                        else
                           select 0 as test;
                        end if;
                      else
                         select 0 as test;
                      end if;
          end if;

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.userViewEditDomainUserPurge 구조 내보내기
DELIMITER //
CREATE PROCEDURE `userViewEditDomainUserPurge`(IN `domain_idkey` int, IN `domaintype` varchar(100), IN `acountkey` varchar(100))
BEGIN
        declare domaincreator varchar(100);
        declare mb varchar(100);
        declare targetmb varchar(100);
        
        if(domaintype='data') then
              select user_id into domaincreator from domain_data where id=domain_idkey;
              if acountkey != domaincreator then
                  select member_type into mb from members_domain_data where domain_id=domain_idkey and user_id=@nervuser;
                  select member_type into targetmb from members_domain_data where domain_id=domain_idkey and user_id=acountkey;
                  if @nervuser = domaincreator or (mb='manager' and targetmb!='manager') or supermanagerTest(@nervuser) then
                        if loginTest() then
                                select 1 as test;
                                 delete from members_domain_data where domain_id=domain_idkey and user_id=acountkey;
                                
                        else
                                select 0 as test;
                        end if;
                  else
                        select 0 as test;
                  end if;
              else
                select 0 as test;
              end if;
        end if;
        
        if(domaintype='method') then
              select user_id into domaincreator from domain_method where id=domain_idkey;
              if acountkey != domaincreator then
                  select member_type into mb from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
                  select member_type into targetmb from members_domain_method where domain_id=domain_idkey and user_id=acountkey;
                  if @nervuser = domaincreator or (mb='manager' and targetmb!='manager') or supermanagerTest(@nervuser) then
                        if loginTest() then
                                select 1 as test;
                                 delete from members_domain_method where domain_id=domain_idkey and user_id=acountkey;
                        else
                                select 0 as test;
                        end if;
                  else
                        select 0 as test;
                  end if;
              else
                select 0 as test;
              end if;
        end if;
        
        if(domaintype='system') then
              select user_id into domaincreator from domain_system where id=domain_idkey;
              if acountkey != domaincreator then
                  select member_type into mb from members_domain_system where domain_id=domain_idkey and user_id=@nervuser;
                  select member_type into targetmb from members_domain_system where domain_id=domain_idkey and user_id=acountkey;
                  if @nervuser = domaincreator or (mb='manager' and targetmb!='manager') or supermanagerTest(@nervuser) then
                        if loginTest() then
                                select 1 as test;
                                 delete from members_domain_system where domain_id=domain_idkey and user_id=acountkey;
                        else
                                select 0 as test;
                        end if;
                  else
                        select 0 as test;
                  end if;
              else
                select 0 as test;
              end if;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.userViewJoinDomain 구조 내보내기
DELIMITER //
CREATE PROCEDURE `userViewJoinDomain`(domain_idkey int, domaintype varchar(100))
BEGIN
        if loginTest() then
                if (domaintype ='data') then
                   select 1 as test;
                   insert into members_domain_data(domain_id,user_id,member_type) values(domain_idkey,@nervuser,'guest');
                end if;
                if (domaintype ='method') then
                   select 1 as test;
                   insert into members_domain_method(domain_id,user_id,member_type) values(domain_idkey,@nervuser,'guest');
                end if;
                if (domaintype ='system') then
                   select 1 as test;
                   insert into members_domain_system(domain_id,user_id,member_type) values(domain_idkey,@nervuser,'guest');
                end if;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.userViewSecessionDomain 구조 내보내기
DELIMITER //
CREATE PROCEDURE `userViewSecessionDomain`(domain_idkey int, domaintype varchar(100))
BEGIN
        if loginTest() then
                if (domaintype ='data') then
                   select 1 as test;
                   delete from members_domain_data where domain_id=domain_idkey and user_id=@nervuser;
                end if;
                if (domaintype ='method') then
                   select 1 as test;
                   delete from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
                end if;
                if (domaintype ='system') then
                   select 1 as test;
                   delete from members_domain_system where domain_id=domain_idkey and user_id=@nervuser;
                end if;       
        
               
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.userViewUserList 구조 내보내기
DELIMITER //
CREATE PROCEDURE `userViewUserList`(domain_idkey int, domaintype varchar(100), userkey varchar(100),memberkey varchar(100))
BEGIN
        if loginTest() then
                select 1 as test;
                if domainReadTest(domain_idkey, domaintype) then                
                   if (domaintype ='data') then
                        if memberkey='all' then
                                select a.user_id,member_type, description from
                                        (select * from members_domain_data where domain_id=domain_idkey and user_id like userkey) as a
                                                join
                                        (select user_id,description from users where user_id like userkey ) as b on a.user_id=b.user_id;
                        else
                                select a.user_id,member_type, description from
                                        (select * from members_domain_data where domain_id=domain_idkey and user_id like userkey and member_type=memberkey) as a
                                                join
                                        (select user_id,description from users where user_id like userkey ) as b on a.user_id=b.user_id;
                        end if;
                   end if;
                   
                   if (domaintype ='method') then
                        if memberkey='all' then
                                select a.user_id,member_type, description from
                                        (select * from members_domain_method where domain_id=domain_idkey and user_id like userkey) as a
                                                join
                                        (select user_id,description from users where user_id like userkey ) as b on a.user_id=b.user_id;
                        else
                                select a.user_id,member_type, description from
                                        (select * from members_domain_method where domain_id=domain_idkey and user_id like userkey and member_type=memberkey) as a
                                                join
                                        (select user_id,description from users where user_id like userkey ) as b on a.user_id=b.user_id;
                        end if;
                   end if;
                   
                   if (domaintype ='system') then
                        if memberkey='all' then
                                select a.user_id,member_type, description from
                                        (select * from members_domain_system where domain_id=domain_idkey and user_id like userkey) as a
                                                join
                                        (select user_id,description from users where user_id like userkey ) as b on a.user_id=b.user_id;
                        else
                                select a.user_id,member_type, description from
                                        (select * from members_domain_system where domain_id=domain_idkey and user_id like userkey and member_type=memberkey) as a
                                                join
                                        (select user_id,description from users where user_id like userkey ) as b on a.user_id=b.user_id;
                        end if;
                   end if;
                   
                else
                     if (domaintype ='data') then
                        if memberkey='all' then
                                select a.user_id,member_type, description from
                                        (select * from members_domain_data where domain_id=domain_idkey and (user_id='anonymous' or user_id=@nervuser) and user_id like userkey) as a
                                                join
                                        (select user_id,description from users where userid like userkey ) as b on a.user_id=b.user_id;
                        else
                                select a.user_id,member_type, description from
                                        (select * from members_domain_data where domain_id=domain_idkey and (user_id='anonymous' or user_id=@nervuser) and user_id like userkey and member_type=memberkey) as a
                                                join
                                        (select user_id,description from users where user_id like userkey ) as b on a.user_id=b.user_id;
                        end if;
                     end if;
                     
                     if (domaintype ='method') then
                        if memberkey='all' then
                                select a.user_id,member_type, description from
                                        (select * from members_domain_method where domain_id=domain_idkey and (user_id='anonymous' or user_id=@nervuser) and user_id like userkey) as a
                                                join
                                        (select user_id,description from users where userid like userkey ) as b on a.user_id=b.user_id;
                        else
                                select a.user_id,member_type, description from
                                        (select * from members_domain_method where domain_id=domain_idkey and (user_id='anonymous' or user_id=@nervuser) and user_id like userkey and member_type=memberkey) as a
                                                join
                                        (select user_id,description from users where user_id like userkey ) as b on a.user_id=b.user_id;
                        end if;
                     end if;
                     
                     if (domaintype ='system') then
                        if memberkey='all' then
                                select a.user_id,member_type, description from
                                        (select * from members_domain_system where domain_id=domain_idkey and (user_id='anonymous' or user_id=@nervuser) and user_id like userkey) as a
                                                join
                                        (select user_id,description from users where userid like userkey ) as b on a.user_id=b.user_id;
                        else
                                select a.user_id,member_type, description from
                                        (select * from members_domain_system where domain_id=domain_idkey and (user_id='anonymous' or user_id=@nervuser) and user_id like userkey and member_type=memberkey) as a
                                                join
                                        (select user_id,description from users where user_id like userkey ) as b on a.user_id=b.user_id;
                        end if;
                     end if;
                end if;
       else
               select 0 as test;
       end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.xmldocumentViewimportData 구조 내보내기
DELIMITER //
CREATE PROCEDURE `xmldocumentViewimportData`(IN `domain_idkey` int, IN `data_namevalue` varchar(100), IN `typevalue` varchar(100), IN `physicalvalue` varchar(100), IN `realdomain_idvalue` int, IN `realmetadatavalue` varchar(100), IN `scminvalue` varchar(100), IN `scmaxvalue` varchar(100), IN `descriptionvalue` varchar(100))
BEGIN

	declare in_data_auto_id int default null;
	declare in_real_data_auto_id int default null;

        if typevalue ='alias' and realdomain_idvalue != 0 then
               select data.data_auto_id into in_real_data_auto_id from data where data.domain_id=realdomain_idvalue and data.name=realmetadatavalue;
         end if;
                
        if loginTest() and domainManageTest(domain_idkey) and ( typevalue!='alias' or existMetadata(in_real_data_auto_id) )then
        
        			select data.data_auto_id into in_data_auto_id from data where data.domain_id=domain_idkey and data.name=data_namevalue;
        
                
                select 1 as test;
                if existMetadata(in_data_auto_id) then
                
                update data set name=data_namevalue,
                                type=typevalue,
                                real_data_auto_id=in_real_data_auto_id,                                
                                scmin=scminvalue,
                                scmax=scmaxvalue,
                                description=descriptionvalue
                                where data.data_auto_id=in_data_auto_id;
                else
                   insert into data (domain_id   ,name       ,type     , real_data_auto_id,       scmin     ,scmax     , description, user_id)
                              values(domain_idkey,data_namevalue, typevalue, in_real_data_auto_id,scminvalue,scmaxvalue,descriptionvalue, @nervuser );
                end if;
                        
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.xmldocumentViewimportDatafield 구조 내보내기
DELIMITER //
CREATE PROCEDURE `xmldocumentViewimportDatafield`(IN `domain_idkey` int, IN `metadatakey` varchar(100), IN `metafieldvalue` varchar(100), IN `bitsizevalue` int unsigned, IN `typevalue` varchar(100), IN `physicalvalue` varchar(100), IN `realdomainvalue` int, IN `realmetadatavalue` varchar(100), IN `minvalue` varchar(100), IN `in_maxvalue` varchar(100), IN `arraytypevalue` varchar(100), IN `arraysizevalue` int unsigned, IN `descriptionvalue` text)
BEGIN

	declare data_auto_id_key int default null;
	declare in_real_data_auto_id int default null;
	
	select data.data_auto_id into data_auto_id_key from data where data.domain_id=domain_idkey and data.name=metadatakey;  	   	
	
      if typevalue ='alias' and realdomainvalue !=0 then
	      select data.data_auto_id into in_real_data_auto_id from data where data.domain_id=realdomainvalue and data.name=realmetadatavalue;  	   	
      end if;
      
      if loginTest() and domainManageTest(domain_idkey) and (typevalue!='alias' or existMetadata(in_real_data_auto_id)) then                
                select 1 as test;
                if existMetadatafield(domain_idkey, metadatakey, metafieldvalue) then
                
                update data_field set member_name=metafieldvalue,
                                      type=typevalue,
                                      real_data_auto_id=in_real_data_auto_id,
                                      bitsize=bitsizevalue,
                                      scimin=minvalue,
                                      scimax=in_maxvalue,
                                      arraytype=arraytypevalue,
                                      arraysize=arraysizevalue,
                                      description=descriptionvalue                                      
                                 where data_field.data_auto_id=data_auto_id_key and member_name=metafieldvalue;
                else
                     insert into data_field( data_auto_id, member_name, type, real_data_auto_id, bitsize, user_id, scimin, scimax, arraytype, arraysize, description)
          values(data_auto_id_key, metafieldvalue, typevalue, in_real_data_auto_id, bitsizevalue, @nervuser, minvalue, in_maxvalue, arraytypevalue, arraysizevalue, descriptionvalue);
                end if;
                        
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.xmldocumentViewimportDomain 구조 내보내기
DELIMITER //
CREATE PROCEDURE `xmldocumentViewimportDomain`(IN `in_id` INT, IN `upper_idvalue` INT, IN `domaintype` VARCHAR(50), IN `namevalue` VARCHAR(100), IN `standardportvalue` SMALLINT, IN `publicvalue` TINYINT, IN `descriptionvalue` TEXT)
BEGIN

	 
        if loginTest() and newDomainTest() then
                select 1 as test;
                
					 if (domaintype='data') then
					 	if existDomain(in_id,domaintype) then
                		update domain_data set upper_id=upper_idvalue, name=namevalue,  public=publicvalue  where domain_data.id=in_id;
                	else
                		insert into domain_data(id, upper_id, name, user_id, public, create_date, last_update,description )
                                 values(in_id, upper_idvalue, namevalue, @nervuser, publicvalue, @logdate, @logdate,descriptionvalue);
               	end if;
                end if;
                
					 if (domaintype='method') then
                	if existDomain(in_id,domaintype) then
                		update domain_method set upper_id=upper_idvalue, name=namevalue,  public=publicvalue,  standard_port=standardportvalue where domain_method.id=in_id;
                	else
		                insert into domain_method(id, upper_id, name, user_id, public,  standard_port, create_date, last_update,description )
                                 values(in_id, upper_idvalue, namevalue, @nervuser, publicvalue, standardportvalue, @logdate, @logdate,descriptionvalue);
                  end if;
                end if;
                
			else
                select 0 as test;
        end if;

END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.xmldocumentViewimportInterface 구조 내보내기
DELIMITER //
CREATE PROCEDURE `xmldocumentViewimportInterface`(domain_idkey int,
                                                                     interfacevalue varchar(100),
                                                                     descriptionvalue varchar(100))
BEGIN

        if loginTest() and domainManageTest(domain_idkey) then
                select 1 as test;
                if existInterface(domain_idkey,interfacevalue) then
                       update interface set name=interfacevalue,description=descriptionvalue where domain_id=domain_idkey and name=interfacevalue;
                else
                insert into interface (domain_id,                name,  user_id, description)
                                values(domain_idkey, interfacevalue, @nervuser, descriptionvalue );
                end if;
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.xmldocumentViewimportInterfacemembermethod 구조 내보내기
DELIMITER //
CREATE PROCEDURE `xmldocumentViewimportInterfacemembermethod`(domain_idkey int,
                                                                                interfacekey varchar(100),
                                                                                methodvalue varchar(100),
                                                                                descriptionvalue varchar(100))
BEGIN
        if loginTest() and domainManageTest(domain_idkey) and existMethod(domain_idkey, methodvalue) and !existInterfaceMemberMethod(domain_idkey,interfacekey,methodvalue)then
                select 1 as test;
                insert into interface_member(domain_id,        interface,     method_domain_id,   method_name, description)
                                    values(domain_idkey, interfacekey, domain_idkey, methodvalue, descriptionvalue);
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 프로시저 nerv_icde_xxxx.xmldocumentViewimportMethod 구조 내보내기
DELIMITER //
CREATE PROCEDURE `xmldocumentViewimportMethod`(IN `in_domain_id` int, IN `in_methodvalue` varchar(100), IN `in_typevalue` varchar(100), IN `in_codevalue` varchar(100), IN `inputdomainvalue` int(10) unsigned, IN `inputmetadatavalue` varchar(100), IN `outputdomainvalue` int(10) unsigned, IN `outputmetadatavalue` varchar(100), IN `descriptionvalue` text)
BEGIN

	declare in_real_data_auto_id int default null;
	declare out_real_data_auto_id int default null;

	
     if inputdomainvalue!=0 then
     		select data.data_auto_id into in_real_data_auto_id from data where data.domain_id=inputdomainvalue and data.name=inputmetadatavalue;
     end if;
     
     if outputdomainvalue!=0 then
	     select data.data_auto_id into out_real_data_auto_id from data where data.domain_id=outputdomainvalue and data.name=outputmetadatavalue;
     end if;

     if loginTest() and domainManageTest(in_domain_id) and (in_real_data_auto_id is NULL or existMetadata(in_real_data_auto_id) )
                                                       and (out_real_data_auto_id is NULL or existMetadata(out_real_data_auto_id)) then
                select 1 as test;
                if existMethod(in_domain_id, in_methodvalue) then
                
                update method set       code=in_codevalue,
                                        type=in_typevalue,
                                        name=in_methodvalue,
                                        in_data_auto_id=in_real_data_auto_id,
													 out_data_auto_id=out_real_data_auto_id,
                                        description=descriptionvalue
                              where     domain_id=in_domain_id and name=in_methodvalue;
                else
                insert into method(    domain_id,           name,         type,         code,      in_data_auto_id,  out_data_auto_id,  user_id, description)
                            values( in_domain_id, in_methodvalue, in_typevalue, in_codevalue, in_real_data_auto_id, out_data_auto_id, @nervuser, descriptionvalue);
                end if;
                        
        else
                select 0 as test;
        end if;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.check_system_lock_component_f 구조 내보내기
DELIMITER //
CREATE FUNCTION `check_system_lock_component_f`(
	`in_component_id` INT
) RETURNS tinyint(1)
BEGIN

	declare deploy_id int default 0;
	declare proxy_cnt int default 0;
	declare stub_cnt int default 0;

	
	select deployments.Id into deploy_id from deployments where component_id=in_component_id;	
	select count(*) into proxy_cnt from custum_proxy where custum_proxy.deploy_id=deploy_id and public=1;
	select count(*) into stub_cnt  from custum_stub where custum_stub.deploy_id=deploy_id and public=1;


	if proxy_cnt > 0  or stub_cnt > 0 then
		return 0;
	else
		return 0;
	end if;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.check_system_lock_domain 구조 내보내기
DELIMITER //
CREATE FUNCTION `check_system_lock_domain`(
	`in_domain_id` INT
) RETURNS tinyint(1)
BEGIN
	declare cnt int default 0;

	select count(node.Id) into cnt from node where node.sub_system_domain_id=in_domain_id and node.complete='Y';

	if cnt > 0 then
		return 0;
	else
		return 0;
	end if;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.check_system_lock_domainport 구조 내보내기
DELIMITER //
CREATE FUNCTION `check_system_lock_domainport`(
	`in_node_id` INT,
	`in_domain_id` INT,
	`in_port_num` INT
) RETURNS tinyint(1)
BEGIN

	declare cnt int default 0;

	select count(b.d_node_id) into cnt from
	(select * from domain_system_port where domain_system_port.domain_system_id=in_domain_id and domain_system_port.port_group in
		(select port_group from domain_system_port where domain_system_port.domain_system_id=in_domain_id and domain_system_port.port_num=in_port_num))as a
	join
	(select * from network_link) as b on b.s_port_id = a.port_num and b.s_node_id = in_node_id and b.d_node_id = 0;

	if cnt > 0 then
		return 0;
	else
		return 0;
	end if; 

END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.check_system_lock_interface 구조 내보내기
DELIMITER //
CREATE FUNCTION `check_system_lock_interface`(
	`in_domain_id` INT,
	`in_interface_name` VARCHAR(50)

) RETURNS tinyint(1)
BEGIN

		declare proxy_cnt int default 0;
		declare stub_cnt int default 0;		
		
		select count(id) into proxy_cnt from custum_proxy where custum_proxy.public=1 and custum_proxy.proxy_interface_id in (
			select id from proxy_interface_relation where proxy_interface_relation.method_domain_id=in_domain_id
																 and proxy_interface_relation.interface_name =in_interface_name);
																 
	  select count(id) into stub_cnt from custum_stub where custum_stub.public=1 and custum_stub.stub_interface_id in (
			select id from stub_interface_relation where stub_interface_relation.method_domain_id=in_domain_id
																 and stub_interface_relation.interface_name =in_interface_name);
		
		
	if proxy_cnt > 0 or stub_cnt > 0 then
		return 0;
	else
		return 0;
	end if; 

END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.check_system_lock_node_port_f 구조 내보내기
DELIMITER //
CREATE FUNCTION `check_system_lock_node_port_f`(
	`in_node_id` INT,
	`in_node_port` INT
) RETURNS tinyint(1)
BEGIN

	declare cnt int default 0;
	select count(*) into cnt from node where node.complete='Y' and node.id in (
		select node_id from network where network.original_node_id=in_node_id and network.original_node_port=in_node_port);

	if cnt > 0 then
		return 0;
	else
		return 0;
	end if; 

END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.check_system_lock_proxy_class 구조 내보내기
DELIMITER //
CREATE FUNCTION `check_system_lock_proxy_class`(
	`in_proxy_id` INT
) RETURNS tinyint(1)
BEGIN

	declare cnt int default 0;

	
	select count(*) into cnt from node where node.complete='y' and node.sub_system_domain_id in 
		(select systemdomain_id from deployments where deployments.id in
			(select deploy_id from custum_proxy where custum_proxy.proxy_interface_id = in_proxy_id and custum_proxy.public=1));
	
	
		if cnt > 0 then
		return 0;
	else
		return 0;
	end if;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.check_system_lock_proxy_object_f 구조 내보내기
DELIMITER //
CREATE FUNCTION `check_system_lock_proxy_object_f`(
	`in_proxy_id` INT,
	`in_proxy_object_name` VARCHAR(50)
) RETURNS tinyint(1)
BEGIN

declare cnt int default 0;

select count(*) into cnt from custum_proxy where proxy_interface_id=in_proxy_id and object_name=in_proxy_object_name and public=1;

if cnt > 0 then
		return 0;
	else
		return 0;
	end if;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.check_system_lock_proxy_public 구조 내보내기
DELIMITER //
CREATE FUNCTION `check_system_lock_proxy_public`(
	`in_custum_id` INT
) RETURNS tinyint(1)
BEGIN
		declare cnt int default 0;
		select count(id) into cnt from custum_proxy where custum_proxy.Id = in_custum_id and custum_proxy.public=1;
		
	if cnt > 0 then
		return 0;
	else
		return 0;
	end if; 
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.check_system_lock_stub_class_f 구조 내보내기
DELIMITER //
CREATE FUNCTION `check_system_lock_stub_class_f`(
	`in_stub_id` INT
) RETURNS tinyint(1)
BEGIN
	declare cnt int default 0;

	
	select count(*) into cnt from node where node.complete='y' and node.sub_system_domain_id in 
		(select systemdomain_id from deployments where deployments.id in
			(select deploy_id from custum_stub where custum_stub.stub_interface_id = in_stub_id and custum_stub.public=1));
	
	
		if cnt > 0 then
		return 0;
	else
		return 0;
	end if;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.check_system_lock_stub_object_f 구조 내보내기
DELIMITER //
CREATE FUNCTION `check_system_lock_stub_object_f`(
	`in_stub_id` INT,
	`in_stub_object_name` VARCHAR(50)
) RETURNS tinyint(1)
BEGIN

declare cnt int default 0;

select count(*) into cnt from custum_stub where stub_interface_id=in_stub_id and object_name=in_stub_object_name and public=1;

if cnt > 0 then
		return 0;
	else
		return 0;
	end if;
	
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.componentEntityCheck 구조 내보내기
DELIMITER //
CREATE FUNCTION `componentEntityCheck`(in_diagrameid int, in_component_id int) RETURNS tinyint(1)
BEGIN
        declare cnt int default 0;
        select count(id) into cnt from umlcomponent where diagrame_id=in_diagrameid and component_id=in_component_id;
        if cnt > 0 then
                return 1;
        else
                return 0;
        end if;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.domainDataPath 구조 내보내기
DELIMITER //
CREATE FUNCTION `domainDataPath`(`in_domain_idkey` INT, `in_path` TEXT) RETURNS text CHARSET utf8
BEGIN

	declare path varchar(50);
	declare in_upper_id int default null;
	declare in_name varchar(50) default null;
	
	 loop
		select domain_data.upper_id into in_upper_id from domain_data where domain_data.id=in_domain_idkey;
		select name into path from domain_data where id=in_domain_idkey;
		
		
		 select (concat_WS('\\',path,in_path)) into in_path;
		
		 if in_upper_id=0 then
		 	return in_path;
		 end if;
		
		set in_domain_idkey=in_upper_id;
	 end loop;
		
	

END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.domainManageTest 구조 내보내기
DELIMITER //
CREATE FUNCTION `domainManageTest`(domain_idkey int) RETURNS tinyint(1)
BEGIN
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;

        set sa = '';

        if( supermanagerTest(@nervuser) ) then
            return 1;
        end if;

              select member_type into sa from members_domain_data where domain_id=domain_idkey and user_id=@nervuser;
               if( sa='manager' ) then
                   return 1;
               end if;
               
               select user_id into acount from domain_data where id=domain_idkey;
               if(acount = @nervuser) then
                    return 1;
               end if;
    
               select member_type into sa from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
               if( sa='manager' ) then
                   return 1;
               end if;
               select user_id into acount from domain_method where id=domain_idkey;
               if(acount = @nervuser) then
                    return 1;
               end if;
    
               select member_type into sa from members_domain_system where domain_id=domain_idkey and user_id=@nervuser;
               if( sa='manager' ) then
                   return 1;
               end if;
               select user_id into acount from domain_system where id=domain_idkey;
               if(acount = @nervuser) then
                    return 1;
               end if;


        return 0;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.domainMethodPath 구조 내보내기
DELIMITER //
CREATE FUNCTION `domainMethodPath`(`in_domain_idkey` INT, `in_path` TEXT) RETURNS text CHARSET utf8
BEGIN
	declare path varchar(50);
	declare in_upper_id int default null;
	declare in_name varchar(50) default null;
	
	 loop
		select domain_method.upper_id into in_upper_id from domain_method where domain_method.id=in_domain_idkey;
		select name into path from domain_method where id=in_domain_idkey;
		
		
		 select (concat_WS('\\',path,in_path)) into in_path;
		
		 if in_upper_id=0 then
		 	return in_path;
		 end if;
		
		set in_domain_idkey=in_upper_id;
	 end loop;

END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.domainReadTest 구조 내보내기
DELIMITER //
CREATE FUNCTION `domainReadTest`(domain_idkey int, domaintype varchar(50)) RETURNS tinyint(1)
BEGIN
        declare sa varchar(100);
        declare acount varchar(100);
        declare pbc bool;
        set sa = '';



        if( supermanagerTest(@nervuser) ) then
             return 1;
        end if;
        
        if (domaintype = 'system') then
           select member_type into sa from members_domain_system where domain_id=domain_idkey and user_id=@nervuser;
        end if;
        if (domaintype = 'method') then
           select member_type into sa from members_domain_method where domain_id=domain_idkey and user_id=@nervuser;
        end if;
        if (domaintype = 'data') then
           select member_type into sa from members_domain_data where domain_id=domain_idkey and user_id=@nervuser;
        end if;

        if( sa='member' or sa='manager' ) then
           return 1;
        end if;
        
        

        if (domaintype = 'system') then
           select user_id into acount from domain_system where id=domain_idkey;   
        end if;
        if (domaintype = 'method') then
           select user_id into acount from domain_method where id=domain_idkey;   
        end if;
        if (domaintype = 'data') then
           select user_id into acount from domain_data where id=domain_idkey;   
        end if;
        
        if(acount = @nervuser) then
           return 1;
        end if;
        
        

        if (domaintype = 'system') then
           select public into pbc from domain_system where id=domain_idkey;   
        end if;
        if (domaintype = 'method') then
           select public into pbc from domain_method where id=domain_idkey;   
        end if;
        if (domaintype = 'data') then
           select public into pbc from domain_data where id=domain_idkey;   
        end if;
        
        if(pbc) then
         return 1;
        end if;
        return 0;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.domainSystemPath 구조 내보내기
DELIMITER //
CREATE FUNCTION `domainSystemPath`(`in_domain_idkey` INT, `in_path` TEXT) RETURNS text CHARSET utf8
BEGIN
	declare path varchar(50);
	declare in_upper_id int default null;
	declare in_name varchar(50) default null;
	
	 loop
		select domain_system.upper_id into in_upper_id from domain_system where domain_system.id=in_domain_idkey;
		select name into path from domain_system where id=in_domain_idkey;
		
		select (concat_WS('\\',path,in_path)) into in_path;
		
		 if in_upper_id=0 then
		 	return in_path;
		 end if;
		
		set in_domain_idkey=in_upper_id;
	 end loop;

END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.domainWriteTest 구조 내보내기
DELIMITER //
CREATE FUNCTION `domainWriteTest`(domain_idkey int, domaintypevalue varchar(100)) RETURNS tinyint(1)
BEGIN
        declare sa varchar(100);
        declare acount varchar(100);
        
           if( supermanagerTest(@nervuser) ) then
             return 1;
        end if;
        
        if domaintypevalue = 'data' then
          select user_id into acount from members_domain_data where domain_id=domain_idkey;
          if(acount = @nervuser) then
              return 1;
          end if;
            select user_id into acount from domain_data where id = domain_idkey;
            
          
        end if;

        if domaintypevalue = 'method' then
          select user_id into acount from members_domain_method where domain_id=domain_idkey;
          if(acount = @nervuser) then
              return 1;
          end if;
          select user_id into acount from domain_method where id = domain_idkey;
        end if;
        
        if domaintypevalue = 'system' then
          select user_id into acount from members_domain_system where domain_id=domain_idkey;
          if(acount = @nervuser) then
              return 1;
          end if;
          select user_id into acount from domain_system where id = domain_idkey;
        end if;
                
        if(acount = @nervuser) then
              return 1;
        end if;      
        return 0;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.existDomain 구조 내보내기
DELIMITER //
CREATE FUNCTION `existDomain`(`domainkey` int, `domaintypevalue` varchar(100)) RETURNS tinyint(1)
BEGIN
        declare cnt tinyint(1);
        declare cnt_2 tinyint(1);
        set cnt = 0;
        
        if(domaintypevalue = 'data') then
             select count(*) into cnt from domain_data where id=domainkey;
             return cnt;
        end if;
        if(domaintypevalue = 'method') then
             select count(*) into cnt from domain_method where id=domainkey;
             return cnt;
             
             
        end if;
        if(domaintypevalue = 'system') then
             select count(*) into cnt from domain_system where id=domainkey;
             return cnt;
        end if;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.existInterface 구조 내보내기
DELIMITER //
CREATE FUNCTION `existInterface`(domain_idkey int, interface_name varchar(100)) RETURNS tinyint(1)
BEGIN
        declare cnt tinyint(1);
        set cnt = 0;

        select count(*) into cnt from interface where domain_id=domain_idkey and name=interface_name;

        return cnt;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.existInterfaceMemberMethod 구조 내보내기
DELIMITER //
CREATE FUNCTION `existInterfaceMemberMethod`(domain_idkey int ,
                                                                interfacekey varchar(100),
                                                                methodnamekey varchar(100) ) RETURNS tinyint(1)
BEGIN
        declare cnt tinyint(1);
        set cnt = 0;

        select count(*) into cnt from interface_member where domain_id=domain_idkey and interface=interfacekey and method_name=methodnamekey;

        return cnt;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.existMemberDomain 구조 내보내기
DELIMITER //
CREATE FUNCTION `existMemberDomain`(in_domainid int, in_userid varchar(100), in_domaintype varchar(100) ) RETURNS tinyint(1)
BEGIN
        declare cnt tinyint(1);
        set cnt = 0;
        if(in_domaintype='data')then
            select count(*) into cnt from members_domain_data where domain_id=in_domainid and user_id=in_userid;
        end if;
        if(in_domaintype='method')then
            select count(*) into cnt from members_domain_method where domain_id=in_domainid and user_id=in_userid;
        end if;
        if(in_domaintype='system')then
            select count(*) into cnt from members_domain_system where domain_id=in_domainid and user_id=in_userid;
        end if;

        return cnt;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.existMetadata 구조 내보내기
DELIMITER //
CREATE FUNCTION `existMetadata`(`in_data_auto_id_key` int) RETURNS tinyint(1)
BEGIN
        declare cnt tinyint(1);
        set cnt = 0;
        select count(*) into cnt from data where data.data_auto_id=in_data_auto_id_key;

        return cnt;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.existMetadatafield 구조 내보내기
DELIMITER //
CREATE FUNCTION `existMetadatafield`(`domain_idkey` int, `metadata_name` varchar(100), `metadatafield_name` varchar(100) ) RETURNS tinyint(1)
BEGIN
        declare cnt tinyint(1);
        declare data_auto_id_key int default null;
        
		  select data.data_auto_id into data_auto_id_key from data where data.domain_id=domain_idkey and data.name=metadata_name;
		  
        set cnt = 0;
        select count(*) into cnt from data_field where data_field.data_auto_id=data_auto_id_key and member_name=metadatafield_name;

        return cnt;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.existMethod 구조 내보내기
DELIMITER //
CREATE FUNCTION `existMethod`(domain_idkey int , method_name varchar(100) ) RETURNS tinyint(1)
BEGIN
        declare cnt tinyint(1);
        set cnt = 0;

        select count(*) into cnt from method where domain_id=domain_idkey and name=method_name;

        return cnt;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.exitDomainId 구조 내보내기
DELIMITER //
CREATE FUNCTION `exitDomainId`(in_domainname varchar(100), in_upperid varchar(100), in_domaintype varchar(100) ) RETURNS int(10) unsigned
BEGIN
        declare domain_id int unsigned;
        set domain_id = 0;
        
        if(in_domaintype='data')then
            select id into domain_id from domain_data where name=in_domainname and upper_id=in_upperid;            
        end if;
        if(in_domaintype='method')then
            select id into domain_id from domain_method where name=in_domainname and upper_id=in_upperid;
        end if;
        if(in_domaintype='system')then
            select id into domain_id from domain_system where name=in_domainname and upper_id=in_upperid;
        end if;

        return domain_id;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.inheritanceSystemMehtodParentOverlapCheck 구조 내보내기
DELIMITER //
CREATE FUNCTION `inheritanceSystemMehtodParentOverlapCheck`(domainkey int, parentdomainidkey int) RETURNS tinyint(1)
BEGIN
        declare cnt tinyint(1);
        
        set cnt = 0;
              
        select count(*) into cnt from inheritance_system_method where domain_id=domainkey and parent_domain_id=parentdomainidkey;
        
        if(cnt = 0) then
            return 1;
        end if;
                
         return 0;
        
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.logical_port_group_count 구조 내보내기
DELIMITER //
CREATE FUNCTION `logical_port_group_count`(in_system_domain_id int, in_port_group int) RETURNS tinyint(1)
BEGIN
        declare cnt tinyint(1);
        set cnt=0;
        
        select count(*) into cnt from domain_system_port where domain_system_id=in_system_domain_id and port_group=in_port_group;
        return cnt;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.loginTest 구조 내보내기
DELIMITER //
CREATE FUNCTION `loginTest`() RETURNS tinyint(1)
BEGIN
        declare cnt int default 0;
        select count(user_id) into cnt from users where user_id=@nervuser and password = [REDACTED]
        if cnt > 0 then
                return 1;
        else
                return 0;
        end if;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.method_domainCompatibleTest 구조 내보내기
DELIMITER //
CREATE FUNCTION `method_domainCompatibleTest`(domain_idkey int, parent_domain_idkey int , depth int ) RETURNS tinyint(1)
BEGIN
        declare cnt int;
        declare itor int default 0;
        declare pdomain int;
        
        DECLARE cur1 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=domain_idkey;
        DECLARE cur2 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=parent_domain_idkey;

        
        if( domain_idkey = parent_domain_idkey) then
            return 1;
        end if;
        
        open cur1;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=domain_idkey;
        while itor < cnt do
            fetch cur1 into pdomain;
            if( !method_domainCompatibleTest_depth_0( parent_domain_idkey , pdomain,depth+1) ) then
                 close cur1;
                 return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur1;

        open cur2;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=parent_domain_idkey;
        while itor < cnt do
            fetch cur2 into pdomain;
            if( !method_domainCompatibleTest_depth_0( domain_idkey , pdomain,depth+1) ) then
                    close cur2;
                    return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur2;

        select count(*) into cnt from
            (select type,code from method where domain_id=domain_idkey) as a
            join
            (select type,code from method where domain_id=parent_domain_idkey) as b
            on a.type=b.type and a.code = b.code;

         if( cnt > 0) then
            return 0;
         end if;
         
         return 1;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.method_domainCompatibleTest_depth_0 구조 내보내기
DELIMITER //
CREATE FUNCTION `method_domainCompatibleTest_depth_0`(domain_idkey int, parent_domain_idkey int , depth int ) RETURNS tinyint(1)
BEGIN
        declare cnt int;
        declare itor int default 0;
        declare pdomain int;
        
        DECLARE cur1 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=domain_idkey;
        DECLARE cur2 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=parent_domain_idkey;

        
        if( domain_idkey = parent_domain_idkey) then
            return 1;
        end if;
        
        open cur1;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=domain_idkey;
        while itor < cnt do
            fetch cur1 into pdomain;
            if( !method_domainCompatibleTest_depth_1( parent_domain_idkey , pdomain,depth+1) ) then
                 close cur1;
                 return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur1;

        open cur2;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=parent_domain_idkey;
        while itor < cnt do
            fetch cur2 into pdomain;
            if( !method_domainCompatibleTest_depth_1( domain_idkey , pdomain,depth+1) ) then
                    close cur2;
                    return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur2;

        select count(*) into cnt from
            (select type,code from method where domain_id=domain_idkey) as a
            join
            (select type,code from method where domain_id=parent_domain_idkey) as b
            on a.type=b.type and a.code = b.code;

         if( cnt > 0) then
            return 0;
         end if;
         
         return 1;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.method_domainCompatibleTest_depth_1 구조 내보내기
DELIMITER //
CREATE FUNCTION `method_domainCompatibleTest_depth_1`(domain_idkey int, parent_domain_idkey int , depth int ) RETURNS tinyint(1)
BEGIN
        declare cnt int;
        declare itor int default 0;
        declare pdomain int;
        
        DECLARE cur1 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=domain_idkey;
        DECLARE cur2 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=parent_domain_idkey;

        
        if( domain_idkey = parent_domain_idkey) then
            return 1;
        end if;
        
        open cur1;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=domain_idkey;
        while itor < cnt do
            fetch cur1 into pdomain;
            if( !method_domainCompatibleTest_depth_2( parent_domain_idkey , pdomain,depth+1) ) then
                 close cur1;
                 return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur1;

        open cur2;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=parent_domain_idkey;
        while itor < cnt do
            fetch cur2 into pdomain;
            if( !method_domainCompatibleTest_depth_2( domain_idkey , pdomain,depth+1) ) then
                    close cur2;
                    return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur2;

        select count(*) into cnt from
            (select type,code from method where domain_id=domain_idkey) as a
            join
            (select type,code from method where domain_id=parent_domain_idkey) as b
            on a.type=b.type and a.code = b.code;

         if( cnt > 0) then
            return 0;
         end if;
         
         return 1;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.method_domainCompatibleTest_depth_10 구조 내보내기
DELIMITER //
CREATE FUNCTION `method_domainCompatibleTest_depth_10`(domain_idkey int, parent_domain_idkey int , depth int ) RETURNS tinyint(1)
BEGIN
        declare cnt int;
        declare itor int default 0;
        declare pdomain int;
        
        DECLARE cur1 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=domain_idkey;
        DECLARE cur2 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=parent_domain_idkey;

        
        if( domain_idkey = parent_domain_idkey) then
            return 1;
        end if;
        
        open cur1;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=domain_idkey;
        while itor < cnt do
            fetch cur1 into pdomain;
            if( !method_domainCompatibleTest_depth_1( parent_domain_idkey , pdomain,depth+1) ) then
                 close cur1;
                 return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur1;

        open cur2;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=parent_domain_idkey;
        while itor < cnt do
            fetch cur2 into pdomain;
            if( !method_domainCompatibleTest_depth_1( domain_idkey , pdomain,depth+1) ) then
                    close cur2;
                    return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur2;

        select count(*) into cnt from
            (select type,code from method where domain_id=domain_idkey) as a
            join
            (select type,code from method where domain_id=parent_domain_idkey) as b
            on a.type=b.type and a.code = b.code;

         if( cnt > 0) then
            return 0;
         end if;
         
         return 1;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.method_domainCompatibleTest_depth_2 구조 내보내기
DELIMITER //
CREATE FUNCTION `method_domainCompatibleTest_depth_2`(domain_idkey int, parent_domain_idkey int , depth int ) RETURNS tinyint(1)
BEGIN
        declare cnt int;
        declare itor int default 0;
        declare pdomain int;
        
        DECLARE cur1 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=domain_idkey;
        DECLARE cur2 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=parent_domain_idkey;

        
        if( domain_idkey = parent_domain_idkey) then
            return 1;
        end if;
        
        open cur1;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=domain_idkey;
        while itor < cnt do
            fetch cur1 into pdomain;
            if( !method_domainCompatibleTest_depth_3( parent_domain_idkey , pdomain,depth+1) ) then
                 close cur1;
                 return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur1;

        open cur2;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=parent_domain_idkey;
        while itor < cnt do
            fetch cur2 into pdomain;
            if( !method_domainCompatibleTest_depth_3( domain_idkey , pdomain,depth+1) ) then
                    close cur2;
                    return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur2;

        select count(*) into cnt from
            (select type,code from method where domain_id=domain_idkey) as a
            join
            (select type,code from method where domain_id=parent_domain_idkey) as b
            on a.type=b.type and a.code = b.code;

         if( cnt > 0) then
            return 0;
         end if;
         
         return 1;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.method_domainCompatibleTest_depth_3 구조 내보내기
DELIMITER //
CREATE FUNCTION `method_domainCompatibleTest_depth_3`(domain_idkey int, parent_domain_idkey int , depth int ) RETURNS tinyint(1)
BEGIN
        declare cnt int;
        declare itor int default 0;
        declare pdomain int;
        
        DECLARE cur1 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=domain_idkey;
        DECLARE cur2 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=parent_domain_idkey;

        
        if( domain_idkey = parent_domain_idkey) then
            return 1;
        end if;
        
        open cur1;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=domain_idkey;
        while itor < cnt do
            fetch cur1 into pdomain;
            if( !method_domainCompatibleTest_depth_4( parent_domain_idkey , pdomain,depth+1) ) then
                 close cur1;
                 return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur1;

        open cur2;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=parent_domain_idkey;
        while itor < cnt do
            fetch cur2 into pdomain;
            if( !method_domainCompatibleTest_depth_4( domain_idkey , pdomain,depth+1) ) then
                    close cur2;
                    return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur2;

        select count(*) into cnt from
            (select type,code from method where domain_id=domain_idkey) as a
            join
            (select type,code from method where domain_id=parent_domain_idkey) as b
            on a.type=b.type and a.code = b.code;

         if( cnt > 0) then
            return 0;
         end if;
         
         return 1;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.method_domainCompatibleTest_depth_4 구조 내보내기
DELIMITER //
CREATE FUNCTION `method_domainCompatibleTest_depth_4`(domain_idkey int, parent_domain_idkey int , depth int ) RETURNS tinyint(1)
BEGIN
        declare cnt int;
        declare itor int default 0;
        declare pdomain int;
        
        DECLARE cur1 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=domain_idkey;
        DECLARE cur2 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=parent_domain_idkey;

        
        if( domain_idkey = parent_domain_idkey) then
            return 1;
        end if;
        
        open cur1;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=domain_idkey;
        while itor < cnt do
            fetch cur1 into pdomain;
            if( !method_domainCompatibleTest_depth_5( parent_domain_idkey , pdomain,depth+1) ) then
                 close cur1;
                 return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur1;

        open cur2;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=parent_domain_idkey;
        while itor < cnt do
            fetch cur2 into pdomain;
            if( !method_domainCompatibleTest_depth_5( domain_idkey , pdomain,depth+1) ) then
                    close cur2;
                    return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur2;

        select count(*) into cnt from
            (select type,code from method where domain_id=domain_idkey) as a
            join
            (select type,code from method where domain_id=parent_domain_idkey) as b
            on a.type=b.type and a.code = b.code;

         if( cnt > 0) then
            return 0;
         end if;
         
         return 1;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.method_domainCompatibleTest_depth_5 구조 내보내기
DELIMITER //
CREATE FUNCTION `method_domainCompatibleTest_depth_5`(domain_idkey int, parent_domain_idkey int , depth int ) RETURNS tinyint(1)
BEGIN
        declare cnt int;
        declare itor int default 0;
        declare pdomain int;
        
        DECLARE cur1 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=domain_idkey;
        DECLARE cur2 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=parent_domain_idkey;

        
        if( domain_idkey = parent_domain_idkey) then
            return 1;
        end if;
        
        open cur1;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=domain_idkey;
        while itor < cnt do
            fetch cur1 into pdomain;                   
            if( !method_domainCompatibleTest_depth_6( parent_domain_idkey , pdomain,depth+1) ) then
                 close cur1;
                 return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur1;

        open cur2;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=parent_domain_idkey;
        while itor < cnt do
            fetch cur2 into pdomain;
            if( !method_domainCompatibleTest_depth_6( domain_idkey , pdomain,depth+1) ) then
                    close cur2;
                    return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur2;

        select count(*) into cnt from
            (select type,code from method where domain_id=domain_idkey) as a
            join
            (select type,code from method where domain_id=parent_domain_idkey) as b
            on a.type=b.type and a.code = b.code;

         if( cnt > 0) then
            return 0;
         end if;
         
         return 1;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.method_domainCompatibleTest_depth_6 구조 내보내기
DELIMITER //
CREATE FUNCTION `method_domainCompatibleTest_depth_6`(domain_idkey int, parent_domain_idkey int , depth int ) RETURNS tinyint(1)
BEGIN
        declare cnt int;
        declare itor int default 0;
        declare pdomain int;
        
        DECLARE cur1 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=domain_idkey;
        DECLARE cur2 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=parent_domain_idkey;

        
        if( domain_idkey = parent_domain_idkey) then
            return 1;
        end if;
        
        open cur1;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=domain_idkey;
        while itor < cnt do
            fetch cur1 into pdomain;                   
            if( !method_domainCompatibleTest_depth_7( parent_domain_idkey , pdomain,depth+1) ) then
                 close cur1;
                 return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur1;

        open cur2;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=parent_domain_idkey;
        while itor < cnt do
            fetch cur2 into pdomain;
            if( !method_domainCompatibleTest_depth_7( domain_idkey , pdomain,depth+1) ) then
                    close cur2;
                    return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur2;

        select count(*) into cnt from
            (select type,code from method where domain_id=domain_idkey) as a
            join
            (select type,code from method where domain_id=parent_domain_idkey) as b
            on a.type=b.type and a.code = b.code;

         if( cnt > 0) then
            return 0;
         end if;
         
         return 1;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.method_domainCompatibleTest_depth_7 구조 내보내기
DELIMITER //
CREATE FUNCTION `method_domainCompatibleTest_depth_7`(domain_idkey int, parent_domain_idkey int , depth int ) RETURNS tinyint(1)
BEGIN
        declare cnt int;
        declare itor int default 0;
        declare pdomain int;
        
        DECLARE cur1 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=domain_idkey;
        DECLARE cur2 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=parent_domain_idkey;

        
        if( domain_idkey = parent_domain_idkey) then
            return 1;
        end if;
        
        open cur1;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=domain_idkey;
        while itor < cnt do
            fetch cur1 into pdomain;
            if( !method_domainCompatibleTest_depth_8( parent_domain_idkey , pdomain,depth+1) ) then
                 close cur1;
                 return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur1;

        open cur2;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=parent_domain_idkey;
        while itor < cnt do
            fetch cur2 into pdomain;
            if( !method_domainCompatibleTest_depth_8( domain_idkey , pdomain,depth+1) ) then
                    close cur2;
                    return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur2;

        select count(*) into cnt from
            (select type,code from method where domain_id=domain_idkey) as a
            join
            (select type,code from method where domain_id=parent_domain_idkey) as b
            on a.type=b.type and a.code = b.code;

         if( cnt > 0) then
            return 0;
         end if;
         
         return 1;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.method_domainCompatibleTest_depth_8 구조 내보내기
DELIMITER //
CREATE FUNCTION `method_domainCompatibleTest_depth_8`(domain_idkey int, parent_domain_idkey int , depth int ) RETURNS tinyint(1)
BEGIN
        declare cnt int;
        declare itor int default 0;
        declare pdomain int;
        
        DECLARE cur1 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=domain_idkey;
        DECLARE cur2 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=parent_domain_idkey;

        
        if( domain_idkey = parent_domain_idkey) then
            return 1;
        end if;
        
        open cur1;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=domain_idkey;
        while itor < cnt do
            fetch cur1 into pdomain;                   
            if( !method_domainCompatibleTest_depth_9( parent_domain_idkey , pdomain,depth+1) ) then
                 close cur1;
                 return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur1;

        open cur2;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=parent_domain_idkey;
        while itor < cnt do
            fetch cur2 into pdomain;
            if( !method_domainCompatibleTest_depth_9( domain_idkey , pdomain,depth+1) ) then
                    close cur2;
                    return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur2;

        select count(*) into cnt from
            (select type,code from method where domain_id=domain_idkey) as a
            join
            (select type,code from method where domain_id=parent_domain_idkey) as b
            on a.type=b.type and a.code = b.code;

         if( cnt > 0) then
            return 0;
         end if;
         
         return 1;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.method_domainCompatibleTest_depth_9 구조 내보내기
DELIMITER //
CREATE FUNCTION `method_domainCompatibleTest_depth_9`(domain_idkey int, parent_domain_idkey int , depth int ) RETURNS tinyint(1)
BEGIN
        declare cnt int;
        declare itor int default 0;
        declare pdomain int;
        
        DECLARE cur1 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=domain_idkey;
        DECLARE cur2 CURSOR FOR SELECT parent_domain_id FROM inheritance_method_method where domain_id=parent_domain_idkey;

        
        if( domain_idkey = parent_domain_idkey) then
            return 1;
        end if;
        
        open cur1;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=domain_idkey;
        while itor < cnt do
            fetch cur1 into pdomain;                   
            if( !method_domainCompatibleTest_depth_10( parent_domain_idkey , pdomain,depth+1) ) then
                 close cur1;
                 return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur1;

        open cur2;
        set itor = 0;
        select count(*) into cnt from inheritance_method_method where domain_id=parent_domain_idkey;
        while itor < cnt do
            fetch cur2 into pdomain;
            if( !method_domainCompatibleTest_depth_10( domain_idkey , pdomain,depth+1) ) then
                    close cur2;
                    return 0;
            end if;
            set itor = itor + 1;
        end while;
        close cur2;

        select count(*) into cnt from
            (select type,code from method where domain_id=domain_idkey) as a
            join
            (select type,code from method where domain_id=parent_domain_idkey) as b
            on a.type=b.type and a.code = b.code;

         if( cnt > 0) then
            return 0;
         end if;
         
         return 1;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.newDomainTest 구조 내보내기
DELIMITER //
CREATE FUNCTION `newDomainTest`() RETURNS tinyint(1)
BEGIN
        declare nd bool;
        set nd = false;
        select newdomain into nd from users where user_id=@nervuser;
        return nd;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.return_domainid 구조 내보내기
DELIMITER //
CREATE FUNCTION `return_domainid`(in_domainname int, in_upperid int, in_domaintype varchar(100)) RETURNS int(1)
BEGIN
        declare cnt int(1);
        set cnt = 0;
        
        if(in_domaintype ='data') then
                         select id into cnt from domain_data where name=in_domainname and upper_id=in_upperid;
        end if;
        if(in_domaintype ='method') then
                         select id into cnt from domain_method where name=in_domainname and upper_id=in_upperid;
        end if;
                if(in_domaintype ='system') then
                         select id into cnt from domain_system where name=in_domainname and upper_id=in_upperid;
        end if;
        
        return cnt;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.return_proxy_interface id 구조 내보내기
DELIMITER //
CREATE FUNCTION `return_proxy_interface id`(in_component_id int unsigned, in_method_domain_id int unsigned, in_interface_name varchar(100), in_class_name varchar(255)) RETURNS int(10) unsigned
BEGIN
        declare interface_key_id int unsigned;
        set interface_key_id=0;
      
        select count(*) into interface_key_id from proxy_interface_relation
         where component_id=in_component_id and method_domain_id=in_method_domain_id and interface_name=in_interface_name and class_name=in_class_name;
      
      if interface_key_id>0 then     
        return 1;
      else
          return 0;
      end if;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.supermanagerTest 구조 내보내기
DELIMITER //
CREATE FUNCTION `supermanagerTest`(useridkey varchar(100)) RETURNS tinyint(1)
BEGIN
        declare sm bool;
        select supermanager into sm from users where user_id=useridkey;
        return sm;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.updata_data_real_data_auto_id 구조 내보내기
DELIMITER //
CREATE FUNCTION `updata_data_real_data_auto_id`() RETURNS int(11)
BEGIN

update data d,
(select a.data_auto_id as auto_id, b.data_auto_id from
	(select data_auto_id, domain_id, name,real_data_auto_id, real_domain_id, real_data from data where data.real_domain_id != 0) as a
	join 
	(select data_auto_id, domain_id, name from data) as b on a.real_domain_id=b.domain_id and a.real_data=b.name
)as f
set d.real_data_auto_id = f.data_auto_id
where d.data_auto_id = f.auto_id;

return 0;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.update_data_field_table_data_auto_id 구조 내보내기
DELIMITER //
CREATE FUNCTION `update_data_field_table_data_auto_id`() RETURNS int(11)
BEGIN
update data_field d,
(select a.domain_id, a.data_name as name, b.data_auto_id as data_id from
	(select * from data_field) as a
	join
	(select data.data_auto_id,data.domain_id,data.name from data) as b on a.domain_id=b.domain_id and a.data_name=b.name
)as f
set d.data_auto_id=f.data_id
where d.domain_id=f.domain_id and d.data_name=f.name;

return 0;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.update_data_field_table_real_data_id 구조 내보내기
DELIMITER //
CREATE FUNCTION `update_data_field_table_real_data_id`() RETURNS int(11)
BEGIN

 update data_field d,
 (
	select a.data_auto_id, a.member_name,b.data_auto_id as data_id from
	(select * from data_field) as a
	join
	(select data.data_auto_id,data.domain_id,data.name from data) as b on a.real_domain=b.domain_id and a.real_data=b.name
 )as f
 	set d.real_data_auto_id=f.data_id
 	where d.data_auto_id=f.data_auto_id and d.member_name=f.member_name;
 	
 	return 0;
END//
DELIMITER ;

-- 함수 nerv_icde_xxxx.update_method_table_data_auto_id 구조 내보내기
DELIMITER //
CREATE FUNCTION `update_method_table_data_auto_id`() RETURNS int(11)
BEGIN

update method c,
 (
	select a.domain_id as method_domain_id,a.name as method_name, a.in_domain_id, a.in_data, b.* from
	(select * from method) as a
	join
	(select data.data_auto_id, data.domain_id, data.name from data) as b on a.in_domain_id=b.domain_id and a.in_data=b.name
 )as f
 set c.in_data_auto_id=f.data_auto_id
 where c.domain_id=f.method_domain_id and c.name=f.method_name ;


 update method c,
 (
	select a.domain_id as method_domain_id,a.name as method_name, a.out_domain_id, a.out_data, b.* from
	(select * from method) as a
	join
	(select data.data_auto_id, data.domain_id, data.name from data) as b on a.out_domain_id=b.domain_id and a.out_data=b.name
 )as f
 set c.out_data_auto_id=f.data_auto_id
 where c.domain_id=f.method_domain_id and c.name=f.method_name ;
 
 return 0;
 
END//
DELIMITER ;

-- 뷰 nerv_icde_xxxx.view_a 구조 내보내기
-- 임시 테이블을 제거하고 최종 VIEW 구조를 생성
DROP TABLE IF EXISTS `view_a`;
CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `view_a` AS select `network_link`.`s_node_id` AS `s_node_id`,`network_link`.`s_sub_system_id` AS `s_sub_system_id`,`network_link`.`s_port_id` AS `s_port_id`,`network_link`.`d_node_id` AS `d_node_id`,`network_link`.`d_sub_system_id` AS `d_sub_system_id`,`network_link`.`d_port_id` AS `d_port_id` from `network_link` where `network_link`.`d_sub_system_id` in (select `node`.`sub_system_domain_id` from `node` where (`node`.`Id` = 165));

-- 뷰 nerv_icde_xxxx.view_b 구조 내보내기
-- 임시 테이블을 제거하고 최종 VIEW 구조를 생성
DROP TABLE IF EXISTS `view_b`;
CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `view_b` AS select `network_link`.`s_node_id` AS `s_node_id`,`network_link`.`s_sub_system_id` AS `s_sub_system_id`,`network_link`.`s_port_id` AS `s_port_id`,`network_link`.`d_node_id` AS `d_node_id`,`network_link`.`d_sub_system_id` AS `d_sub_system_id`,`network_link`.`d_port_id` AS `d_port_id` from `network_link` where `network_link`.`d_sub_system_id` in (select `node`.`sub_system_domain_id` from `node` where (`node`.`Id` = 165));

/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
