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);
}
}
}
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);
}
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);
}
}
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);
}
Aggregations