[]
        
(Showing Draft Content)

数据库连接选择属性

@Data
public class MyPluginServerCommand2 extends Command implements ICommandExecutableInServerSide {

    @DatabaseConnectionSelectorProperty
    private String string;

    @Override
    public ExecuteResult execute(IServerCommandExecuteContext dataContext) {
        var dataAccess = dataContext.getDataAccess();
        var connectionStr = dataContext.getDataAccess().getConnectionStringByID(string);
        dataAccess.beginTransaction(connectionStr);
        var sqlValue = dataAccess.executeSql(string, "select * from test", null);
        dataAccess.commitTransaction(connectionStr);
        var result = new ExecuteResult();
        result.getReturnValues().put("connectionStr",connectionStr);
        result.getReturnValues().put("sqlValue",sqlValue);
        return result;
    }

    @Override
    public String toString() {
        return "我的服务端命令插件";
    }
}

在设计器中效果如下,在数据库连接管理中连接了外部数据库之后:

 image

可以通过标注了@DatabaseConnectionSelectorProperty 的属性选择特定数据库。

image

如果需要更细致的控制,可以通过@DatabaseConnectionSelectorProperty的其他属性来控制

(空)显示为内建库

  1. 设置DatabaseConnectionSelectorProperty的IncludeBuiltInDatabase属性

  2. 代码

    @Data
    public class MyPluginServerCommand2 extends Command implements ICommandExecutableInServerSide {
    
        @DatabaseConnectionSelectorProperty(includeBuiltInDatabase = true)
        private String string;
    
        @Override
        public ExecuteResult execute(IServerCommandExecuteContext dataContext) {
            var dataAccess = dataContext.getDataAccess();
            var connectionStr = dataContext.getDataAccess().getConnectionStringByID(string);
            dataAccess.beginTransaction(connectionStr);
            var sqlValue = dataAccess.executeSql(string, "select * from test", null);
            dataAccess.commitTransaction(connectionStr);
            var result = new ExecuteResult();
            result.getReturnValues().put("connectionStr",connectionStr);
            result.getReturnValues().put("sqlValue",sqlValue);
            return result;
        }
    
        @Override
        public String toString() {
            return "我的服务端命令插件";
        }
    }
  3. 效果

    image


  4. 说明

    对于内建数据库(Sqlite)连接名称为null

注意,标注@DatabaseConnectionSelectorProperty的属性类型必须是 String。