diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java
index f769367b3dba..65ebbabf0b54 100644
--- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java
+++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java
@@ -18,7 +18,10 @@
import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.api.core.ApiFunction;
import com.google.api.services.bigquery.model.Dataset.Access;
+import com.google.cloud.StringEnumType;
+import com.google.cloud.StringEnumValue;
import java.io.Serializable;
import java.util.Objects;
@@ -43,21 +46,61 @@ public final class Acl implements Serializable {
*
* @see Dataset Roles
*/
- public enum Role {
+ public static final class Role extends StringEnumValue {
+ private static final long serialVersionUID = -1992679397135956912L;
+
+ private static final ApiFunction CONSTRUCTOR =
+ new ApiFunction() {
+ @Override
+ public Role apply(String constant) {
+ return new Role(constant);
+ }
+ };
+
+ private static final StringEnumType type = new StringEnumType(
+ Role.class,
+ CONSTRUCTOR);
+
/**
* Can read, query, copy or export tables in the dataset.
*/
- READER,
+ public static final Role READER = type.createAndRegister("READER");
/**
* Same as {@link #READER} plus can edit or append data in the dataset.
*/
- WRITER,
+ public static final Role WRITER = type.createAndRegister("WRITER");
/**
* Same as {@link #WRITER} plus can update and delete the dataset.
*/
- OWNER
+ public static final Role OWNER = type.createAndRegister("OWNER");
+
+ private Role(String constant) {
+ super(constant);
+ }
+
+ /**
+ * Get the Role for the given String constant, and throw an exception if the constant is
+ * not recognized.
+ */
+ public static Role valueOfStrict(String constant) {
+ return type.valueOfStrict(constant);
+ }
+
+ /**
+ * Get the Role for the given String constant, and allow unrecognized values.
+ */
+ public static Role valueOf(String constant) {
+ return type.valueOf(constant);
+ }
+
+ /**
+ * Return the known values for Role.
+ */
+ public static Role[] values() {
+ return type.values();
+ }
}
/**
diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobStatus.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobStatus.java
index 4be8a3843414..f6e49be63b80 100644
--- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobStatus.java
+++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobStatus.java
@@ -16,6 +16,9 @@
package com.google.cloud.bigquery;
+import com.google.api.core.ApiFunction;
+import com.google.cloud.StringEnumType;
+import com.google.cloud.StringEnumValue;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
@@ -35,22 +38,62 @@ public class JobStatus implements Serializable {
/**
* Possible states that a BigQuery Job can assume.
*/
- public enum State {
+ public static final class State extends StringEnumValue {
+ private static final long serialVersionUID = 818920627219751204L;
+
+ private static final ApiFunction CONSTRUCTOR =
+ new ApiFunction() {
+ @Override
+ public State apply(String constant) {
+ return new State(constant);
+ }
+ };
+
+ private static final StringEnumType type = new StringEnumType(
+ State.class,
+ CONSTRUCTOR);
+
/**
* The BigQuery Job is waiting to be executed.
*/
- PENDING,
+ public static final State PENDING = type.createAndRegister("PENDING");
/**
* The BigQuery Job is being executed.
*/
- RUNNING,
+ public static final State RUNNING = type.createAndRegister("RUNNING");
/**
* The BigQuery Job has completed either succeeding or failing. If failed {@link #getError()}
* will be non-null.
*/
- DONE
+ public static final State DONE = type.createAndRegister("DONE");
+
+ private State(String constant) {
+ super(constant);
+ }
+
+ /**
+ * Get the State for the given String constant, and throw an exception if the constant is
+ * not recognized.
+ */
+ public static State valueOfStrict(String constant) {
+ return type.valueOfStrict(constant);
+ }
+
+ /**
+ * Get the State for the given String constant, and allow unrecognized values.
+ */
+ public static State valueOf(String constant) {
+ return type.valueOf(constant);
+ }
+
+ /**
+ * Return the known values for State.
+ */
+ public static State[] values() {
+ return type.values();
+ }
}
private final State state;
diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/LegacySQLTypeName.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/LegacySQLTypeName.java
index a5da8f66e3d3..5ee57e5ff029 100644
--- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/LegacySQLTypeName.java
+++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/LegacySQLTypeName.java
@@ -16,44 +16,63 @@
package com.google.cloud.bigquery;
+import com.google.api.core.ApiFunction;
+import com.google.cloud.StringEnumType;
+import com.google.cloud.StringEnumValue;
+
/**
* A type used in legacy SQL contexts. NOTE: some contexts use a mix of types; for example,
* for queries that use standard SQL, the return types are the legacy SQL types.
*
* @see https://cloud.google.com/bigquery/data-types
*/
-public enum LegacySQLTypeName {
+public final class LegacySQLTypeName extends StringEnumValue {
+ private static final long serialVersionUID = 1421040468991161123L;
+
+ private static final ApiFunction CONSTRUCTOR =
+ new ApiFunction() {
+ @Override
+ public LegacySQLTypeName apply(String constant) {
+ return new LegacySQLTypeName(constant);
+ }
+ };
+
+ private static final StringEnumType type = new StringEnumType(
+ LegacySQLTypeName.class,
+ CONSTRUCTOR);
+
/** Variable-length binary data. */
- BYTES(StandardSQLTypeName.BYTES),
+ public static final LegacySQLTypeName BYTES = type.createAndRegister("BYTES").setStandardType(StandardSQLTypeName.BYTES);
/** Variable-length character (Unicode) data. */
- STRING(StandardSQLTypeName.STRING),
+ public static final LegacySQLTypeName STRING = type.createAndRegister("STRING").setStandardType(StandardSQLTypeName.STRING);
/** A 64-bit signed integer value. */
- INTEGER(StandardSQLTypeName.INT64),
+ public static final LegacySQLTypeName INTEGER = type.createAndRegister("INTEGER").setStandardType(StandardSQLTypeName.INT64);
/** A 64-bit IEEE binary floating-point value. */
- FLOAT(StandardSQLTypeName.FLOAT64),
+ public static final LegacySQLTypeName FLOAT = type.createAndRegister("FLOAT").setStandardType(StandardSQLTypeName.FLOAT64);
/** A Boolean value (true or false). */
- BOOLEAN(StandardSQLTypeName.BOOL),
+ public static final LegacySQLTypeName BOOLEAN = type.createAndRegister("BOOLEAN").setStandardType(StandardSQLTypeName.BOOL);
/** Represents an absolute point in time, with microsecond precision. */
- TIMESTAMP(StandardSQLTypeName.TIMESTAMP),
+ public static final LegacySQLTypeName TIMESTAMP = type.createAndRegister("TIMESTAMP").setStandardType(StandardSQLTypeName.TIMESTAMP);
/** Represents a logical calendar date. Note, support for this type is limited in legacy SQL. */
- DATE(StandardSQLTypeName.DATE),
+ public static final LegacySQLTypeName DATE = type.createAndRegister("DATE").setStandardType(StandardSQLTypeName.DATE);
/**
* Represents a time, independent of a specific date, to microsecond precision. Note, support for
* this type is limited in legacy SQL.
*/
- TIME(StandardSQLTypeName.TIME),
+ public static final LegacySQLTypeName TIME = type.createAndRegister("TIME").setStandardType(StandardSQLTypeName.TIME);
/**
* Represents a year, month, day, hour, minute, second, and subsecond (microsecond precision).
* Note, support for this type is limited in legacy SQL.
*/
- DATETIME(StandardSQLTypeName.DATETIME),
+ public static final LegacySQLTypeName DATETIME = type.createAndRegister("DATETIME").setStandardType(StandardSQLTypeName.DATETIME);
/** A record type with a nested schema. */
- RECORD(StandardSQLTypeName.STRUCT);
+ public static final LegacySQLTypeName RECORD = type.createAndRegister("RECORD").setStandardType(StandardSQLTypeName.STRUCT);
private StandardSQLTypeName equivalent;
- LegacySQLTypeName(StandardSQLTypeName equivalent) {
+ private LegacySQLTypeName setStandardType(StandardSQLTypeName equivalent) {
this.equivalent = equivalent;
+ return this;
}
/**
@@ -62,4 +81,30 @@ public enum LegacySQLTypeName {
public StandardSQLTypeName getStandardType() {
return equivalent;
}
+
+ private LegacySQLTypeName(String constant) {
+ super(constant);
+ }
+
+ /**
+ * Get the LegacySQLTypeName for the given String constant, and throw an exception if the constant is
+ * not recognized.
+ */
+ public static LegacySQLTypeName valueOfStrict(String constant) {
+ return type.valueOfStrict(constant);
+ }
+
+ /**
+ * Get the LegacySQLTypeName for the given String constant, and allow unrecognized values.
+ */
+ public static LegacySQLTypeName valueOf(String constant) {
+ return type.valueOf(constant);
+ }
+
+ /**
+ * Return the known values for LegacySQLTypeName.
+ */
+ public static LegacySQLTypeName[] values() {
+ return type.values();
+ }
}
diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableDefinition.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableDefinition.java
index 324e527e0e64..64019fe32b51 100644
--- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableDefinition.java
+++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableDefinition.java
@@ -18,7 +18,10 @@
import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.api.core.ApiFunction;
import com.google.api.services.bigquery.model.Table;
+import com.google.cloud.StringEnumType;
+import com.google.cloud.StringEnumValue;
import com.google.common.base.MoreObjects;
import java.io.Serializable;
@@ -37,12 +40,26 @@ public abstract class TableDefinition implements Serializable {
/**
* The table type.
*/
- public enum Type {
+ public static final class Type extends StringEnumValue {
+ private static final long serialVersionUID = -551560816480511474L;
+
+ private static final ApiFunction CONSTRUCTOR =
+ new ApiFunction() {
+ @Override
+ public Type apply(String constant) {
+ return new Type(constant);
+ }
+ };
+
+ private static final StringEnumType type = new StringEnumType(
+ Type.class,
+ CONSTRUCTOR);
+
/**
* A normal BigQuery table. Instances of {@code TableDefinition} for this type are implemented
* by {@link StandardTableDefinition}.
*/
- TABLE,
+ public static final Type TABLE = type.createAndRegister("TABLE");
/**
* A virtual table defined by a SQL query. Instances of {@code TableDefinition} for this type
@@ -50,7 +67,7 @@ public enum Type {
*
* @see Views
*/
- VIEW,
+ public static final Type VIEW = type.createAndRegister("VIEW");
/**
* A BigQuery table backed by external data. Instances of {@code TableDefinition} for this type
@@ -59,7 +76,33 @@ public enum Type {
* @see Federated Data
* Sources
*/
- EXTERNAL
+ public static final Type EXTERNAL = type.createAndRegister("EXTERNAL");
+
+ private Type(String constant) {
+ super(constant);
+ }
+
+ /**
+ * Get the Type for the given String constant, and throw an exception if the constant is
+ * not recognized.
+ */
+ public static Type valueOfStrict(String constant) {
+ return type.valueOfStrict(constant);
+ }
+
+ /**
+ * Get the Type for the given String constant, and allow unrecognized values.
+ */
+ public static Type valueOf(String constant) {
+ return type.valueOf(constant);
+ }
+
+ /**
+ * Return the known values for Type.
+ */
+ public static Type[] values() {
+ return type.values();
+ }
}
/**
@@ -170,12 +213,12 @@ Table toPb() {
@SuppressWarnings("unchecked")
static T fromPb(Table tablePb) {
- switch (Type.valueOf(tablePb.getType())) {
- case TABLE:
+ switch (Type.valueOf(tablePb.getType()).toString()) {
+ case "TABLE":
return (T) StandardTableDefinition.fromPb(tablePb);
- case VIEW:
+ case "VIEW":
return (T) ViewDefinition.fromPb(tablePb);
- case EXTERNAL:
+ case "EXTERNAL":
return (T) ExternalTableDefinition.fromPb(tablePb);
default:
// never reached