use of com.google.api.core.BetaApi in project gapic-generator-java by googleapis.
the class AbstractServiceClientClassComposer method createGetterMethods.
private List<MethodDefinition> createGetterMethods(Service service, TypeStore typeStore, boolean hasLroClient) {
Map<String, TypeNode> methodNameToTypes = new LinkedHashMap<>();
methodNameToTypes.put("getSettings", typeStore.get(ClassNames.getServiceSettingsClassName(service)));
methodNameToTypes.put("getStub", typeStore.get(ClassNames.getServiceStubClassName(service)));
Set<String> getOperationsClientMethodNames = new HashSet<>();
if (hasLroClient) {
Iterator<String> opClientNamesIt = getTransportContext().operationsClientNames().iterator();
Iterator<TypeNode> opClientTypesIt = getTransportContext().operationsClientTypes().iterator();
while (opClientNamesIt.hasNext() && opClientTypesIt.hasNext()) {
String opClientMethodName = String.format("get%s", JavaStyle.toUpperCamelCase(opClientNamesIt.next()));
getOperationsClientMethodNames.add(opClientMethodName);
methodNameToTypes.put(opClientMethodName, opClientTypesIt.next());
}
}
AnnotationNode betaStubAnnotation = AnnotationNode.builder().setType(typeStore.get("BetaApi")).setDescription("A restructuring of stub classes is planned, so this may break in the future").build();
return methodNameToTypes.entrySet().stream().map(e -> {
String methodName = e.getKey();
TypeNode methodReturnType = e.getValue();
String returnVariableName = JavaStyle.toLowerCamelCase(methodName.substring(3));
MethodDefinition.Builder methodBuilder = MethodDefinition.builder();
if (getOperationsClientMethodNames.contains(methodName)) {
methodBuilder = methodBuilder.setHeaderCommentStatements(ServiceClientCommentComposer.GET_OPERATIONS_CLIENT_METHOD_COMMENT);
}
return methodBuilder.setAnnotations(methodName.equals("getStub") ? Arrays.asList(betaStubAnnotation) : Collections.emptyList()).setScope(ScopeNode.PUBLIC).setName(methodName).setIsFinal(!methodName.equals("getStub")).setReturnType(methodReturnType).setReturnExpr(VariableExpr.builder().setVariable(Variable.builder().setName(returnVariableName).setType(methodReturnType).build()).build()).build();
}).collect(Collectors.toList());
}
use of com.google.api.core.BetaApi in project gapic-generator-java by googleapis.
the class ResourceNameHelperClassComposer method createBuilderCreatorMethods.
private static List<MethodDefinition> createBuilderCreatorMethods(ResourceName resourceName, List<List<String>> tokenHierarchies, TypeStore typeStore) {
List<MethodDefinition> javaMethods = new ArrayList<>();
String newMethodNameFormat = "new%s";
AnnotationNode betaAnnotation = AnnotationNode.builder().setType(FIXED_TYPESTORE.get("BetaApi")).setDescription("The per-pattern Builders are not stable yet and may be changed in the future.").build();
List<AnnotationNode> annotations = Arrays.asList(betaAnnotation);
// Variation example: newProjectLocationAutoscalingPolicyBuilder().
for (int i = 0; i < tokenHierarchies.size(); i++) {
// PubSub special-case handling.
if (tokenHierarchies.get(i).contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) {
continue;
}
final TypeNode returnType = getBuilderType(typeStore, tokenHierarchies, i);
final Expr returnExpr = NewObjectExpr.withType(returnType);
Function<String, MethodDefinition.Builder> methodDefStarterFn = methodName -> MethodDefinition.builder().setScope(ScopeNode.PUBLIC).setIsStatic(true).setReturnType(returnType).setName(methodName).setReturnExpr(returnExpr);
String variantName = getBuilderTypeName(tokenHierarchies, i);
javaMethods.add(methodDefStarterFn.apply(String.format(newMethodNameFormat, variantName)).setAnnotations(i == 0 ? Collections.emptyList() : annotations).build());
if (i == 0 && tokenHierarchies.size() > 1) {
// Create another builder creator method, but with the per-variant name.
javaMethods.add(methodDefStarterFn.apply(String.format(newMethodNameFormat, getBuilderTypeName(tokenHierarchies.get(i)))).setAnnotations(annotations).build());
}
}
// TODO(miraleung, v2): It seems weird that we currently generate a toBuilder method only for
// the default class, and none for the Builder variants.
TypeNode toBuilderReturnType = getBuilderType(typeStore, tokenHierarchies, 0);
TypeNode thisClassType = typeStore.get(getThisClassName(resourceName));
javaMethods.add(MethodDefinition.builder().setScope(ScopeNode.PUBLIC).setReturnType(toBuilderReturnType).setName("toBuilder").setReturnExpr(NewObjectExpr.builder().setType(toBuilderReturnType).setArguments(Arrays.asList(ValueExpr.withValue(ThisObjectValue.withType(thisClassType)))).build()).build());
return javaMethods;
}
use of com.google.api.core.BetaApi in project java-bigtable by googleapis.
the class ReadModifyWriteRow method fromProto.
/**
* Wraps the protobuf {@link ReadModifyWriteRowRequest}.
*
* <p>WARNING: Please note that the table_name will be overwritten by the configuration in the
* BigtableDataClient.
*/
@BetaApi
public static ReadModifyWriteRow fromProto(@Nonnull ReadModifyWriteRowRequest request) {
String tableId = NameUtil.extractTableIdFromTableName(request.getTableName());
ReadModifyWriteRow row = ReadModifyWriteRow.create(tableId, request.getRowKey());
row.builder = request.toBuilder();
return row;
}
use of com.google.api.core.BetaApi in project java-bigquery by googleapis.
the class ConnectionImpl method executeSelect.
/**
* This method executes a SQL SELECT query
*
* @param sql SQL SELECT query
* @param parameters named or positional parameters. The set of query parameters must either be
* all positional or all named parameters.
* @param labels the labels associated with this query. You can use these to organize and group
* your query jobs. Label keys and values can be no longer than 63 characters, can only
* contain lowercase letters, numeric characters, underscores and dashes. International
* characters are allowed. Label values are optional and Label is a Varargs. You should pass
* all the Labels in a single Map .Label keys must start with a letter and each label in the
* list must have a different key.
* @return BigQueryResult containing the output of the query
* @throws BigQuerySQLException
*/
@BetaApi
@Override
public BigQueryResult executeSelect(String sql, List<Parameter> parameters, Map<String, String>... labels) throws BigQuerySQLException {
Map<String, String> labelMap = null;
if (labels != null && labels.length == 1) {
// We expect label as a key value pair in a single Map
labelMap = labels[0];
}
try {
// use jobs.query if possible
if (isFastQuerySupported()) {
final String projectId = bigQueryOptions.getProjectId();
final QueryRequest queryRequest = createQueryRequest(connectionSettings, sql, parameters, labelMap);
return queryRpc(projectId, queryRequest, parameters != null);
}
// use jobs.insert otherwise
com.google.api.services.bigquery.model.Job queryJob = createQueryJob(sql, connectionSettings, parameters, labelMap);
JobId jobId = JobId.fromPb(queryJob.getJobReference());
GetQueryResultsResponse firstPage = getQueryResultsFirstPage(jobId);
return getResultSet(firstPage, jobId, sql, parameters != null);
} catch (BigQueryException e) {
throw new BigQuerySQLException(e.getMessage(), e, e.getErrors());
}
}
use of com.google.api.core.BetaApi in project java-bigtable by googleapis.
the class ConditionalRowMutation method fromProto.
/**
* Wraps the protobuf {@link CheckAndMutateRowRequest}.
*
* <p>WARNING: Please note that the table_name will be overwritten by the configuration in the
* BigtableDataClient.
*/
@BetaApi
public static ConditionalRowMutation fromProto(@Nonnull CheckAndMutateRowRequest request) {
String tableId = NameUtil.extractTableIdFromTableName(request.getTableName());
ConditionalRowMutation rowMutation = ConditionalRowMutation.create(tableId, request.getRowKey());
rowMutation.builder = request.toBuilder();
return rowMutation;
}
Aggregations