Refine search
@Override public List<Pair<String, String>> withHandle(Handle handle) { return handle .createQuery( buildLookupQuery(table, filter, keyColumn, valueColumn) ).map( new ResultSetMapper<Pair<String, String>>() { @Override public Pair<String, String> map( final int index, final ResultSet r, final StatementContext ctx ) throws SQLException { return new Pair<>(r.getString(keyColumn), r.getString(valueColumn)); } } ).list(); } }
@Override public List<TaskInfo<EntryType, StatusType>> getCompletedTaskInfo( DateTime timestamp, @Nullable Integer maxNumStatuses, @Nullable String dataSource ) { return getConnector().retryWithHandle( handle -> { final Query<Map<String, Object>> query = createCompletedTaskInfoQuery( handle, timestamp, maxNumStatuses, dataSource ); return query.map(taskInfoMapper).list(); } ); }
public byte[] lookupWithHandle( final Handle handle, final String tableName, final String keyColumn, final String valueColumn, final String key ) { final String selectStatement = StringUtils.format( "SELECT %s FROM %s WHERE %s = :key", valueColumn, tableName, keyColumn ); List<byte[]> matched = handle.createQuery(selectStatement) .bind("key", key) .map(ByteArrayMapper.FIRST) .list(); if (matched.isEmpty()) { return null; } if (matched.size() > 1) { throw new ISE("Error! More than one matching entry[%d] found for [%s]?!", matched.size(), key); } return matched.get(0); }
@Override public boolean tableExists(Handle handle, String tableName) { String databaseCharset = handle .createQuery("SELECT @@character_set_database") .map(StringMapper.FIRST) .first(); if (!databaseCharset.startsWith("utf8")) { throw new ISE( "Druid requires its MySQL database to be created with an UTF8 charset, found `%1$s`. " + "The recommended charset is `utf8mb4`.", databaseCharset ); } else if (!"utf8mb4".equals(databaseCharset)) { log.warn("The current database charset `%1$s` does not match the recommended charset `utf8mb4`", databaseCharset); } return !handle.createQuery("SHOW tables LIKE :tableName") .bind("tableName", tableName) .list() .isEmpty(); }
@Override public List<AuditEntry> withHandle(Handle handle) { Query<Map<String, Object>> query = handle.createQuery(theQueryString); if (key != null) { query.bind("audit_key", key); } return query.bind("type", type) .setMaxRows(theLimit) .map( new ResultSetMapper<AuditEntry>() { @Override public AuditEntry map(int index, ResultSet r, StatementContext ctx) throws SQLException { try { return jsonMapper.readValue(r.getBytes("payload"), AuditEntry.class); } catch (IOException e) { throw new SQLException(e); } } } ) .list(); } }
private List<DataSegment> getUsedSegmentsList(DerbyConnectorTestUtility connector, final MetadataStorageTablesConfig metadataStorageTablesConfig) { return connector.getDBI() .withHandle(handle -> handle.createQuery(String.format( "SELECT payload FROM %s WHERE used=true ORDER BY created_date ASC", metadataStorageTablesConfig.getSegmentsTable())) .map((i, resultSet, statementContext) -> { try { return DruidStorageHandlerUtils.JSON_MAPPER.readValue(resultSet.getBytes("payload"), DataSegment.class); } catch (IOException e) { throw Throwables.propagate(e); } }).list()); }
public Map<String, Object> getAll(Handle handle, @Named("user_id") UIPermissionParameterProvider.Project project) { return handle.createQuery("SELECT name, value FROM ui_user_defaults WHERE user_id = :user AND project_id = :project") .bind("project", project.project) .bind("user", project.userId) .map((ResultSetMapper<Map.Entry<String, Object>>) (index, r, ctx) -> new AbstractMap.SimpleImmutableEntry<>(r.getString(1), JsonHelper.read(r.getString(2), Object.class))) .list().stream().collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); }