8000
We read every piece of feedback, and take your input very seriously.
2 parents 14ddc54 + b0850b9 commit 01ecbefCopy full SHA for 01ecbef
appengine/datastore/src/main/java/com/example/appengine/StatsServlet.java
@@ -0,0 +1,49 @@
1
+/*
2
+ * Copyright 2016 Google Inc. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+package com.example.appengine;
18
19
+import com.google.appengine.api.datastore.DatastoreService;
20
+import com.google.appengine.api.datastore.DatastoreServiceFactory;
21
+import com.google.appengine.api.datastore.Entity;
22
+import com.google.appengine.api.datastore.Query;
23
24
+import java.io.IOException;
25
+import java.io.PrintWriter;
26
27
+import javax.servlet.ServletException;
28
+import javax.servlet.http.HttpServlet;
29
+import javax.servlet.http.HttpServletRequest;
30
+import javax.servlet.http.HttpServletResponse;
31
32
+public class StatsServlet extends HttpServlet {
33
+ @Override
34
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
35
+ throws ServletException, IOException {
36
+ // [START stat_example]
37
+ DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
38
+ Entity globalStat = datastore.prepare(new Query("__Stat_Total__")).asSingleEntity();
39
+ Long totalBytes = (Long) globalStat.getProperty("bytes");
40
+ Long totalEntities = (Long) globalStat.getProperty("count");
41
+ // [END stat_example]
42
43
+ resp.setContentType("text/plain");
44
+ resp.setCharacterEncoding("UTF-8");
45
+ PrintWriter w = resp.getWriter();
46
+ w.printf("%d bytes\n%d entities\n", totalBytes, totalEntities);
47
+ }
48
+}
49
+// [END cursors]
appengine/datastore/src/main/webapp/WEB-INF/web.xml
@@ -50,6 +50,14 @@
50
<servlet-name>projection</servlet-name>
51
<url-pattern>/projection</url-pattern>
52
</servlet-mapping>
53
+ <servlet>
54
+ <servlet-name>stats</servlet-name>
55
+ <servlet-class>com.example.appengine.StatsServlet</servlet-class>
56
+ </servlet>
57
+ <servlet-mapping>
58
59
+ <url-pattern>/stats</url-pattern>
60
+ </servlet-mapping>
61
62
<!-- Special handler to populate Datastore with default values. -->
63
<servlet>
@@ -73,4 +81,17 @@
73
81
<role-name>*</role-name> <!-- Require users to login. -->
74
82
</auth-constraint>
75
83
</security-constraint>
84
85
+ <security-constraint>
86
+ <web-resource-collection>
87
+ <web-resource-name>profile</web-resource-name>
88
89
+ </web-resource-collection>
90
+ <user-data-constraint>
91
+ <transport-guarantee>CONFIDENTIAL</transport-guarantee>
92
+ </user-data-constraint>
93
+ <auth-constraint>
94
+ <role-name>admin</role-name>
95
+ </auth-constraint>
96
+ </security-constraint>
76
97
</web-app>