Esempio: ambiente standard di App Engine Java
Questo esempio è un'applicazione App Engine, scritta in Java, che scrive alcuni saluti "hello world" in una tabella Bigtable e li legge di nuovo. L'applicazione viene eseguita su Google Cloud nell'ambiente standard di App Engine. L'applicazione utilizza il runtime Java 8. Il codice di questa applicazione si trova nel repository GitHub GoogleCloudPlatform/java-docs-samples, nella directory appengine-java8/bigtable
.
Panoramica dell'esempio di codice
Il codice di esempio include le seguenti classi:
BigtableHelper
, che fornisce una connessione a Bigtable.BigtableHelloWorld
, che scrive e legge da Bigtable.
BigtableHelper
BigtableHelper
fornisce un metodo per creare una connessione a
Bigtable. Inoltre, memorizza nella cache la connessione e fornisce un metodo
recupererà la connessione memorizzata nella cache, se esistente. La creazione di una connessione è un'operazione relativamente costosa, pertanto, come best practice, dovresti sempre creare una singola connessione e riutilizzarla.
BigtableHelloWorld
BigtableHelloWorld
viene utilizzato per scrivere una serie di saluti per
Bigtable, leggete e visualizzate i saluti. La classe recupera una connessione Bigtable da BigtableHelper
, utilizza la connessione per recuperare un oggetto Table
che ti consente di leggere e scrivere valori, quindi utilizza l'oggetto Table
per scrivere e leggere dalla tabella.