在谷歌应用引擎数据存储(Java)中更新查询

如何在使用gwt时在Google App引擎中使用更新查询.我正在尝试创建一个聊天应用程序,除了提交和删除以前的消息之外,管理员可以编辑现有消息的部分.

要编辑现有消息,需要更新查询,我在数据存储中找不到更新查询等内容.

我们如何更新现有数据?

以下是http://www.ibm.com/developerworks/java/library/j-gaej3.html的一些示例代码
你可以修改你的数据,然后make make persistent然后提交.

请参阅附加代码中的updateContact()方法.

主要的警告是跨实体执行此操作 – 注意:DataStore中的数据存储与关系数据库不同.

package gaej.example.contact.server;

import gaej.example.contact.client.Contact;

import java.util.List;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;

public class ContactJdoDAO implements ContactDAO {
    private static final PersistenceManagerFactory pmfInstance = JDOHelper
            .getPersistenceManagerFactory("transactions-optional");

    public static PersistenceManagerFactory getPersistenceManagerFactory() {
        return pmfInstance;
    }

    public void addContact(Contact contact) {
        PersistenceManager pm = getPersistenceManagerFactory()
                .getPersistenceManager();
        try {
            pm.makePersistent(contact);
        } finally {
            pm.close();
        }
    }

    @SuppressWarnings("unchecked")
    public List<Contact> listContacts() {
        PersistenceManager pm = getPersistenceManagerFactory()
                .getPersistenceManager();
        String query = "select from " + Contact.class.getName();
        return (List<Contact>) pm.newQuery(query).execute();
    }

    public void removeContact(Contact contact) {
        PersistenceManager pm = getPersistenceManagerFactory()
                .getPersistenceManager();
        try {
            pm.currentTransaction().begin();

            // We don't have a reference to the selected Product.
            // So we have to look it up first,
            contact = pm.getObjectById(Contact.class, contact.getId());
            pm.deletePersistent(contact);

            pm.currentTransaction().commit();
        } catch (Exception ex) {
            pm.currentTransaction().rollback();
            throw new RuntimeException(ex);
        } finally {
            pm.close();
        }
    }

    public void updateContact(Contact contact) {
        PersistenceManager pm = getPersistenceManagerFactory()
                .getPersistenceManager();
        String name = contact.getName();
        String phone = contact.getPhone();
        String email = contact.getEmail();

        try {
            pm.currentTransaction().begin();
            // We don't have a reference to the selected Product.
            // So we have to look it up first,
            contact = pm.getObjectById(Contact.class, contact.getId());
            contact.setName(name);
            contact.setPhone(phone);
            contact.setEmail(email);
            pm.makePersistent(contact);
            pm.currentTransaction().commit();
        } catch (Exception ex) {
            pm.currentTransaction().rollback();
            throw new RuntimeException(ex);
        } finally {
            pm.close();
        }
    }

}
https://stackoverflow.com/questions/2679759/update-query-in-google-app-engine-data-store-java

转载注明原文:在谷歌应用引擎数据存储(Java)中更新查询