GlobalId与普通的字段转换


// Converts a GlobalID field to a GUID field.
public static void ConvertGlobalIdToGuid(IWorkspace workspace, String
  datasetName)
{
  // Open the table.
  IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
  ITable table = featureWorkspace.OpenTable(datasetName);

  // Get the GlobalID field.
  IClassEx classEx = (IClassEx)table;
  if (!classEx.HasGlobalID)
  {
    throw new Exception(String.Format("No GlobalID column in table: {0}.",
      datasetName));
  }
  String globalIDFieldName = classEx.GlobalIDFieldName;

  // Convert the GlobalID column to a GUID column.
  IClassSchemaEditEx classSchemaEditEx = (IClassSchemaEditEx)table;
  classSchemaEditEx.UnregisterGlobalIDColumn(globalIDFieldName);
}

2 一下代码实现将普通的字段转变成GlobalID

/ Converts a GUID field to a GlobalID field.
public static void ConvertGuidToGlobalId(IWorkspace workspace, String
  datasetName, String guidFieldName)
{
  // Open the table.
  IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
  ITable table = featureWorkspace.OpenTable(datasetName);

  // Get the GUID field to convert.
  IFields fields = table.Fields;
  int guidFieldIndex = fields.FindField(guidFieldName);
  IField guidField = fields.get_Field(guidFieldIndex);
  if (guidField.Type != esriFieldType.esriFieldTypeGUID)
  {
    throw new Exception(String.Format("Field {0} is not a GUID field.",
      guidFieldName));
  }

  // Convert the GUID column to a GlobalID column.
  IClassSchemaEditEx classSchemaEditEx = (IClassSchemaEditEx)table;
  classSchemaEditEx.RegisterGlobalIDColumn(guidField.Name);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在使用`undolog`进行事务管理时,每个事务都会被分配一个唯一的`xid`。如果需要手动回滚一个事务,可以使用以下步骤: 1. 获取需要回滚的事务的`xid`,可以通过查询`undolog`表来获取: ```sql SELECT xid FROM undolog WHERE status = 'ACTIVE'; ``` 2. 在代码中使用`Connection`对象的`rollback(Xid xid)`方法来手动回滚该事务: ```java import javax.transaction.xa.Xid; import com.mysql.jdbc.jdbc2.optional.MysqlXADataSource; import com.mysql.jdbc.jdbc2.optional.MysqlXid; import com.mysql.jdbc.jdbc2.optional.XAConnection; import java.sql.Connection; import java.sql.SQLException; public class RollbackExample { public static void main(String[] args) throws SQLException { MysqlXADataSource xaDataSource = new MysqlXADataSource(); xaDataSource.setURL("jdbc:mysql://localhost:3306/test"); xaDataSource.setUser("user"); xaDataSource.setPassword("password"); XAConnection xaConnection = xaDataSource.getXAConnection(); Connection connection = xaConnection.getConnection(); // Get Xid of active transaction String xidString = "0001"; // replace with actual Xid string byte[] globalId = xidString.getBytes(); byte[] branchId = new byte[] {0x01}; Xid xid = new MysqlXid(globalId, branchId, 1); // Rollback transaction with given Xid connection.rollback(xid); connection.close(); xaConnection.close(); } } ``` 在上述代码中,将`xidString`替换为需要回滚的事务的`xid`字符串,然后使用`MysqlXid`类创建`Xid`对象,并将其传递给`Connection`对象的`rollback()`方法即可。注意,当使用`rollback(Xid xid)`方法回滚事务时,不需要显式调用`commit()`方法,因为在回滚时所有的修改都会被撤销。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值