@Override public String createKeyString(String kind, long id) { return KeyFactory.createKeyString(kind, id); }
@Override public String createKeyString(String kind, String name) { return KeyFactory.createKeyString(kind, name); }
@Override public String createKeyString(Key parent, String kind, long id) { return KeyFactory.createKeyString(parent, kind, id); }
@Override public String createKeyString(Key parent, String kind, String name) { return KeyFactory.createKeyString(parent, kind, name); }
/** Allocates lock for the managing entity. */ @Override public void prepare() { List<Log> logs = global.logs(); Object parent = null; for (int i = logs.size() - 1; i >=0; i--) { if (logs.get(i).operation() != Log.Operation.GET) { parent = logs.get(i).entity(); break; } } Lock lock = new Lock(global.id(), KeyFactory.createKeyString( Keys.create(Translation.toKind(parent.getClass()), Entities.keyValue(parent)), Translation.TRANSACTION_KIND, global.id()), new Date()); datastore.put(local, Translation.toEntity(lock, Keys.create( Translation.toKind(entity.getClass()), Entities.keyValue(entity)))); local.commit(); this.lock = lock; }
Key pKey = service.put(parent); String keyString = KeyFactory.createKeyString(pKey, kind, 1); assertTrue(Base64.isBase64(keyString.getBytes())); Entity entity = new Entity(KeyFactory.stringToKey(keyString)); assertEquals(kind, entity.getKey().getKind()); keyString = KeyFactory.createKeyString(pKey, kind, "2"); assertTrue(Base64.isBase64(keyString.getBytes())); entity = new Entity(KeyFactory.stringToKey(keyString)); assertEquals(pKey, entity.getParent()); keyString = KeyFactory.createKeyString(kind, 3); assertTrue(Base64.isBase64(keyString.getBytes())); entity = new Entity(KeyFactory.stringToKey(keyString)); assertEquals(3, entity.getKey().getId()); keyString = KeyFactory.createKeyString(kind, "4"); assertTrue(Base64.isBase64(keyString.getBytes())); entity = new Entity(KeyFactory.stringToKey(keyString));