当前位置: 首页>>代码示例>>Java>>正文


Java Key类代码示例

本文整理汇总了Java中com.google.appengine.api.datastore.Key的典型用法代码示例。如果您正苦于以下问题:Java Key类的具体用法?Java Key怎么用?Java Key使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Key类属于com.google.appengine.api.datastore包,在下文中一共展示了Key类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import com.google.appengine.api.datastore.Key; //导入依赖的package包/类
@Override
public void process() {
    UserService userService = UserServiceFactory.getUserService();
    // Step 1: Add Text into DB.
    Entity textEntity = getNewEntity();
    textEntity.setProperty("rawText", new Text(text));
    textEntity.setProperty("user",
            userService.getCurrentUser().getNickname());
    textEntity.setProperty("date", new Date());
    putIntoDatabase(textEntity);
    Key parentKey = textEntity.getKey();
    factory.setParentKey(parentKey);
    // Step 2: Call other processors.
    factory.createTypePredictor().process();
    factory.createKnowledgeGraphBuilder().process();
    factory.createSummaryGenerator().process();
}
 
开发者ID:SamChou19815,项目名称:chunk-reader,代码行数:18,代码来源:MainProcessor.java

示例2: shouldReindexEntities

import com.google.appengine.api.datastore.Key; //导入依赖的package包/类
@Test
public void shouldReindexEntities() {
    DatastoreKeyTestEntity testEntity = new DatastoreKeyTestEntity(1, "original");
    DatastoreKeyTestEntity testEntity2 = new DatastoreKeyTestEntity(2, "original");
    DatastoreKeyTestEntity testEntity3 = new DatastoreKeyTestEntity(3, "original");
    repository.putAsync(testEntity, testEntity2, testEntity3).complete();

    assertThat(repository.search().field("name", Is.Is, "original").run().getResults(), hasItems(testEntity, testEntity2, testEntity3));

    List<DatastoreKeyTestEntity> all = ObjectifyService.ofy().load().type(DatastoreKeyTestEntity.class).list();
    for (DatastoreKeyTestEntity e : all) {
        e.setName("other name");
    }
    ObjectifyService.ofy().save().entities(all).now();

    List<Key> keys = list(testEntity.getKey(), testEntity2.getKey(), testEntity3.getKey());
    int reindexed = repository.reindex(keys, 10, null);
    assertThat(reindexed, is(3));

    assertThat(repository.search().field("name", Is.Is, "original").run().getResults().isEmpty(), is(true));
    assertThat(repository.search().field("name", Is.Is, "other name").run().getResults().size(), is(3));
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:23,代码来源:DatastoreKeyRepositoryTest.java

示例3: shouldReindexEntitiesAndWriteBackToDatastoreWhenReindexOperationProvided

import com.google.appengine.api.datastore.Key; //导入依赖的package包/类
@Test
public void shouldReindexEntitiesAndWriteBackToDatastoreWhenReindexOperationProvided() {
    DatastoreKeyTestEntity testEntity = new DatastoreKeyTestEntity(1, "name");
    DatastoreKeyTestEntity testEntity2 = new DatastoreKeyTestEntity(2, "name");
    DatastoreKeyTestEntity testEntity3 = new DatastoreKeyTestEntity(3, "name");
    repository.putAsync(testEntity, testEntity2, testEntity3).complete();

    assertThat(repository.search().field("id", list(1, 2, 3)).run().getResults(), hasItems(testEntity, testEntity2, testEntity3));

    List<Key> keys = list(testEntity.getKey(), testEntity2.getKey(), testEntity3.getKey());
    int reindexed = repository.reindex(keys, 10, batch -> {
        for (DatastoreKeyTestEntity entity : batch) {
            entity.setName("different");
        }
        return batch;
    });
    assertThat(reindexed, is(3));

    assertThat(repository.search().field("name", Is.Is, "different").run().getResults(), hasItems(testEntity, testEntity2, testEntity3));
    assertThat(repository.getByField("name", "different"), hasItems(testEntity, testEntity2, testEntity3));
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:22,代码来源:DatastoreKeyRepositoryTest.java

示例4: toModel

import com.google.appengine.api.datastore.Key; //导入依赖的package包/类
@Override
public <T> T toModel(Class<T> entityClass, Entity entity) {
    try {
        T instance = entityClass.newInstance();

        Field idField = getIdField(entityClass);
        Key key = entity.getKey();
        Object id = (key.getName() != null ? key.getName() : key.getId());
        idField.set(instance, id);

        Map<String, Object> properties = entity.getProperties();
        for (Map.Entry<String, Object> entry : properties.entrySet()) {
            Field field = ReflectionUtils.findRequiredField(entityClass, entry.getKey());
            ReflectionUtils.setField(field, instance, entry.getValue());
        }

        return instance;
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:22,代码来源:GenericEntityToModelMapper.java

示例5: delete

import com.google.appengine.api.datastore.Key; //导入依赖的package包/类
public void delete(final StableUserId userId) throws PermanentFailure {
  Preconditions.checkNotNull(userId, "Null userId");
  log.info("Deleting record for user " + userId);
  final Key key = makeKey(userId);
  new RetryHelper().run(new RetryHelper.VoidBody() {
      @Override public void run() throws RetryableFailure, PermanentFailure {
        CheckedTransaction tx = datastore.beginTransaction();
        log.info("About to delete " + key);
        tx.delete(key);
        memcache.enqueuePutNull(tx, userId);
        tx.commit();
        log.info("Committed " + tx);
      }
    });
  memcache.delete(userId);
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:17,代码来源:AccountStore.java

示例6: getHTML

import com.google.appengine.api.datastore.Key; //导入依赖的package包/类
@GET
@Produces(MediaType.TEXT_XML)
public WishlistProduct getHTML() {
	DatastoreService datastore = DatastoreServiceFactory
			.getDatastoreService();
	try {
		Key entKey = KeyFactory.createKey(email, productID);
		Entity entity = datastore.get(entKey);
		String productName = (String) entity.getProperty("productName");
		double currentPrice = (double) entity.getProperty("currentPrice");
		double lowestPrice = (double) entity.getProperty("lowestPrice");
		Date lowestDate = (Date) entity.getProperty("lowestDate");
		return new WishlistProduct(productID, productName, currentPrice,
				lowestPrice, lowestDate);
	} catch (EntityNotFoundException e) {
		throw new RuntimeException("GET: Wishlist with " + productID
				+ " not found.");
	}
}
 
开发者ID:fasthall,项目名称:amazon-price-tracker,代码行数:20,代码来源:WishlistProductResource.java

示例7: get

import com.google.appengine.api.datastore.Key; //导入依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public WishlistProduct get() {
	DatastoreService datastore = DatastoreServiceFactory
			.getDatastoreService();
	try {
		Key entKey = KeyFactory.createKey(email, productID);
		Entity entity = datastore.get(entKey);
		String productName = (String) entity.getProperty("productName");
		double currentPrice = (double) entity.getProperty("currentPrice");
		double lowestPrice = (double) entity.getProperty("lowestPrice");
		Date lowestDate = (Date) entity.getProperty("lowestDate");
		return new WishlistProduct(productID, productName, currentPrice,
				lowestPrice, lowestDate);
	} catch (EntityNotFoundException e) {
		throw new RuntimeException("GET: Wishlist with " + productID
				+ " not found.");
	}
}
 
开发者ID:fasthall,项目名称:amazon-price-tracker,代码行数:20,代码来源:WishlistProductResource.java

示例8: getPossibleIdsForPipelineJobRecur

import com.google.appengine.api.datastore.Key; //导入依赖的package包/类
/**
 * Called by getPossibleIdsForPipelineJob(), and by itself recursively.
 *
 * @param datastore The datastore service, which can be either synchronous or asynchronous, since
 *     the only interaction with the database is via prepared queries
 * @param jobId The pipeline job ID
 * @param handledJobIds The set of job IDs which have been handled so far; this is a sanity check
 *     to prevent an infinite loop if, for some crazy reason, the job dependency graph is cyclic
 * @return the IDs of MR-ShardedJob entities that the Mapreduce library might have created,
 *     depending on which steps of the mapreduce were used
 */
private ImmutableSet<String> getPossibleIdsForPipelineJobRecur(
    BaseDatastoreService datastore, String jobId, Set<String> handledJobIds) {
  if (handledJobIds.contains(jobId)) {
    return ImmutableSet.of();
  }
  handledJobIds.add(jobId);

  JobRecord jobRecord;
  try {
    jobRecord = PipelineManager.getJob(jobId);
  } catch (NoSuchObjectException e) {
    return ImmutableSet.of();
  }

  ImmutableSet.Builder<String> idSetBuilder = new ImmutableSet.Builder<>();
  for (String jobPrefix : JOB_PREFIXES) {
    idSetBuilder.add("MR-ShardedJob", jobPrefix + jobId);
  }

  for (Key childKey : jobRecord.getChildKeys()) {
    idSetBuilder
        .addAll(getPossibleIdsForPipelineJobRecur(datastore, childKey.getName(), handledJobIds));
  }
  return idSetBuilder.build();
}
 
开发者ID:google,项目名称:nomulus,代码行数:37,代码来源:MapreduceEntityCleanupUtil.java

示例9: next

import com.google.appengine.api.datastore.Key; //导入依赖的package包/类
@Override
public List<Key> next() throws IOException {
  ImmutableList.Builder<Key> chunk = new ImmutableList.Builder<>();
  try {
    for (int i = 0; i < chunkSize; i++) {
      chunk.add(reader.next());
    }
  } catch (NoSuchElementException e) {
    // Amazingly this is the recommended (and only) way to test for hasNext().
  }
  ImmutableList<Key> builtChunk = chunk.build();
  if (builtChunk.isEmpty()) {
    throw new NoSuchElementException();  // Maintain the contract.
  }
  return builtChunk;
}
 
开发者ID:google,项目名称:nomulus,代码行数:17,代码来源:ChunkingKeyInput.java

示例10: getAllOwnedGroups

import com.google.appengine.api.datastore.Key; //导入依赖的package包/类
/**
   * Get ALL the UserGroups in the database that belong to a customer
   * and return them in a List structure
   * @param customerKey
   * @return all userGroups in the datastore that belong to the given 
   * 			customer
   * TODO: Make more efficient "touching" of the user groups
   */
  public static List<UserGroup> getAllOwnedGroups(Key customerKey) {
PersistenceManager pm = PMF.get().getPersistenceManager();

      try {
      	Customer customer = pm.getObjectById(Customer.class, customerKey);
      	
      	List<UserGroup> userGroups = customer.getOwnedUserGroups();
      	// Touch the user to keep in memory
      	for (UserGroup userGroup : userGroups) {
      		userGroup.getKey();
      	}

      	return userGroups;
      } 
      finally {
      	pm.close();
      }
  }
 
开发者ID:gfigueroa,项目名称:internet-radio-gae,代码行数:27,代码来源:UserGroupManager.java

示例11: getExpiredProgramsFromChannel

import com.google.appengine.api.datastore.Key; //导入依赖的package包/类
/**
    * Get expired program in the datastore from a specific channel
    * and returns them in a List structure
    * @param channelKey: 
    * 				the key of the channel whose program will be retrieved
    * @param ascendingOrder:
    * 				whether the list should be sorted
 * 				in ascending order or not
    * @return all programs that are "EXPIRED" belonging to the given channel
    */
public static List<Program> getExpiredProgramsFromChannel(Key channelKey,
		boolean ascendingOrder) {
	PersistenceManager pm = PMF.get().getPersistenceManager();
	
	Channel channel = pm.getObjectById(Channel.class, channelKey);
	
       List<Program> result = null;
       ArrayList<Program> finalResult = new ArrayList<Program>();
       try {
           result = channel.getPrograms();
           for (Program program : result) {
           	if (program.getCurrentStatus() == Program.Status.EXPIRED) {
           		finalResult.add(program);
           	}
           }
       }
       finally {
       	pm.close();
       }

       finalResult = (ArrayList<Program>) sortPrograms(finalResult, ascendingOrder);
       return finalResult;
   }
 
开发者ID:gfigueroa,项目名称:internet-radio-gae,代码行数:34,代码来源:ProgramManager.java

示例12: deleteSessionVariables

import com.google.appengine.api.datastore.Key; //导入依赖的package包/类
/**
 * Delete a value stored in the project's datastore.
 * @param sessionId Request from which the session is extracted.
 */
protected void deleteSessionVariables(String sessionId, String... varNames) {
  if (sessionId.equals("")) {
    return;
  }
  Key key = KeyFactory.createKey(SESSION_KIND, sessionId);
  Transaction transaction = datastore.beginTransaction();
  try {
    Entity stateEntity = datastore.get(transaction, key);
    for (String varName : varNames) {
      stateEntity.removeProperty(varName);
    }
    datastore.put(transaction, stateEntity);
    transaction.commit();
  } catch (EntityNotFoundException e) {
    // Ignore - if there's no session, there's nothing to delete.
  } finally {
    if (transaction.isActive()) {
      transaction.rollback();
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:26,代码来源:DatastoreSessionFilter.java

示例13: contextInitialized

import com.google.appengine.api.datastore.Key; //导入依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent event) {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Key key = KeyFactory.createKey(ENTITY_KIND, ENTITY_KEY);

    Entity entity;
    try {
      entity = datastore.get(key);
    } catch(EntityNotFoundException e) {
        entity = new Entity(key);
        // NOTE: it's not possible to change entities in the local server, so
        // it will be necessary to hardcode the API key below if you are running
        // it locally.
        entity.setProperty(ACCESS_KEY_FIELD,
          API_KEY);
        datastore.put(entity);
        mLogger.severe("Created fake key. Please go to App Engine admin "
                + "console, change its value to your API Key (the entity "
                + "type is '" + ENTITY_KIND + "' and its field to be changed is '"
                + ACCESS_KEY_FIELD + "'), then restart the server!");
    }
    String accessKey = (String) entity.getProperty(ACCESS_KEY_FIELD);
    event.getServletContext().setAttribute(ATTRIBUTE_ACCESS_KEY, accessKey);
}
 
开发者ID:xunboo,项目名称:JJCamera,代码行数:25,代码来源:ApiKeyInitializer.java

示例14: getStationChannels

import com.google.appengine.api.datastore.Key; //导入依赖的package包/类
/**
    * Get ALL the Channels in the datastore from a specific station
    * and returns them in a List structure
    * @param stationKey: 
    * 				the key of the station whose channels will be retrieved
    * @return all channels in the datastore belonging to the given station
    * TODO: Fix "touching" of channels
    */
public static List<Channel> getStationChannels(Key stationKey) {
	PersistenceManager pm = PMF.get().getPersistenceManager();
	
	Station station = pm.getObjectById(Station.class, stationKey);
	
       List<Channel> result = null;
       try {
           result = station.getChannels();
           // Touch each channel
           for (Channel channel : result) {
           	channel.getChannelName();
           }
       } 
       finally {
       	pm.close();
       }

       return result;
   }
 
开发者ID:gfigueroa,项目名称:internet-radio-gae,代码行数:28,代码来源:ChannelManager.java

示例15: deleteUserGroup

import com.google.appengine.api.datastore.Key; //导入依赖的package包/类
/**
 * Delete a User Group from a mobile device
 * @param req:
 * 			the HTTP request
 * @param customer:
 * 			the customer who is executing the action
 * @throws Exception
 * @throws IOException 
 * @throws UnauthorizedUserOperationException
 */
public void deleteUserGroup(HttpServletRequest req, 
		Customer customer) 
				throws Exception, IOException,
				UnauthorizedUserOperationException {
	
	String userGroupKeyString = req.getParameter("g_key");
	Key userGroupKey = KeyFactory.stringToKey(userGroupKeyString);
    
	// Check that the group belongs to the user
    if (!userGroupKey.getParent().equals(customer.getKey())) {
        throw new UnauthorizedUserOperationException(customer.getUser(), 
        		"This group does not belong to the given user.");
    }
	
	UserGroupManager.deleteUserGroup(userGroupKey);
}
 
开发者ID:gfigueroa,项目名称:internet-radio-gae,代码行数:27,代码来源:CloudSyncServlet.java


注:本文中的com.google.appengine.api.datastore.Key类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。