@Override protected Object internalConvert(Object value, Type targetType) { if (value == null) return null; return KeyFactory.stringToKey((String)value); }
@Override public Key stringToKey(String encoded) { return KeyFactory.stringToKey(encoded); }
/** * Reconstitute a Key from a web safe string. This can be generated with getString() * or KeyFactory.strongToKey(). */ public Key(String webSafe) { this(KeyFactory.stringToKey(webSafe)); }
@Override public Key from(String from) { return from == null ? null : KeyFactory.stringToKey(from); }
/** * Construct a new FanoutTask from the given Properties. This constructor * is used to construct an instance that is being handled. */ public FanoutTask(Type type, String taskName, Properties properties) { super(type, taskName, properties); this.recordKey = KeyFactory.stringToKey(properties.getProperty(RECORD_KEY_PROPERTY)); }
/** * Converts the specified value to * {@code com.google.appengine.api.datastore.Key}. * * @see org.apache.commons.beanutils.converters.AbstractConverter#convertToType(java.lang.Class, java.lang.Object) */ @SuppressWarnings("rawtypes") @Override protected Object convertToType(Class type, Object value) throws Throwable { return KeyFactory.stringToKey(value.toString()); }
protected HandleChildExceptionTask(Type type, String taskName, Properties properties) { super(type, taskName, properties); failedChildKey = KeyFactory.stringToKey(properties.getProperty(FAILED_CHILD_KEY_PARAM)); }
protected DelayedSlotFillTask(Type type, String taskName, Properties properties) { super(type, taskName, properties); rootJobKey = KeyFactory.stringToKey(properties.getProperty(ROOT_JOB_KEY_PARAM)); }
/** * This constructor is used on the receiving side. That is, it is used to * construct an {@code ObjRefTask} from an HttpRequest sent from the App * Engine task queue. * * @param type The type of task being constructed * @param properties In addition to the properties specified in the parent * constructor, {@code properties} must also contain a property named "key" * with a value of a stringified data store key. This will be used as * the {@link #key} of the object to which this {@code ObjRefTask} * refers. */ protected ObjRefTask(Type type, String taskName, Properties properties) { super(type, taskName, properties); key = KeyFactory.stringToKey(properties.getProperty(KEY_PARAM)); }
/** * Converts a String generated with {@code keyToString()} back into an Objectify * Key. The String could also have been generated by the GAE {@code KeyFactory}. * * @param stringifiedKey is generated by either {@code ObjectifyFactory.keyToString()} or * {@code KeyFactory.keyToString()}. * @return a Key<?> */ public <T> Key<T> stringToKey(String stringifiedKey) { return new Key<T>(KeyFactory.stringToKey(stringifiedKey)); }
public static Todo findByKey(String key) { return findByKey(KeyFactory.stringToKey(key)); }
private void storeParentStringField(String value) { Key key = null; if (value != null) { try { key = KeyFactory.stringToKey(value); } catch (IllegalArgumentException iae) { throw new NucleusFatalUserException("Attempt was made to set parent to " + value + " but this cannot be converted into a Key."); } } storeParentKeyPK(key); }
public static Key getPrimaryKeyAsKey(Object pk, ExecutionContext ec, AbstractClassMetaData cmd) { String kind = EntityUtils.determineKind(cmd, ec); if (pk instanceof Key) { return (Key) pk; } else if (long.class.isInstance(pk) || pk instanceof Long) { return KeyFactory.createKey(kind, (Long) pk); } try { return KeyFactory.stringToKey((String) pk); } catch (IllegalArgumentException iae) { return KeyFactory.createKey(kind, (String) pk); } }
static Key getPkAsKey(Object pk, AbstractClassMetaData acmd, ExecutionContext ec) { if (pk == null) { throw new IllegalStateException( "Primary key for object of type " + acmd.getName() + " is null."); } else if (pk instanceof Key) { return (Key) pk; } else if (pk instanceof String) { if (MetaDataUtils.hasEncodedPKField(acmd)) { return KeyFactory.stringToKey((String) pk); } else { String kind = EntityUtils.determineKind(acmd, ec); return KeyFactory.createKey(kind, (String) pk); } } else if (pk instanceof Long || long.class.isInstance(pk)) { String kind = EntityUtils.determineKind(acmd, ec); return KeyFactory.createKey(kind, (Long) pk); } else { throw new IllegalStateException( "Primary key for object of type " + acmd.getName() + " is of unexpected type " + pk.getClass().getName() + " (must be String, Long, long, or " + Key.class.getName() + ")"); } }
/** * Applies the transactional operation (WAL: Write Ahead Log) to the * managing entity and unlocks it. */ @Override public void commit() { List<Key> deletes = new ArrayList<Key>(); deletes.add(Translation.toEntity(lock, Keys.create( Translation.toKind(entity.getClass()), Entities.keyValue(entity))).getKey()); Key transactionKey = KeyFactory.stringToKey(lock.transaction()); if (Keys.ancestor(transactionKey).equals( Keys.create(Translation.toKind(entity.getClass()), Entities.keyValue(entity)))) { deletes.add(transactionKey); for (Entity entity : datastore.query( new Query(transactionKey).setKeysOnly())) { deletes.add(entity.getKey()); } } Key parent = Keys.create(Translation.toKind(entity.getClass()), Entities.keyValue(entity)); apply(operation, entity, Translation.toEntity(lock, parent).getKey(), deletes); }
private Key internalPkToKey(AbstractClassMetaData acmd, Object internalPk) { Key key; if (internalPk instanceof String) { try { key = KeyFactory.stringToKey((String) internalPk); } catch (IllegalArgumentException iae) { String kind = getIdentifierFactory().newDatastoreContainerIdentifier(acmd).getIdentifierName(); key = KeyFactory.createKey(kind, (String) internalPk); } } else if (internalPk instanceof Long) { String kind = getIdentifierFactory().newDatastoreContainerIdentifier(acmd).getIdentifierName(); key = KeyFactory.createKey(kind, (Long) internalPk); } else { key = (Key) internalPk; } return key; }
protected int[] internalShift(ObjectProvider op, boolean batched, int oldIndex, int amount) throws MappedDatastoreException { if (orderMapping == null) { return null; } DatastoreServiceConfig config = storeMgr.getDefaultDatastoreServiceConfigForReads(); DatastoreService service = DatastoreServiceFactoryInternal.getDatastoreService(config); AbstractClassMetaData acmd = elementCmd; String kind = storeMgr.getIdentifierFactory().newDatastoreContainerIdentifier(acmd).getIdentifierName(); Query q = new Query(kind); ExecutionContext ec = op.getExecutionContext(); Object id = ec.getApiAdapter().getTargetKeyForSingleFieldIdentity(op.getInternalObjectId()); Key key = id instanceof Key ? (Key) id : KeyFactory.stringToKey((String) id); q.setAncestor(key); // create an entity just to capture the name of the index property Entity entity = new Entity(kind); orderMapping.setObject(ec, entity, new int[] {1}, oldIndex); String indexProp = entity.getProperties().keySet().iterator().next(); q.addFilter(indexProp, Query.FilterOperator.GREATER_THAN_OR_EQUAL, oldIndex); for (Entity shiftMe : service.prepare(service.getCurrentTransaction(null), q).asIterable()) { Long pos = (Long) shiftMe.getProperty(indexProp); shiftMe.setProperty(indexProp, pos + amount); EntityUtils.putEntityIntoDatastore(ec, shiftMe); } return null; }
if (value != null) { try { key = KeyFactory.stringToKey(value); } catch (IllegalArgumentException iae) { throw new NucleusFatalUserException(
? (Key) childKeyOrString : KeyFactory.stringToKey((String) childKeyOrString);
Entity entity = new Entity(KeyFactory.stringToKey(keyString)); entity.setProperty("role", "keystring+id"); service.put(entity); entity = new Entity(KeyFactory.stringToKey(keyString)); entity.setProperty("role", "keystring+name"); service.put(entity); entity = new Entity(KeyFactory.stringToKey(keyString)); entity.setProperty("role", "keystring+id"); service.put(entity); entity = new Entity(KeyFactory.stringToKey(keyString)); entity.setProperty("role", "keystring+name"); service.put(entity);