Search in sources :

Example 1 with TABLE_NAME

use of com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.TABLE_NAME in project atlasdb by palantir.

the class JdbcKeyValueService method create.

public static JdbcKeyValueService create(JdbcKeyValueConfiguration config) {
    JdbcDataSourceConfiguration dataSourceConfig = config.getDataSourceConfig();
    SQLDialect sqlDialect = SQLDialect.valueOf(dataSourceConfig.getSqlDialect());
    DataSource dataSource = dataSourceConfig.createDataSource();
    Settings settings = new Settings();
    settings.setRenderNameStyle(RenderNameStyle.AS_IS);
    final JdbcKeyValueService kvs = new JdbcKeyValueService(settings, sqlDialect, dataSource, config.getTablePrefix(), config.getRowBatchSize(), config.getBatchSizeForReads(), config.getBatchSizeForMutations());
    kvs.run((Function<DSLContext, Void>) ctx -> {
        String partialSql = ctx.createTable(kvs.METADATA_TABLE).column(TABLE_NAME, VARCHAR.nullable(false)).column(METADATA, BLOB.nullable(false)).getSQL();
        int endIndex = partialSql.lastIndexOf(')');
        String fullSql = partialSql.substring(0, endIndex) + "," + " CONSTRAINT pk_" + kvs.METADATA_TABLE.getName() + " PRIMARY KEY (" + TABLE_NAME.getName() + ")" + partialSql.substring(endIndex);
        try {
            ctx.execute(fullSql);
        } catch (DataAccessException e) {
            kvs.handleTableCreationException(e);
        }
        return null;
    });
    return kvs;
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) DSL(org.jooq.impl.DSL) DSL.field(org.jooq.impl.DSL.field) CheckAndSetRequest(com.palantir.atlasdb.keyvalue.api.CheckAndSetRequest) Condition(org.jooq.Condition) Record1(org.jooq.Record1) SelectField(org.jooq.SelectField) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) SQLDialect(org.jooq.SQLDialect) CandidateCellForSweeping(com.palantir.atlasdb.keyvalue.api.CandidateCellForSweeping) Select(org.jooq.Select) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) Cell(com.palantir.atlasdb.keyvalue.api.Cell) T1_TIMESTAMP(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.T1_TIMESTAMP) Set(java.util.Set) PutBatch(com.palantir.atlasdb.keyvalue.jdbc.impl.PutBatch) T1_COL_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.T1_COL_NAME) Result(org.jooq.Result) StandardCharsets(java.nio.charset.StandardCharsets) InsufficientConsistencyException(com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException) KeyAlreadyExistsException(com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException) AbstractKeyValueService(com.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService) ColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection) Iterables(com.google.common.collect.Iterables) METADATA(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.METADATA) DSL.row(org.jooq.impl.DSL.row) ClusterAvailabilityStatus(com.palantir.atlasdb.keyvalue.api.ClusterAvailabilityStatus) R_TIMESTAMP(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.R_TIMESTAMP) SQLException(java.sql.SQLException) T2_MAX_TIMESTAMP(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.T2_MAX_TIMESTAMP) Lists(com.google.common.collect.Lists) VARBINARY(org.jooq.impl.SQLDataType.VARBINARY) RANGE_TABLE(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.RANGE_TABLE) VARCHAR(org.jooq.impl.SQLDataType.VARCHAR) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Record(org.jooq.Record) UnsignedBytes(com.google.common.primitives.UnsignedBytes) JdbcDataSourceConfiguration(com.palantir.atlasdb.jdbc.config.JdbcDataSourceConfiguration) T1_ROW_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.T1_ROW_NAME) BaseEncoding(com.google.common.io.BaseEncoding) COL_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.COL_NAME) MoreObjects(com.google.common.base.MoreObjects) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) BLOB(org.jooq.impl.SQLDataType.BLOB) MultiTimestampPutBatch(com.palantir.atlasdb.keyvalue.jdbc.impl.MultiTimestampPutBatch) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) DSL.table(org.jooq.impl.DSL.table) VALUE(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.VALUE) GetCandidateCellsForSweepingShim(com.palantir.atlasdb.keyvalue.impl.GetCandidateCellsForSweepingShim) TEMP_TABLE_1(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.TEMP_TABLE_1) RowN(org.jooq.RowN) RangeRequests(com.palantir.atlasdb.keyvalue.api.RangeRequests) TEMP_TABLE_2(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.TEMP_TABLE_2) Row(org.jooq.Row) Connection(java.sql.Connection) TABLE_VALUES(org.jooq.Clause.TABLE_VALUES) ATLAS_TABLE(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.ATLAS_TABLE) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) ClosableIterator(com.palantir.common.base.ClosableIterator) Table(org.jooq.Table) TABLE_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.TABLE_NAME) SelectOffsetStep(org.jooq.SelectOffsetStep) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) KeyValueServices(com.palantir.atlasdb.keyvalue.impl.KeyValueServices) A_TIMESTAMP(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.A_TIMESTAMP) RenderContext(org.jooq.RenderContext) HashMultimap(com.google.common.collect.HashMultimap) DSLContext(org.jooq.DSLContext) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractPagingIterable(com.palantir.util.paging.AbstractPagingIterable) Row3(org.jooq.Row3) Collection(java.util.Collection) SingleTimestampPutBatch(com.palantir.atlasdb.keyvalue.jdbc.impl.SingleTimestampPutBatch) ROW_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.ROW_NAME) T1_VALUE(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.T1_VALUE) NavigableMap(java.util.NavigableMap) Sets(com.google.common.collect.Sets) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) List(java.util.List) InsertValuesStep4(org.jooq.InsertValuesStep4) CandidateCellForSweepingRequest(com.palantir.atlasdb.keyvalue.api.CandidateCellForSweepingRequest) Entry(java.util.Map.Entry) Query(org.jooq.Query) SortedMap(java.util.SortedMap) T2_COL_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.T2_COL_NAME) A_COL_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.A_COL_NAME) HashMap(java.util.HashMap) Hashing(com.google.common.hash.Hashing) Multimap(com.google.common.collect.Multimap) BIGINT(org.jooq.impl.SQLDataType.BIGINT) TableLike(org.jooq.TableLike) ImmutableList(com.google.common.collect.ImmutableList) A_VALUE(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.A_VALUE) DataSource(javax.sql.DataSource) R_ROW_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.R_ROW_NAME) ClosableIterators(com.palantir.common.base.ClosableIterators) DataAccessException(org.jooq.exception.DataAccessException) Value(com.palantir.atlasdb.keyvalue.api.Value) Settings(org.jooq.conf.Settings) MAX_TIMESTAMP(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.MAX_TIMESTAMP) TIMESTAMP(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.TIMESTAMP) A_ROW_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.A_ROW_NAME) TokenBackedBasicResultsPage(com.palantir.util.paging.TokenBackedBasicResultsPage) Maps(com.google.common.collect.Maps) T2_ROW_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.T2_ROW_NAME) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) Closeable(java.io.Closeable) SimpleTokenBackedResultsPage(com.palantir.util.paging.SimpleTokenBackedResultsPage) BatchBindStep(org.jooq.BatchBindStep) RenderNameStyle(org.jooq.conf.RenderNameStyle) SQLDialect(org.jooq.SQLDialect) DSLContext(org.jooq.DSLContext) JdbcDataSourceConfiguration(com.palantir.atlasdb.jdbc.config.JdbcDataSourceConfiguration) Settings(org.jooq.conf.Settings) DataAccessException(org.jooq.exception.DataAccessException) DataSource(javax.sql.DataSource)

Aggregations

Function (com.google.common.base.Function)1 MoreObjects (com.google.common.base.MoreObjects)1 Throwables (com.google.common.base.Throwables)1 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 HashMultimap (com.google.common.collect.HashMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Multimap (com.google.common.collect.Multimap)1 Sets (com.google.common.collect.Sets)1 Hashing (com.google.common.hash.Hashing)1 BaseEncoding (com.google.common.io.BaseEncoding)1 UnsignedBytes (com.google.common.primitives.UnsignedBytes)1 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)1 JdbcDataSourceConfiguration (com.palantir.atlasdb.jdbc.config.JdbcDataSourceConfiguration)1 BatchColumnRangeSelection (com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection)1