@Override public Long get() { if (currentIdIndex < OVERFLOW_ID_CACHE_SIZE) { return currentBatchStartId + currentIdIndex++; } currentBatchStartId = conns.get() .selectLongUnregisteredQuery( "SELECT " + tablePrefix + AtlasDbConstants.ORACLE_OVERFLOW_SEQUENCE + ".NEXTVAL FROM DUAL"); currentIdIndex = 0; return currentBatchStartId + currentIdIndex++; } }
private <T> T runRead(TableReference tableRef, Function<DbReadTable, T> runner) { ConnectionSupplier conns = new ConnectionSupplier(connections); try { return runner.apply(dbTables.createRead(tableRef, conns)); } finally { conns.close(); } }
AtomicReference<T> result = Atomics.newReference(); Thread writeThread = new Thread(() -> { SqlConnection freshConn = conns.getFresh(); try { result.set(runner.apply(dbTables.createWrite(tableRef, new ConnectionSupplier(Suppliers.ofInstance(freshConn))))); } finally { try {
private <T> void runWriteForceAutocommit(TableReference tableRef, Function<DbWriteTable, T> runner) { try (ConnectionSupplier conns = new ConnectionSupplier(connections)) { SqlConnection conn = conns.get(); boolean autocommit; try { autocommit = conn.getUnderlyingConnection().getAutoCommit(); } catch (PalantirSqlException | SQLException e1) { throw Throwables.rewrapAndThrowUncheckedException(e1); } if (!autocommit) { runWriteFreshConnection(conns, tableRef, runner); } else { runner.apply(dbTables.createWrite(tableRef, conns)); } } }
private TableMetadata getTableMetadataUsingNewConnection(TableReference tableRef) { try (ConnectionSupplier conns = new ConnectionSupplier(connectionPool)) { return tableMetadataCache.getTableMetadata(tableRef, conns); } }
/** * Returns fresh PalantirSqlConnection. It is the responsibility of the consumer of this method * to close the returned connection when done. */ public SqlConnection getFresh() { close(); return delegate.get(); }
@Override public SqlConnection get() { if (sharedConnection == null) { sharedConnection = getFresh(); } return sharedConnection; }
private List<CellTsPairInfo> loadPage(boolean singleRow) { FullQuery query = getQuery(singleRow); try (ConnectionSupplier conns = new ConnectionSupplier(connectionPool); AgnosticLightResultSet resultSet = executeQuery(conns.get(), query)) { List<CellTsPairInfo> ret = new ArrayList<>(); for (AgnosticLightResultRow row : resultSet) { ret.add(new CellTsPairInfo( row.getBytes("row_name"), row.getBytes("col_name"), row.getLong("ts"), request.shouldCheckIfLatestValueIsEmpty() && row.getInteger("empty_val") == 1)); } return ret; } }
private boolean checkIfTableHasOverflowUsingNewConnection(TableReference tableRef) { try (ConnectionSupplier conns = new ConnectionSupplier(connectionPool)) { return valueStyleCache.getTableType(conns, tableRef, config.metadataTable()) == TableValueStyle.OVERFLOW; } }
/** * Returns fresh PalantirSqlConnection. It is the responsibility of the consumer of this method * to close the returned connection when done. */ public SqlConnection getFresh() { close(); return delegate.get(); }
@Override public SqlConnection get() { if (sharedConnection == null) { sharedConnection = getFresh(); } return sharedConnection; }
private boolean overflowColumnExists(String shortTableName) { // All table names in user_tab_cols are upper case return conns.get().selectExistsUnregisteredQuery( "SELECT 1 FROM user_tab_cols WHERE TABLE_NAME = ? AND COLUMN_NAME = 'OVERFLOW'", shortTableName.toUpperCase()); }
private <T> T runMetadata(TableReference tableRef, Function<DbMetadataTable, T> runner) { ConnectionSupplier conns = new ConnectionSupplier(connections); try { /* The metadata table operates only on the fully qualified table reference */ return runner.apply(dbTables.createMetadata(tableRef, conns)); } finally { conns.close(); } }
private <T> void runWriteForceAutocommit(TableReference tableRef, Function<DbWriteTable, T> runner) { try (ConnectionSupplier conns = new ConnectionSupplier(connections)) { SqlConnection conn = conns.get(); boolean autocommit; try { autocommit = conn.getUnderlyingConnection().getAutoCommit(); } catch (PalantirSqlException | SQLException e1) { throw Throwables.rewrapAndThrowUncheckedException(e1); } if (!autocommit) { runWriteFreshConnection(conns, tableRef, runner); } else { runner.apply(dbTables.createWrite(tableRef, conns)); } } }
@Override protected Iterator<RowResult<Value>> computeNext() { if (endOfResults) { return endOfData(); } else { try (ConnectionSupplier conns = new ConnectionSupplier(connectionPool)) { List<RawSqlRow> sqlRows = loadSqlRows(conns); Map<Long, byte[]> overflowValues = overflowValueLoader.loadOverflowValues( conns, tableRef, sqlRows.stream() .map(r -> r.overflowId) .filter(Objects::nonNull) .collect(Collectors.toList())); List<RowResult<Value>> rowResults = createRowResults(sqlRows, overflowValues, maxRowsPerPage); if (rowResults.isEmpty()) { endOfResults = true; } else { byte[] lastRowName = rowResults.get(rowResults.size() - 1).getRowName(); startInclusive = RangeRequests.getNextStartRowUnlessTerminal(reverse, lastRowName); endOfResults = (rowResults.size() < maxRowsPerPage) || startInclusive == null; } return rowResults.iterator(); } } }
AtomicReference<T> result = Atomics.newReference(); Thread writeThread = new Thread(() -> { SqlConnection freshConn = conns.getFresh(); try { result.set(runner.apply(dbTables.createWrite(tableRef, new ConnectionSupplier(Suppliers.ofInstance(freshConn))))); } finally { try {
private void executeIgnoringError(String sql, String errorToIgnore) { try { connectionSupplier.get().executeUnregisteredQuery(sql); } catch (PalantirSqlException e) { if (!e.getMessage().contains(errorToIgnore)) { log.error("Error occurred trying to execute the query {}", sql, e); throw e; } } } }
private <T> T runInitialization(Function<DbTableInitializer, T> runner) { ConnectionSupplier conns = new ConnectionSupplier(connections); try { return runner.apply(dbTables.createInitializer(conns)); } finally { conns.close(); } }
private List<CellTsPairInfo> loadPage(boolean singleRow) { FullQuery query = getQuery(singleRow); try (ConnectionSupplier conns = new ConnectionSupplier(connectionPool); AgnosticLightResultSet resultSet = executeQuery(conns.get(), query)) { List<CellTsPairInfo> ret = new ArrayList<>(); for (AgnosticLightResultRow row : resultSet) { ret.add(new CellTsPairInfo( row.getBytes("row_name"), row.getBytes("col_name"), row.getLong("ts"), request.shouldCheckIfLatestValueIsEmpty() && row.getInteger("empty_val") == 1)); } return ret; } }
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); } }