Java Code Examples for com.google.appengine.api.datastore.Text#getValue()

The following examples show how to use com.google.appengine.api.datastore.Text#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringDataTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testTextType() {
    String propertyName = "textProp";
    List<Entity> elist = doQuery(kindName, propertyName, null, false);
    Text text = (Text) elist.get(0).getProperty(propertyName);
    Text sameDat = (Text) elist.get(0).getProperty(propertyName);
    Text diffDat = (Text) elist.get(1).getProperty(propertyName);
    assertTrue(text.equals(sameDat));
    assertFalse(text.equals(diffDat));
    String getText = text.getValue();
    assertTrue(getText.equals("english") || getText.equals("chinese")
        || getText.equals("japanese"));
    assertEquals(text.hashCode(), text.hashCode());
}
 
Example 2
Source File: RemoveWhitespaceTextAdapter.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@Override
public String marshal(Text t) {
  return (t == null) ? null : t.getValue();
}
 
Example 3
Source File: MyIndex.java    From google-geoEngine with Apache License 2.0 4 votes vote down vote up
public static int buildIndex(String group) throws IOException{
    //Get all fences of group from DataStore.
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Key fenceKey = KeyFactory.createKey("Geofence", group);

    Query query = new Query("Fence", fenceKey).addSort("id", Query.SortDirection.DESCENDING);
    List<Entity> fencesFromStore = datastore.prepare(query).asList(FetchOptions.Builder.withDefaults());

    if (!fencesFromStore.isEmpty()) {
    	//Create STRTree-Index.
        STRtree index = new STRtree();
        //Loop through the fences from DataStore.
        for (Entity fenceFromStore : fencesFromStore) {
            long id = (long) fenceFromStore.getProperty("id");
            Gson gson = new Gson();
            Text vText = (Text) fenceFromStore.getProperty("vertices");
            String vString = vText.getValue();
            double[][] vertices = gson.fromJson(vString, double[][].class);

            //Store coordinates in an array.
            Coordinate[] coordinates = new Coordinate[vertices.length];
            int i = 0;
            for(double[] point : vertices){
                Coordinate coordinate = new Coordinate(point[0],point[1]);
                coordinates[i++] = coordinate;
            }
            //Create polygon from the coordinates.
            GeometryFactory fact = new GeometryFactory();
            LinearRing linear = new GeometryFactory().createLinearRing(coordinates);
            MyPolygon polygon = new MyPolygon(linear, null, fact, id);
            //Add polygon to index.
            index.insert(polygon.getEnvelopeInternal(), polygon);
        }
        //Build the index.
        index.build();
        //Write the index to Memcache.
        MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
        //Last param is expiration date. Set to null to keep it in Memcache forever.
        syncCache.put(group, index, null); 
    }
    return fencesFromStore.size();
}
 
Example 4
Source File: JobRecord.java    From appengine-pipelines with Apache License 2.0 4 votes vote down vote up
/**
 * Re-constitutes an instance of this class from a Data Store entity.
 *
 * @param entity
 */
public JobRecord(Entity entity) {
  super(entity);
  jobInstanceKey = (Key) entity.getProperty(JOB_INSTANCE_PROPERTY);
  finalizeBarrierKey = (Key) entity.getProperty(FINALIZE_BARRIER_PROPERTY);
  runBarrierKey = (Key) entity.getProperty(RUN_BARRIER_PROPERTY);
  outputSlotKey = (Key) entity.getProperty(OUTPUT_SLOT_PROPERTY);
  state = State.valueOf((String) entity.getProperty(STATE_PROPERTY));
  exceptionHandlingAncestorKey =
      (Key) entity.getProperty(EXCEPTION_HANDLING_ANCESTOR_KEY_PROPERTY);
  Object exceptionHandlerSpecifiedProperty =
      entity.getProperty(EXCEPTION_HANDLER_SPECIFIED_PROPERTY);
  if (null != exceptionHandlerSpecifiedProperty) {
    exceptionHandlerSpecified = (Boolean) exceptionHandlerSpecifiedProperty;
  }
  exceptionHandlerJobKey = (Key) entity.getProperty(EXCEPTION_HANDLER_JOB_KEY_PROPERTY);
  Text exceptionHandlerGraphGuidText =
      (Text) entity.getProperty(EXCEPTION_HANDLER_JOB_GRAPH_GUID_PROPERTY);
  if (null != exceptionHandlerGraphGuidText) {
    exceptionHandlerJobGraphGuid = exceptionHandlerGraphGuidText.getValue();
  }
  Object callExceptionHandlerProperty = entity.getProperty(CALL_EXCEPTION_HANDLER_PROPERTY);
  if (null != callExceptionHandlerProperty) {
    callExceptionHandler = (Boolean) callExceptionHandlerProperty;
  }
  Object ignoreExceptionProperty = entity.getProperty(IGNORE_EXCEPTION_PROPERTY);
  if (null != ignoreExceptionProperty) {
    ignoreException = (Boolean) ignoreExceptionProperty;
  }
  Text childGraphGuidText = (Text) entity.getProperty(CHILD_GRAPH_GUID_PROPERTY);
  if (null != childGraphGuidText) {
    childGraphGuid = childGraphGuidText.getValue();
  }
  exceptionKey = (Key) entity.getProperty(EXCEPTION_KEY_PROPERTY);
  startTime = (Date) entity.getProperty(START_TIME_PROPERTY);
  endTime = (Date) entity.getProperty(END_TIME_PROPERTY);
  childKeys = (List<Key>) entity.getProperty(CHILD_KEYS_PROPERTY);
  if (null == childKeys) {
    childKeys = new LinkedList<>();
  }
  attemptNumber = (Long) entity.getProperty(ATTEMPT_NUM_PROPERTY);
  maxAttempts = (Long) entity.getProperty(MAX_ATTEMPTS_PROPERTY);
  backoffSeconds = (Long) entity.getProperty(BACKOFF_SECONDS_PROPERTY);
  backoffFactor = (Long) entity.getProperty(BACKOFF_FACTOR_PROPERTY);
  queueSettings.setOnBackend((String) entity.getProperty(ON_BACKEND_PROPERTY));
  queueSettings.setOnModule((String) entity.getProperty(ON_MODULE_PROPERTY));
  queueSettings.setModuleVersion((String) entity.getProperty(MODULE_VERSION_PROPERTY));
  queueSettings.setOnQueue((String) entity.getProperty(ON_QUEUE_PROPERTY));
  statusConsoleUrl = (String) entity.getProperty(STATUS_CONSOLE_URL);
  rootJobDisplayName = (String) entity.getProperty(ROOT_JOB_DISPLAY_NAME);
}
 
Example 5
Source File: StringUtility.java    From io2014-codelabs with Apache License 2.0 2 votes vote down vote up
/**
 * Determine if an input text is null or empty.
 *
 * @param text Input text that might contain null, empty text or non-empty text
 * @return True if the input text is null or empty; false, the otherwise
 */
public static boolean isNullOrEmpty(Text text) {
  return (text == null || text.getValue() == null || text.getValue().isEmpty());
}
 
Example 6
Source File: StringUtility.java    From solutions-mobile-backend-starter-java with Apache License 2.0 2 votes vote down vote up
/**
 * Determine if an input text is null or empty.
 *
 * @param text Input text that might contain null, empty text or non-empty text
 * @return True if the input text is null or empty; false, the otherwise
 */
public static boolean isNullOrEmpty(Text text) {
  return (text == null || text.getValue() == null || text.getValue().isEmpty());
}