ArcSDE SDK Java 快速实践 7

I. 版本

· 添加删除版本

通过如下的代码可以基于Default版本创建一个新的子版本:

SeConnection conn = getConn();

if (conn != null) {

try {

SeVersion v_1 = new SeVersion(conn, SeVersion.SE_QUALIFIED_DEFAULT_VERSION_NAME);

v_1.setName("v_1");

v_1.create(true, v_1);

} catch (SeException e) {

e.printStackTrace();

} finally {

try {

conn.close();

} catch (SeException e) {

e.printStackTrace();

}

}

}

至于删除版本就更容易了:

SeConnection conn = getConn();

if (conn != null) {

try {

SeVersion v_1 = new SeVersion(conn, "v_1");

v_1.delete();

} catch (SeException e) {

e.printStackTrace();

} finally {

try {

conn.close();

} catch (SeException e) {

e.printStackTrace();

}

}

}

· 进行一个版本编辑

进行版本编辑关键在于对版本状态(State)的管理,下面的代码展示了如何从一个版本数据集中删除一条记录:

SeConnection conn = getConn();

if (conn != null) {

try {

SeVersion version = new SeVersion(conn, "v1");

SeObjectId oldStateId = version.getStateId();

SeState oldState = new SeState(conn, oldStateId);

if(oldState.isOpen()){

try {

oldState.close();

} catch (Exception e) {

e.printStackTrace();

}

}

SeState newState = new SeState(conn);

newState.create(oldStateId);

version.changeState(newState.getId());

SeDelete delete = new SeDelete(conn);

delete.setState(newState.getId(),

new SeObjectId(SeState.SE_NULL_STATE_ID),

SeState.SE_STATE_DIFF_NOCHECK);

delete.fromTable("TEST", "OBJECTID=3");

delete.close();

} catch (SeException e) {

e.printStackTrace();

} finally {

try {

conn.close();

} catch (SeException e) {

e.printStackTrace();

}

}

}

你可能感兴趣的:(java,exception,null,delete)