liquibase.ext.cosmosdb.persistence.AbstractRepository Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liquibase-cosmosdb Show documentation
Show all versions of liquibase-cosmosdb Show documentation
Liquibase extension for Cosmos DB via Core (SQL) API
package liquibase.ext.cosmosdb.persistence;
import com.azure.cosmos.CosmosContainer;
import com.azure.cosmos.models.*;
import liquibase.ext.cosmosdb.statement.JsonUtils;
import lombok.Getter;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import static com.azure.cosmos.implementation.Constants.Properties.ID;
public abstract class AbstractRepository {
@Getter
private final CosmosContainer container;
@Getter
private final AbstractItemToDocumentConverter> converter;
public AbstractRepository(final CosmosContainer container, final AbstractItemToDocumentConverter> converter) {
this.container = container;
this.converter = converter;
}
public Optional get(final String id) {
final SqlQuerySpec querySpec
= new SqlQuerySpec("SELECT * FROM c WHERE c.id=" + JsonUtils.COSMOS_ID_PARAMETER, new SqlParameter(JsonUtils.COSMOS_ID_PARAMETER, id));
//return container.queryItems(querySpec, null, Map.class).stream().findFirst().map(converter::fromDocument);
return container.queryItems(querySpec, null, Map.class).stream().findFirst().map(map -> (T) converter.fromDocument(map));
}
public List getAll() {
return readAllItems().stream().map(converter::fromDocument).collect(Collectors.toList());
}
@SuppressWarnings("unchecked")
public List