use of com.facebook.presto.jdbc.PrestoConnection in project presto by prestodb.
the class JdbcPrestoAction method getConnection.
private PrestoConnection getConnection(QueryStage queryStage, String clientInfo) throws SQLException {
PrestoConnection connection = DriverManager.getConnection(jdbcUrlSelector.next(), queryConfiguration.getUsername().orElse(null), queryConfiguration.getPassword().orElse(null)).unwrap(PrestoConnection.class);
try {
connection.setClientInfo("ApplicationName", applicationName);
connection.setClientInfo("ClientInfo", clientInfo);
connection.setCatalog(queryConfiguration.getCatalog());
connection.setSchema(queryConfiguration.getSchema());
} catch (SQLClientInfoException ignored) {
// Do nothing
}
Map<String, String> sessionProperties = mangleSessionProperties(queryConfiguration.getSessionProperties(), queryStage, getTimeout(queryStage), removeMemoryRelatedSessionProperties);
for (Entry<String, String> entry : sessionProperties.entrySet()) {
connection.setSessionProperty(entry.getKey(), entry.getValue());
}
return connection;
}
use of com.facebook.presto.jdbc.PrestoConnection in project presto by prestodb.
the class JdbcDriverUtils method setSessionProperty.
public static void setSessionProperty(Connection connection, String key, String value) throws SQLException {
if (usingPrestoJdbcDriver(connection)) {
PrestoConnection prestoConnection = connection.unwrap(PrestoConnection.class);
prestoConnection.setSessionProperty(key, value);
} else if (usingTeradataJdbcDriver(connection)) {
try (Statement statement = connection.createStatement()) {
if (shouldValueBeQuoted(value)) {
value = "'" + value + "'";
}
statement.execute(String.format("set session %s=%s", key, value));
}
} else {
throw new IllegalStateException();
}
}
Aggregations