com.cognite.client.RawDatabases Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cdf-sdk-java Show documentation
Show all versions of cdf-sdk-java Show documentation
Java SDK for reading and writing from/to CDF resources.
/*
* Copyright (c) 2020 Cognite AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.cognite.client;
import com.cognite.client.servicesV1.ConnectorServiceV1;
import com.cognite.client.servicesV1.ResponseItems;
import com.cognite.client.util.Partition;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
/**
* This class represents the Cognite raw databases api endpoint.
*
* It provides methods for interacting with the Raw service.
*/
@AutoValue
public abstract class RawDatabases extends ApiBase {
private static Builder builder() {
return new AutoValue_RawDatabases.Builder();
}
protected static final Logger LOG = LoggerFactory.getLogger(RawDatabases.class);
/**
* Constructs a new {@link RawDatabases} object using the provided client configuration.
*
* This method is intended for internal use--SDK clients should always use {@link CogniteClient}
* as the entry point to this class.
*
* @param client The {@link CogniteClient} to use for configuration settings.
* @return the assets api object.
*/
public static RawDatabases of(CogniteClient client) {
return RawDatabases.builder()
.setClient(client)
.build();
}
/**
* Returns all database names.
*
* @return an {@link Iterator} to page through the db names.
* @throws Exception
*/
public Iterator> list() throws Exception {
ConnectorServiceV1 connector = getClient().getConnectorService();
ConnectorServiceV1.ResultFutureIterator futureIterator =
connector.readRawDbNames(getClient().buildAuthConfig());
return AdapterIterator.of(FanOutIterator.of(ImmutableList.of(futureIterator)), this::parseName);
}
/**
* Creates Raw databases.
*
* @param databases The databases to create.
* @return The created table names.
* @throws Exception
*/
public List create(List databases) throws Exception {
String loggingPrefix = "create() - ";
Instant startInstant = Instant.now();
LOG.info(loggingPrefix + "Received {} databases to create.",
databases.size());
List deduplicated = new ArrayList<>(new HashSet<>(databases));
ConnectorServiceV1 connector = getClient().getConnectorService();
ConnectorServiceV1.ItemWriter createItemWriter = connector.writeRawDbNames();
List> batches = Partition.ofSize(deduplicated, 100);
for (List batch : batches) {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy