Search in sources :

Example 1 with LogicSchemaConfig

use of io.mycat.config.LogicSchemaConfig in project Mycat2 by MyCATApache.

the class TreeItemCellFactory method call.

@Override
public TreeCell<ObjectItem> call(TreeView<ObjectItem> tree) {
    TreeCell<ObjectItem> cell = new SchemaObjectCell();
    cell.setOnMouseClicked(event -> {
        Optional<Command> commandOptional = Command.parsePath(getPath(cell.getTreeItem()));
        if (event != null) {
            if (event.getButton() == MouseButton.SECONDARY) {
                ContextMenu contextMenu = new ContextMenu();
                TreeItem<ObjectItem> treeItem = cell.getTreeItem();
                if (treeItem == null) {
                    return;
                }
                if (!treeItem.isLeaf() && treeItem.getParent() == tree.getRoot()) {
                    ObjectItem value = treeItem.getValue();
                    switch(value.getText()) {
                        case "schemas":
                            {
                                MenuItem item1 = new MenuItem("新建逻辑库");
                                item1.setId("addSchema");
                                item1.setOnAction(new EventHandler<ActionEvent>() {

                                    @Override
                                    public void handle(ActionEvent event1) {
                                        try {
                                            controller.edit(new LogicSchemaConfig());
                                        } catch (Exception e) {
                                            popAlter(e);
                                        }
                                    }
                                });
                                contextMenu.getItems().add(item1);
                                break;
                            }
                        case "datasources":
                            {
                                MenuItem item1 = new MenuItem("新建数据源");
                                item1.setId("addDatasource");
                                item1.setOnAction(new EventHandler<ActionEvent>() {

                                    @Override
                                    public void handle(ActionEvent event1) {
                                        try {
                                            controller.edit(new DatasourceConfig());
                                        } catch (Exception e) {
                                            popAlter(e);
                                        }
                                    }
                                });
                                contextMenu.getItems().add(item1);
                                break;
                            }
                        case "clusters":
                            {
                                MenuItem item1 = new MenuItem("新建集群");
                                item1.setId("addCluster");
                                item1.setOnAction(new EventHandler<ActionEvent>() {

                                    @Override
                                    public void handle(ActionEvent event1) {
                                        try {
                                            controller.edit(new ClusterConfig());
                                        } catch (Exception e) {
                                            popAlter(e);
                                        }
                                    }
                                });
                                contextMenu.getItems().add(item1);
                                break;
                            }
                    }
                } else {
                    if (commandOptional.isPresent()) {
                        Command command = commandOptional.get();
                        String schema = command.getSchema();
                        switch(command.getType()) {
                            case SCHEMA:
                                {
                                    MenuItem item1 = new MenuItem("删除逻辑库配置");
                                    item1.setId("deleteSchema");
                                    item1.setOnAction(new EventHandler<ActionEvent>() {

                                        @Override
                                        public void handle(ActionEvent event1) {
                                            try {
                                                boolean doAction = display("删除逻辑库配置", "确认删除逻辑库配置");
                                                if (doAction) {
                                                    controller.getInfoProvider().deleteLogicalSchema(command.getSchema());
                                                    controller.flashRoot();
                                                }
                                            } catch (Exception e) {
                                                popAlter(e);
                                            }
                                        }
                                    });
                                    contextMenu.getItems().add(item1);
                                    break;
                                }
                            case SHARDING_TABLES:
                                {
                                    MenuItem item1 = new MenuItem("新建分片表");
                                    item1.setId("addShardingTable");
                                    item1.setOnAction(new EventHandler<ActionEvent>() {

                                        @Override
                                        public void handle(ActionEvent event1) {
                                            try {
                                                controller.addShardingTable(schema);
                                            } catch (Exception e) {
                                                popAlter(e);
                                            }
                                        }
                                    });
                                    contextMenu.getItems().add(item1);
                                    break;
                                }
                            case GLOBAL_TABLES:
                                {
                                    MenuItem item1 = new MenuItem("新建全局表");
                                    item1.setId("addGlobalTable");
                                    item1.setOnAction(new EventHandler<ActionEvent>() {

                                        @Override
                                        public void handle(ActionEvent event1) {
                                            try {
                                                controller.addGlobalTableConfig(schema);
                                            } catch (Exception e) {
                                                popAlter(e);
                                            }
                                        }
                                    });
                                    contextMenu.getItems().add(item1);
                                    break;
                                }
                            case SINGLE_TABLES:
                                {
                                    MenuItem item1 = new MenuItem("新建单表");
                                    item1.setId("addSingleTable");
                                    item1.setOnAction(new EventHandler<ActionEvent>() {

                                        @Override
                                        public void handle(ActionEvent event1) {
                                            try {
                                                controller.addNormalTableConfig(schema);
                                            } catch (Exception e) {
                                                popAlter(e);
                                            }
                                        }
                                    });
                                    contextMenu.getItems().add(item1);
                                    break;
                                }
                            case SHARDING_TABLE:
                                {
                                    MenuItem item1 = new MenuItem("删除分片表配置");
                                    item1.setId("deleteShardingTable");
                                    item1.setOnAction(new EventHandler<ActionEvent>() {

                                        @Override
                                        public void handle(ActionEvent event1) {
                                            try {
                                                boolean doAction = display("删除分片表", "确认删除分片表配置");
                                                if (doAction) {
                                                    controller.getInfoProvider().deleteTable(schema, command.getTable());
                                                    controller.flashSchemas();
                                                }
                                            } catch (Exception e) {
                                                popAlter(e);
                                            }
                                        }
                                    });
                                    contextMenu.getItems().add(item1);
                                    break;
                                }
                            case GLOBAL_TABLE:
                                {
                                    MenuItem item1 = new MenuItem("删除全局表配置");
                                    item1.setId("deleteGlobalTable");
                                    item1.setOnAction(new EventHandler<ActionEvent>() {

                                        @Override
                                        public void handle(ActionEvent event1) {
                                            try {
                                                boolean doAction = display("删除全局表配置", "确认删除全局表配置");
                                                if (doAction) {
                                                    controller.getInfoProvider().deleteTable(command.getSchema(), command.getTable());
                                                    controller.flashSchemas();
                                                }
                                            } catch (Exception e) {
                                                popAlter(e);
                                            }
                                        }
                                    });
                                    contextMenu.getItems().add(item1);
                                    break;
                                }
                            case SINGLE_TABLE:
                                {
                                    MenuItem item1 = new MenuItem("删除单表配置");
                                    item1.setId("deleteSingleTable");
                                    item1.setOnAction(new EventHandler<ActionEvent>() {

                                        @Override
                                        public void handle(ActionEvent event1) {
                                            try {
                                                boolean doAction = display("删除单表配置", "确认删除单表配置");
                                                if (doAction) {
                                                    controller.getInfoProvider().deleteTable(command.getSchema(), command.getTable());
                                                    controller.flashSchemas();
                                                }
                                            } catch (Exception e) {
                                                popAlter(e);
                                            }
                                        }
                                    });
                                    contextMenu.getItems().add(item1);
                                    break;
                                }
                            case CLUSTER:
                                {
                                    MenuItem item1 = new MenuItem("删除");
                                    item1.setId("deleteCluster");
                                    item1.setOnAction(new EventHandler<ActionEvent>() {

                                        @Override
                                        public void handle(ActionEvent event1) {
                                            try {
                                                boolean doAction = display("删除集群", "确认删除集群");
                                                if (doAction) {
                                                    controller.getInfoProvider().deleteCluster(command.getCluster());
                                                    controller.flashClusterAndDataSource();
                                                }
                                            } catch (Exception e) {
                                                popAlter(e);
                                            }
                                        }
                                    });
                                    contextMenu.getItems().add(item1);
                                    break;
                                }
                            case DATASOURCE:
                                {
                                    MenuItem item1 = new MenuItem("删除");
                                    item1.setId("deleteDatasource");
                                    item1.setOnAction(event1 -> {
                                        try {
                                            boolean doAction = display("删除数据源", "确认删除数据源");
                                            if (doAction) {
                                                controller.getInfoProvider().deleteDatasource(command.getDatasource());
                                                controller.flashClusterAndDataSource();
                                            }
                                        } catch (Exception e) {
                                            popAlter(e);
                                        }
                                    });
                                    contextMenu.getItems().add(item1);
                                    break;
                                }
                        }
                    }
                }
                if (contextMenu != null) {
                    cell.setContextMenu(contextMenu);
                }
            }
        }
        if (!cell.isEmpty()) {
            controller.clearObjectInfo();
            if (!commandOptional.isPresent()) {
                return;
            }
            Command command = commandOptional.get();
            switch(command.getType()) {
                case SCHEMA:
                    Optional<LogicSchemaConfig> logicSchemaConfigOptional = controller.getInfoProvider().getSchemaConfigByName(command.getSchema());
                    logicSchemaConfigOptional.ifPresent(r -> controller.edit(r));
                    break;
                case SHARDING_TABLE:
                case GLOBAL_TABLE:
                case SINGLE_TABLE:
                    {
                        if (command.getSchema() == null || command.getTable() == null) {
                            return;
                        }
                        LogicTableType logicTableType;
                        String schemaName = command.getSchema();
                        String tableName = command.getTable();
                        switch(command.getType()) {
                            case GLOBAL_TABLE:
                                logicTableType = LogicTableType.GLOBAL;
                                break;
                            case SINGLE_TABLE:
                                logicTableType = LogicTableType.NORMAL;
                                break;
                            case SHARDING_TABLE:
                                logicTableType = LogicTableType.SHARDING;
                                break;
                            default:
                                throw new IllegalArgumentException();
                        }
                        Optional<Object> config = controller.getInfoProvider().getTableConfigByName(command.getSchema(), command.getTable());
                        config.ifPresent(c -> controller.edit(logicTableType, schemaName, tableName, c));
                        break;
                    }
                case CLUSTER:
                    Optional<ClusterConfig> clusterConfigOptional = controller.getInfoProvider().getClusterConfigByPath(command.getCluster());
                    clusterConfigOptional.ifPresent(c -> controller.edit(c));
                    break;
                case DATASOURCE:
                    Optional<DatasourceConfig> datasourceConfigOptional = controller.getInfoProvider().getDatasourceConfigByPath(command.getDatasource());
                    datasourceConfigOptional.ifPresent(c -> controller.edit(c));
                    break;
            }
            System.out.println("");
        }
    });
    return cell;
}
Also used : ClusterConfig(io.mycat.config.ClusterConfig) EventHandler(javafx.event.EventHandler) Pos(javafx.geometry.Pos) Scene(javafx.scene.Scene) HBox(javafx.scene.layout.HBox) MouseButton(javafx.scene.input.MouseButton) Modality(javafx.stage.Modality) javafx.scene.control(javafx.scene.control) MainPaneVO.popAlter(io.mycat.ui.MainPaneVO.popAlter) Node(javafx.scene.Node) UIMain.getPath(io.mycat.ui.UIMain.getPath) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) VBox(javafx.scene.layout.VBox) ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) LogicTableType(io.mycat.LogicTableType) LogicSchemaConfig(io.mycat.config.LogicSchemaConfig) Optional(java.util.Optional) DatasourceConfig(io.mycat.config.DatasourceConfig) Callback(javafx.util.Callback) Optional(java.util.Optional) ActionEvent(javafx.event.ActionEvent) EventHandler(javafx.event.EventHandler) LogicTableType(io.mycat.LogicTableType) DatasourceConfig(io.mycat.config.DatasourceConfig) LogicSchemaConfig(io.mycat.config.LogicSchemaConfig) ClusterConfig(io.mycat.config.ClusterConfig)

Example 2 with LogicSchemaConfig

use of io.mycat.config.LogicSchemaConfig in project Mycat2 by MyCATApache.

the class CreateSchemaHint method createConfig.

@NotNull
public static LogicSchemaConfig createConfig(String schemaName, String targetName) {
    LogicSchemaConfig schemaConfig = new LogicSchemaConfig();
    schemaConfig.setTargetName(targetName);
    schemaConfig.setSchemaName(schemaName);
    return schemaConfig;
}
Also used : LogicSchemaConfig(io.mycat.config.LogicSchemaConfig) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with LogicSchemaConfig

use of io.mycat.config.LogicSchemaConfig in project Mycat2 by MyCATApache.

the class DropSchemaHint method create.

public static String create(String schemaName) {
    DropSchemaHint dropSchemaHint = new DropSchemaHint();
    LogicSchemaConfig logicSchemaConfig = new LogicSchemaConfig();
    logicSchemaConfig.setSchemaName(schemaName);
    dropSchemaHint.setConfig(logicSchemaConfig);
    return dropSchemaHint.build();
}
Also used : LogicSchemaConfig(io.mycat.config.LogicSchemaConfig)

Example 4 with LogicSchemaConfig

use of io.mycat.config.LogicSchemaConfig in project Mycat2 by MyCATApache.

the class MysqlSchema method getStringNormalTableConfigMap.

private static Map<String, NormalTableConfig> getStringNormalTableConfigMap(String path) throws IOException {
    byte[] bytes = Files.readAllBytes(Paths.get(path));
    String s = new String(bytes);
    LogicSchemaConfig logicSchemaConfig = JsonUtil.from(s, LogicSchemaConfig.class);
    Map<String, NormalTableConfig> normalTables1 = logicSchemaConfig.getNormalTables();
    return normalTables1;
}
Also used : LogicSchemaConfig(io.mycat.config.LogicSchemaConfig) NormalTableConfig(io.mycat.config.NormalTableConfig)

Example 5 with LogicSchemaConfig

use of io.mycat.config.LogicSchemaConfig in project Mycat2 by MyCATApache.

the class PerformanceSchema method getStringNormalTableConfigMap.

private static Map<String, NormalTableConfig> getStringNormalTableConfigMap(String path) throws IOException {
    byte[] bytes = Files.readAllBytes(Paths.get(path));
    String s = new String(bytes);
    LogicSchemaConfig logicSchemaConfig = JsonUtil.from(s, LogicSchemaConfig.class);
    Map<String, NormalTableConfig> normalTables1 = logicSchemaConfig.getNormalTables();
    return normalTables1;
}
Also used : LogicSchemaConfig(io.mycat.config.LogicSchemaConfig) NormalTableConfig(io.mycat.config.NormalTableConfig)

Aggregations

LogicSchemaConfig (io.mycat.config.LogicSchemaConfig)5 NormalTableConfig (io.mycat.config.NormalTableConfig)2 LogicTableType (io.mycat.LogicTableType)1 ClusterConfig (io.mycat.config.ClusterConfig)1 DatasourceConfig (io.mycat.config.DatasourceConfig)1 MainPaneVO.popAlter (io.mycat.ui.MainPaneVO.popAlter)1 UIMain.getPath (io.mycat.ui.UIMain.getPath)1 Optional (java.util.Optional)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ActionEvent (javafx.event.ActionEvent)1 EventHandler (javafx.event.EventHandler)1 Pos (javafx.geometry.Pos)1 Node (javafx.scene.Node)1 Scene (javafx.scene.Scene)1 javafx.scene.control (javafx.scene.control)1 MouseButton (javafx.scene.input.MouseButton)1 HBox (javafx.scene.layout.HBox)1 VBox (javafx.scene.layout.VBox)1 Modality (javafx.stage.Modality)1 Stage (javafx.stage.Stage)1