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);
}
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations