Created
November 18, 2012 01:59
-
-
Save tadamatu/4102787 to your computer and use it in GitHub Desktop.
[BlobMigrationRecord Class] get_new_blob_key() method for Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.myproject; | |
import com.google.appengine.api.blobstore.BlobKey; | |
import com.google.appengine.api.datastore.DatastoreService; | |
import com.google.appengine.api.datastore.DatastoreServiceFactory; | |
import com.google.appengine.api.datastore.Entity; | |
import com.google.appengine.api.datastore.EntityNotFoundException; | |
import com.google.appengine.api.datastore.Key; | |
import com.google.appengine.api.datastore.KeyFactory; | |
public class BlobMigrationRecord { | |
/* ============================== | |
* Python get_new_blob_key() メソッド の Java版 | |
* Python get_new_blob_key() method for Java | |
* | |
* <<補足>> | |
* [Google App Engine]でBlobを利用していると、 | |
* [M/S]から[HRD]へDatastore移行した際にBlobkeyが変更される | |
* この関数では旧Blobkeyから新Blobkeyへ変換を行う | |
* | |
* <Input> oldBlobKey 旧Blobkey | |
* <Output> 新Blobkey | |
* ============================== */ | |
public static String getNewBlobKey(String oldBlobKey) { | |
String newBlobKey = ""; | |
try { | |
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); | |
Key key = KeyFactory.createKey("__BlobMigration__", oldBlobKey); | |
Entity blobkey = datastore.get(key); | |
BlobKey blobKey = (BlobKey) blobkey.getProperty("new_blob_key"); | |
newBlobKey = blobKey.getKeyString(); | |
} catch (EntityNotFoundException e) { | |
newBlobKey = oldBlobKey; | |
} | |
return newBlobKey; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment