Search in sources :

Example 1 with ConnectionSupplier

use of com.palantir.atlasdb.keyvalue.dbkvs.impl.ConnectionSupplier in project atlasdb by palantir.

the class DbKvsGetRanges method getRangeQueryAndArgs.

private Pair<String, List<Object>> getRangeQueryAndArgs(TableReference tableRef, byte[] startRow, byte[] endRow, boolean reverse, int numRowsToGet, int queryNum) {
    String extraWhere;
    List<Object> args = Lists.newArrayList();
    args.add(queryNum);
    if (reverse) {
        extraWhere = " t.row_name <= ? ";
    } else {
        extraWhere = " t.row_name >= ? ";
    }
    if (startRow.length > 0) {
        args.add(startRow);
    } else {
        args.add(reverse ? LARGEST_NAME : SMALLEST_NAME);
    }
    if (endRow.length > 0) {
        if (reverse) {
            extraWhere += " AND t.row_name > ? ";
        } else {
            extraWhere += " AND t.row_name < ? ";
        }
        args.add(endRow);
    }
    String order = reverse ? "DESC" : "ASC";
    try (ConnectionSupplier conns = new ConnectionSupplier(connectionSupplier)) {
        if (numRowsToGet == 1) {
            String minMax = reverse ? "max" : "min";
            // QA-69854 Special case 1 row reads because oracle is terrible at optimizing queries
            String query = dbType == DBType.ORACLE ? getSimpleRowSelectOneQueryOracle(tableRef, minMax, extraWhere, conns) : getSimpleRowSelectOneQueryPostgres(tableRef, extraWhere, order, conns);
            return Pair.create(query, args);
        } else {
            String query = String.format(SIMPLE_ROW_SELECT_TEMPLATE, DbKvs.internalTableName(tableRef), getPrimaryKeyConstraintName(tableRef, conns), getPrefixedTableName(tableRef, conns), extraWhere, order);
            String limitQuery = BasicSQLUtils.limitQuery(query, numRowsToGet, args, dbType);
            return Pair.create(limitQuery, args);
        }
    }
}
Also used : ConnectionSupplier(com.palantir.atlasdb.keyvalue.dbkvs.impl.ConnectionSupplier)

Example 2 with ConnectionSupplier

use of com.palantir.atlasdb.keyvalue.dbkvs.impl.ConnectionSupplier in project atlasdb by palantir.

the class OracleTableNameUnmapperTest method setup.

@Before
public void setup() {
    connectionSupplier = mock(ConnectionSupplier.class);
    oracleTableNameUnmapper = new OracleTableNameUnmapper();
    SqlConnection sqlConnection = mock(SqlConnection.class);
    Connection connection = mock(Connection.class);
    when(sqlConnection.getUnderlyingConnection()).thenReturn(connection);
    when(connectionSupplier.get()).thenReturn(sqlConnection);
    resultSet = mock(AgnosticResultSet.class);
    when(sqlConnection.selectResultSetUnregisteredQuery(startsWith("SELECT short_table_name FROM atlasdb_table_names WHERE table_name"), anyObject())).thenReturn(resultSet);
}
Also used : ConnectionSupplier(com.palantir.atlasdb.keyvalue.dbkvs.impl.ConnectionSupplier) AgnosticResultSet(com.palantir.nexus.db.sql.AgnosticResultSet) Connection(java.sql.Connection) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) Before(org.junit.Before)

Example 3 with ConnectionSupplier

use of com.palantir.atlasdb.keyvalue.dbkvs.impl.ConnectionSupplier in project atlasdb by palantir.

the class OracleCellTsPageLoader method getTableDetailsUsingNewConnection.

private TableDetails getTableDetailsUsingNewConnection(TableReference tableRef) {
    try (ConnectionSupplier conns = new ConnectionSupplier(connectionPool)) {
        String shortName = tableNameGetter.getInternalShortTableName(conns, tableRef);
        TableValueStyle style = valueStyleCache.getTableType(conns, tableRef, config.metadataTable());
        boolean hasOverflow = style == TableValueStyle.OVERFLOW;
        return new TableDetails(shortName, hasOverflow);
    } catch (TableMappingNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : SqlConnectionSupplier(com.palantir.atlasdb.keyvalue.dbkvs.impl.SqlConnectionSupplier) ConnectionSupplier(com.palantir.atlasdb.keyvalue.dbkvs.impl.ConnectionSupplier) TableMappingNotFoundException(com.palantir.atlasdb.keyvalue.impl.TableMappingNotFoundException) TableValueStyle(com.palantir.atlasdb.keyvalue.dbkvs.impl.TableValueStyle)

Example 4 with ConnectionSupplier

use of com.palantir.atlasdb.keyvalue.dbkvs.impl.ConnectionSupplier in project atlasdb by palantir.

the class OracleTableNameMapperTest method setup.

@Before
public void setup() {
    connectionSupplier = mock(ConnectionSupplier.class);
    oracleTableNameMapper = new OracleTableNameMapper();
    SqlConnection sqlConnection = mock(SqlConnection.class);
    when(connectionSupplier.get()).thenReturn(sqlConnection);
    resultSet = mock(AgnosticResultSet.class);
    when(sqlConnection.selectResultSetUnregisteredQuery(startsWith("SELECT short_table_name FROM atlasdb_table_names WHERE LOWER(short_table_name)"), anyObject())).thenReturn(resultSet);
}
Also used : ConnectionSupplier(com.palantir.atlasdb.keyvalue.dbkvs.impl.ConnectionSupplier) AgnosticResultSet(com.palantir.nexus.db.sql.AgnosticResultSet) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) Before(org.junit.Before)

Aggregations

ConnectionSupplier (com.palantir.atlasdb.keyvalue.dbkvs.impl.ConnectionSupplier)4 AgnosticResultSet (com.palantir.nexus.db.sql.AgnosticResultSet)2 SqlConnection (com.palantir.nexus.db.sql.SqlConnection)2 Before (org.junit.Before)2 SqlConnectionSupplier (com.palantir.atlasdb.keyvalue.dbkvs.impl.SqlConnectionSupplier)1 TableValueStyle (com.palantir.atlasdb.keyvalue.dbkvs.impl.TableValueStyle)1 TableMappingNotFoundException (com.palantir.atlasdb.keyvalue.impl.TableMappingNotFoundException)1 Connection (java.sql.Connection)1