Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ownerName=“backend.company.com”,packagePath=“”)) 公共类AppVersionEndpoint{ @ApiMethod(name=“listAppVersion”) 公共集合响应listAppVersion(){ 列表执行; execute=ofy().load().type(AppVersion.class).list(); 返回CollectionResponse.builder().setItems(execute.build(); } /** *此方法获取具有主键id的实体。它使用HTTP GET方法。 * *@param id是java bean的主键。 *@返回主键id为的实体(如果为DNE,则为null)。 */ @ApiMethod(name=“getAppVersion”) 公共AppVersion getAppVersion(@Named(“id”)字符串id){ 返回y().load().type(AppVersion.class).id(id).now(); } /** *这将在App Engine数据存储中插入一个新实体。如果该实体已存在 *如果数据存储中存在,将引发异常。 *它使用HTTPPOST方法。 * *@param appversion要插入的实体。 *@返回插入的实体。 */ @ApiMethod(name=“insertAppVersion”) 公共AppVersion insertAppVersion(AppVersion AppVersion){ AppVersion exist=getAppVersion(AppVersion.getApplicationName()); 应用版本结果; if(exist==null){ ofy().save().entity(appversion.now(); 结果=getAppVersion(appversion.getApplicationName()); }否则{ 抛出新的IllegalArgumentException(appversion.getApplicationName()+“已存在”); } 返回结果; } }_Android_Google App Engine_Google Cloud Datastore - Fatal编程技术网

Android ownerName=“backend.company.com”,packagePath=“”)) 公共类AppVersionEndpoint{ @ApiMethod(name=“listAppVersion”) 公共集合响应listAppVersion(){ 列表执行; execute=ofy().load().type(AppVersion.class).list(); 返回CollectionResponse.builder().setItems(execute.build(); } /** *此方法获取具有主键id的实体。它使用HTTP GET方法。 * *@param id是java bean的主键。 *@返回主键id为的实体(如果为DNE,则为null)。 */ @ApiMethod(name=“getAppVersion”) 公共AppVersion getAppVersion(@Named(“id”)字符串id){ 返回y().load().type(AppVersion.class).id(id).now(); } /** *这将在App Engine数据存储中插入一个新实体。如果该实体已存在 *如果数据存储中存在,将引发异常。 *它使用HTTPPOST方法。 * *@param appversion要插入的实体。 *@返回插入的实体。 */ @ApiMethod(name=“insertAppVersion”) 公共AppVersion insertAppVersion(AppVersion AppVersion){ AppVersion exist=getAppVersion(AppVersion.getApplicationName()); 应用版本结果; if(exist==null){ ofy().save().entity(appversion.now(); 结果=getAppVersion(appversion.getApplicationName()); }否则{ 抛出新的IllegalArgumentException(appversion.getApplicationName()+“已存在”); } 返回结果; } }

Android ownerName=“backend.company.com”,packagePath=“”)) 公共类AppVersionEndpoint{ @ApiMethod(name=“listAppVersion”) 公共集合响应listAppVersion(){ 列表执行; execute=ofy().load().type(AppVersion.class).list(); 返回CollectionResponse.builder().setItems(execute.build(); } /** *此方法获取具有主键id的实体。它使用HTTP GET方法。 * *@param id是java bean的主键。 *@返回主键id为的实体(如果为DNE,则为null)。 */ @ApiMethod(name=“getAppVersion”) 公共AppVersion getAppVersion(@Named(“id”)字符串id){ 返回y().load().type(AppVersion.class).id(id).now(); } /** *这将在App Engine数据存储中插入一个新实体。如果该实体已存在 *如果数据存储中存在,将引发异常。 *它使用HTTPPOST方法。 * *@param appversion要插入的实体。 *@返回插入的实体。 */ @ApiMethod(name=“insertAppVersion”) 公共AppVersion insertAppVersion(AppVersion AppVersion){ AppVersion exist=getAppVersion(AppVersion.getApplicationName()); 应用版本结果; if(exist==null){ ofy().save().entity(appversion.now(); 结果=getAppVersion(appversion.getApplicationName()); }否则{ 抛出新的IllegalArgumentException(appversion.getApplicationName()+“已存在”); } 返回结果; } },android,google-app-engine,google-cloud-datastore,Android,Google App Engine,Google Cloud Datastore,我更希望它像最初一样可以过滤,但我不知道为什么它会有所不同。有人能告诉我吗?这里有两件事:首先,默认情况下,Objectify假设您不想为类的属性编制索引(这使您的数据存储索引保持精简和平均)。其次,我相信新的数据存储控制台的filter UI只显示具有与其相关联的索引的属性(因为您不能对未索引的属性进行筛选) 因此,如果您希望能够按minVersionRequired进行查询或排序,只需在POJO中的该字段中添加一个@Index注释,Objectify将在底层数据存储API的底层实体类中使用s

我更希望它像最初一样可以过滤,但我不知道为什么它会有所不同。有人能告诉我吗?

这里有两件事:首先,默认情况下,Objectify假设您不想为类的属性编制索引(这使您的数据存储索引保持精简和平均)。其次,我相信新的数据存储控制台的filter UI只显示具有与其相关联的索引的属性(因为您不能对未索引的属性进行筛选)

因此,如果您希望能够按minVersionRequired进行查询或排序,只需在POJO中的该字段中添加一个
@Index
注释,Objectify将在底层数据存储API的底层实体类中使用
setIndexedProperty()
方法


如果您想在默认情况下索引类中的所有属性,可以在类上放置
@index
注释,然后
@Unindex
任何您特别不想索引的属性。

似乎不起作用。也许需要一些时间?我不需要重新添加所有的实体,对吗?嘿,你知道什么…我回来检查了几个小时后,更改生效了。谢谢
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class AppVersion {

@Id
private String applicationName;
private int minVersionRequired;

public String getApplicationName() {
    return applicationName;
}
public int getMinVersionRequired() {
    return minVersionRequired;
}
public void setApplicationName(String applicationName) {
    this.applicationName = applicationName;
}
public void setminVersionRequired(int minVersionRequired) {
    this.minVersionRequired = minVersionRequired;
}
}
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;

@Entity
public class AppVersion {

@Id
private String applicationName;
private int minVersionRequired;

public String getApplicationName() {
    return applicationName;
}
public int getMinVersionRequired() {
    return minVersionRequired;
}
public void setApplicationName(String applicationName) {
    this.applicationName = applicationName;
}
public void setminVersionRequired(int minVersionRequired) {
    this.minVersionRequired = minVersionRequired;
}
}
import com.companionfree.zooperthemeviewer.EMF;

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiNamespace;
import com.google.api.server.spi.response.CollectionResponse;
import com.google.appengine.api.datastore.Cursor;
import com.google.appengine.datanucleus.query.JPACursorHelper;

import java.util.List;

import javax.annotation.Nullable;
import javax.inject.Named;
import javax.persistence.EntityExistsException;
import javax.persistence.EntityNotFoundException;
import javax.persistence.EntityManager;
import javax.persistence.Query;

@Api(name = "appversionendpoint", namespace = @ApiNamespace(ownerDomain = "company.com", ownerName = "company.com", packagePath = "app"))
public class AppVersionEndpoint {

/**
 * This method lists all the entities inserted in datastore.
 * It uses HTTP GET method and paging support.
 *
 * @return A CollectionResponse class containing the list of all entities
 * persisted and a cursor to the next page.
 */
@SuppressWarnings({ "unchecked", "unused" })
@ApiMethod(name = "listAppVersion")
public CollectionResponse<AppVersion> listAppVersion(
        @Nullable @Named("cursor") String cursorString,
        @Nullable @Named("limit") Integer limit) {

    EntityManager mgr = null;
    Cursor cursor = null;
    List<AppVersion> execute = null;

    try {
        mgr = getEntityManager();
        Query query = mgr
                .createQuery("select from AppVersion as AppVersion");
        if (cursorString != null && cursorString != "") {
            cursor = Cursor.fromWebSafeString(cursorString);
            query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
        }

        if (limit != null) {
            query.setFirstResult(0);
            query.setMaxResults(limit);
        }

        execute = (List<AppVersion>) query.getResultList();
        cursor = JPACursorHelper.getCursor(execute);
        if (cursor != null)
            cursorString = cursor.toWebSafeString();

        // Tight loop for fetching all entities from datastore and accomodate
        // for lazy fetch.
        for (AppVersion obj : execute)
            ;
    } finally {
        mgr.close();
    }

    return CollectionResponse.<AppVersion> builder().setItems(execute)
            .setNextPageToken(cursorString).build();
}

/**
 * This method gets the entity having primary key id. It uses HTTP GET method.
 *
 * @param id the primary key of the java bean.
 * @return The entity with primary key id.
 */
@ApiMethod(name = "getAppVersion")
public AppVersion getAppVersion(@Named("id") String id) {
    EntityManager mgr = getEntityManager();
    AppVersion appversion = null;
    try {
        appversion = mgr.find(AppVersion.class, id);
    } finally {
        mgr.close();
    }
    return appversion;
}

/**
 * This inserts a new entity into App Engine datastore. If the entity already
 * exists in the datastore, an exception is thrown.
 * It uses HTTP POST method.
 *
 * @param appversion the entity to be inserted.
 * @return The inserted entity.
 */
@ApiMethod(name = "insertAppVersion")
public AppVersion insertAppVersion(AppVersion appversion) {
    EntityManager mgr = getEntityManager();
    try {
        if (containsAppVersion(appversion)) {
            throw new EntityExistsException("Object already exists");
        }
        mgr.persist(appversion);
    } finally {
        mgr.close();
    }
    return appversion;
}

/**
 * This method is used for updating an existing entity. If the entity does not
 * exist in the datastore, an exception is thrown.
 * It uses HTTP PUT method.
 *
 * @param appversion the entity to be updated.
 * @return The updated entity.
 */
@ApiMethod(name = "updateAppVersion")
public AppVersion updateAppVersion(AppVersion appversion) {
    EntityManager mgr = getEntityManager();
    try {
        if (!containsAppVersion(appversion)) {
            throw new EntityNotFoundException("Object does not exist");
        }
        mgr.persist(appversion);
    } finally {
        mgr.close();
    }
    return appversion;
}

/**
 * This method removes the entity with primary key id.
 * It uses HTTP DELETE method.
 *
 * @param id the primary key of the entity to be deleted.
 */
@ApiMethod(name = "removeAppVersion")
public void removeAppVersion(@Named("id") String id) {
    EntityManager mgr = getEntityManager();
    try {
        AppVersion appversion = mgr.find(AppVersion.class, id);
        mgr.remove(appversion);
    } finally {
        mgr.close();
    }
}

private boolean containsAppVersion(AppVersion appversion) {
    EntityManager mgr = getEntityManager();
    boolean contains = true;
    try {
        AppVersion item = mgr.find(AppVersion.class,
                appversion.getApplicationName());
        if (item == null) {
            contains = false;
        }
    } finally {
        mgr.close();
    }
    return contains;
}

private static EntityManager getEntityManager() {
    return EMF.get().createEntityManager();
}

}
import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiNamespace;
import com.google.api.server.spi.response.CollectionResponse;
import java.util.List;

import javax.inject.Named;

import static com.company.backend.OfyService.ofy;

@Api(name = "appversionendpoint", version = "v1", namespace =
@ApiNamespace(ownerDomain = "backend.company.com",
    ownerName = "backend.company.com", packagePath = ""))
public class AppVersionEndpoint {

@ApiMethod(name = "listAppVersion")
public CollectionResponse<AppVersion> listAppVersion() {
    List<AppVersion> execute;
   execute =  ofy().load().type(AppVersion.class).list();
return CollectionResponse.<AppVersion> builder().setItems(execute).build();

}


/**
 * This method gets the entity having primary key id. It uses HTTP GET method.
 *
 * @param id the primary key of the java bean.
 * @return The entity with primary key id (null if DNE).
 */
@ApiMethod(name = "getAppVersion")
public AppVersion getAppVersion(@Named("id") String id) {
    return ofy().load().type(AppVersion.class).id(id).now();

}

/**
 * This inserts a new entity into App Engine datastore. If the entity already
 * exists in the datastore, an exception is thrown.
 * It uses HTTP POST method.
 *
 * @param appversion the entity to be inserted.
 * @return The inserted entity.
 */
@ApiMethod(name = "insertAppVersion")
public AppVersion insertAppVersion(AppVersion appversion) {
    AppVersion exist = getAppVersion(appversion.getApplicationName());
    AppVersion result;
    if (exist == null) {
        ofy().save().entity(appversion).now();
        result = getAppVersion(appversion.getApplicationName());
    } else {
        throw new IllegalArgumentException(appversion.getApplicationName() + " exists already");
    }
    return result;
}
}