use of java.sql.SQLNonTransientException in project jdk8u_jdk by JetBrains.
the class SQLNonTransientExceptionTests method test3.
/**
* Create SQLNonTransientException with message, and SQLState
*/
@Test
public void test3() {
SQLNonTransientException ex = new SQLNonTransientException(reason, state);
assertTrue(ex.getMessage().equals(reason) && ex.getSQLState().equals(state) && ex.getCause() == null && ex.getErrorCode() == 0);
}
use of java.sql.SQLNonTransientException in project cobar by alibaba.
the class ServerConnection method execute.
public void execute(String sql, int type) {
// 状态检查
if (txInterrupted) {
writeErrMessage(ErrorCode.ER_YES, "Transaction error, need to rollback.");
return;
}
// 检查当前使用的DB
String db = this.schema;
if (db == null) {
writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No database selected");
return;
}
SchemaConfig schema = CobarServer.getInstance().getConfig().getSchemas().get(db);
if (schema == null) {
writeErrMessage(ErrorCode.ER_BAD_DB_ERROR, "Unknown database '" + db + "'");
return;
}
// 路由计算
RouteResultset rrs = null;
try {
rrs = ServerRouter.route(schema, sql, this.charset, this);
} catch (SQLNonTransientException e) {
StringBuilder s = new StringBuilder();
LOGGER.warn(s.append(this).append(sql).toString(), e);
String msg = e.getMessage();
writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e.getClass().getSimpleName() : msg);
return;
}
// session执行
session.execute(rrs, type);
}
use of java.sql.SQLNonTransientException in project cobar by alibaba.
the class ExplainHandler method getRouteResultset.
private static RouteResultset getRouteResultset(ServerConnection c, String stmt) {
String db = c.getSchema();
if (db == null) {
c.writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No database selected");
return null;
}
SchemaConfig schema = CobarServer.getInstance().getConfig().getSchemas().get(db);
if (schema == null) {
c.writeErrMessage(ErrorCode.ER_BAD_DB_ERROR, "Unknown database '" + db + "'");
return null;
}
try {
return ServerRouter.route(schema, stmt, c.getCharset(), c);
} catch (SQLNonTransientException e) {
StringBuilder s = new StringBuilder();
logger.warn(s.append(c).append(stmt).toString(), e);
String msg = e.getMessage();
c.writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e.getClass().getSimpleName() : msg);
return null;
}
}
use of java.sql.SQLNonTransientException in project presto by prestodb.
the class JdbcRecordSink method commit.
@Override
public Collection<Slice> commit() {
// commit and close
try (Connection connection = this.connection) {
if (batchSize > 0) {
statement.executeBatch();
connection.commit();
}
} catch (SQLNonTransientException e) {
throw new PrestoException(JDBC_NON_TRANSIENT_ERROR, e);
} catch (SQLException e) {
throw new PrestoException(JDBC_ERROR, e);
}
// the committer does not need any additional info
return ImmutableList.of();
}
use of java.sql.SQLNonTransientException in project Mycat-Server by MyCATApache.
the class DruidCreateTableParser method statementParse.
@Override
public void statementParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt) throws SQLNonTransientException {
MySqlCreateTableStatement createStmt = (MySqlCreateTableStatement) stmt;
if (createStmt.getQuery() != null) {
String msg = "create table from other table not supported :" + stmt;
LOGGER.warn(msg);
throw new SQLNonTransientException(msg);
}
String tableName = StringUtil.removeBackquote(createStmt.getTableSource().toString().toUpperCase());
if (schema.getTables().containsKey(tableName)) {
TableConfig tableConfig = schema.getTables().get(tableName);
AbstractPartitionAlgorithm algorithm = tableConfig.getRule().getRuleAlgorithm();
if (algorithm instanceof SlotFunction) {
SQLColumnDefinition column = new SQLColumnDefinition();
column.setDataType(new SQLCharacterDataType("int"));
column.setName(new SQLIdentifierExpr("_slot"));
column.setComment(new SQLCharExpr("自动迁移算法slot,禁止修改"));
((SQLCreateTableStatement) stmt).getTableElementList().add(column);
String sql = createStmt.toString();
rrs.setStatement(sql);
ctx.setSql(sql);
}
}
ctx.addTable(tableName);
}
Aggregations