来自数据存储区谷歌应用引擎的端点查询

时间:2022-08-22 10:10:34

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

我编写了这段代码,它将从应用引擎数据存储区中的实体“ContactInfo”中提取所有内容并将其放入字符串中。

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.

我的问题是如何在android端点中进行特定查询。我只想在实体中显示某个名称或邮政编码的项目。这是我必须将整个实体放入一个字符串。

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());

}





}

1 个解决方案

#1


1  

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

要在通过云端点从Android发送查询请求时应用过滤器,您需要添加选项来设置参数。我将用一个简短的例子来解释

1, Assume your contactinfo endpoint has 2 properties

1,假设您的contactinfo端点有2个属性

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.

2,现在如果您需要查询特定的联系人类型,那么您的应用引擎代码应该有一个基于属性contacttype进行过滤的查询方法。您的端点应该通过传递用户的输入参数来调用此查询方法。

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

3,现在从android发送所需的参数,你的类Listcontactinfo你要定义REST路径和方法类型,应该包含一个选项来设置contacttype参数

@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:

4,最后在从你的android代码调用端点方法时,你应该使用setContacttype传递一个值,它将类似于:

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"

这是一个示例情况,您要查询具有值“personal”的contacttype的实体

#1


1  

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

要在通过云端点从Android发送查询请求时应用过滤器,您需要添加选项来设置参数。我将用一个简短的例子来解释

1, Assume your contactinfo endpoint has 2 properties

1,假设您的contactinfo端点有2个属性

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.

2,现在如果您需要查询特定的联系人类型,那么您的应用引擎代码应该有一个基于属性contacttype进行过滤的查询方法。您的端点应该通过传递用户的输入参数来调用此查询方法。

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

3,现在从android发送所需的参数,你的类Listcontactinfo你要定义REST路径和方法类型,应该包含一个选项来设置contacttype参数

@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:

4,最后在从你的android代码调用端点方法时,你应该使用setContacttype传递一个值,它将类似于:

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"

这是一个示例情况,您要查询具有值“personal”的contacttype的实体