Skip to content

Commit

Permalink
deprecated methods -> undeprecated versions. (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerjou authored and dpebot committed Nov 30, 2016
1 parent 62df113 commit 0acc57d
Show file tree
Hide file tree
Showing 41 changed files with 284 additions and 279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Greeting(String book, String content, String id, String email) {
}

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

Builder<Key> builder = FullEntity.builder(key);
Builder<Key> builder = FullEntity.newBuilder(key);

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

private IncompleteKey makeIncompleteKey() {
// The book is our ancestor key.
return Key.builder(book.getKey(), "Greeting").build();
return Key.newBuilder(book.getKey(), "Greeting").build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public Key getKey() {
public List<Greeting> getGreetings() {
// This query requires the index defined in index.yaml to work because of the orderBy on date.
EntityQuery query =
Query.entityQueryBuilder()
.kind("Greeting")
.filter(hasAncestor(key))
.orderBy(desc("date"))
.limit(5)
Query.newEntityQueryBuilder()
.setKind("Greeting")
.setFilter(hasAncestor(key))
.setOrderBy(desc("date"))
.setLimit(5)
.build();

QueryResults<Entity> results = getDatastore().run(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public class Persistence {

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

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

public static KeyFactory getKeyFactory(Class<?> c) {
return getDatastore().newKeyFactory().kind(c.getSimpleName());
return getDatastore().newKeyFactory().setKind(c.getSimpleName());
}
}
//[END all]
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class TestUtils {
public static void startDatastore() {
try {
datastore.start();
Persistence.setDatastore(datastore.options().service());
Persistence.setDatastore(datastore.getOptions().getService());
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
Expand All @@ -35,7 +35,8 @@ public static void stopDatastore() {

public static void wipeDatastore() {
Datastore datastore = getDatastore();
QueryResults<Key> guestbooks = datastore.run(Query.keyQueryBuilder().kind("Greeting").build());
QueryResults<Key> guestbooks = datastore.run(Query.newKeyQueryBuilder().setKind("Greeting")
.build());
ArrayList<Key> keys = Lists.newArrayList(guestbooks);

if (!keys.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<application>your-app-id</application>
<version>${appengine.app.version}</version>
<threadsafe>true</threadsafe>

<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
Expand Down
4 changes: 2 additions & 2 deletions appengine/helloworld-new-plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Use either:
### Running locally

$ mvn appengine:run

### Deploying

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

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

<!--
<!--
## Intelij Idea
Limitations - Appengine Standard support in the Intellij plugin is only available for the Ultimate Edition of Idea.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc
FileChannel fileChannel = fileInputStream.getChannel();
ByteBuffer byteBuffer = ByteBuffer.allocate((int)fileChannel.size());
fileChannel.read(byteBuffer);

byte[] imageBytes = byteBuffer.array();

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

// Output some simple HTML to display the images we wrote to Cloud Storage
// in the browser.
// in the browser.
PrintWriter out = resp.getWriter();
out.println("<html><body>\n");
out.println("<img src='//storage.cloud.google.com/" + bucket
Expand Down
4 changes: 2 additions & 2 deletions appengine/logs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Engine][ae-docs].
[log-docs]: https://cloud.google.com/appengine/docs/java/logs/
[ae-docs]: https://cloud.google.com/appengine/docs/java/

## Running locally
## Running locally

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

## Deploying

This example uses the
[Maven gcloud plugin](https://cloud.google.com/appengine/docs/java/managed-vms/maven).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
// a time, using a Next link to cycle through to the next 5.
public class LogsServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {

resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
writer.println("<!DOCTYPE html>");
writer.println("<meta charset=\"utf-8\">");
writer.println("<title>App Engine Logs Sample</title>");

// We use this to break out of our iteration loop, limiting record
// display to 5 request logs at a time.
int limit = 5;
Expand Down Expand Up @@ -81,17 +81,17 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp)
writer.println(String.format("<br>Date: %s", appTime.toString()));
writer.println("<br>Level: " + appLog.getLogLevel() + "<br>");
writer.println("Message: " + appLog.getLogMessage() + "<br> <br>");
}
}

if (++count >= limit) {
break;
}
}
}

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

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<application>your-app-id</application>
<version>${appengine.app.version}</version>
<threadsafe>true</threadsafe>

<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
Expand Down
2 changes: 1 addition & 1 deletion appengine/oauth2/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public void setUp() throws Exception {
servletUnderTest = new LoggingServlet();
}

@After
@After
public void tearDown() {
// Restore stderr
// Restore stderr
System.setErr(LoggingServletTest.REAL_ERR);
}

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

String out = stderr.toString();

// We expect three log messages to be created
// with the following messages.
assertThat(out).contains("An informational message.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void setUp() throws Exception {

servletUnderTest = new RequestsServlet();
}

@Test
public void doGet_writesResponse() throws Exception {
servletUnderTest.doGet(mockRequest, mockResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@
public class QuickstartSample {
public static void main(String... args) throws Exception {
// Instantiates a client
BigQuery bigquery = BigQueryOptions.defaultInstance().service();
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();

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

// Prepares a new dataset
Dataset dataset = null;
DatasetInfo datasetInfo = DatasetInfo.builder(datasetName).build();
DatasetInfo datasetInfo = DatasetInfo.newBuilder(datasetName).build();

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

System.out.printf("Dataset %s created.%n", dataset.datasetId().dataset());
System.out.printf("Dataset %s created.%n", dataset.getDatasetId().getDataset());
}
}
// [END bigquery_quickstart]
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,46 @@
public class SimpleApp {
public static void main(String... args) throws Exception {
// [START create_client]
BigQuery bigquery = BigQueryOptions.defaultInstance().service();
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
// [END create_client]
// [START run_query]
QueryRequest queryRequest =
QueryRequest
.builder(
.newBuilder(
"SELECT "
+ "APPROX_TOP_COUNT(corpus, 10) as title, "
+ "COUNT(*) as unique_words "
+ "FROM `publicdata.samples.shakespeare`;")
// Use standard SQL syntax for queries.
// See: https://cloud.google.com/bigquery/sql-reference/
.useLegacySql(false)
.setUseLegacySql(false)
.build();
QueryResponse response = bigquery.query(queryRequest);
// [END run_query]

// [START print_results]
QueryResult result = response.result();
QueryResult result = response.getResult();

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

while (iter.hasNext()) {
List<FieldValue> row = iter.next();
List<FieldValue> titles = row.get(0).repeatedValue();
List<FieldValue> titles = row.get(0).getRepeatedValue();
System.out.println("titles:");

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

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

result = result.nextPage();
result = result.getNextPage();
}
// [END print_results]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,27 @@ public static void run(
final long waitTime,
final boolean useLegacySql) throws IOException {
BigQuery bigquery =
new BigQueryOptions.DefaultBigqueryFactory().create(BigQueryOptions.defaultInstance());
new BigQueryOptions.DefaultBigqueryFactory().create(BigQueryOptions.getDefaultInstance());

QueryRequest queryRequest =
QueryRequest.builder(queryString)
.maxWaitTime(waitTime)
QueryRequest.newBuilder(queryString)
.setMaxWaitTime(waitTime)
// Use standard SQL syntax or legacy SQL syntax for queries.
// See: https://cloud.google.com/bigquery/sql-reference/
.useLegacySql(useLegacySql)
.setUseLegacySql(useLegacySql)
.build();
QueryResponse response = bigquery.query(queryRequest);

if (response.hasErrors()) {
throw new RuntimeException(
response
.executionErrors()
.getExecutionErrors()
.stream()
.<String>map(err -> err.message())
.<String>map(err -> err.getMessage())
.collect(Collectors.joining("\n")));
}

QueryResult result = response.result();
QueryResult result = response.getResult();
Iterator<List<FieldValue>> iter = result.iterateAll();
while (iter.hasNext()) {
List<FieldValue> row = iter.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class QuickstartSampleIT {
private PrintStream out;

private static final void deleteMyNewDataset() {
BigQuery bigquery = BigQueryOptions.defaultInstance().service();
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
String datasetName = "my_new_dataset";
DatasetId datasetId = DatasetId.of(datasetName);
DatasetDeleteOption deleteContents = DatasetDeleteOption.deleteContents();
Expand Down
2 changes: 1 addition & 1 deletion compute/cmdline/src/main/java/ComputeEngineSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static boolean printInstances(Compute compute) throws IOException {
return found;
}
// [END list_instances]

// [START create_instances]
public static Operation startInstance(Compute compute, String instanceName) throws IOException {
System.out.println("================== Starting New Instance ==================");
Expand Down
2 changes: 1 addition & 1 deletion compute/error-reporting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This sample demonstrates how to use [Stackdriver](https://cloud.google.com/error
1. Restart the logging agent

`sudo service google-fluentd restart`

1. Clone the repo

`git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ public static void main(String... args) throws Exception {
// The name/ID for the new entity
String name = "sampletask1";
// The Cloud Datastore key for the new entity
Key taskKey = datastore.newKeyFactory().kind(kind).newKey(name);
Key taskKey = datastore.newKeyFactory().setKind(kind).newKey(name);

// Prepares the new entity
Entity task = Entity.builder(taskKey)
Entity task = Entity.newBuilder(taskKey)
.set("description", "Buy milk")
.build();

// Saves the entity
datastore.put(task);

System.out.printf("Saved %s: %s%n", task.key().name(), task.getString("description"));
System.out.printf("Saved %s: %s%n", task.getKey().getName(), task.getString("description"));
}
}
// [END datastore_quickstart]
Loading

0 comments on commit 0acc57d

Please sign in to comment.