Search in sources :

Example 1 with BetaApi

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());
}
Also used : Arrays(java.util.Arrays) ServiceClientHeaderSampleComposer(com.google.api.generator.gapic.composer.samplecode.ServiceClientHeaderSampleComposer) OperationFuture(com.google.api.gax.longrunning.OperationFuture) BiFunction(java.util.function.BiFunction) Reference(com.google.api.generator.engine.ast.Reference) ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) ThisObjectValue(com.google.api.generator.engine.ast.ThisObjectValue) Variable(com.google.api.generator.engine.ast.Variable) BackgroundResource(com.google.api.gax.core.BackgroundResource) Field(com.google.api.generator.gapic.model.Field) Generated(javax.annotation.Generated) MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) TypeStore(com.google.api.generator.gapic.composer.store.TypeStore) Method(com.google.api.generator.gapic.model.Method) MethodArgument(com.google.api.generator.gapic.model.MethodArgument) PrimitiveValue(com.google.api.generator.engine.ast.PrimitiveValue) LongrunningOperation(com.google.api.generator.gapic.model.LongrunningOperation) Stream(com.google.api.generator.gapic.model.Method.Stream) Map(java.util.Map) ServiceClientMethodSampleComposer(com.google.api.generator.gapic.composer.samplecode.ServiceClientMethodSampleComposer) ServerStreamingCallable(com.google.api.gax.rpc.ServerStreamingCallable) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) ApiFutures(com.google.api.core.ApiFutures) PageContext(com.google.api.gax.rpc.PageContext) Status(com.google.rpc.Status) Set(java.util.Set) ScopeNode(com.google.api.generator.engine.ast.ScopeNode) ServiceClientCommentComposer(com.google.api.generator.gapic.composer.comment.ServiceClientCommentComposer) Collectors(java.util.stream.Collectors) ApiFuture(com.google.api.core.ApiFuture) Objects(java.util.Objects) ClassNames(com.google.api.generator.gapic.composer.utils.ClassNames) List(java.util.List) ServiceClientCallableMethodSampleComposer(com.google.api.generator.gapic.composer.samplecode.ServiceClientCallableMethodSampleComposer) SampleCodeWriter(com.google.api.generator.gapic.composer.samplecode.SampleCodeWriter) Optional(java.util.Optional) GapicContext(com.google.api.generator.gapic.model.GapicContext) ApiFunction(com.google.api.core.ApiFunction) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) BetaApi(com.google.api.core.BetaApi) TypeNode(com.google.api.generator.engine.ast.TypeNode) BidiStreamingCallable(com.google.api.gax.rpc.BidiStreamingCallable) Kind(com.google.api.generator.gapic.model.GapicClass.Kind) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition) PackageChecker(com.google.api.generator.gapic.composer.utils.PackageChecker) HashMap(java.util.HashMap) GapicMetadata(com.google.gapic.metadata.GapicMetadata) Operation(com.google.longrunning.Operation) Function(java.util.function.Function) ArrayList(java.util.ArrayList) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Strings(com.google.common.base.Strings) Expr(com.google.api.generator.engine.ast.Expr) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) ClientStreamingCallable(com.google.api.gax.rpc.ClientStreamingCallable) TriFunction(com.google.api.generator.util.TriFunction) AbstractFixedSizeCollection(com.google.api.gax.paging.AbstractFixedSizeCollection) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Iterator(java.util.Iterator) AbstractPage(com.google.api.gax.paging.AbstractPage) CastExpr(com.google.api.generator.engine.ast.CastExpr) CommentStatement(com.google.api.generator.engine.ast.CommentStatement) IOException(java.io.IOException) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) Sample(com.google.api.generator.gapic.model.Sample) GapicClass(com.google.api.generator.gapic.model.GapicClass) ResourceName(com.google.api.generator.gapic.model.ResourceName) Trie(com.google.api.generator.util.Trie) TimeUnit(java.util.concurrent.TimeUnit) OperationCallable(com.google.api.gax.rpc.OperationCallable) UnaryCallable(com.google.api.gax.rpc.UnaryCallable) Statement(com.google.api.generator.engine.ast.Statement) Service(com.google.api.generator.gapic.model.Service) LambdaExpr(com.google.api.generator.engine.ast.LambdaExpr) SuperObjectValue(com.google.api.generator.engine.ast.SuperObjectValue) SampleComposerUtil(com.google.api.generator.gapic.composer.samplecode.SampleComposerUtil) JavaStyle(com.google.api.generator.gapic.utils.JavaStyle) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Message(com.google.api.generator.gapic.model.Message) Collections(java.util.Collections) AbstractPagedListResponse(com.google.api.gax.paging.AbstractPagedListResponse) AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) TypeNode(com.google.api.generator.engine.ast.TypeNode) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet)

Example 2 with BetaApi

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;
}
Also used : Arrays(java.util.Arrays) Reference(com.google.api.generator.engine.ast.Reference) PathTemplate(com.google.api.pathtemplate.PathTemplate) ThisObjectValue(com.google.api.generator.engine.ast.ThisObjectValue) Variable(com.google.api.generator.engine.ast.Variable) StringObjectValue(com.google.api.generator.engine.ast.StringObjectValue) LogicalOperationExpr(com.google.api.generator.engine.ast.LogicalOperationExpr) Generated(javax.annotation.Generated) MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) TypeStore(com.google.api.generator.gapic.composer.store.TypeStore) PrimitiveValue(com.google.api.generator.engine.ast.PrimitiveValue) CommentComposer(com.google.api.generator.gapic.composer.comment.CommentComposer) Map(java.util.Map) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) ImmutableMap(com.google.common.collect.ImmutableMap) ForStatement(com.google.api.generator.engine.ast.ForStatement) Set(java.util.Set) ScopeNode(com.google.api.generator.engine.ast.ScopeNode) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ResourceNameConstants(com.google.api.generator.gapic.utils.ResourceNameConstants) List(java.util.List) GapicContext(com.google.api.generator.gapic.model.GapicContext) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) IfStatement(com.google.api.generator.engine.ast.IfStatement) BetaApi(com.google.api.core.BetaApi) TypeNode(com.google.api.generator.engine.ast.TypeNode) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition) ReturnExpr(com.google.api.generator.engine.ast.ReturnExpr) HashMap(java.util.HashMap) JavaDocComment(com.google.api.generator.engine.ast.JavaDocComment) Function(java.util.function.Function) ArrayList(java.util.ArrayList) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) Expr(com.google.api.generator.engine.ast.Expr) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) SynchronizedStatement(com.google.api.generator.engine.ast.SynchronizedStatement) ValidationException(com.google.api.pathtemplate.ValidationException) LinkedHashSet(java.util.LinkedHashSet) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Iterator(java.util.Iterator) CastExpr(com.google.api.generator.engine.ast.CastExpr) CommentStatement(com.google.api.generator.engine.ast.CommentStatement) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) GapicClass(com.google.api.generator.gapic.model.GapicClass) ResourceName(com.google.api.generator.gapic.model.ResourceName) Statement(com.google.api.generator.engine.ast.Statement) JavaStyle(com.google.api.generator.gapic.utils.JavaStyle) AssignmentOperationExpr(com.google.api.generator.engine.ast.AssignmentOperationExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) LogicalOperationExpr(com.google.api.generator.engine.ast.LogicalOperationExpr) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) ReturnExpr(com.google.api.generator.engine.ast.ReturnExpr) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) Expr(com.google.api.generator.engine.ast.Expr) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) CastExpr(com.google.api.generator.engine.ast.CastExpr) AssignmentOperationExpr(com.google.api.generator.engine.ast.AssignmentOperationExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) ArrayList(java.util.ArrayList) TypeNode(com.google.api.generator.engine.ast.TypeNode)

Example 3 with BetaApi

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;
}
Also used : ByteString(com.google.protobuf.ByteString) BetaApi(com.google.api.core.BetaApi)

Example 4 with BetaApi

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());
    }
}
Also used : QueryRequest(com.google.api.services.bigquery.model.QueryRequest) GetQueryResultsResponse(com.google.api.services.bigquery.model.GetQueryResultsResponse) BetaApi(com.google.api.core.BetaApi)

Example 5 with BetaApi

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;
}
Also used : ByteString(com.google.protobuf.ByteString) BetaApi(com.google.api.core.BetaApi)

Aggregations

BetaApi (com.google.api.core.BetaApi)11 AnnotationNode (com.google.api.generator.engine.ast.AnnotationNode)5 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)5 CastExpr (com.google.api.generator.engine.ast.CastExpr)5 ClassDefinition (com.google.api.generator.engine.ast.ClassDefinition)5 CommentStatement (com.google.api.generator.engine.ast.CommentStatement)5 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)5 Expr (com.google.api.generator.engine.ast.Expr)5 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)5 MethodDefinition (com.google.api.generator.engine.ast.MethodDefinition)5 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)5 NewObjectExpr (com.google.api.generator.engine.ast.NewObjectExpr)5 PrimitiveValue (com.google.api.generator.engine.ast.PrimitiveValue)5 Reference (com.google.api.generator.engine.ast.Reference)5 RelationalOperationExpr (com.google.api.generator.engine.ast.RelationalOperationExpr)5 ScopeNode (com.google.api.generator.engine.ast.ScopeNode)5 Statement (com.google.api.generator.engine.ast.Statement)5 TernaryExpr (com.google.api.generator.engine.ast.TernaryExpr)5 ThisObjectValue (com.google.api.generator.engine.ast.ThisObjectValue)5 TypeNode (com.google.api.generator.engine.ast.TypeNode)5