internal.sql.base.api.odbc.OdbcParam Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdplus-sql-base-api Show documentation
Show all versions of jdplus-sql-base-api Show documentation
${project.parent.artifactId} - ${project.artifactId}
/*
* Copyright 2016 National Bank of Belgium
*
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
* by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://ec.europa.eu/idabc/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package internal.sql.base.api.odbc;
import jdplus.sql.base.api.odbc.OdbcBean;
import jdplus.toolkit.base.api.timeseries.util.ObsGathering;
import jdplus.toolkit.base.tsp.DataSet;
import jdplus.toolkit.base.tsp.DataSource;
import jdplus.toolkit.base.tsp.cube.*;
import jdplus.toolkit.base.tsp.legacy.LegacyHandler;
import jdplus.toolkit.base.tsp.util.ObsFormat;
import jdplus.toolkit.base.tsp.util.PropertyHandler;
import lombok.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
import java.time.Duration;
import java.util.Collections;
import java.util.function.BiConsumer;
import java.util.function.Function;
import static jdplus.toolkit.base.tsp.util.PropertyHandler.onString;
import static jdplus.toolkit.base.tsp.util.PropertyHandler.onStringList;
/**
* @author Philippe Charles
*/
public interface OdbcParam extends DataSource.Converter {
String getVersion();
DataSet.@NonNull Converter getIdParam(@NonNull CubeConnection connection) throws IOException;
final class V1 implements OdbcParam {
private static final BulkCube DEFAULT_BULK = BulkCube.builder().ttl(Duration.ofMinutes(5)).depth(1).build();
@lombok.experimental.Delegate
private final DataSource.Converter converter =
OdbcBeanHandler
.builder()
.dsn(onString("dbName", ""))
.table(PropertyHandler.onString("tableName", ""))
.cube(
TableAsCubeHandler
.builder()
.dimensions(onStringList("dimColumns", Collections.emptyList(), ','))
.timeDimension(onString("periodColumn", ""))
.measure(onString("valueColumn", ""))
.format(LegacyHandler.onObsFormat("locale", "datePattern", "numberPattern", ObsFormat.getSystemDefault()))
.version(onString("versionColumn", ""))
.label(onString("labelColumn", ""))
.gathering(LegacyHandler.onObsGathering("frequency", "aggregationType", "cleanMissing", ObsGathering.DEFAULT))
.build()
)
.cache(
BulkCubeHandler
.builder()
.ttl(PropertyHandler.onDurationInMillis("cacheTtl", DEFAULT_BULK.getTtl()))
.depth(PropertyHandler.onInteger("cacheDepth", DEFAULT_BULK.getDepth()))
.build()
)
.build()
.asDataSourceConverter();
@Override
public String getVersion() {
return "20111201";
}
@Override
public DataSet.Converter getIdParam(CubeConnection connection) throws IOException {
return CubeSupport.idByName(connection.getRoot());
}
}
@lombok.Builder(toBuilder = true)
final class OdbcBeanHandler implements PropertyHandler {
@lombok.NonNull
private final PropertyHandler dsn;
@lombok.NonNull
private final PropertyHandler table;
@lombok.NonNull
private final PropertyHandler cube;
@lombok.NonNull
private final PropertyHandler cache;
@Override
public @NonNull OdbcBean get(@NonNull Function super String, ? extends CharSequence> properties) {
OdbcBean result = new OdbcBean();
result.setDsn(dsn.get(properties));
result.setTable(table.get(properties));
result.setCube(cube.get(properties));
result.setCache(cache.get(properties));
return result;
}
@Override
public void set(@NonNull BiConsumer super String, ? super String> properties, @Nullable OdbcBean value) {
if (value != null) {
dsn.set(properties, value.getDsn());
table.set(properties, value.getTable());
cube.set(properties, value.getCube());
cache.set(properties, value.getCache());
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy