2017-01-26 5 views
0

一部のデータをMysqlからDatastoreに移動しました。このデータ移行のために、古いIDをMysqlから削除したいと思います。Google Cloud Datastore JavaライブラリのallocateIdsはどこにありますか?

私はhere

Instead of using key name strings or generating numeric IDs automatically, advanced applications may sometimes wish to assign their own numeric IDs manually to the entities they create. Be aware, however, that there is nothing to prevent Datastore from assigning one of your manual numeric IDs to another entity. The only way to avoid such conflicts is to have your application obtain a block of IDs with the allocateIds() method. Cloud Datastore's automatic ID generator will keep track of IDs that have been allocated with these methods and will avoid reusing them for another entity, so you can safely use such IDs without conflict. 

このノートを見つけたのでallocateIdsは私がやろうとしています何のための完璧なようです。私はこのメソッドを使用して、Mysqlからすべての自動インクリメントされたIDを割り当てて、衝突について心配することなくデータストアIDジェネレータを使用できるようにします。

しかし、私はどこでもこのメソッドを見つけることができません。私は、アプリケーションエンジンを使用せずに、スタンドアロンのライブラリとしてクラウドデータストアJavaライブラリを使用しています。

答えて

1

Cloud Datastore APIでは、ユーザー指定のIDを予約する方法は公開されていません。 AllocateIdsメソッドはIDを選択します。

可能なアプローチの1つは、鍵のname(文字列)フィールドにMySQL生成のIDを割り当てることです。 Cloud Datastoreでは、nameフィールドは自動割り当てされません。欠点は、アプリケーションコードが将来の値を生成することになることです。

+0

この段落の最後にあるので、ちょっと混乱しています。https://cloud.google.com/datastore/docs/concepts/entities#assigning_identifiers allocateIdsを使用して手動IDを割り当てることができますが、メソッドを見つける。 – danielz

+0

'com.google.cloud.datastore.Datastore'に' allocateId'メソッドがありますが、不完全キー(IDや名前を指定していないキー)だけを受け付けます。あなたがリンクしている段落は、その前で少し誤解を招いています。 –

+0

@EdDavisson - allocateIdメソッドは、IncompleteKeyとKey(IncompleteKeyが拡張されているため)を受け入れ、うれしく「新しい」IDのキーを返します。入力に設定したIDはかなり破棄されます。おそらく、このメソッドは、(IDを持つ)Keyオブジェクトを拒否する修正も必要です。 –

関連する問題