本文整理汇总了Java中com.googlecode.objectify.ObjectifyService.begin方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectifyService.begin方法的具体用法?Java ObjectifyService.begin怎么用?Java ObjectifyService.begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.objectify.ObjectifyService
的用法示例。
在下文中一共展示了ObjectifyService.begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMostDownloadedApps
import com.googlecode.objectify.ObjectifyService; //导入方法依赖的package包/类
/**
* Returns a wrapped class which contains a list of most downloaded
* gallery apps and total number of results in database
* @param start starting index of apps you want
* @param count number of apps you want
* @return list of {@link GalleryApp}
*/
@Override
public GalleryAppListResult getMostDownloadedApps(int start, final int count) {
final List<GalleryApp> apps = new ArrayList<GalleryApp>();
// If I try to run this in runjobwithretries, it tells me can't run
// non-ancestor query as a transaction. ObjectifyStorageio has some samples
// of not using transactions (run with) so I grabbed.
Objectify datastore = ObjectifyService.begin();
for (GalleryAppData appData:datastore.query(GalleryAppData.class).order("-numDownloads").filter("active", true).offset(start).limit(count)) {
GalleryApp gApp = new GalleryApp();
makeGalleryApp(appData, gApp);
apps.add(gApp);
}
int totalCount = datastore.query(GalleryAppData.class).order("-numDownloads").filter("active", true).count();
return new GalleryAppListResult(apps, totalCount);
}
示例2: getDeveloperApps
import com.googlecode.objectify.ObjectifyService; //导入方法依赖的package包/类
/**
* Returns a wrapped class which contains a list of galleryApps
* by a particular developer and total number of results in database
* @param userId id of developer
* @param start starting index of apps you want
* @param count number of apps you want
* @return list of {@link GalleryApp}
*/ @Override
public GalleryAppListResult getDeveloperApps(String userId, int start, final int count) {
final List<GalleryApp> apps = new ArrayList<GalleryApp>();
// if i try to run this in runjobwithretries it tells me can't run
// non-ancestor query as a transaction. ObjectifyStorageio has some samples
// of not using transactions (run with) so i grabbed
Objectify datastore = ObjectifyService.begin();
for (GalleryAppData appData:datastore.query(GalleryAppData.class).filter("userId",userId).filter("active", true).offset(start).limit(count)) {
GalleryApp gApp = new GalleryApp();
makeGalleryApp(appData, gApp);
apps.add(gApp);
}
int totalCount = datastore.query(GalleryAppData.class).filter("userId",userId).filter("active", true).count();
return new GalleryAppListResult(apps, totalCount);
}
示例3: getCommentReports
import com.googlecode.objectify.ObjectifyService; //导入方法依赖的package包/类
/**
* Returns a list of reports (flags) for all comments
* @return list of {@link GalleryCommentReport}
*/
@Override
public List<GalleryCommentReport> getCommentReports() {
final List<GalleryCommentReport> reports = new ArrayList<GalleryCommentReport>();
Objectify datastore = ObjectifyService.begin();
for (GalleryCommentReportData reportData : datastore.query(GalleryCommentReportData.class).order("-dateCreated")) {
User commenter = storageIo.getUser(reportData.userId);
String name="unknown";
if (commenter!= null) {
name = commenter.getUserName();
}
GalleryCommentReport galleryCommentReport = new GalleryCommentReport(reportData.galleryCommentKey.getId(),
reportData.userId,reportData.report,reportData.dateCreated);
galleryCommentReport.setUserName(name);
reports.add(galleryCommentReport);
}
return reports;
}
示例4: getEmail
import com.googlecode.objectify.ObjectifyService; //导入方法依赖的package包/类
/**
* Returns the email with a particular emailId
* @param emailId id of the email
*/ @Override
public Email getEmail(final long emailId) {
final Result<Email> result = new Result<Email>();
// if i try to run this in runjobwithretries it tells me can't run
// non-ancestor query as a transaction. ObjectifyStorageio has some samples
// of not using transactions (run with) so i grabbed
Objectify datastore = ObjectifyService.begin();
for (EmailData emailData : datastore.query(EmailData.class)
.filter("id", emailId)/*.order("-datestamp")*/) {
Email email = new Email(emailData.id, emailData.senderId, emailData.receiverId,
emailData.title, emailData.body, emailData.datestamp);
result.t = email;
break;
}
return result.t;
}
示例5: setUp
import com.googlecode.objectify.ObjectifyService; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
helper.setUp();
session = ObjectifyService.begin();
sut = new MomentEndpoint(DaoModule.userDAO(),
DaoModule.friendDAO(),
DaoModule.momentDAO(),
new FakeImagesService(),
new FakeGcmHelper());
ofy().save().entity(currentUserRecord).now();
ofy().save().entity(otherUserRecord).now();
ofy().save().entity(new FriendRecord()
.setUser(Key.create(currentUserRecord))
.addFriend(otherUserRecord.getId())).now();
ofy().save().entity(new FriendRecord()
.setUser(Key.create(otherUserRecord))
.addFriend(currentUserRecord.getId())).now();
}
示例6: setUp
import com.googlecode.objectify.ObjectifyService; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
helper.setUp();
ds = DatastoreServiceFactory.getDatastoreService();
// Set up some fake HTTP requests
when(mockRequest.getRequestURI()).thenReturn(FAKE_URL);
when(mockRequest.getParameter("guestbookName")).thenReturn("default");
when(mockRequest.getParameter("content")).thenReturn(testPhrase);
stringWriter = new StringWriter();
when(mockResponse.getWriter()).thenReturn(new PrintWriter(stringWriter));
servletUnderTest = new SignGuestbookServlet();
ObjectifyService.register(Guestbook.class);
ObjectifyService.register(Greeting.class);
closeable = ObjectifyService.begin();
cleanDatastore(ds, "default");
}
示例7: getPoints
import com.googlecode.objectify.ObjectifyService; //导入方法依赖的package包/类
public List<Float> getPoints(String line) throws IllegalArgumentException {
QuotaService qs = QuotaServiceFactory.getQuotaService();
long start = qs.getCpuTimeInMegaCycles();
Dao.getInstance();
Objectify ofy = ObjectifyService.begin();
Key<Line> k = new Key<Line>(Line.class, Long.parseLong(line));
Line l = Dao.getInstance().getLineByKey(k, ofy);
Collection<Point> points = Dao.getInstance().getPointsToDisplayForLine(l, ofy);
List<Float> coords = new ArrayList<Float>();
for(Point p : points) {
coords.add(p.getLatlon().getLatitude());
coords.add(p.getLatlon().getLongitude());
}
// Logger.getLogger("AdminInterface").log(Level.INFO, "In getPoints("+line+")");
// Logger.getLogger("AdminInterface").log(Level.INFO, "Line: " + l.toString());
// Logger.getLogger("AdminInterface").log(Level.INFO, "Key: " + k.toString());
long end = qs.getCpuTimeInMegaCycles();
double cpuSeconds = qs.convertMegacyclesToCpuSeconds(end - start);
Logger.getLogger("GetPointsServiceImpl").log(Level.INFO, "getPoints() for line " + l.getLinenum() + " " + l.getRamal() + ": " + cpuSeconds + " CPU seconds");
return coords;
}
示例8: setUp
import com.googlecode.objectify.ObjectifyService; //导入方法依赖的package包/类
/**
* Setup method for the test.
*/
@Before
public void setUp() {
helper.setUp();
ObjectifyService.register(TechGalleryUser.class);
ObjectifyService.register(UserProfile.class);
ObjectifyService.register(Technology.class);
ObjectifyService.begin();
createProfiles();
ObjectifyService.ofy().save().entity(techGalleryUser).now();
ObjectifyService.ofy().save().entity(techGalleryUser2).now();
ObjectifyService.ofy().save().entity(userProfile).now();
ObjectifyService.ofy().save().entity(userProfile2).now();
}
示例9: getTrainKeys
import com.googlecode.objectify.ObjectifyService; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static synchronized List<Key<Line>> getTrainKeys() {
String functionName = "getTrainKeys()";
if(trainKeys == null || trainKeys.size() == 0) {
Objectify ofy = ObjectifyService.begin();
Query<Line> q = ofy.query(Line.class).filter("type", 21);
List<Key<Line>> keys;
try {
Cache cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
keys = (List<Key<Line>>)cache.get(q.toString());
if(keys == null) {
keys = q.listKeys();
cache.put(q.toString(), keys);
}
} catch (CacheException e) {
keys = q.listKeys();
Logger.getLogger(location).log(Level.SEVERE, functionName + ": Cache error: " + e);
e.printStackTrace();
}
trainKeys = keys;
Logger.getLogger(location).log(Level.INFO, functionName + ": served new trainKeys. #" + trainKeys.size());
}
return trainKeys;
}
示例10: getTrainConnections
import com.googlecode.objectify.ObjectifyService; //导入方法依赖的package包/类
public SearchResultProxy getTrainConnections(float lat1, float lon1, float lat2, float lon2, boolean ignoreTrains, boolean ignoreSubte) throws IllegalArgumentException {
QuotaService qs = QuotaServiceFactory.getQuotaService();
long start = qs.getCpuTimeInMegaCycles();
Dao.getInstance();
Objectify ofy = ObjectifyService.begin();
String functionName = "getTrainConnections";
HashSet<Key<Line>> tabuTrainsSet = new HashSet<Key<Line>>();
if(ignoreTrains) {
tabuTrainsSet.addAll(Dao.getTrainKeys());
}
if(ignoreSubte) {
tabuTrainsSet.addAll(Dao.getSubteKeys());
}
ConnectionProxy connTren = Dao.getInstance().indirectSearch(new GeoPt(lat1, lon1), new GeoPt(lat2, lon2), tabuTrainsSet, new HashSet<Key<Line>>(), ofy);
List<ConnectionProxy> conns = new LinkedList<ConnectionProxy>();
conns.add(connTren);
long end = qs.getCpuTimeInMegaCycles();
double cpuSeconds = qs.convertMegacyclesToCpuSeconds(end - start);
Logger.getLogger("LineListServiceImpl").log(Level.INFO, functionName + ": " + cpuSeconds + " CPU seconds.");
if(connTren != null) {
return new SearchResultProxy(conns, null, null);
} else {
return null;
}
}
示例11: createRawUserFile
import com.googlecode.objectify.ObjectifyService; //导入方法依赖的package包/类
@VisibleForTesting
void createRawUserFile(String userId, String fileName, byte[] content) {
Objectify datastore = ObjectifyService.begin();
UserFileData ufd = createUserFile(datastore, userKey(userId), fileName);
if (ufd != null) {
ufd.content = content;
datastore.put(ufd);
}
}
示例12: main
import com.googlecode.objectify.ObjectifyService; //导入方法依赖的package包/类
public static void main(String[] args) {
ObjectifyService.register(Customer.class);
Closeable closeable = ObjectifyService.begin();
TestApp app = SpringApplication.run(TestApp.class, args).getBean(TestApp.class);
app.repository.save(new Customer("Tom", 31));
app.repository.save(new Customer("Chris", 33));
app.repository.save(new Customer("Dave", 47));
System.out.println(app.repository.findAll());
closeable.close();
}
示例13: getNumGalleryApps
import com.googlecode.objectify.ObjectifyService; //导入方法依赖的package包/类
/**
* Returns total number of GalleryApps
* @return number of GalleryApps
*/
@Override
public Integer getNumGalleryApps() {
Objectify datastore = ObjectifyService.begin();
int num = datastore.query(GalleryAppData.class).count();
return num;
}
示例14: checkUpgrade
import com.googlecode.objectify.ObjectifyService; //导入方法依赖的package包/类
public void checkUpgrade(String userId) {
if (!conversionEnabled) // Unless conversion is enabled...
return;
Objectify datastore = ObjectifyService.begin();
UserData userData = datastore.find(userKey(userId));
if ((userData.upgradedGCS && useGcs) ||
(!userData.upgradedGCS && !useGcs))
return; // All done.
Queue queue = QueueFactory.getQueue("blobupgrade");
queue.add(TaskOptions.Builder.withUrl("/convert").param("user", userId)
.etaMillis(System.currentTimeMillis() + 60000));
return;
}
示例15: isGcsFile
import com.googlecode.objectify.ObjectifyService; //导入方法依赖的package包/类
@VisibleForTesting
boolean isGcsFile(long projectId, String fileName) {
Objectify datastore = ObjectifyService.begin();
Key<FileData> fileKey = projectFileKey(projectKey(projectId), fileName);
FileData fd;
fd = (FileData) memcache.get(fileKey.getString());
if (fd == null) {
fd = datastore.find(fileKey);
}
if (fd != null) {
return isTrue(fd.isGCS);
} else {
return false;
}
}