Skip to content

Commit 0acc57d

Browse files
jerjoudpebot
authored andcommitted
deprecated methods -> undeprecated versions. (#428)
1 parent 62df113 commit 0acc57d

File tree

41 files changed

+284
-279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+284
-279
lines changed

appengine/guestbook-cloud-datastore/src/main/java/com/example/guestbook/Greeting.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public Greeting(String book, String content, String id, String email) {
5454
}
5555

5656
public Greeting(Entity entity) {
57-
key = entity.hasKey() ? entity.key() : null;
57+
key = entity.hasKey() ? entity.getKey() : null;
5858
authorEmail = entity.contains("authorEmail") ? entity.getString("authorEmail") : null;
5959
authorId = entity.contains("authorId") ? entity.getString("authorId") : null;
6060
date = entity.contains("date") ? entity.getDateTime("date").toDate() : null;
@@ -66,7 +66,7 @@ public void save() {
6666
key = getDatastore().allocateId(makeIncompleteKey()); // Give this greeting a unique ID
6767
}
6868

69-
Builder<Key> builder = FullEntity.builder(key);
69+
Builder<Key> builder = FullEntity.newBuilder(key);
7070

7171
if (authorEmail != null) {
7272
builder.set("authorEmail", authorEmail);
@@ -84,7 +84,7 @@ public void save() {
8484

8585
private IncompleteKey makeIncompleteKey() {
8686
// The book is our ancestor key.
87-
return Key.builder(book.getKey(), "Greeting").build();
87+
return Key.newBuilder(book.getKey(), "Greeting").build();
8888
}
8989

9090
@Override

appengine/guestbook-cloud-datastore/src/main/java/com/example/guestbook/Guestbook.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ public Key getKey() {
5252
public List<Greeting> getGreetings() {
5353
// This query requires the index defined in index.yaml to work because of the orderBy on date.
5454
EntityQuery query =
55-
Query.entityQueryBuilder()
56-
.kind("Greeting")
57-
.filter(hasAncestor(key))
58-
.orderBy(desc("date"))
59-
.limit(5)
55+
Query.newEntityQueryBuilder()
56+
.setKind("Greeting")
57+
.setFilter(hasAncestor(key))
58+
.setOrderBy(desc("date"))
59+
.setLimit(5)
6060
.build();
6161

6262
QueryResults<Entity> results = getDatastore().run(query);

appengine/guestbook-cloud-datastore/src/main/java/com/example/guestbook/Persistence.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public class Persistence {
2525

2626
public static Datastore getDatastore() {
2727
if (datastore.get() == null) {
28-
datastore.set(DatastoreOptions.builder().projectId("your-project-id-here").build().service());
28+
datastore.set(DatastoreOptions.newBuilder().setProjectId("your-project-id-here")
29+
.build().getService());
2930
}
3031

3132
return datastore.get();
@@ -36,7 +37,7 @@ public static void setDatastore(Datastore datastore) {
3637
}
3738

3839
public static KeyFactory getKeyFactory(Class<?> c) {
39-
return getDatastore().newKeyFactory().kind(c.getSimpleName());
40+
return getDatastore().newKeyFactory().setKind(c.getSimpleName());
4041
}
4142
}
4243
//[END all]

appengine/guestbook-cloud-datastore/src/test/java/com/example/guestbook/TestUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class TestUtils {
1818
public static void startDatastore() {
1919
try {
2020
datastore.start();
21-
Persistence.setDatastore(datastore.options().service());
21+
Persistence.setDatastore(datastore.getOptions().getService());
2222
} catch (IOException | InterruptedException e) {
2323
throw new RuntimeException(e);
2424
}
@@ -35,7 +35,8 @@ public static void stopDatastore() {
3535

3636
public static void wipeDatastore() {
3737
Datastore datastore = getDatastore();
38-
QueryResults<Key> guestbooks = datastore.run(Query.keyQueryBuilder().kind("Greeting").build());
38+
QueryResults<Key> guestbooks = datastore.run(Query.newKeyQueryBuilder().setKind("Greeting")
39+
.build());
3940
ArrayList<Key> keys = Lists.newArrayList(guestbooks);
4041

4142
if (!keys.isEmpty()) {

appengine/guestbook-objectify/src/main/webapp/WEB-INF/appengine-web.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<application>your-app-id</application>
44
<version>${appengine.app.version}</version>
55
<threadsafe>true</threadsafe>
6-
6+
77
<system-properties>
88
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
99
</system-properties>

appengine/helloworld-new-plugins/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Use either:
1818
### Running locally
1919

2020
$ mvn appengine:run
21-
21+
2222
### Deploying
2323

2424
$ mvn appengine:deploy
@@ -36,7 +36,7 @@ If you do not have gradle installed, you can run using `./gradlew appengineRun`.
3636

3737
If you do not have gradle installed, you can deploy using `./gradlew appengineDeploy`.
3838

39-
<!--
39+
<!--
4040
## Intelij Idea
4141
Limitations - Appengine Standard support in the Intellij plugin is only available for the Ultimate Edition of Idea.
4242

appengine/images/src/main/java/com/example/appengine/images/ImagesServlet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc
6161
FileChannel fileChannel = fileInputStream.getChannel();
6262
ByteBuffer byteBuffer = ByteBuffer.allocate((int)fileChannel.size());
6363
fileChannel.read(byteBuffer);
64-
64+
6565
byte[] imageBytes = byteBuffer.array();
6666

6767
// Write the original image to Cloud Storage
@@ -103,7 +103,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc
103103
//[END rotate]
104104

105105
// Output some simple HTML to display the images we wrote to Cloud Storage
106-
// in the browser.
106+
// in the browser.
107107
PrintWriter out = resp.getWriter();
108108
out.println("<html><body>\n");
109109
out.println("<img src='//storage.cloud.google.com/" + bucket

appengine/logs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ Engine][ae-docs].
66
[log-docs]: https://cloud.google.com/appengine/docs/java/logs/
77
[ae-docs]: https://cloud.google.com/appengine/docs/java/
88

9-
## Running locally
9+
## Running locally
1010

1111
The Logs API only generates output for deployed apps, so this program should not be run locally.
1212

1313
## Deploying
14-
14+
1515
This example uses the
1616
[Maven gcloud plugin](https://cloud.google.com/appengine/docs/java/managed-vms/maven).
1717

appengine/logs/src/main/java/com/example/appengine/logs/LogsServlet.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@
3434
// a time, using a Next link to cycle through to the next 5.
3535
public class LogsServlet extends HttpServlet {
3636
@Override
37-
public void doGet(HttpServletRequest req, HttpServletResponse resp)
37+
public void doGet(HttpServletRequest req, HttpServletResponse resp)
3838
throws IOException {
3939

4040
resp.setContentType("text/html");
4141
PrintWriter writer = resp.getWriter();
4242
writer.println("<!DOCTYPE html>");
4343
writer.println("<meta charset=\"utf-8\">");
4444
writer.println("<title>App Engine Logs Sample</title>");
45-
45+
4646
// We use this to break out of our iteration loop, limiting record
4747
// display to 5 request logs at a time.
4848
int limit = 5;
@@ -81,17 +81,17 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp)
8181
writer.println(String.format("<br>Date: %s", appTime.toString()));
8282
writer.println("<br>Level: " + appLog.getLogLevel() + "<br>");
8383
writer.println("Message: " + appLog.getLogMessage() + "<br> <br>");
84-
}
84+
}
8585

8686
if (++count >= limit) {
8787
break;
8888
}
89-
}
89+
}
9090

9191
// When the user clicks this link, the offset is processed in the
9292
// GET handler and used to cycle through to the next 5 request logs.
9393
writer.println(String.format("<br><a href=\"/?offset=%s\">Next</a>", lastOffset));
94-
}
95-
}
94+
}
95+
}
9696
// [END logs_API_example]
9797

appengine/multitenancy/src/main/webapp/WEB-INF/appengine-web.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<application>your-app-id</application>
44
<version>${appengine.app.version}</version>
55
<threadsafe>true</threadsafe>
6-
6+
77
<system-properties>
88
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
99
</system-properties>

appengine/oauth2/src/main/webapp/WEB-INF/web.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<servlet-name>hello</servlet-name>
2121
<url-pattern>/hello</url-pattern>
2222
</servlet-mapping>
23-
23+
2424
<welcome-file-list>
2525
<welcome-file>index.html</welcome-file>
2626
</welcome-file-list>

appengine/requests/src/test/java/com/example/appengine/requests/LoggingServletTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public void setUp() throws Exception {
6363
servletUnderTest = new LoggingServlet();
6464
}
6565

66-
@After
66+
@After
6767
public void tearDown() {
68-
// Restore stderr
68+
// Restore stderr
6969
System.setErr(LoggingServletTest.REAL_ERR);
7070
}
7171

@@ -74,7 +74,7 @@ public void testListLogs() throws Exception {
7474
servletUnderTest.doGet(mockRequest, mockResponse);
7575

7676
String out = stderr.toString();
77-
77+
7878
// We expect three log messages to be created
7979
// with the following messages.
8080
assertThat(out).contains("An informational message.");

appengine/requests/src/test/java/com/example/appengine/requests/RequestsServletTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void setUp() throws Exception {
5252

5353
servletUnderTest = new RequestsServlet();
5454
}
55-
55+
5656
@Test
5757
public void doGet_writesResponse() throws Exception {
5858
servletUnderTest.doGet(mockRequest, mockResponse);

bigquery/cloud-client/src/main/java/com/example/bigquery/QuickstartSample.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@
2626
public class QuickstartSample {
2727
public static void main(String... args) throws Exception {
2828
// Instantiates a client
29-
BigQuery bigquery = BigQueryOptions.defaultInstance().service();
29+
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
3030

3131
// The name for the new dataset
3232
String datasetName = "my_new_dataset";
3333

3434
// Prepares a new dataset
3535
Dataset dataset = null;
36-
DatasetInfo datasetInfo = DatasetInfo.builder(datasetName).build();
36+
DatasetInfo datasetInfo = DatasetInfo.newBuilder(datasetName).build();
3737

3838
// Creates the dataset
3939
dataset = bigquery.create(datasetInfo);
4040

41-
System.out.printf("Dataset %s created.%n", dataset.datasetId().dataset());
41+
System.out.printf("Dataset %s created.%n", dataset.getDatasetId().getDataset());
4242
}
4343
}
4444
// [END bigquery_quickstart]

bigquery/cloud-client/src/main/java/com/example/bigquery/SimpleApp.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,46 +32,46 @@
3232
public class SimpleApp {
3333
public static void main(String... args) throws Exception {
3434
// [START create_client]
35-
BigQuery bigquery = BigQueryOptions.defaultInstance().service();
35+
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
3636
// [END create_client]
3737
// [START run_query]
3838
QueryRequest queryRequest =
3939
QueryRequest
40-
.builder(
40+
.newBuilder(
4141
"SELECT "
4242
+ "APPROX_TOP_COUNT(corpus, 10) as title, "
4343
+ "COUNT(*) as unique_words "
4444
+ "FROM `publicdata.samples.shakespeare`;")
4545
// Use standard SQL syntax for queries.
4646
// See: https://cloud.google.com/bigquery/sql-reference/
47-
.useLegacySql(false)
47+
.setUseLegacySql(false)
4848
.build();
4949
QueryResponse response = bigquery.query(queryRequest);
5050
// [END run_query]
5151

5252
// [START print_results]
53-
QueryResult result = response.result();
53+
QueryResult result = response.getResult();
5454

5555
while (result != null) {
5656
Iterator<List<FieldValue>> iter = result.iterateAll();
5757

5858
while (iter.hasNext()) {
5959
List<FieldValue> row = iter.next();
60-
List<FieldValue> titles = row.get(0).repeatedValue();
60+
List<FieldValue> titles = row.get(0).getRepeatedValue();
6161
System.out.println("titles:");
6262

6363
for (FieldValue titleValue : titles) {
64-
List<FieldValue> titleRecord = titleValue.recordValue();
65-
String title = titleRecord.get(0).stringValue();
66-
long uniqueWords = titleRecord.get(1).longValue();
64+
List<FieldValue> titleRecord = titleValue.getRecordValue();
65+
String title = titleRecord.get(0).getStringValue();
66+
long uniqueWords = titleRecord.get(1).getLongValue();
6767
System.out.printf("\t%s: %d\n", title, uniqueWords);
6868
}
6969

70-
long uniqueWords = row.get(1).longValue();
70+
long uniqueWords = row.get(1).getLongValue();
7171
System.out.printf("total unique words: %d\n", uniqueWords);
7272
}
7373

74-
result = result.nextPage();
74+
result = result.getNextPage();
7575
}
7676
// [END print_results]
7777
}

bigquery/cloud-client/src/main/java/com/example/bigquery/SyncQuerySample.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,27 @@ public static void run(
8484
final long waitTime,
8585
final boolean useLegacySql) throws IOException {
8686
BigQuery bigquery =
87-
new BigQueryOptions.DefaultBigqueryFactory().create(BigQueryOptions.defaultInstance());
87+
new BigQueryOptions.DefaultBigqueryFactory().create(BigQueryOptions.getDefaultInstance());
8888

8989
QueryRequest queryRequest =
90-
QueryRequest.builder(queryString)
91-
.maxWaitTime(waitTime)
90+
QueryRequest.newBuilder(queryString)
91+
.setMaxWaitTime(waitTime)
9292
// Use standard SQL syntax or legacy SQL syntax for queries.
9393
// See: https://cloud.google.com/bigquery/sql-reference/
94-
.useLegacySql(useLegacySql)
94+
.setUseLegacySql(useLegacySql)
9595
.build();
9696
QueryResponse response = bigquery.query(queryRequest);
9797

9898
if (response.hasErrors()) {
9999
throw new RuntimeException(
100100
response
101-
.executionErrors()
101+
.getExecutionErrors()
102102
.stream()
103-
.<String>map(err -> err.message())
103+
.<String>map(err -> err.getMessage())
104104
.collect(Collectors.joining("\n")));
105105
}
106106

107-
QueryResult result = response.result();
107+
QueryResult result = response.getResult();
108108
Iterator<List<FieldValue>> iter = result.iterateAll();
109109
while (iter.hasNext()) {
110110
List<FieldValue> row = iter.next();

bigquery/cloud-client/src/test/java/com/example/bigquery/QuickstartSampleIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class QuickstartSampleIT {
4141
private PrintStream out;
4242

4343
private static final void deleteMyNewDataset() {
44-
BigQuery bigquery = BigQueryOptions.defaultInstance().service();
44+
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
4545
String datasetName = "my_new_dataset";
4646
DatasetId datasetId = DatasetId.of(datasetName);
4747
DatasetDeleteOption deleteContents = DatasetDeleteOption.deleteContents();

compute/cmdline/src/main/java/ComputeEngineSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public static boolean printInstances(Compute compute) throws IOException {
152152
return found;
153153
}
154154
// [END list_instances]
155-
155+
156156
// [START create_instances]
157157
public static Operation startInstance(Compute compute, String instanceName) throws IOException {
158158
System.out.println("================== Starting New Instance ==================");

compute/error-reporting/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This sample demonstrates how to use [Stackdriver](https://cloud.google.com/error
1818
1. Restart the logging agent
1919

2020
`sudo service google-fluentd restart`
21-
21+
2222
1. Clone the repo
2323

2424
`git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git`

datastore/cloud-client/src/main/java/com/example/datastore/QuickstartSample.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ public static void main(String... args) throws Exception {
3333
// The name/ID for the new entity
3434
String name = "sampletask1";
3535
// The Cloud Datastore key for the new entity
36-
Key taskKey = datastore.newKeyFactory().kind(kind).newKey(name);
36+
Key taskKey = datastore.newKeyFactory().setKind(kind).newKey(name);
3737

3838
// Prepares the new entity
39-
Entity task = Entity.builder(taskKey)
39+
Entity task = Entity.newBuilder(taskKey)
4040
.set("description", "Buy milk")
4141
.build();
4242

4343
// Saves the entity
4444
datastore.put(task);
4545

46-
System.out.printf("Saved %s: %s%n", task.key().name(), task.getString("description"));
46+
System.out.printf("Saved %s: %s%n", task.getKey().getName(), task.getString("description"));
4747
}
4848
}
4949
// [END datastore_quickstart]

0 commit comments

Comments
 (0)