Search in sources :

Example 1 with LongValueFactory

use of com.mysql.cj.result.LongValueFactory in project aws-mysql-jdbc by awslabs.

the class NativeSession method getProcessHost.

public String getProcessHost() {
    try {
        long threadId = getThreadId();
        String processHost = findProcessHost(threadId);
        if (processHost == null) {
            // http://bugs.mysql.com/bug.php?id=44167 - connection ids on the wire wrap at 4 bytes even though they're 64-bit numbers
            this.log.logWarn(String.format("Connection id %d not found in \"SHOW PROCESSLIST\", assuming 32-bit overflow, using SELECT CONNECTION_ID() instead", threadId));
            NativePacketPayload resultPacket = sendCommand(this.commandBuilder.buildComQuery(null, "SELECT CONNECTION_ID()"), false, 0);
            Resultset rs = ((NativeProtocol) this.protocol).readAllResults(-1, false, resultPacket, false, null, new ResultsetFactory(Type.FORWARD_ONLY, null));
            ValueFactory<Long> lvf = new LongValueFactory(getPropertySet());
            Row r;
            if ((r = rs.getRows().next()) != null) {
                threadId = r.getValue(0, lvf);
                processHost = findProcessHost(threadId);
            } else {
                this.log.logError("No rows returned for statement \"SELECT CONNECTION_ID()\", local connection check will most likely be incorrect");
            }
        }
        if (processHost == null) {
            this.log.logWarn(String.format("Cannot find process listing for connection %d in SHOW PROCESSLIST output, unable to determine if locally connected", threadId));
        }
        return processHost;
    } catch (IOException e) {
        throw ExceptionFactory.createException(e.getMessage(), e);
    }
}
Also used : LongValueFactory(com.mysql.cj.result.LongValueFactory) Resultset(com.mysql.cj.protocol.Resultset) NativeProtocol(com.mysql.cj.protocol.a.NativeProtocol) Row(com.mysql.cj.result.Row) IOException(java.io.IOException) NativePacketPayload(com.mysql.cj.protocol.a.NativePacketPayload) ResultsetFactory(com.mysql.cj.protocol.a.ResultsetFactory)

Example 2 with LongValueFactory

use of com.mysql.cj.result.LongValueFactory in project aws-mysql-jdbc by awslabs.

the class NativeSession method findProcessHost.

private String findProcessHost(long threadId) {
    try {
        String processHost = null;
        String ps = this.protocol.getServerSession().getServerVariable("performance_schema");
        NativePacketPayload resultPacket = // performance_schema.threads in MySQL 5.5 does not contain PROCESSLIST_HOST column
        versionMeetsMinimum(5, 6, 0) && ps != null && ("1".contentEquals(ps) || "ON".contentEquals(ps)) ? sendCommand(this.commandBuilder.buildComQuery(null, "select PROCESSLIST_ID, PROCESSLIST_USER, PROCESSLIST_HOST from performance_schema.threads where PROCESSLIST_ID=" + threadId), false, 0) : sendCommand(this.commandBuilder.buildComQuery(null, "SHOW PROCESSLIST"), false, 0);
        Resultset rs = ((NativeProtocol) this.protocol).readAllResults(-1, false, resultPacket, false, null, new ResultsetFactory(Type.FORWARD_ONLY, null));
        ValueFactory<Long> lvf = new LongValueFactory(getPropertySet());
        ValueFactory<String> svf = new StringValueFactory(this.propertySet);
        Row r;
        while ((r = rs.getRows().next()) != null) {
            long id = r.getValue(0, lvf);
            if (threadId == id) {
                processHost = r.getValue(2, svf);
                break;
            }
        }
        return processHost;
    } catch (IOException e) {
        throw ExceptionFactory.createException(e.getMessage(), e);
    }
}
Also used : StringValueFactory(com.mysql.cj.result.StringValueFactory) NativeProtocol(com.mysql.cj.protocol.a.NativeProtocol) IOException(java.io.IOException) NativePacketPayload(com.mysql.cj.protocol.a.NativePacketPayload) ResultsetFactory(com.mysql.cj.protocol.a.ResultsetFactory) LongValueFactory(com.mysql.cj.result.LongValueFactory) Resultset(com.mysql.cj.protocol.Resultset) Row(com.mysql.cj.result.Row)

Example 3 with LongValueFactory

use of com.mysql.cj.result.LongValueFactory in project aws-mysql-jdbc by awslabs.

the class DataStoreMetadataImpl method getTableRowCount.

@Override
public long getTableRowCount(String schemaName, String tableName) {
    StringBuilder stmt = new StringBuilder("select count(*) from ");
    stmt.append(ExprUnparser.quoteIdentifier(schemaName));
    stmt.append(".");
    stmt.append(ExprUnparser.quoteIdentifier(tableName));
    Function<com.mysql.cj.result.Row, Long> rowToLong = r -> r.getValue(0, new LongValueFactory(this.session.getPropertySet()));
    List<Long> counters = this.session.query(this.session.getMessageBuilder().buildSqlStatement(stmt.toString()), null, rowToLong, Collectors.toList());
    return counters.get(0);
}
Also used : List(java.util.List) LongValueFactory(com.mysql.cj.result.LongValueFactory) ExprUnparser(com.mysql.cj.xdevapi.ExprUnparser) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) LongValueFactory(com.mysql.cj.result.LongValueFactory)

Example 4 with LongValueFactory

use of com.mysql.cj.result.LongValueFactory in project aws-mysql-jdbc by awslabs.

the class DataStoreMetadataImpl method tableExists.

public boolean tableExists(String schemaName, String tableName) {
    StringBuilder stmt = new StringBuilder("select count(*) from information_schema.tables where table_schema = '");
    // TODO: verify quoting rules
    stmt.append(schemaName.replaceAll("'", "\\'"));
    stmt.append("' and table_name = '");
    stmt.append(tableName.replaceAll("'", "\\'"));
    stmt.append("'");
    Function<com.mysql.cj.result.Row, Long> rowToLong = r -> r.getValue(0, new LongValueFactory(this.session.getPropertySet()));
    List<Long> counters = this.session.query(this.session.getMessageBuilder().buildSqlStatement(stmt.toString()), null, rowToLong, Collectors.toList());
    return 1 == counters.get(0);
}
Also used : List(java.util.List) LongValueFactory(com.mysql.cj.result.LongValueFactory) ExprUnparser(com.mysql.cj.xdevapi.ExprUnparser) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) LongValueFactory(com.mysql.cj.result.LongValueFactory)

Example 5 with LongValueFactory

use of com.mysql.cj.result.LongValueFactory in project aws-mysql-jdbc by awslabs.

the class DataStoreMetadataImpl method schemaExists.

public boolean schemaExists(String schemaName) {
    StringBuilder stmt = new StringBuilder("select count(*) from information_schema.schemata where schema_name = '");
    // TODO: verify quoting rules
    stmt.append(schemaName.replaceAll("'", "\\'"));
    stmt.append("'");
    Function<com.mysql.cj.result.Row, Long> rowToLong = r -> r.getValue(0, new LongValueFactory(this.session.getPropertySet()));
    List<Long> counters = this.session.query(this.session.getMessageBuilder().buildSqlStatement(stmt.toString()), null, rowToLong, Collectors.toList());
    return 1 == counters.get(0);
}
Also used : List(java.util.List) LongValueFactory(com.mysql.cj.result.LongValueFactory) ExprUnparser(com.mysql.cj.xdevapi.ExprUnparser) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) LongValueFactory(com.mysql.cj.result.LongValueFactory)

Aggregations

LongValueFactory (com.mysql.cj.result.LongValueFactory)6 ExprUnparser (com.mysql.cj.xdevapi.ExprUnparser)3 List (java.util.List)3 Function (java.util.function.Function)3 Collectors (java.util.stream.Collectors)3 Resultset (com.mysql.cj.protocol.Resultset)2 NativePacketPayload (com.mysql.cj.protocol.a.NativePacketPayload)2 NativeProtocol (com.mysql.cj.protocol.a.NativeProtocol)2 ResultsetFactory (com.mysql.cj.protocol.a.ResultsetFactory)2 Row (com.mysql.cj.result.Row)2 IOException (java.io.IOException)2 ColumnDefinition (com.mysql.cj.protocol.ColumnDefinition)1 DefaultColumnDefinition (com.mysql.cj.result.DefaultColumnDefinition)1 StringValueFactory (com.mysql.cj.result.StringValueFactory)1