4

我正在尝试以编程方式删除我在 JBoss 7 中创建的数据源。

创建它很容易...

        ModelNode request = new ModelNode();
    request.get(ClientConstants.OP).set(ClientConstants.ADD);
    request.get(ClientConstants.OP_ADDR).add("subsystem",
            "datasources");
    request.get(ClientConstants.OP_ADDR).add("data-source",
        dataSourceName);

    request.get("jndi-name").set(dataSourceName);
    request.get("pool-name").set(poolName);
    request.get("use-java-context").set(Boolean.TRUE);
    request.get("connection-url").set(url);
    request.get("driver-name").set(driver-name));
    request.get("min-pool-size").set(.minPoolSize);
    request.get("max-pool-size").set(maxPoolSize);
    request.get("user-name").set(username);
    request.get("password").set("password");

    ModelControllerClient client = ModelControllerClient.Factory.create(
            InetAddress.getByName(LOCALHOST), 9999);
    client.execute(new OperationBuilder(request).build());
    client.close();

我的standalone.xml 创建并启用

...
<subsystem xmlns="urn:jboss:domain:datasources:1.1">
  <datasources>
     <datasource jndi-name="name" pool-name="poolName" enabled="true" use-java-context="true">
       <connection-url>*url*</connection-url>
       <driver>driver</driver>
       ...
      </datasource>
      <drivers>
        <driver...>
           ...
        </driver>
      </drivers>
    </datasources>
  </subsystem>
...

但是...我找不到如何以编程方式删除它。有谁能够帮我?

谢谢 :)

4

2 回答 2

3

其实很简单。您需要知道对象的完整地址,然后简单地调用删除操作。

ModelNode request = new ModelNode();
request.get(ClientConstants.OP).set("remove");
request.get(ClientConstants.OP_ADDR).add("subsystem",
    "datasources");
request.get(ClientConstants.OP_ADDR).add("data-source",
    dataSourceName);

ModelControllerClient client = ModelControllerClient.Factory.create(
        InetAddress.getByName(LOCALHOST), 9999);
client.execute(new OperationBuilder(request).build());
client.close();
于 2012-11-22T07:21:45.933 回答
0

现在可以使用完整的 API 来处理此类操作。

Jboss 控制器操作执行器

希望这可以帮助。

于 2013-03-24T13:47:34.617 回答