2012-03-03 19 views
0

オンラインのINIファイルとしてGDataDBを使用して、ユーザーの設定を「クラウド」に保存します。GDataDB:同時接続とGoogleドキュメント

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がある場合は、同じオブジェクトを複数のクライアントが同時に処理する場合を除き、問題はありません.- –

+0

Ghaachの発明者はここに... –

+0

.FindStructured(String.Format( "username = '{0}'、username))が失敗します。 '記号を確認してください。私はちょうど先行ゼロでユーザ名を埋めたいと思った。 –