use of io.mycat.datasource.jdbc.datasource.DefaultConnection in project Mycat2 by MyCATApache.
the class SpmTest method testCheckStore.
@Test
@SneakyThrows
public void testCheckStore() {
try (DefaultConnection defaultConnection = jdbcManager.getConnection("prototypeDs")) {
Connection rawConnection = defaultConnection.getRawConnection();
JdbcUtils.execute(rawConnection, "DROP TABLE IF EXISTS mycat.spm_baseline");
JdbcUtils.execute(rawConnection, "DROP TABLE IF EXISTS mycat.spm_plan");
dbPlanManagerPersistor.checkStore();
JdbcUtils.executeQuery(rawConnection, "SELECT * FROM mycat.spm_baseline", Collections.emptyList());
JdbcUtils.executeQuery(rawConnection, "SELECT * FROM mycat.spm_plan", Collections.emptyList());
}
}
use of io.mycat.datasource.jdbc.datasource.DefaultConnection in project Mycat2 by MyCATApache.
the class TransactionSessionTemplate method closeStatementState.
@Override
@SneakyThrows
public Future<Void> closeStatementState() {
try {
if (!isInTransaction()) {
Set<Map.Entry<String, DefaultConnection>> entries = updateConnectionMap.entrySet();
for (Map.Entry<String, DefaultConnection> entry : entries) {
DefaultConnection value = entry.getValue();
if (value != null) {
value.close();
}
}
updateConnectionMap.clear();
dataSourceNearness.clear();
}
Iterator<AutoCloseable> iterator = closeResourceQueue.iterator();
while (iterator.hasNext()) {
iterator.next().close();
iterator.remove();
}
} catch (Throwable throwable) {
return Future.failedFuture(throwable);
}
return Future.succeededFuture();
}
use of io.mycat.datasource.jdbc.datasource.DefaultConnection in project Mycat2 by MyCATApache.
the class TransactionSessionTemplate method setAutocommit.
@SneakyThrows
public void setAutocommit(boolean autocommit) {
for (DefaultConnection c : updateConnectionMap.values()) {
c.getRawConnection().setAutoCommit(autocommit);
}
if (autocommit) {
for (DefaultConnection value : updateConnectionMap.values()) {
value.close();
}
updateConnectionMap.clear();
setInTranscation(false);
}
}
use of io.mycat.datasource.jdbc.datasource.DefaultConnection in project Mycat2 by MyCATApache.
the class UnsolvedMysqlFunctionUtil method eval.
@SneakyThrows
public static Object eval(String fun, Object... args) {
ArrayList<String> p = new ArrayList<>(args.length);
for (Object arg : args) {
if (arg == null) {
p.add("null");
} else if (arg instanceof String) {
p.add("'" + arg + "'");
} else {
p.add(Objects.toString(arg));
}
}
String sql = "select " + fun + "(" + String.join(",", p) + ")";
return objectCache.get(sql, () -> {
ReplicaSelectorManager replicaSelectorRuntime = MetaClusterCurrent.wrapper(ReplicaSelectorManager.class);
JdbcConnectionManager jdbcConnectionManager = MetaClusterCurrent.wrapper(JdbcConnectionManager.class);
String datasource = replicaSelectorRuntime.getDatasourceNameByRandom();
try (DefaultConnection connection = jdbcConnectionManager.getConnection(datasource)) {
RowBaseIterator rowBaseIterator = connection.executeQuery(sql);
rowBaseIterator.next();
return rowBaseIterator.getObject(1);
}
});
}
use of io.mycat.datasource.jdbc.datasource.DefaultConnection in project Mycat2 by MyCATApache.
the class MySQLLogConsumer method init.
private void init() throws SQLException {
JdbcConnectionManager jdbcConnectionManager = MetaClusterCurrent.wrapper(JdbcConnectionManager.class);
MetadataManager metadataManager = MetaClusterCurrent.wrapper(MetadataManager.class);
try (DefaultConnection connection = jdbcConnectionManager.getConnection(metadataManager.getPrototype())) {
JdbcUtils.execute(connection.getRawConnection(), "CREATE TABLE IF NOT EXISTS mycat.`sql_log` (\n" + " `instanceId` bigint(20) DEFAULT NULL,\n" + " `user` varchar(64) DEFAULT NULL,\n" + " `connectionId` bigint(20) DEFAULT NULL,\n" + " `ip` varchar(22) DEFAULT NULL,\n" + " `port` bigint(20) DEFAULT NULL,\n" + " `traceId` varchar(22) NOT NULL,\n" + " `hash` varchar(22) DEFAULT NULL,\n" + " `sqlType` varchar(22) DEFAULT NULL,\n" + " `sql` longtext,\n" + " `transactionId` varchar(22) DEFAULT NULL,\n" + " `sqlTime` bigint(20) DEFAULT NULL,\n" + " `responseTime` datetime DEFAULT NULL,\n" + " `affectRow` int(11) DEFAULT NULL,\n" + " `result` tinyint(1) DEFAULT NULL,\n" + " `externalMessage` tinytext,\n" + " PRIMARY KEY (`traceId`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", Collections.emptyList());
}
}
Aggregations