com.google.appengine.api.datastore.Entity类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(230)

本文整理了Java中com.google.appengine.api.datastore.Entity类的一些代码示例,展示了Entity类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity类的具体详情如下:
包路径:com.google.appengine.api.datastore.Entity
类名称:Entity

Entity介绍

暂无

代码示例

代码示例来源:origin: PeterKnego/LeanEngine-Server

public static void saveSettings(Map<String, Object> newSettings) {
  // there is only one instance of LeanEngineSettings so the same ID=1 is always used
  Entity leanEntity = new Entity("_settings", 1);
  for (String propName : newSettings.keySet()) {
    leanEntity.setProperty(propName, newSettings.get(propName));
  }
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
  datastore.put(leanEntity);
  LeanEngineSettings.settings = newSettings;
}

代码示例来源:origin: com.google.appengine.orm/datanucleus-appengine

/**
 * Convenience method to return an Entity with the same properties as the input Entity but with the
 * specified parent.
 * @param parentKey Key for the parent
 * @param originalEntity The original Entity
 * @return The new Entity
 */
public static Entity recreateEntityWithParent(Key parentKey, Entity originalEntity) {
 Entity entity = null;
 if (originalEntity.getKey().getName() != null) {
  entity = new Entity(originalEntity.getKind(), originalEntity.getKey().getName(), parentKey);
 } else {
  entity = new Entity(originalEntity.getKind(), parentKey);
 }
 EntityUtils.copyProperties(originalEntity, entity);
 return entity;
}

代码示例来源:origin: PeterKnego/LeanEngine-Server

public static AuthToken getAuthToken(String token) {
  //todo use MemCache
  Entity tokenEntity;
  try {
    tokenEntity = datastore.get(KeyFactory.createKey(authTokenKind, token));
  } catch (EntityNotFoundException e) {
    return null;
  }
  return new AuthToken(
      token,
      (Long) tokenEntity.getProperty("account"),
      (Long) tokenEntity.getProperty("time")
  );
}

代码示例来源:origin: com.google.appengine.tools/appengine-pipeline

protected Entity toProtoEntity() {
 Entity entity = new Entity(key);
 entity.setProperty(ROOT_JOB_KEY_PROPERTY, rootJobKey);
 if (generatorJobKey != null) {
  entity.setProperty(GENERATOR_JOB_PROPERTY, generatorJobKey);
 }
 if (graphGUID != null) {
  entity.setUnindexedProperty(GRAPH_GUID_PROPERTY, graphGUID);
 }
 return entity;
}

代码示例来源:origin: org.eiichiro.acidhouse/acidhouse-appengine

private static void setProperty(Entity entity, String name, Object value, boolean unindexed) {
  if (unindexed) {
    entity.setUnindexedProperty(name, value);
  } else {
    entity.setProperty(name, value);
  }
}

代码示例来源:origin: org.vesalainen.dsql/dsql

@Override
public void set(Entity r, String column, Object value)
{
  if (r.isUnindexedProperty(column))
  {
    r.setUnindexedProperty(column, value);
  }
  else
  {
    r.setProperty(column, value);
  }
}

代码示例来源:origin: OhadR/oAuth2-sample

@Override
public void changePassword(String username, String newEncodedPassword) 
{
  Key userKey = KeyFactory.createKey(AUTH_FLOWS_USER_DB_KIND, username);
  Entity entity;
  try 
  {
    entity = datastore.get(userKey);
    log.debug("got entity of " + username + ": " + entity);
  } 
  catch (EntityNotFoundException e) 
  {
    log.error("entity of " + username + " not found");
    throw new NoSuchElementException(e.getMessage());
  }
  
  entity.setProperty(LAST_PSWD_CHANGE_DATE_PROP_NAME, new Date( System.currentTimeMillis()));
  entity.setProperty(PASSWORD_PROP_NAME, newEncodedPassword);
  datastore.put(entity);	
}

代码示例来源:origin: feroult/yawp

@Override
public void deleteAll(String namespace) {
  NamespaceManager.set(namespace);
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
  Query query = new Query();
  PreparedQuery pq = datastore.prepare(query);
  for (Entity entity : pq.asIterable()) {
    String kind = entity.getKind();
    if (kind.startsWith("__") && !kind.contains("yawp")) {
      continue;
    }
    datastore.delete(entity.getKey());
  }
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void batchGetReturnsOnlyExistingKeysInMap() throws Exception {
  Key existingKey = KeyFactory.createKey("batch", "existing");
  Key nonExistingKey = KeyFactory.createKey("batch", "nonExisting");
  service.put(new Entity(existingKey));
  Map<Key, Entity> map = service.get(Arrays.asList(existingKey, nonExistingKey));
  assertEquals(1, map.size());
  assertTrue(map.containsKey(existingKey));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testIntegerPropertySortingIsNotLexicographic() throws Exception {
  String methodName = "testIntegerPropertySortingIsNotLexicographic";
  Entity parent = createTestEntityWithUniqueMethodNameKey(QUERY_SORTING_ENTITY, methodName);
  Key key = parent.getKey();
  Entity ten = storeTestEntityWithSingleProperty(key, 10);
  Entity five = storeTestEntityWithSingleProperty(key, 5);
  Query query = createQuery().setAncestor(key).addSort(SINGLE_PROPERTY_NAME, ASCENDING);
  List<Entity> results = service.prepare(query).asList(withDefaults());
  assertTrue(results.indexOf(five) < results.indexOf(ten));   // if sorting were lexicographic, "10" would come before "5"
  service.delete(ten.getKey(), five.getKey());
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testKeySerialization() throws EntityNotFoundException, IOException {
  Key parentKeyB = KeyFactory.createKey("family", "same");
  Key childKeyB = KeyFactory.createKey(parentKeyB, "children", "same");
  Entity entB1 = new Entity(childKeyB);
  service.put(entB1);
  Entity entB2 = service.get(childKeyB);
  assertEquals(new String(MemcacheSerialization.makePbKey(entB1.getKey())),
    new String(MemcacheSerialization.makePbKey(childKeyB)));
  assertEquals(new String(MemcacheSerialization.makePbKey(entB2.getKey())),
    new String(MemcacheSerialization.makePbKey(childKeyB)));
  service.delete(childKeyB);
  service.delete(parentKeyB);
}

代码示例来源:origin: com.google.appengine.orm/datanucleus-appengine

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;
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testFilterByEntityKey() {
  Entity parentEntity = createTestEntityWithUniqueMethodNameKey(TEST_ENTITY_KIND, "testFilterByEntityKey");
  Key parentKey = parentEntity.getKey();
  Key fooKey = KeyFactory.createKey(parentKey, "foo", 1);
  Entity fooEntity = new Entity(fooKey);
  service.put(fooEntity);
  Query query = new Query("foo")
    .setAncestor(parentKey)
    .setFilter(new Query.FilterPredicate(Entity.KEY_RESERVED_PROPERTY, EQUAL, fooKey));
  PreparedQuery preparedQuery = service.prepare(query);
  List<Entity> results = preparedQuery.asList(FetchOptions.Builder.withDefaults());
  assertEquals(1, results.size());
  assertEquals(fooEntity, results.get(0));
}

代码示例来源:origin: PeterKnego/LeanEngine-Server

public static void deletePrivateEntity(String entityKind, long entityId) throws LeanException {
  LeanAccount account = findCurrentAccount();
  if (entityId <= 0 || entityKind == null) throw new LeanException(LeanException.Error.EntityNotFound,
      " Entity 'kind' and 'id' must NOT be null.");
  Entity entity;
  try {
    entity = datastore.get(KeyFactory.createKey(entityKind, entityId));
  } catch (EntityNotFoundException e) {
    throw new LeanException(LeanException.Error.EntityNotFound);
  }
  if (account.id != (Long) entity.getProperty("_account"))
    throw new LeanException(LeanException.Error.NotAuthorized,
        " Account not authorized to access entity '" + entityKind + "'with ID '" + entityId + "'");
  datastore.delete(entity.getKey());
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testDataPut() throws Exception {
  Entity parent = createTestEntityWithUniqueMethodNameKey(ASYNC_ENTITY, "testDataPut");
  Key key = parent.getKey();
  Entity newRec = new Entity(ASYNC_ENTITY, key);
  newRec.setProperty("count", 0);
  newRec.setProperty("timestamp", new Date());
  Future<Key> future = asyncService.put(newRec);
  future.get();
  assertTaskIsDoneAndNotCancelled(future);
  assertEquals(1, service.prepare(simpleQuery(key)).countEntities(withDefaults()));
}

代码示例来源:origin: bedatadriven/activityinfo

private Entity updateDouble(Entity blockEntity, int recordOffset, double doubleValue) {
  Blob valueArray = (Blob) blockEntity.getProperty(valuesProperty);
  valueArray = DoubleValueArray.update(valueArray, recordOffset, doubleValue);
  blockEntity.setUnindexedProperty(formatProperty, REAL64_STORAGE);
  blockEntity.setProperty(valuesProperty, valueArray);
  return blockEntity;
}

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

public static void main(String[] args) throws IOException {
  String serverString = args[0];
  RemoteApiOptions options;
  if (serverString.equals("localhost")) {
   options = new RemoteApiOptions().server(serverString,
    8080).useDevelopmentServerCredential();
  } else {
   options = new RemoteApiOptions().server(serverString,
    443).useApplicationDefaultCredential();
  }
  RemoteApiInstaller installer = new RemoteApiInstaller();
  installer.install(options);
  try {
   DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
   System.out.println("Key of new entity is " + ds.put(new Entity("Hello Remote API!")));
  } finally {
   installer.uninstall();
  }
 }
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test(expected = IllegalStateException.class)
public void testClosedTx() throws InterruptedException {
  clearData(kindName);
  Transaction tx = service.beginTransaction();
  Entity newRec = new Entity(kindName);
  newRec.setProperty("check", "4100331");
  newRec.setProperty("stamp", new Date());
  service.put(newRec);
  tx.commit();
  service.put(tx, new Entity(kindName));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

protected Object[] getResult(Query query, String pName) {
  int count = service.prepare(query).countEntities(FetchOptions.Builder.withDefaults());
  Object result[] = new Object[count];
  int pt = 0;
  for (Entity readRec : service.prepare(query).asIterable()) {
    result[pt++] = readRec.getProperty(pName);
  }
  return result;
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
  public void testEntityGainsNoAdditionalPropertiesWhenStored() throws Exception {
    clearData(kindName);
    Entity entity = new Entity(kindName);
    Key key = service.put(entity);
    entity = service.get(key);
    assertEquals(Collections.<String, Object>emptyMap(), entity.getProperties());
  }
}

相关文章