}Tit@N{
unread,Feb 11, 2011, 11:06:50 AM2/11/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google App Engine for Java on Russian
Шалом, скиньте пожалуйста рабочий пример обновления поля в бд. вот что
то крутил мутил, не получается. с Явой только начинаю дружить и в
восторге=) но весь побитый хожу от нескольких дней совместной жизни с
ней)) еще только сдружившемся.
Код весь в режиме самообучения)), поэтому не обращайте внимания на
return "true >>>|"+authDev.toString();
package emetemunoy.dbp;
//~--- JDK imports
------------------------------------------------------------
import java.util.Date;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
/**
* @author root
*/
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class AuthDev {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private String nearID;
@Persistent
private String connectTo;
@Persistent
private String description;
@Persistent
@Extension(vendorName="datanucleus", key="gae.pk-title",
value="true")
private String title;
@Persistent
private Date lastdate;
public AuthDev(String nearID, String connectTo, String title,
String description, Date lastdate) {
this.nearID = nearID;
this.connectTo = connectTo;
this.title = title;
this.description = description;
this.lastdate = lastdate;
}
public Long getId() {
return id;
}
public String getNearID() {
return nearID;
}
public String getConnectTo() {
return connectTo;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public Date getLastdate() {
return lastdate;
}
public void setNearID(String nearID) {
this.nearID = nearID;
}
public void setConnectTo(String connectTo) {
this.connectTo = connectTo;
}
public void setTitle(String title) {
this.title = title;
}
public void setDescription(String description) {
this.description = description;
}
public void setLastDate(Date lastdate) {
this.lastdate = lastdate;
}
}
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import emetemunoy.dbp.AuthDev;
import emetemunoy.dbp.PMF;
import java.util.List;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
/**
*
* @author root
*/
public class DevAuthService {
public String Authentication(String title, String nearID) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(AuthDev.class);//pm.newQuery("select
from " + AuthDev.class.getName() + " where title==\""+title+"\"");
query.setFilter("title == ptitle");
query.declareParameters("String ptitle");
List<AuthDev> authDev = (List<AuthDev>) query.execute(title);
if (authDev.isEmpty()) {
query.closeAll();
return "isEmpty";
} else {
//query = "select from " + AuthDev.class.getName() + "
where title==\""+title+"\"";
//AuthDev Dev = pm.newQuery(query).execute();
Key k =
KeyFactory.createKey(AuthDev.class.getSimpleName(), nearID);
AuthDev Dev = pm.getObjectById(AuthDev.class, k);
Dev.setNearID(nearID);
query.closeAll();
return "true >>>|"+authDev.toString();
}
}
}