本文整理汇总了Java中com.google.appengine.api.datastore.DatastoreServiceFactory.getDatastoreService方法的典型用法代码示例。如果您正苦于以下问题:Java DatastoreServiceFactory.getDatastoreService方法的具体用法?Java DatastoreServiceFactory.getDatastoreService怎么用?Java DatastoreServiceFactory.getDatastoreService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.datastore.DatastoreServiceFactory
的用法示例。
在下文中一共展示了DatastoreServiceFactory.getDatastoreService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import com.google.appengine.api.datastore.DatastoreServiceFactory; //导入方法依赖的package包/类
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/html");
resp.getWriter().println("<html><body>");
DatastoreService datastore = DatastoreServiceFactory
.getDatastoreService();
Query query = new Query("SharedList");
query.addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);
List<Entity> results = datastore.prepare(query).asList(
FetchOptions.Builder.withDefaults());
for (Entity entity : results) {
String email = (String) entity.getProperty("email");
String productID = (String) entity.getKey().getName();
String productName = (String) entity.getProperty("productName");
Date sharedDate = (Date) entity.getProperty("sharedDate");
resp.getWriter().println(
email + " shared <a href=\"http://www.amazon.com/dp/"
+ productID + "\" target=\"_blank\">" + "<b>"
+ productName + "</b></a>!<br>");
}
resp.getWriter().println("</body></html>");
}
示例2: saveFile
import com.google.appengine.api.datastore.DatastoreServiceFactory; //导入方法依赖的package包/类
/**
* Save Full File
*
* @param inputStream
*/
private static void saveFile(InputStream inputStream) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("CET"));
time.set(Calendar.HOUR_OF_DAY,0);
time.set(Calendar.MINUTE,0);
time.set(Calendar.SECOND,0);
Date measuredAt = time.getTime();
long millis = time.getTimeInMillis();
//
Entity entity = new Entity(ENTITY_TYPE_FICHEROS,millis);
entity.setIndexedProperty("Date", measuredAt);
entity.setUnindexedProperty("File", GlobalUtils.getString(inputStream));
// Store
datastore.put(entity);
}
示例3: getHTML
import com.google.appengine.api.datastore.DatastoreServiceFactory; //导入方法依赖的package包/类
@GET
@Produces(MediaType.TEXT_XML)
public WishlistProduct getHTML() {
DatastoreService datastore = DatastoreServiceFactory
.getDatastoreService();
try {
Key entKey = KeyFactory.createKey(email, productID);
Entity entity = datastore.get(entKey);
String productName = (String) entity.getProperty("productName");
double currentPrice = (double) entity.getProperty("currentPrice");
double lowestPrice = (double) entity.getProperty("lowestPrice");
Date lowestDate = (Date) entity.getProperty("lowestDate");
return new WishlistProduct(productID, productName, currentPrice,
lowestPrice, lowestDate);
} catch (EntityNotFoundException e) {
throw new RuntimeException("GET: Wishlist with " + productID
+ " not found.");
}
}
示例4: get
import com.google.appengine.api.datastore.DatastoreServiceFactory; //导入方法依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public WishlistProduct get() {
DatastoreService datastore = DatastoreServiceFactory
.getDatastoreService();
try {
Key entKey = KeyFactory.createKey(email, productID);
Entity entity = datastore.get(entKey);
String productName = (String) entity.getProperty("productName");
double currentPrice = (double) entity.getProperty("currentPrice");
double lowestPrice = (double) entity.getProperty("lowestPrice");
Date lowestDate = (Date) entity.getProperty("lowestDate");
return new WishlistProduct(productID, productName, currentPrice,
lowestPrice, lowestDate);
} catch (EntityNotFoundException e) {
throw new RuntimeException("GET: Wishlist with " + productID
+ " not found.");
}
}
示例5: getEntities
import com.google.appengine.api.datastore.DatastoreServiceFactory; //导入方法依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public List<SharedProduct> getEntities() {
List<SharedProduct> list = new ArrayList<SharedProduct>();
DatastoreService datastore = DatastoreServiceFactory
.getDatastoreService();
Query query = new Query("SharedList");
query.addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);
List<Entity> results = datastore.prepare(query).asList(
FetchOptions.Builder.withDefaults());
for (Entity entity : results) {
String email = (String) entity.getProperty("email");
String productID = (String) entity.getKey().getName();
String productName = (String) entity.getProperty("productName");
Date sharedDate = (Date) entity.getProperty("sharedDate");
list.add(new SharedProduct(email, productID, productName,
sharedDate));
}
return list;
}
示例6: testJobIdAndNumJobs_fails
import com.google.appengine.api.datastore.DatastoreServiceFactory; //导入方法依赖的package包/类
@Test
public void testJobIdAndNumJobs_fails() throws Exception {
action = new MapreduceEntityCleanupAction(
Optional.of("jobid"),
Optional.empty(), // jobName
Optional.of(1), // numJobsToDelete
Optional.empty(), // daysOld
Optional.empty(), // force
mapreduceEntityCleanupUtil,
clock,
DatastoreServiceFactory.getDatastoreService(),
response);
action.run();
assertThat(response.getStatus()).isEqualTo(SC_BAD_REQUEST);
assertThat(response.getContentType()).isEqualTo(PLAIN_TEXT_UTF_8);
assertThat(response.getPayload())
.isEqualTo("Do not specify both a job ID and a number of jobs to delete");
assertNumMapreducesAndShardedJobs(0, 0);
}
示例7: main
import com.google.appengine.api.datastore.DatastoreServiceFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
String serverString = args[0];
RemoteApiOptions options;
if (serverString.equals("localhost")) {
options = new RemoteApiOptions().server(serverString,
8080).useDevelopmentServerCredential();
} else {
options = new RemoteApiOptions().server(serverString,
443).useApplicationDefaultCredential();
}
RemoteApiInstaller installer = new RemoteApiInstaller();
installer.install(options);
try {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
System.out.println("Key of new entity is " + ds.put(new Entity("Hello Remote API!")));
} finally {
installer.uninstall();
}
}
示例8: setUp
import com.google.appengine.api.datastore.DatastoreServiceFactory; //导入方法依赖的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");
}
示例9: doPost
import com.google.appengine.api.datastore.DatastoreServiceFactory; //导入方法依赖的package包/类
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
String guestbookName = req.getParameter("guestbookName");
Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName);
String content = req.getParameter("content");
Date date = new Date();
Entity greeting = new Entity("Greeting", guestbookKey);
greeting.setProperty("user", user);
greeting.setProperty("date", date);
greeting.setProperty("content", content);
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
datastore.put(greeting);
resp.sendRedirect("/guestbook.jsp?guestbookName=" + guestbookName);
}
示例10: getLastStatus
import com.google.appengine.api.datastore.DatastoreServiceFactory; //导入方法依赖的package包/类
private ArrayList<Medicion> getLastStatus(int amountData) {
// Poner Key estacion + hora_muestra
Calendar calendarTwoAgo = Calendar.getInstance(TimeZone.getTimeZone("CET"));
calendarTwoAgo.add(Calendar.DATE, -3);
Date dateTwoAgo = calendarTwoAgo.getTime();
// Prepare
Query.Filter keyFilter = new Query.FilterPredicate(PROPERTY_MEASURE_DATE, Query.FilterOperator.GREATER_THAN, dateTwoAgo);
Query.Filter no2Filter = new Query.FilterPredicate(PROPERTY_COMPUESTO, Query.FilterOperator.EQUAL, NO2.name());
List<Query.Filter> filterList = new ArrayList<>();
filterList.add(keyFilter);
filterList.add(no2Filter);
Query.Filter filter = new Query.CompositeFilter(Query.CompositeFilterOperator.AND, filterList);
Query query = new Query(ENTITY_TYPE_MEDIDAS)
.setFilter(filter)
.addSort(PROPERTY_MEASURE_DATE
, Query.SortDirection.DESCENDING);
// Query
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
PreparedQuery pq = datastore.prepare(query);
// Get results
List<com.google.appengine.api.datastore.Entity> resultList = pq.asList(FetchOptions.Builder.withLimit(amountData));
ArrayList<Medicion> result = new ArrayList<>();
if (resultList.size()!=0) {
mLogger.info("Watching " + resultList.size() + " last values of ESTADO");
for (com.google.appengine.api.datastore.Entity item : resultList){
result.add(new Medicion((Date) item.getProperty(PROPERTY_MEASURE_DATE), (String) item.getProperty(PROPERTY_AVISO), (String) item.getProperty(PROPERTY_AVISO_STATE), (String) item.getProperty(PREPERTY_AVISO_MAX_TODAY), (String) item.getProperty(PROPERTY_ESCENARIO_STATE_TODAY), (String) item.getProperty(PROPERTY_ESCENARIO_STATE_TOMORROW), (String) item.getProperty(PROPERTY_ESCENARIO_STATE_TOMORROW_MANUAL) ,isPureMadrid()));
}
} else {
// No hay datos
mLogger.info("No previous values for ESTADO");
}
return result;
}
示例11: getKey
import com.google.appengine.api.datastore.DatastoreServiceFactory; //导入方法依赖的package包/类
/**
* Gets the access key.
*/
protected String getKey() {
com.google.appengine.api.datastore.DatastoreService datastore = DatastoreServiceFactory
.getDatastoreService();
Key key = KeyFactory.createKey(ENTITY_KIND, ENTITY_KEY);
String apiKey = "";
try {
Entity entity = datastore.get(key);
apiKey = (String) entity.getProperty(ACCESS_KEY_FIELD);
} catch (EntityNotFoundException e) {
mLogger.severe("Exception will retrieving the API Key"
+ e.toString());
}
return apiKey;
}
示例12: listRawEntity
import com.google.appengine.api.datastore.DatastoreServiceFactory; //导入方法依赖的package包/类
public Iterable<Entity> listRawEntity(Query q, Boolean returnKeysOnly) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
if (returnKeysOnly) {
q.setKeysOnly();
}
PreparedQuery pq = datastore.prepare(q);
return pq.asIterable();
}
示例13: deleteAllObjects
import com.google.appengine.api.datastore.DatastoreServiceFactory; //导入方法依赖的package包/类
public void deleteAllObjects(Query query){
final DatastoreService dss=DatastoreServiceFactory.getDatastoreService();
final ArrayList<Key> keys=new ArrayList<>();
for ( final Entity entity : dss.prepare(query).asIterable(FetchOptions.Builder.withLimit(100000))) {
keys.add(entity.getKey());
}
dss.delete(keys);
}
示例14: provideDatastore
import com.google.appengine.api.datastore.DatastoreServiceFactory; //导入方法依赖的package包/类
@Provides
DatastoreService provideDatastore(@DatastoreTimeoutMillis long datastoreTimeoutMillis) {
return DatastoreServiceFactory.getDatastoreService(DatastoreServiceConfig.Builder
.withDeadline(datastoreTimeoutMillis * 1000.0)
.implicitTransactionManagementPolicy(ImplicitTransactionManagementPolicy.NONE)
.readPolicy(new ReadPolicy(ReadPolicy.Consistency.STRONG)));
}
示例15: getEntitiesBrowser
import com.google.appengine.api.datastore.DatastoreServiceFactory; //导入方法依赖的package包/类
@GET
@Produces(MediaType.TEXT_XML)
public List<WishlistProduct> getEntitiesBrowser() {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user == null) {
System.out.println("Login first");
return null;
}
List<WishlistProduct> list = new ArrayList<WishlistProduct>();
DatastoreService datastore = DatastoreServiceFactory
.getDatastoreService();
Query query = new Query(user.getEmail());
query.addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);
List<Entity> results = datastore.prepare(query).asList(
FetchOptions.Builder.withDefaults());
for (Entity entity : results) {
String productID = (String) entity.getKey().getName();
String productName = (String) entity.getProperty("productName");
double currentPrice = (double) entity.getProperty("currentPrice");
double lowestPrice = (double) entity.getProperty("lowestPrice");
Date lowestDate = (Date) entity.getProperty("lowestDate");
list.add(new WishlistProduct(productID, productName, currentPrice,
lowestPrice, lowestDate));
}
return list;
}