com.axibase.tsd.driver.jdbc.content.ContentMetadata Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of atsd-jdbc Show documentation
Show all versions of atsd-jdbc Show documentation
JDBC driver for SQL API using
/*
* Copyright 2016 Axibase Corporation or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* https://www.axibase.com/atsd/axibase-apache-2.0.pdf
*
* or in the "license" file accompanying this file. This file 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.axibase.tsd.driver.jdbc.content;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import com.axibase.tsd.driver.jdbc.enums.AtsdType;
import com.axibase.tsd.driver.jdbc.ext.AtsdException;
import com.axibase.tsd.driver.jdbc.logging.LoggingFacade;
import com.axibase.tsd.driver.jdbc.util.EnumUtil;
import com.axibase.tsd.driver.jdbc.util.JsonMappingUtil;
import org.apache.calcite.avatica.AvaticaParameter;
import org.apache.calcite.avatica.ColumnMetaData;
import org.apache.calcite.avatica.Meta.CursorFactory;
import org.apache.calcite.avatica.Meta.MetaResultSet;
import org.apache.calcite.avatica.Meta.Signature;
import org.apache.calcite.avatica.Meta.StatementType;
import org.apache.calcite.avatica.com.fasterxml.jackson.core.JsonParseException;
import org.apache.calcite.avatica.com.fasterxml.jackson.core.JsonParser;
import org.apache.calcite.avatica.com.fasterxml.jackson.core.JsonToken;
import org.apache.commons.lang3.StringUtils;
import static com.axibase.tsd.driver.jdbc.DriverConstants.*;
@SuppressWarnings("unchecked")
public class ContentMetadata {
private static final LoggingFacade logger = LoggingFacade.getLogger(ContentMetadata.class);
private final Signature sign;
private final List list;
private final List metadataList;
public ContentMetadata(String scheme, String sql, String connectionId, int statementId)
throws AtsdException, IOException {
metadataList = StringUtils.isNoneEmpty(scheme) ? buildMetadataList(scheme)
: Collections.emptyList();
sign = new Signature(metadataList, sql, Collections.emptyList(), null, CursorFactory.LIST,
StatementType.SELECT);
list = Collections.unmodifiableList(
Collections.singletonList(MetaResultSet.create(connectionId, statementId, false, sign, null)));
}
public Signature getSign() {
return sign;
}
public List getList() {
return list;
}
public List getMetadataList() {
return metadataList;
}
static List buildMetadataList(String json)
throws JsonParseException, MalformedURLException, IOException, AtsdException {
final Map jsonObject = getJsonScheme(json);
if (jsonObject == null) {
throw new AtsdException("Wrong metadata content");
}
final Map publisher = (Map) jsonObject.get(PUBLISHER_SECTION);
if (publisher == null) {
throw new AtsdException("Wrong metadata publisher");
}
final String schema = (String) publisher.get(SCHEMA_NAME_PROPERTY);
if (schema == null) {
throw new AtsdException("Wrong metadata schema");
}
final Map tableSchema = (Map) jsonObject.get(TABLE_SCHEMA_SECTION);
if (tableSchema == null) {
throw new AtsdException("Wrong table schema");
}
final List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy