2012-03-03 86 views
0

我使用GDataDB作爲在線INI文件來保存用戶在「雲」上的設置。我使用如下的單個電子表格:GDataDB:Concurrent connections&Google Docs

username create  update  expire   amount 
3600001 20120303 20120303  20180303  9 
3600001 20120303 20120303  20160303  9 
3600020 20120301 20120303  20190505  14 

我想知道併發寫入/更新會發生什麼。我的意思是安全嗎?你怎麼看?

以下是代碼:正如您所看到的,它同時訪問該文件的機會很少,但我要求將來參考,以便查看它可以用於或不用於大量讀取操作 - 而不是大量讀取操作。或者我可以實現鎖定機制?

 public class License 
     { 
      public string username { get; set; } 
      public string create { get; set; } 
      public string update { get; set; } 
      public string expire { get; set; } 
      public double amount { get; set; } 
     } 



     private static void Main(string[] args) { 


      string myaccount = "[email protected]"; 
      string mypass = "xxxxxxxxxxxxxxxx"; 
      string spreadsheet = "licence"; 

      string username = "03600001"; 
      double amount = 9.0d; //bucks 
      int extend = 1; //year 

      // create the DatabaseClient passing my Gmail or Google Apps credentials 
      IDatabaseClient client = new DatabaseClient(myaccount, mypass); 

      // get or create the database. This is the spreadsheet file 
      IDatabase db = client.GetDatabase(spreadsheet) ?? client.CreateDatabase(spreadsheet); 

      // get or create the table. This is a worksheet in the file 
      // note I am using my Person object so it knows what my schema needs to be 
      // for my data. It will create a header row with the property names 
      ITable<License> table = db.GetTable<License>(spreadsheet) ?? db.CreateTable<License>(spreadsheet); 




      var license = new License(); 


      IList<IRow<License>> rows = table.FindStructured(String.Format("username={0}", username)).OrderByDescending(o => o.Element.expire).Take(1).ToList(); 

      if (rows == null || rows.Count == 0) 
      { 
       //add new 
       license.username = username; 
       license.create = DateTime.Now.ToString("yyyyMMdd"); 
       license.update = license.create; 
       license.expire = DateTime.Now.AddYears(extend).ToString("yyyyMMdd"); 
       license.amount = amount; 

       table.Add(license); 
      } 
      else 
      { 
       //update 
       IRow<License> row = rows[0]; 

       DateTime expire = DateTime.ParseExact(row.Element.expire, "yyyyMMdd", null); 

       row.Element.expire = expire.AddYears(extend).ToString("yyyyMMdd"); 
       row.Element.update = DateTime.Now.ToString("yyyyMMdd"); 
       row.Element.amount = amount; 

       row.Update(); 
      } 

      } 

回答

1

據我所知,應該沒有問題。當然,由於沒有內置的鎖定機制,除非您自己實現鎖定機制,否則對特定單元格的最後更新將會獲勝。

+0

是在客戶端還是服務器端進行文檔處理?我假設是服務器端。如果所有行和單元格都有唯一的ID,那麼應該沒有問題 - 除了同時由多個客戶端處理相同的對象.- – 2012-03-04 09:07:40

+0

Aha,GDataDB的發明者在這裏... – 2012-03-04 09:11:44

+0

.FindStructured(String.Format(「username ='{0}「,用戶名))失敗。注意'標誌。我只是想填充前導零的用戶名。 – 2012-03-04 11:25:37