More build fixes

Original commit: elastic/x-pack-elasticsearch@8b241ea4d1
This commit is contained in:
Nik Everett 2017-06-29 12:59:56 -04:00
parent e5df9a0269
commit 2f9c0858f7
4 changed files with 12 additions and 73 deletions

View File

@ -5,6 +5,14 @@
*/
package org.elasticsearch.xpack.sql.cli;
import org.elasticsearch.xpack.sql.cli.net.protocol.CommandResponse;
import org.elasticsearch.xpack.sql.cli.net.protocol.ErrorResponse;
import org.elasticsearch.xpack.sql.cli.net.protocol.ExceptionResponse;
import org.elasticsearch.xpack.sql.cli.net.protocol.InfoResponse;
import org.elasticsearch.xpack.sql.cli.net.protocol.Response;
import org.elasticsearch.xpack.sql.net.client.SuppressForbidden;
import org.jline.utils.AttributedStringBuilder;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
@ -12,13 +20,6 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import org.elasticsearch.xpack.sql.cli.net.protocol.CommandResponse;
import org.elasticsearch.xpack.sql.cli.net.protocol.ErrorResponse;
import org.elasticsearch.xpack.sql.cli.net.protocol.ExceptionResponse;
import org.elasticsearch.xpack.sql.cli.net.protocol.InfoResponse;
import org.elasticsearch.xpack.sql.cli.net.protocol.Response;
import org.jline.utils.AttributedStringBuilder;
import static org.jline.utils.AttributedStyle.BOLD;
import static org.jline.utils.AttributedStyle.BRIGHT;
import static org.jline.utils.AttributedStyle.CYAN;
@ -68,7 +69,7 @@ abstract class ResponseToString {
return sb;
}
@SuppressForbidden(reason="ignore for now") // NOCOMMIT figure this out
private static void displayGraphviz(String str) {
try {
// save the content to a temp file

View File

@ -131,7 +131,7 @@ public class ProtoTests extends ESTestCase {
);
for (String c : commands) {
Response command = (Response) client.command(c, null);
Response command = client.command(c, null);
String msg = "";
if (command instanceof ExceptionResponse) {
msg = ((ExceptionResponse) command).message;

View File

@ -22,6 +22,7 @@ import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.transport.Netty4Plugin;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcDriver;
import org.elasticsearch.xpack.sql.net.client.SuppressForbidden;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@ -52,6 +53,7 @@ public abstract class JdbcIntegrationTestCase extends ESRestTestCase {
* enabled.
*/
@BeforeClass
@SuppressForbidden(reason="it is a hack anyway")
public static void startInternalTestClusterIfNeeded() throws IOException, InterruptedException {
if (System.getProperty("tests.rest.cluster") != null) {
// Nothing to do, using an external Elasticsearch node.

View File

@ -8,7 +8,6 @@ package org.elasticsearch.xpack.sql.jdbc;
import org.elasticsearch.common.CheckedConsumer;
import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.CheckedSupplier;
import org.elasticsearch.xpack.sql.net.client.SuppressForbidden;
import java.sql.Connection;
import java.sql.PreparedStatement;
@ -23,71 +22,12 @@ import java.util.Map;
// poor's man JdbcTemplate
public class JdbcTemplate {
private static final int MAX_WIDTH = 20;
private final CheckedSupplier<Connection, SQLException> conn;
public JdbcTemplate(CheckedSupplier<Connection, SQLException> conn) {
this.conn = conn;
}
@SuppressForbidden(reason="temporary")
public static CheckedFunction<ResultSet, Void, SQLException> resultSetToConsole() {
// NOCOMMIT this doesn't really test anything. If we want to log the whole result set we can do that too, but we have to add assertions
return rs -> {
ResultSetMetaData metaData = rs.getMetaData();
StringBuilder sb = new StringBuilder();
StringBuilder column = new StringBuilder();
int columns = metaData.getColumnCount();
for (int i = 1; i <= columns; i++) {
if (i > 1) {
sb.append(" | ");
}
column.setLength(0);
column.append(metaData.getColumnName(i));
column.append("(");
column.append(metaData.getColumnTypeName(i));
column.append(")");
sb.append(trimOrPad(column));
}
int l = sb.length();
sb.append("\n");
for (int i = 0; i < l; i++) {
sb.append("=");
}
System.out.println(sb);
while (rs.next()) {
sb.setLength(0);
for (int i = 1; i <= columns; i++) {
column.setLength(0);
if (i > 1) {
sb.append(" | ");
}
sb.append(trimOrPad(column.append(rs.getString(i))));
}
System.out.println(sb);
}
return null;
};
}
private static StringBuilder trimOrPad(StringBuilder buffer) {
if (buffer.length() > MAX_WIDTH) {
buffer.setLength(MAX_WIDTH - 1);
buffer.append("~");
}
else {
for (int i = buffer.length(); i < MAX_WIDTH; i++) {
buffer.append(" ");
}
}
return buffer;
}
public void consume(CheckedConsumer<Connection, SQLException> c) throws SQLException {
try (Connection con = conn.get()) {
c.accept(con);
@ -109,10 +49,6 @@ public class JdbcTemplate {
});
}
public void queryToConsole(String q) throws SQLException {
query(q, resultSetToConsole());
}
public <T> T queryObject(String q, Class<T> type) throws SQLException {
return query(q, singleResult(type));
}