从数据存储谷歌应用程序引擎的端点查询 [英] endpoint query from datastore google app engine

查看:247
本文介绍了从数据存储谷歌应用程序引擎的端点查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写这篇code,它会从App Engine数据存储拉一切从我的实体CONTACTINFO,并把它转化为字符串。

我的问题是如何让我在Android终端的特定查询。我只是想显示的实体是一个特定的名称或ZIP code例如项目。以下是我必须把整个实体为一个字符串。

 包com.indeeditis;

进口java.io.IOException异常;



进口java.util.Date;

进口org.json.JSONException;

进口android.os.AsyncTask;
进口android.content.Context;
进口android.content.Intent;

进口com.indeeditis.MainActivity.EndpointsTask;
进口com.indeeditis.contactinfoendpoint.Contactinfoendpoint;
进口com.indeeditis.contactinfoendpoint.model.CollectionResponseContactInfo;
进口com.indeeditis.contactinfoendpoint.model.ContactInfo;

进口com.google.api.client.extensions.android.http.AndroidHttp;
进口com.google.api.client.http.Htt prequest;
进口com.google.api.client.http.Htt prequestInitializer;
进口com.google.api.client.json.jackson.JacksonFactory;


进口android.os.Bundle;
进口android.util.Log;
进口android.view.View;
进口android.widget.ArrayAdapter;
进口android.widget.Button;
进口android.widget.EditText;
进口android.widget.Spinner;
进口android.app.Activity;
进口android.view.View.OnClickListener;


公共类FinderActivity扩展活动实现OnClickListener {





@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.finder);

    按钮启动=(按钮)findViewById(R.id.button9000);
    start.setOnClickListener(本);


}



公共类EndpointsTask扩展的AsyncTask<背景下,为Integer,Long> {




    保护龙doInBackground(上下文...上下文){

      Contactinfoendpoint.Builder endpointBuilder =新Contactinfoendpoint.Builder(
          AndroidHttp.newCompatibleTransport(),
          新JacksonFactory(),
          新的Htt prequestInitializer(){
          公共无效初始化(Htt的prequest HTT prequest){}
          });
  Contactinfoendpoint终点= CloudEndpointUtils.updateBuilder(
  endpointBuilder).build();





  尝试 {

     。字符串苹果= endpoint.listContactInfo()执行()的toString()。



        Log.w(对myApp,苹果);



  }赶上(IOException异常E){
    e.printStackTrace();
  }
      返回(长)0;
    }




    }



@覆盖
公共无效的onClick(视图v){
    // TODO自动生成方法存根

    新EndpointsTask()执行(getApplicationContext());

}





}
 

解决方案

有关应用滤镜,同时发送查询请求从机器人通过云终端,需要添加的选项设置参数。我会用一个简单的例子说明

1,假设你的CONTACTINFO端点有2个属性。

 名称= ndb.StringProperty()
contacttype = ndb.StringProperty()//假设这可以有值,个人或企业
 

2,现在,如果你需要查询某个特定contacttype,那么你的应用程序引擎code应该具有滤波器基于属性contacttype的查询方法。 你的终点应该由用户通过输入参数调用此查询方法。

3,我们发送的机器人​​所需要的参数,类 Listcontactinfo 要在其中定义了REST路径和方法的类型,应该包括一个选项设置contacttype参数

  @ com.google.api.client.util.Key
私人字符串contacttype;


公共字符串getContacttype(){
    返回contacttype;
  }

  公共Listcontactinfo setContacttype(字符串contacttype){
    this.contacttype = contacttype;
    回到这一点;
  }
 

4,最后同时呼吁从Android code端点法,你应该通过一个值使用setContacttype,这将是这样的:

 字符串苹果= endpoint.listContactInfo()setContacttype(个人)执行()的toString()。
 

这是您要查询其contacttype与价值实体的例子情况下个人

I wrote this code that will pull everything from my entity "ContactInfo" from the app engine datastore and place it into a string.

My question is how do I make specific queries in the android endpoint. I only want to display the items in the entity that are a certain name or zipcode for example. Here is what I have to put the entire entity into a string.

package com.indeeditis;

import java.io.IOException;



import java.util.Date;

import org.json.JSONException;

import android.os.AsyncTask;
import android.content.Context;
import android.content.Intent;

import com.indeeditis.MainActivity.EndpointsTask;
import com.indeeditis.contactinfoendpoint.Contactinfoendpoint;
import com.indeeditis.contactinfoendpoint.model.CollectionResponseContactInfo;
import com.indeeditis.contactinfoendpoint.model.ContactInfo;

import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.json.jackson.JacksonFactory;


import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.app.Activity;
import android.view.View.OnClickListener;


public class FinderActivity extends Activity  implements OnClickListener {





@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.finder);

    Button start = (Button)findViewById(R.id.button9000);
    start.setOnClickListener(this);


}



public class EndpointsTask extends AsyncTask<Context, Integer, Long> {




    protected Long doInBackground(Context... contexts) {

      Contactinfoendpoint.Builder endpointBuilder = new Contactinfoendpoint.Builder(
          AndroidHttp.newCompatibleTransport(),
          new JacksonFactory(),
          new HttpRequestInitializer() {
          public void initialize(HttpRequest httpRequest) { }
          });
  Contactinfoendpoint endpoint = CloudEndpointUtils.updateBuilder(
  endpointBuilder).build();





  try {

     String apples = endpoint.listContactInfo().execute().toString();



        Log.w("myApp", apples);



  } catch (IOException e) {
    e.printStackTrace();
  }
      return (long) 0;
    }




    }



@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

    new EndpointsTask().execute(getApplicationContext());

}





}

解决方案

For applying filters while sending a query request from android through cloud endpoints, you need to add options to set parameters. I will explain with a short example

1, Assume your contactinfo endpoint has 2 properties

name = ndb.StringProperty()
contacttype = ndb.StringProperty() // assume this can have values personal or business

2, Now if you need to query for a particular contacttype, then your app engine code should have a query method that filters based on the property contacttype. Your endpoint should call this query method by passing on the input parameter from the user.

3, Now to send the required parameter from android , your class Listcontactinfo where you would define the REST Path and method type, should include an option to the set the contacttype parameter

@com.google.api.client.util.Key
private String contacttype;


public String getContacttype() {
    return contacttype;
  }

  public Listcontactinfo setContacttype(String contacttype) {
    this.contacttype = contacttype;
    return this;
  }

4, Finally while calling the endpoint method from your android code, you should pass a value using the setContacttype, which will be something like:

String apples = endpoint.listContactInfo().setContacttype("personal").execute().toString();

This is for an example case where you want to query entities having contacttype with value "personal"

这篇关于从数据存储谷歌应用程序引擎的端点查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆